Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package server.game.players;
- import java.io.BufferedWriter;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.util.Calendar;
- import java.util.GregorianCalendar;
- import server.game.items.Item;
- /**
- * Player Logs
- * @author Connor
- */
- public class Logs {
- private final Client c;
- public Logs(Client Client) {
- c = Client;
- }
- /**
- * Will write what kind of item a player has received. MONTH = 0 = January
- * DAY OF MONTH = 30 || 31
- */
- public void tradeReceived(String itemName, int itemAmount) {
- Client o = (Client) PlayerHandler.players[c.tradeWith];
- Calendar C = Calendar.getInstance();
- try {
- BufferedWriter bItem = new BufferedWriter(new FileWriter(
- "./Data/logs/Trades/Trades Recieved/" + c.playerName
- + ".txt", true));
- try {
- bItem.newLine();
- bItem.write("Year : " + C.get(Calendar.YEAR) + "\tMonth : "
- + C.get(Calendar.MONTH) + "\tDay : "
- + C.get(Calendar.DAY_OF_MONTH));
- bItem.newLine();
- bItem.write("Received " + itemAmount + " " + itemName
- + " From " + o.playerName);
- bItem.newLine();
- bItem.write("--------------------------------------------------");
- } finally {
- bItem.close();
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- /**
- * Will write what kind of item a player has traded with another player.
- * MONTH = 0 = January DAY OF MONTH = 30 || 31
- */
- public void tradeGive(String itemName, int itemAmount) {
- Client o = (Client) PlayerHandler.players[c.tradeWith];
- Calendar C = Calendar.getInstance();
- try {
- BufferedWriter bItem = new BufferedWriter(new FileWriter(
- "./Data/logs/Trades/Trades Gave/" + c.playerName + ".txt",
- true));
- try {
- bItem.newLine();
- bItem.write("Year : " + C.get(Calendar.YEAR) + "\tMonth : "
- + C.get(Calendar.MONTH) + "\tDay : "
- + C.get(Calendar.DAY_OF_MONTH));
- bItem.newLine();
- bItem.write("Gave " + itemAmount + " " + itemName + " To "
- + o.playerName);
- bItem.newLine();
- bItem.write("--------------------------------------------------");
- } finally {
- bItem.close();
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- public void playerKills() {
- Client o = (Client) PlayerHandler.players[c.killerId];
- Calendar C = Calendar.getInstance();
- try {
- BufferedWriter bItem = new BufferedWriter(new FileWriter("./Data/logs/Kills/Players Killed/" + o.playerName + ".txt", true));
- try {
- bItem.newLine();
- bItem.write("Year : " + C.get(Calendar.YEAR) + "\tMonth : " + C.get(Calendar.MONTH) + "\tDay : " + C.get(Calendar.DAY_OF_MONTH));
- bItem.newLine();
- bItem.write("" + o.playerName + " was killed by " + c.playerName + " in pvp.");
- bItem.newLine();
- bItem.write("--------------------------------------------------");
- } finally {
- bItem.close();
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- public void playerKiller() {
- Client o = (Client) PlayerHandler.players[c.killerId];
- Calendar C = Calendar.getInstance();
- try {
- BufferedWriter bItem = new BufferedWriter(new FileWriter("./Data/logs/Kills/Players Killer/" + o.playerName + ".txt", true));
- try {
- bItem.newLine();
- bItem.write("Year : " + C.get(Calendar.YEAR) + "\tMonth : " + C.get(Calendar.MONTH) + "\tDay : " + C.get(Calendar.DAY_OF_MONTH));
- bItem.newLine();
- bItem.write("" + c.playerName + " killed " + o.playerName + " in pvp.");
- bItem.newLine();
- bItem.write("--------------------------------------------------");
- } finally {
- bItem.close();
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- public void duelKills() {
- Client o = (Client) PlayerHandler.players[c.duelingWith];
- Calendar C = Calendar.getInstance();
- try {
- BufferedWriter bItem = new BufferedWriter(new FileWriter("./Data/logs/Duels/Players Killed/" + o.playerName + ".txt", true));
- try {
- bItem.newLine();
- bItem.write("Year : " + C.get(Calendar.YEAR) + "\tMonth : " + C.get(Calendar.MONTH) + "\tDay : " + C.get(Calendar.DAY_OF_MONTH));
- bItem.newLine();
- bItem.write("" + o.playerName + " killed " + c.playerName + " in the duel arena.");
- bItem.newLine();
- bItem.write("--------------------------------------------------");
- } finally {
- bItem.close();
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- public void writeDropLog(String data, int ID, int itemX, int itemY) {
- checkDateAndTime();
- String filePath = "./Data/logs/Drop Center/" + c.playerName + ".txt";
- BufferedWriter bw = null;
- try {
- bw = new BufferedWriter(new FileWriter(filePath, true));
- bw.write("[" + c.date + "]" + "-" + "[" + c.currentTime + " "
- + checkTimeOfDay() + "]: " + "[" + c.connectedFrom + "]: "
- + "" + data + " " + " " + Item.getItemName(ID) + " ("
- + itemX + "/" + itemY + ").");
- bw.newLine();
- bw.flush();
- } catch (IOException ioe) {
- ioe.printStackTrace();
- } finally {
- if (bw != null) {
- try {
- bw.close();
- } catch (IOException ioe2) {
- }
- }
- }
- }
- public void writePickupLog(int ID, int amount) {
- checkDateAndTime();
- String filePath = "./Data/logs/Pickup Center/" + c.playerName + ".txt";
- BufferedWriter bw = null;
- try {
- bw = new BufferedWriter(new FileWriter(filePath, true));
- bw.write("[" + c.date + "]" + "-" + "[" + c.currentTime + " " + checkTimeOfDay() + "]: " + "[" + c.connectedFrom + "]: " + "" + " " + Item.getItemName(ID) + " " + amount + ".");
- bw.newLine();
- bw.flush();
- } catch (IOException ioe) {
- ioe.printStackTrace();
- } finally {
- if (bw != null) {
- try {
- bw.close();
- } catch (IOException ioe2) {
- }
- }
- }
- }
- public void writeClickLog(int ID) {
- checkDateAndTime();
- String filePath = "./Data/logs/Clickitem Center/" + c.playerName
- + ".txt";
- BufferedWriter bw = null;
- try {
- bw = new BufferedWriter(new FileWriter(filePath, true));
- bw.write("[" + c.date + "]" + "-" + "[" + c.currentTime + " "
- + checkTimeOfDay() + "]: " + "[" + c.connectedFrom + "]: "
- + "" + " " + Item.getItemName(ID) + ".");
- bw.newLine();
- bw.flush();
- } catch (IOException ioe) {
- ioe.printStackTrace();
- } finally {
- if (bw != null) {
- try {
- bw.close();
- } catch (IOException ioe2) {
- }
- }
- }
- }
- public void sendPM(String data) {
- checkDateAndTime();
- String filePath = "./Data/logs/Private Messages/Pm Sent/" + c.playerName + ".txt";
- BufferedWriter bw = null;
- try {
- bw = new BufferedWriter(new FileWriter(filePath, true));
- bw.write("[" + c.date + "]" + "-" + "[" + c.currentTime + " "
- + checkTimeOfDay() + "]: " + "[" + c.connectedFrom + "]: "
- + "" + data + " ");
- bw.newLine();
- bw.flush();
- } catch (IOException ioe) {
- ioe.printStackTrace();
- } finally {
- if (bw != null) {
- try {
- bw.close();
- } catch (IOException ioe2) {
- }
- }
- }
- }
- public void recievePM(String data) {
- checkDateAndTime();
- String filePath = "./Data/logs/Private Messages/Pm Recieved/" + c.playerName + ".txt";
- BufferedWriter bw = null;
- try {
- bw = new BufferedWriter(new FileWriter(filePath, true));
- bw.write("[" + c.date + "]" + "-" + "[" + c.currentTime + " "
- + checkTimeOfDay() + "]: " + "[" + c.connectedFrom + "]: "
- + "" + data + " ");
- bw.newLine();
- bw.flush();
- } catch (IOException ioe) {
- ioe.printStackTrace();
- } finally {
- if (bw != null) {
- try {
- bw.close();
- } catch (IOException ioe2) {
- }
- }
- }
- }
- public void writePMLog(String data) {
- checkDateAndTime();
- String filePath = "./Data/logs/Pm Center/" + c.playerName + ".txt";
- BufferedWriter bw = null;
- try {
- bw = new BufferedWriter(new FileWriter(filePath, true));
- bw.write("[" + c.date + "]" + "-" + "[" + c.currentTime + " "
- + checkTimeOfDay() + "]: " + "[" + c.connectedFrom + "]: "
- + "" + data + " ");
- bw.newLine();
- bw.flush();
- } catch (IOException ioe) {
- ioe.printStackTrace();
- } finally {
- if (bw != null) {
- try {
- bw.close();
- } catch (IOException ioe2) {
- }
- }
- }
- }
- public void writeCommandLog(String command) {
- checkDateAndTime();
- String filePath = "./Data/logs/Command Center/Commands.txt";
- BufferedWriter bw = null;
- try {
- bw = new BufferedWriter(new FileWriter(filePath, true));
- bw.write("[" + c.date + "]" + "-" + "[" + c.currentTime + " "
- + checkTimeOfDay() + "]: " + "[" + c.playerName + "]: "
- + "[" + c.connectedFrom + "] " + "::" + command);
- bw.newLine();
- bw.flush();
- } catch (IOException ioe) {
- ioe.printStackTrace();
- } finally {
- if (bw != null) {
- try {
- bw.close();
- } catch (IOException ignored) {
- }
- }
- }
- }
- public void checkDateAndTime() {
- Calendar cal = new GregorianCalendar();
- String day, month, hour, minute, second;
- int YEAR = cal.get(Calendar.YEAR);
- int MONTH = cal.get(Calendar.MONTH) + 1;
- int DAY = cal.get(Calendar.DAY_OF_MONTH);
- int HOUR = cal.get(Calendar.HOUR_OF_DAY);
- int MIN = cal.get(Calendar.MINUTE);
- int SECOND = cal.get(Calendar.SECOND);
- day = DAY < 10 ? "0" + DAY : "" + DAY;
- month = MONTH < 10 ? "0" + MONTH : "" + MONTH;
- hour = HOUR < 10 ? "0" + HOUR : "" + HOUR;
- minute = MIN < 10 ? "0" + MIN : "" + MIN;
- second = SECOND < 10 ? "0" + SECOND : "" + SECOND;
- c.date = day + "" + month + "" + YEAR;
- c.currentTime = hour + ":" + minute + ":" + second;
- }
- public String checkTimeOfDay() {
- Calendar cal = new GregorianCalendar();
- int TIME_OF_DAY = cal.get(Calendar.AM_PM);
- return TIME_OF_DAY > 0 ? "PM" : "AM";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement