Advertisement
Guest User

Untitled

a guest
Sep 2nd, 2014
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.62 KB | None | 0 0
  1. package server.game.players;
  2.  
  3. import java.io.BufferedWriter;
  4. import java.io.FileWriter;
  5. import java.io.IOException;
  6. import java.util.Calendar;
  7. import java.util.GregorianCalendar;
  8.  
  9. import server.game.items.Item;
  10.  
  11. /**
  12. * Player Logs
  13. * @author Connor
  14. */
  15.  
  16. public class Logs {
  17.  
  18. private final Client c;
  19.  
  20. public Logs(Client Client) {
  21. c = Client;
  22. }
  23.  
  24. /**
  25. * Will write what kind of item a player has received. MONTH = 0 = January
  26. * DAY OF MONTH = 30 || 31
  27. */
  28. public void tradeReceived(String itemName, int itemAmount) {
  29. Client o = (Client) PlayerHandler.players[c.tradeWith];
  30. Calendar C = Calendar.getInstance();
  31. try {
  32. BufferedWriter bItem = new BufferedWriter(new FileWriter(
  33. "./Data/logs/Trades/Trades Recieved/" + c.playerName
  34. + ".txt", true));
  35. try {
  36. bItem.newLine();
  37. bItem.write("Year : " + C.get(Calendar.YEAR) + "\tMonth : "
  38. + C.get(Calendar.MONTH) + "\tDay : "
  39. + C.get(Calendar.DAY_OF_MONTH));
  40. bItem.newLine();
  41. bItem.write("Received " + itemAmount + " " + itemName
  42. + " From " + o.playerName);
  43. bItem.newLine();
  44. bItem.write("--------------------------------------------------");
  45. } finally {
  46. bItem.close();
  47. }
  48. } catch (IOException e) {
  49. e.printStackTrace();
  50. }
  51. }
  52.  
  53. /**
  54. * Will write what kind of item a player has traded with another player.
  55. * MONTH = 0 = January DAY OF MONTH = 30 || 31
  56. */
  57. public void tradeGive(String itemName, int itemAmount) {
  58. Client o = (Client) PlayerHandler.players[c.tradeWith];
  59. Calendar C = Calendar.getInstance();
  60. try {
  61. BufferedWriter bItem = new BufferedWriter(new FileWriter(
  62. "./Data/logs/Trades/Trades Gave/" + c.playerName + ".txt",
  63. true));
  64. try {
  65. bItem.newLine();
  66. bItem.write("Year : " + C.get(Calendar.YEAR) + "\tMonth : "
  67. + C.get(Calendar.MONTH) + "\tDay : "
  68. + C.get(Calendar.DAY_OF_MONTH));
  69. bItem.newLine();
  70. bItem.write("Gave " + itemAmount + " " + itemName + " To "
  71. + o.playerName);
  72. bItem.newLine();
  73. bItem.write("--------------------------------------------------");
  74. } finally {
  75. bItem.close();
  76. }
  77. } catch (IOException e) {
  78. e.printStackTrace();
  79. }
  80. }
  81.  
  82. public void playerKills() {
  83. Client o = (Client) PlayerHandler.players[c.killerId];
  84. Calendar C = Calendar.getInstance();
  85. try {
  86. BufferedWriter bItem = new BufferedWriter(new FileWriter("./Data/logs/Kills/Players Killed/" + o.playerName + ".txt", true));
  87. try {
  88. bItem.newLine();
  89. bItem.write("Year : " + C.get(Calendar.YEAR) + "\tMonth : " + C.get(Calendar.MONTH) + "\tDay : " + C.get(Calendar.DAY_OF_MONTH));
  90. bItem.newLine();
  91. bItem.write("" + o.playerName + " was killed by " + c.playerName + " in pvp.");
  92. bItem.newLine();
  93. bItem.write("--------------------------------------------------");
  94. } finally {
  95. bItem.close();
  96. }
  97. } catch (IOException e) {
  98. e.printStackTrace();
  99. }
  100. }
  101.  
  102. public void playerKiller() {
  103. Client o = (Client) PlayerHandler.players[c.killerId];
  104. Calendar C = Calendar.getInstance();
  105. try {
  106. BufferedWriter bItem = new BufferedWriter(new FileWriter("./Data/logs/Kills/Players Killer/" + o.playerName + ".txt", true));
  107. try {
  108. bItem.newLine();
  109. bItem.write("Year : " + C.get(Calendar.YEAR) + "\tMonth : " + C.get(Calendar.MONTH) + "\tDay : " + C.get(Calendar.DAY_OF_MONTH));
  110. bItem.newLine();
  111. bItem.write("" + c.playerName + " killed " + o.playerName + " in pvp.");
  112. bItem.newLine();
  113. bItem.write("--------------------------------------------------");
  114. } finally {
  115. bItem.close();
  116. }
  117. } catch (IOException e) {
  118. e.printStackTrace();
  119. }
  120. }
  121.  
  122. public void duelKills() {
  123. Client o = (Client) PlayerHandler.players[c.duelingWith];
  124. Calendar C = Calendar.getInstance();
  125. try {
  126. BufferedWriter bItem = new BufferedWriter(new FileWriter("./Data/logs/Duels/Players Killed/" + o.playerName + ".txt", true));
  127. try {
  128. bItem.newLine();
  129. bItem.write("Year : " + C.get(Calendar.YEAR) + "\tMonth : " + C.get(Calendar.MONTH) + "\tDay : " + C.get(Calendar.DAY_OF_MONTH));
  130. bItem.newLine();
  131. bItem.write("" + o.playerName + " killed " + c.playerName + " in the duel arena.");
  132. bItem.newLine();
  133. bItem.write("--------------------------------------------------");
  134. } finally {
  135. bItem.close();
  136. }
  137. } catch (IOException e) {
  138. e.printStackTrace();
  139. }
  140. }
  141.  
  142. public void writeDropLog(String data, int ID, int itemX, int itemY) {
  143. checkDateAndTime();
  144. String filePath = "./Data/logs/Drop Center/" + c.playerName + ".txt";
  145. BufferedWriter bw = null;
  146. try {
  147. bw = new BufferedWriter(new FileWriter(filePath, true));
  148. bw.write("[" + c.date + "]" + "-" + "[" + c.currentTime + " "
  149. + checkTimeOfDay() + "]: " + "[" + c.connectedFrom + "]: "
  150. + "" + data + " " + " " + Item.getItemName(ID) + " ("
  151. + itemX + "/" + itemY + ").");
  152. bw.newLine();
  153. bw.flush();
  154. } catch (IOException ioe) {
  155. ioe.printStackTrace();
  156. } finally {
  157. if (bw != null) {
  158. try {
  159. bw.close();
  160. } catch (IOException ioe2) {
  161. }
  162. }
  163. }
  164. }
  165.  
  166. public void writePickupLog(int ID, int amount) {
  167. checkDateAndTime();
  168. String filePath = "./Data/logs/Pickup Center/" + c.playerName + ".txt";
  169. BufferedWriter bw = null;
  170. try {
  171. bw = new BufferedWriter(new FileWriter(filePath, true));
  172. bw.write("[" + c.date + "]" + "-" + "[" + c.currentTime + " " + checkTimeOfDay() + "]: " + "[" + c.connectedFrom + "]: " + "" + " " + Item.getItemName(ID) + " " + amount + ".");
  173. bw.newLine();
  174. bw.flush();
  175. } catch (IOException ioe) {
  176. ioe.printStackTrace();
  177. } finally {
  178. if (bw != null) {
  179. try {
  180. bw.close();
  181. } catch (IOException ioe2) {
  182. }
  183. }
  184. }
  185. }
  186.  
  187. public void writeClickLog(int ID) {
  188. checkDateAndTime();
  189. String filePath = "./Data/logs/Clickitem Center/" + c.playerName
  190. + ".txt";
  191. BufferedWriter bw = null;
  192. try {
  193. bw = new BufferedWriter(new FileWriter(filePath, true));
  194. bw.write("[" + c.date + "]" + "-" + "[" + c.currentTime + " "
  195. + checkTimeOfDay() + "]: " + "[" + c.connectedFrom + "]: "
  196. + "" + " " + Item.getItemName(ID) + ".");
  197. bw.newLine();
  198. bw.flush();
  199. } catch (IOException ioe) {
  200. ioe.printStackTrace();
  201. } finally {
  202. if (bw != null) {
  203. try {
  204. bw.close();
  205. } catch (IOException ioe2) {
  206. }
  207. }
  208. }
  209. }
  210.  
  211. public void sendPM(String data) {
  212. checkDateAndTime();
  213. String filePath = "./Data/logs/Private Messages/Pm Sent/" + c.playerName + ".txt";
  214. BufferedWriter bw = null;
  215.  
  216. try {
  217. bw = new BufferedWriter(new FileWriter(filePath, true));
  218. bw.write("[" + c.date + "]" + "-" + "[" + c.currentTime + " "
  219. + checkTimeOfDay() + "]: " + "[" + c.connectedFrom + "]: "
  220. + "" + data + " ");
  221. bw.newLine();
  222. bw.flush();
  223. } catch (IOException ioe) {
  224. ioe.printStackTrace();
  225. } finally {
  226. if (bw != null) {
  227. try {
  228. bw.close();
  229. } catch (IOException ioe2) {
  230. }
  231. }
  232. }
  233. }
  234.  
  235. public void recievePM(String data) {
  236. checkDateAndTime();
  237. String filePath = "./Data/logs/Private Messages/Pm Recieved/" + c.playerName + ".txt";
  238. BufferedWriter bw = null;
  239.  
  240. try {
  241. bw = new BufferedWriter(new FileWriter(filePath, true));
  242. bw.write("[" + c.date + "]" + "-" + "[" + c.currentTime + " "
  243. + checkTimeOfDay() + "]: " + "[" + c.connectedFrom + "]: "
  244. + "" + data + " ");
  245. bw.newLine();
  246. bw.flush();
  247. } catch (IOException ioe) {
  248. ioe.printStackTrace();
  249. } finally {
  250. if (bw != null) {
  251. try {
  252. bw.close();
  253. } catch (IOException ioe2) {
  254. }
  255. }
  256. }
  257. }
  258.  
  259. public void writePMLog(String data) {
  260. checkDateAndTime();
  261. String filePath = "./Data/logs/Pm Center/" + c.playerName + ".txt";
  262. BufferedWriter bw = null;
  263.  
  264. try {
  265. bw = new BufferedWriter(new FileWriter(filePath, true));
  266. bw.write("[" + c.date + "]" + "-" + "[" + c.currentTime + " "
  267. + checkTimeOfDay() + "]: " + "[" + c.connectedFrom + "]: "
  268. + "" + data + " ");
  269. bw.newLine();
  270. bw.flush();
  271. } catch (IOException ioe) {
  272. ioe.printStackTrace();
  273. } finally {
  274. if (bw != null) {
  275. try {
  276. bw.close();
  277. } catch (IOException ioe2) {
  278. }
  279. }
  280. }
  281. }
  282.  
  283. public void writeCommandLog(String command) {
  284. checkDateAndTime();
  285. String filePath = "./Data/logs/Command Center/Commands.txt";
  286. BufferedWriter bw = null;
  287.  
  288. try {
  289. bw = new BufferedWriter(new FileWriter(filePath, true));
  290. bw.write("[" + c.date + "]" + "-" + "[" + c.currentTime + " "
  291. + checkTimeOfDay() + "]: " + "[" + c.playerName + "]: "
  292. + "[" + c.connectedFrom + "] " + "::" + command);
  293. bw.newLine();
  294. bw.flush();
  295. } catch (IOException ioe) {
  296. ioe.printStackTrace();
  297. } finally {
  298. if (bw != null) {
  299. try {
  300. bw.close();
  301. } catch (IOException ignored) {
  302. }
  303. }
  304. }
  305. }
  306.  
  307. public void checkDateAndTime() {
  308. Calendar cal = new GregorianCalendar();
  309. String day, month, hour, minute, second;
  310.  
  311. int YEAR = cal.get(Calendar.YEAR);
  312. int MONTH = cal.get(Calendar.MONTH) + 1;
  313. int DAY = cal.get(Calendar.DAY_OF_MONTH);
  314. int HOUR = cal.get(Calendar.HOUR_OF_DAY);
  315. int MIN = cal.get(Calendar.MINUTE);
  316. int SECOND = cal.get(Calendar.SECOND);
  317.  
  318. day = DAY < 10 ? "0" + DAY : "" + DAY;
  319. month = MONTH < 10 ? "0" + MONTH : "" + MONTH;
  320. hour = HOUR < 10 ? "0" + HOUR : "" + HOUR;
  321. minute = MIN < 10 ? "0" + MIN : "" + MIN;
  322. second = SECOND < 10 ? "0" + SECOND : "" + SECOND;
  323.  
  324. c.date = day + "" + month + "" + YEAR;
  325. c.currentTime = hour + ":" + minute + ":" + second;
  326. }
  327.  
  328. public String checkTimeOfDay() {
  329. Calendar cal = new GregorianCalendar();
  330. int TIME_OF_DAY = cal.get(Calendar.AM_PM);
  331. return TIME_OF_DAY > 0 ? "PM" : "AM";
  332. }
  333. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement