forked from SpigotMC/BungeeCord
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
123 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,5 +34,5 @@ | |
.idea/ | ||
|
||
# other files | ||
*log* | ||
/*log* | ||
*.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package net.md_5.bungee; | ||
|
||
import java.io.IOException; | ||
import java.io.PrintWriter; | ||
import java.io.StringWriter; | ||
import java.text.SimpleDateFormat; | ||
import java.util.logging.FileHandler; | ||
import java.util.logging.Formatter; | ||
import java.util.logging.Level; | ||
import java.util.logging.LogRecord; | ||
|
||
public class Logger extends java.util.logging.Logger { | ||
|
||
private static final Formatter formatter = new ConsoleLogFormatter(); | ||
private static final Logger instance = new Logger(); | ||
|
||
public Logger() { | ||
super("RubberBand", null); | ||
try { | ||
FileHandler handler = new FileHandler("proxy.log", BungeeCord.instance.config.logNumLines, 1, true); | ||
handler.setFormatter(formatter); | ||
addHandler(handler); | ||
} catch (IOException | SecurityException ex) { | ||
System.err.println("Could not register logger!"); | ||
ex.printStackTrace(); | ||
} | ||
} | ||
|
||
@Override | ||
public void log(LogRecord record) { | ||
super.log(record); | ||
String message = formatter.format(record); | ||
if (record.getLevel() == Level.SEVERE || record.getLevel() == Level.WARNING) { | ||
System.err.print(message); | ||
} else { | ||
System.out.print(message); | ||
} | ||
} | ||
|
||
public static Logger $() { | ||
return instance; | ||
} | ||
|
||
public static class ConsoleLogFormatter extends Formatter { | ||
|
||
private SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss"); | ||
|
||
@Override | ||
public String format(LogRecord logrecord) { | ||
StringBuilder formatted = new StringBuilder(); | ||
|
||
formatted.append(formatter.format(logrecord.getMillis())); | ||
Level level = logrecord.getLevel(); | ||
|
||
if (level == Level.FINEST) { | ||
formatted.append(" [FINEST] "); | ||
} else if (level == Level.FINER) { | ||
formatted.append(" [FINER] "); | ||
} else if (level == Level.FINE) { | ||
formatted.append(" [FINE] "); | ||
} else if (level == Level.INFO) { | ||
formatted.append(" [INFO] "); | ||
} else if (level == Level.WARNING) { | ||
formatted.append(" [WARNING] "); | ||
} else if (level == Level.SEVERE) { | ||
formatted.append(" [SEVERE] "); | ||
} | ||
|
||
formatted.append(logrecord.getMessage()); | ||
formatted.append('\n'); | ||
Throwable throwable = logrecord.getThrown(); | ||
|
||
if (throwable != null) { | ||
StringWriter writer = new StringWriter(); | ||
|
||
throwable.printStackTrace(new PrintWriter(writer)); | ||
formatted.append(writer); | ||
} | ||
|
||
return formatted.toString(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package net.md_5.bungee.packet; | ||
|
||
import lombok.EqualsAndHashCode; | ||
import lombok.ToString; | ||
|
||
@ToString | ||
@EqualsAndHashCode(callSuper = false) | ||
public class Packet1Login extends DefinedPacket { | ||
|
||
public int entityId; | ||
public String levelType; | ||
public byte gameMode; | ||
public byte dimension; | ||
public byte difficulty; | ||
public byte unused; | ||
public byte maxPlayers; | ||
|
||
public Packet1Login(int entityId, String levelType, byte gameMode, byte dimension, byte difficulty, byte unused, byte maxPlayers) { | ||
super(0x01); | ||
writeInt(entityId); | ||
writeUTF(levelType); | ||
writeByte(gameMode); | ||
writeByte(dimension); | ||
writeByte(difficulty); | ||
writeByte(unused); | ||
writeByte(maxPlayers); | ||
} | ||
|
||
public Packet1Login(byte[] buf) { | ||
super(0x01, buf); | ||
this.entityId = readInt(); | ||
this.levelType = readUTF(); | ||
this.gameMode = readByte(); | ||
this.dimension = readByte(); | ||
this.difficulty = readByte(); | ||
this.unused = readByte(); | ||
this.maxPlayers = readByte(); | ||
} | ||
} |