mirror of
https://github.com/2006-Scape/2006Scape.git
synced 2026-07-04 08:39:05 +00:00
d876a923b9
* Clean up part 1 - Removed lots of dead code - Removed unncessary files not in use - Cleaned up small bits of code - Removed a few warnings - Server.java ---> GameEngine.java - Constants.java ---> GameConstants.java * Cape Dye Rewrote cape dying * Packaging - redone ----> com.rebotted * PacketSender/clean up - ActionSender ---> PacketSender - Moved many more packets to packetsender - Cleaned up more dead code * Merge Client/Player - Merged Client.java with Player.java (both were doing same thing so redundant to have both) - Removed some more dead code - Tidy a few small things up * Quests/more clean up - Removed more dead code - Made quests static in order to clean them up a bit * More cleanup - Removed some more of the dead quest code - Correcting naming of some of the shop variables
113 lines
3.8 KiB
Java
113 lines
3.8 KiB
Java
package com.rebotted.util;
|
|
|
|
import java.io.BufferedWriter;
|
|
import java.io.File;
|
|
import java.io.FileWriter;
|
|
import java.io.IOException;
|
|
import java.util.Calendar;
|
|
import java.util.GregorianCalendar;
|
|
|
|
/*
|
|
* Author: Nightleaf <colton.thompson@live.com>
|
|
*/
|
|
|
|
public class GameLogger {
|
|
|
|
public static String getTime() {
|
|
Calendar cal = new GregorianCalendar();
|
|
String day, month, hour, minute;
|
|
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);
|
|
day = DAY < 10 ? "0" + DAY : "" + DAY;
|
|
month = MONTH < 10 ? "0" + MONTH : "" + MONTH;
|
|
hour = HOUR < 10 ? "0" + HOUR : "" + HOUR;
|
|
minute = MIN < 10 ? "0" + MIN : "" + MIN;
|
|
return "[" + YEAR + "/" + month + "/" + day + "] " + hour + ":" + minute + " ";
|
|
}
|
|
|
|
/**
|
|
* Formats a currency string just like RS.
|
|
*
|
|
* @param cash
|
|
* @return
|
|
*/
|
|
public static String formatCurrency(int cash) {
|
|
String s = String.valueOf(cash);
|
|
for (int k = s.length() - 3; k > 0; k -= 3) {
|
|
s = s.substring(0, k).replace(",", ".") + "," + s.substring(k);
|
|
}
|
|
if (s.length() > 8) {
|
|
s = s.substring(0, s.length() - 8).replace(",", ".") + " million (" + s + ")";
|
|
} else if (s.length() > 4) {
|
|
s = s.substring(0, s.length() - 4) + "K (" + s + ")";
|
|
}
|
|
return " " + s;
|
|
}
|
|
|
|
/**
|
|
* Writes to a log file.
|
|
*
|
|
* @param log
|
|
* the log file.
|
|
* @param data
|
|
* the data we are writing to the log.
|
|
*/
|
|
public static void writeLog(String player, String logType, String data) {
|
|
File log = null;
|
|
if (logType.equalsIgnoreCase("alchemy")) {
|
|
log = new File("./data/logs/alchlogs/" + player + ".txt");
|
|
} else if (logType.equalsIgnoreCase("shopselling")) {
|
|
log = new File("./data/logs/shopselling/" + player + ".txt");
|
|
} else if (logType.equalsIgnoreCase("shopbuying")) {
|
|
log = new File("./data/logs/shopbuying/" + player + ".txt");
|
|
} else if (logType.equalsIgnoreCase("dropitem")) {
|
|
log = new File("./data/logs/dropitem/" + player + ".txt");
|
|
} else if (logType.equalsIgnoreCase("clickitem")) {
|
|
log = new File("./data/logs/clickitem/" + player + ".txt");
|
|
} else if (logType.equalsIgnoreCase("pickupitem")) {
|
|
log = new File("./data/logs/pickupitem/" + player + ".txt");
|
|
} else if (logType.equalsIgnoreCase("commands")) {
|
|
log = new File("./data/logs/commands/" + player + ".txt");
|
|
} else if (logType.equalsIgnoreCase("pmsent")) {
|
|
log = new File("./data/logs/privatemessages/pmsent/" + player + ".txt");
|
|
} else if (logType.equalsIgnoreCase("pmrecieved")) {
|
|
log = new File("./data/logs/privatemessages/pmrecieved/" + player + ".txt");
|
|
} else if (logType.equalsIgnoreCase("tradesgave")) {
|
|
log = new File("./data/logs/trades/gave/" + player + ".txt");
|
|
} else if (logType.equalsIgnoreCase("tradesrecieved")) {
|
|
log = new File("./data/logs/trades/recieved/" + player + ".txt");
|
|
} else if (logType.equalsIgnoreCase("pkingkilled")) {
|
|
log = new File("./data/logs/pking/killed/" + player + ".txt");
|
|
} else if (logType.equalsIgnoreCase("pkingkiller")) {
|
|
log = new File("./data/logs/pking/killer/" + player + ".txt");
|
|
} else if (logType.equalsIgnoreCase("duelingkilled")) {
|
|
log = new File("./data/logs/dueling/killed/" + player + ".txt");
|
|
} else if (logType.equalsIgnoreCase("duelingkiller")) {
|
|
log = new File("./data/logs/dueling/killer/" + player + ".txt");
|
|
} else {
|
|
log = new File("./data/logs/" + player + ".txt");
|
|
}
|
|
|
|
if (!log.exists()) {
|
|
try {
|
|
log.createNewFile();
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
try {
|
|
FileWriter logFile = new FileWriter(log, true);
|
|
BufferedWriter bf = new BufferedWriter(logFile);
|
|
bf.write(getTime() + "" + data + "");
|
|
bf.newLine();
|
|
bf.flush();
|
|
bf.close();
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}
|