Advertisement
turt2live

ChatLog.java

Nov 5th, 2011
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.08 KB | None | 0 0
  1. package mw;
  2.  
  3. import java.io.BufferedWriter;
  4. import java.io.FileWriter;
  5. import java.text.DateFormat;
  6. import java.text.SimpleDateFormat;
  7. import java.util.Date;
  8. import java.util.List;
  9.  
  10. import org.bukkit.Bukkit;
  11. import org.bukkit.World;
  12.  
  13. public class ChatLog {
  14.  
  15.     public static void log_whisper(String to, String from, String message,
  16.             char color_to, char color_from) {
  17.         try {
  18.             List<World> worlds = Bukkit.getWorlds();
  19.             String worldname = worlds.get(0).getName();
  20.             String filename = "F:\\xampp\\htdocs\\mc\\logs\\" + worldname
  21.                     + ".LOG";
  22.             BufferedWriter out = new BufferedWriter(new FileWriter(filename,
  23.                     true));
  24.             out.write("Whisper: " + from + " &gt;&gt;&gt; " + to + ": "
  25.                     + message + "<br>\r\n");
  26.             out.close();
  27.         } catch (Exception e) {
  28.             e.printStackTrace();
  29.         }
  30.     }
  31.  
  32.     public static void log_message(String from, String message, boolean color) {
  33.         try {
  34.             List<World> worlds = Bukkit.getWorlds();
  35.             String worldname = worlds.get(0).getName();
  36.             String filename = "F:\\xampp\\htdocs\\mc\\logs\\" + worldname
  37.                     + ".LOG";
  38.             BufferedWriter out = new BufferedWriter(new FileWriter(filename,
  39.                     true));
  40.             String op = "";
  41.             if (color) {
  42.                 op = " [OP]";
  43.             }
  44.             DateFormat dateFormat = new SimpleDateFormat(
  45.                     "EEE, d MMM yyyy HH:mm:ss Z");
  46.             Date date = new Date();
  47.             String timestamp = dateFormat.format(date);
  48.             out.write("[" + timestamp + "] &lt;" + from + "&gt;" + op + " : "
  49.                     + message + "<br>\r\n");
  50.             out.close();
  51.         } catch (Exception e) {
  52.             e.printStackTrace();
  53.         }
  54.     }
  55.  
  56.     public static void log_server_message(String message) {
  57.         try {
  58.             List<World> worlds = Bukkit.getWorlds();
  59.             String worldname = worlds.get(0).getName();
  60.             String filename = "F:\\xampp\\htdocs\\mc\\logs\\" + worldname
  61.                     + ".LOG";
  62.             DateFormat dateFormat = new SimpleDateFormat(
  63.                     "EEE, d MMM yyyy HH:mm:ss Z");
  64.             Date date = new Date();
  65.             String timestamp = dateFormat.format(date);
  66.             BufferedWriter out = new BufferedWriter(new FileWriter(filename,
  67.                     true));
  68.             out.write("[" + timestamp + "] &lt;SERVER&gt; : " + message
  69.                     + "<br>\r\n");
  70.             out.close();
  71.         } catch (Exception e) {
  72.             e.printStackTrace();
  73.         }
  74.     }
  75.  
  76.     public static void log_console_message(String message) {
  77.         try {
  78.             List<World> worlds = Bukkit.getWorlds();
  79.             String worldname = worlds.get(0).getName();
  80.             String filename = "F:\\xampp\\htdocs\\mc\\logs\\" + worldname
  81.                     + ".LOG";
  82.             DateFormat dateFormat = new SimpleDateFormat(
  83.                     "EEE, d MMM yyyy HH:mm:ss Z");
  84.             Date date = new Date();
  85.             String timestamp = dateFormat.format(date);
  86.             BufferedWriter out = new BufferedWriter(new FileWriter(filename,
  87.                     true));
  88.             out.write("[" + timestamp + "] &lt;CONSOLE&gt; : " + message
  89.                     + "<br>\r\n");
  90.             out.close();
  91.         } catch (Exception e) {
  92.             e.printStackTrace();
  93.         }
  94.     }
  95.  
  96.     public static void log_warning(String message) {
  97.         try {
  98.             List<World> worlds = Bukkit.getWorlds();
  99.             String worldname = worlds.get(0).getName();
  100.             String filename = "F:\\xampp\\htdocs\\mc\\logs\\" + worldname
  101.                     + ".LOG";
  102.             DateFormat dateFormat = new SimpleDateFormat(
  103.                     "EEE, d MMM yyyy HH:mm:ss Z");
  104.             Date date = new Date();
  105.             String timestamp = dateFormat.format(date);
  106.             BufferedWriter out = new BufferedWriter(new FileWriter(filename,
  107.                     true));
  108.             out.write("[" + timestamp + "] &lt;WARNING&gt; : " + message
  109.                     + "<br>\r\n");
  110.             out.close();
  111.         } catch (Exception e) {
  112.             e.printStackTrace();
  113.         }
  114.     }
  115.  
  116.     public static void log_error(String message) {
  117.         try {
  118.             List<World> worlds = Bukkit.getWorlds();
  119.             String worldname = worlds.get(0).getName();
  120.             String filename = "F:\\xampp\\htdocs\\mc\\logs\\" + worldname
  121.                     + ".LOG";
  122.             DateFormat dateFormat = new SimpleDateFormat(
  123.                     "EEE, d MMM yyyy HH:mm:ss Z");
  124.             Date date = new Date();
  125.             String timestamp = dateFormat.format(date);
  126.             BufferedWriter out = new BufferedWriter(new FileWriter(filename,
  127.                     true));
  128.             out.write("[" + timestamp + "] &lt;ERROR&gt; : " + message
  129.                     + "<br>\r\n");
  130.             out.close();
  131.         } catch (Exception e) {
  132.             e.printStackTrace();
  133.         }
  134.     }
  135. }
  136.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement