Advertisement
riking

ChatLogger

Jul 4th, 2012
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.08 KB | None | 0 0
  1. import java.io.File;
  2. import java.io.IOException;
  3. import java.io.PrintStream;
  4. import java.net.InetSocketAddress;
  5. import java.util.logging.Logger;
  6. import java.util.logging.Level;
  7. import java.util.Date;
  8. import java.util.SimpleDateFormat;
  9. import net.minecraft.client.Minecraft;
  10.  
  11. public class mod_chatlogfix extends BaseMod
  12. {
  13.     public File outdir;
  14.     public File curLogFile;
  15.     public PrintStream outstream;
  16.     private static Logger loggy = ModLoader.getLogger();
  17.     public static final SimpleDateFormat format = new SimpleDateFormat("-yyyy-MM-dd");
  18.  
  19.     public mod_chatlogfix()
  20.     {
  21.         String s = "Herpaderp, we don't use constructors here in CorrectLand!";
  22.     }
  23.  
  24.     public String getVersion()
  25.     {
  26.         return "1.0 by Riking";
  27.     }
  28.  
  29.     public void load()
  30.     {
  31.         try {
  32.             outdir = new File(ModLoader.getMinecraftInstance().b(), "/logs");
  33.             outdir.mkdirs();
  34.         } catch (IOException e) {
  35.             ModLoader.throwException("ChatLog: Failed to create directories");
  36.         }
  37.         curLogFile = null;
  38.         outstream = null;
  39.     }
  40.     public void receiveChatPacket(String text)
  41.     {
  42.         loggy.finest("ChatLog: recieved chat packet");
  43.         if (curLogFile == null || outstream == null)
  44.         {
  45.             loggy.warning("ChatLog: recieved message while output was not set up. Aborting write.");
  46.             return;
  47.         }
  48.         outstream.println(text);
  49.     }
  50.     /**
  51.      * Create the output File, and open the output stream.
  52.      */
  53.     // serverConnect(NetClientHandler handler)
  54.     public void serverConnect(adl handler)
  55.     {
  56.         try {
  57.             // final NetworkManager networkmanager = ModLoader.getPrivateValue(NetClientHandler.class, handler, "netManager");
  58.             final lg networkmanager = ModLoader.getPrivateValue(adl.class, handler, "g");
  59.             // bla bla bla bla (NetworkManager.class, networkmanager, "remoteSocketAddress");
  60.             final InetSocketAddress addr = (InetSocketAddress) ModLoader.getPrivateValue(lg.class, networkmanager, "i");
  61.             final String serveraddress = addr.getHostName();
  62.            
  63.             StringBuilder sb = new StringBuilder(serveraddress);
  64.             sb.append(format.format(new Date()));
  65.             sb.append(".log");
  66.             curLogFile = new File(outdir, sb.toString());
  67.             outstream = new PrintStream(curLogFile);
  68.            
  69.         } catch (Throwable error) {
  70.             ModLoader.throwException("ChatLog: failed to initialize log",error);
  71.         }
  72.     }
  73.     /**
  74.      * Close the output stream and anull the File object.
  75.      */
  76.     public void serverDisconnect()
  77.     {
  78.         try {
  79.             outstream.close();
  80.         } catch (Throwable error) {
  81.         //}catch (Exception error) {
  82.             ModLoader.throwException("ChatLog: failed to write output",error);
  83.         }
  84.         finally {
  85.             curLogFile = null;
  86.             outstream = null;
  87.         }
  88.     }
  89. }
  90.  
  91. /* Location:           C:\Users\Kane\Downloads\chatlog beta 2.zip
  92. * Qualified Name:     mod_chatlog
  93. * JD-Core Version:    0.6.0
  94. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement