This commit is contained in:
Sen 2025-06-03 12:58:02 +02:00
parent f849ee4526
commit 45834e0cd4
Signed by: sen
GPG key ID: 3AC50A6F47D1B722
49 changed files with 244 additions and 2404 deletions

View file

@ -61,22 +61,18 @@ import proxy.network.NetworkManager;
import proxy.network.ThreadQuickExitException;
import proxy.packet.play.server.S40PacketDisconnect;
import proxy.util.ChatColor;
import proxy.util.ChatComponentText;
import proxy.util.Profile;
import proxy.util.ServerInfo;
import proxy.util.User;
import proxy.util.VersionId;
import proxy.util.LazyLoadBase;
import proxy.util.LazyLoader;
import proxy.util.Log;
import proxy.util.PlayerInfo;
public class Proxy {
public static final LazyLoadBase<NioEventLoopGroup> NIO_EVENT_LOOP = new LazyLoadBase<NioEventLoopGroup>() {
public static final LazyLoader<NioEventLoopGroup> NIO_EVENT_LOOP = new LazyLoader<NioEventLoopGroup>() {
protected NioEventLoopGroup load() {
return new NioEventLoopGroup(0, (new ThreadFactoryBuilder()).setNameFormat("Netty Server IO #%d").setDaemon(true).build());
}
};
public static final LazyLoadBase<EpollEventLoopGroup> EPOLL_EVENT_LOOP = new LazyLoadBase<EpollEventLoopGroup>() {
public static final LazyLoader<EpollEventLoopGroup> EPOLL_EVENT_LOOP = new LazyLoader<EpollEventLoopGroup>() {
protected EpollEventLoopGroup load() {
return new EpollEventLoopGroup(0, (new ThreadFactoryBuilder()).setNameFormat("Netty Epoll Server IO #%d").setDaemon(true).build());
}
@ -105,7 +101,7 @@ public class Proxy {
private ServerInfo status = getStatus(new File("icon.png"), ChatColor.AQUA + "Server\n" + ChatColor.GREEN + "Test!!", 90, 10, "Test1",
"Test2 ...", "Test #3 !!");
private static void addFaviconToStatusResponse(ServerInfo info, File file) {
private static String getIcon(File file) {
if(file.isFile()) {
ByteBuf buf = Unpooled.buffer();
try {
@ -113,8 +109,7 @@ public class Proxy {
if(img.getWidth() != 64 || img.getHeight() != 64)
throw new IllegalArgumentException("Icon must be 64x64 pixels");
ImageIO.write(img, "PNG", new ByteBufOutputStream(buf));
ByteBuf base64 = Base64.encode(buf);
info.setIcon("data:image/png;base64," + base64.toString(Charsets.UTF_8));
return "data:image/png;base64," + Base64.encode(buf).toString(Charsets.UTF_8);
}
catch(Exception e) {
Log.error(e, "Couldn't load server icon");
@ -123,19 +118,16 @@ public class Proxy {
buf.release();
}
}
return null;
}
public static ServerInfo getStatus(File icon, String motd, int max, int current, String... lines) {
ServerInfo info = new ServerInfo();
info.setMotd(new ChatComponentText(motd));
info.setVersion(new VersionId("1.8.9", 47));
addFaviconToStatusResponse(info, icon);
info.setInfo(new PlayerInfo(max, current));
Profile[] profiles = new Profile[Math.min(lines.length, 12)];
for(int z = 0; z < profiles.length; z++) {
profiles[z] = new Profile(Proxy.getOfflineUUID(lines[z]), lines[z]);
}
info.getInfo().setList(profiles);
ServerInfo info = new ServerInfo("1.8.9", 47);
info.setMotd(motd);
info.setCapacity(max);
info.setOnline(current);
info.setList(lines);
info.setIcon(getIcon(icon));
return info;
}
@ -201,7 +193,7 @@ public class Proxy {
public void addLanEndpoint(InetAddress address, int port) throws IOException {
synchronized(this.endpoints) {
Class<? extends ServerSocketChannel> oclass;
LazyLoadBase<? extends EventLoopGroup> lazyloadbase;
LazyLoader<? extends EventLoopGroup> lazyloadbase;
if(Epoll.isAvailable() && this.epoll) {
oclass = EpollServerSocketChannel.class;
@ -269,10 +261,10 @@ public class Proxy {
}
catch(Exception exception) {
Log.error(exception, "Failed to handle packet for " + networkmanager.getRemoteAddress());
final ChatComponentText chatcomponenttext = new ChatComponentText("Internal server error");
networkmanager.sendPacket(new S40PacketDisconnect(chatcomponenttext), new GenericFutureListener<Future<? super Void>>() {
final String reason = "Internal server error";
networkmanager.sendPacket(new S40PacketDisconnect(reason), new GenericFutureListener<Future<? super Void>>() {
public void operationComplete(Future<? super Void> p_operationComplete_1_) throws Exception {
networkmanager.closeChannel(chatcomponenttext);
networkmanager.closeChannel(reason);
}
});
networkmanager.disableAutoRead();

View file

@ -6,11 +6,6 @@ import java.io.IOException;
public abstract class NBTBase
{
public static final String[] NBT_TYPES = new String[] {"END", "BYTE", "SHORT", "INT", "LONG", "FLOAT", "DOUBLE", "BYTE[]", "STRING", "LIST", "COMPOUND", "INT[]"};
/**
* Write the actual data contents of the tag, implemented in NBT extension classes
*/
abstract void write(DataOutput output) throws IOException;
abstract void read(DataInput input, int depth, NBTSizeTracker sizeTracker) throws IOException;
@ -105,19 +100,4 @@ public abstract class NBTBase
{
return this.toString();
}
public abstract static class NBTPrimitive extends NBTBase
{
public abstract long getLong();
public abstract int getInt();
public abstract short getShort();
public abstract byte getByte();
public abstract double getDouble();
public abstract float getFloat();
}
}

View file

@ -4,7 +4,7 @@ import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
public class NBTTagByte extends NBTBase.NBTPrimitive
public class NBTTagByte extends NBTBase
{
/** The byte value for the tag. */
private byte data;

View file

@ -184,114 +184,7 @@ public class NBTTagCompound extends NBTBase
public boolean hasKey(String key, int type)
{
int i = this.getTagId(key);
if (i == type)
{
return true;
}
else if (type != 99)
{
if (i > 0)
{
;
}
return false;
}
else
{
return i == 1 || i == 2 || i == 3 || i == 4 || i == 5 || i == 6;
}
}
/**
* Retrieves a byte value using the specified key, or 0 if no such key was stored.
*/
public byte getByte(String key)
{
try
{
return !this.hasKey(key, 99) ? 0 : ((NBTBase.NBTPrimitive)this.tagMap.get(key)).getByte();
}
catch (ClassCastException var3)
{
return (byte)0;
}
}
/**
* Retrieves a short value using the specified key, or 0 if no such key was stored.
*/
public short getShort(String key)
{
try
{
return !this.hasKey(key, 99) ? 0 : ((NBTBase.NBTPrimitive)this.tagMap.get(key)).getShort();
}
catch (ClassCastException var3)
{
return (short)0;
}
}
/**
* Retrieves an integer value using the specified key, or 0 if no such key was stored.
*/
public int getInteger(String key)
{
try
{
return !this.hasKey(key, 99) ? 0 : ((NBTBase.NBTPrimitive)this.tagMap.get(key)).getInt();
}
catch (ClassCastException var3)
{
return 0;
}
}
/**
* Retrieves a long value using the specified key, or 0 if no such key was stored.
*/
public long getLong(String key)
{
try
{
return !this.hasKey(key, 99) ? 0L : ((NBTBase.NBTPrimitive)this.tagMap.get(key)).getLong();
}
catch (ClassCastException var3)
{
return 0L;
}
}
/**
* Retrieves a float value using the specified key, or 0 if no such key was stored.
*/
public float getFloat(String key)
{
try
{
return !this.hasKey(key, 99) ? 0.0F : ((NBTBase.NBTPrimitive)this.tagMap.get(key)).getFloat();
}
catch (ClassCastException var3)
{
return 0.0F;
}
}
/**
* Retrieves a double value using the specified key, or 0 if no such key was stored.
*/
public double getDouble(String key)
{
try
{
return !this.hasKey(key, 99) ? 0.0D : ((NBTBase.NBTPrimitive)this.tagMap.get(key)).getDouble();
}
catch (ClassCastException var3)
{
return 0.0D;
}
return i == type;
}
/**
@ -378,15 +271,6 @@ public class NBTTagCompound extends NBTBase
}
}
/**
* Retrieves a boolean value using the specified key, or false if no such key was stored. This uses the getByte
* method.
*/
public boolean getBoolean(String key)
{
return this.getByte(key) != 0;
}
/**
* Remove the specified tag.
*/

View file

@ -4,9 +4,7 @@ import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import proxy.util.MathHelper;
public class NBTTagDouble extends NBTBase.NBTPrimitive
public class NBTTagDouble extends NBTBase
{
/** The double value for the tag. */
private double data;
@ -73,34 +71,4 @@ public class NBTTagDouble extends NBTBase.NBTPrimitive
long i = Double.doubleToLongBits(this.data);
return super.hashCode() ^ (int)(i ^ i >>> 32);
}
public long getLong()
{
return (long)Math.floor(this.data);
}
public int getInt()
{
return MathHelper.floor_double(this.data);
}
public short getShort()
{
return (short)(MathHelper.floor_double(this.data) & 65535);
}
public byte getByte()
{
return (byte)(MathHelper.floor_double(this.data) & 255);
}
public double getDouble()
{
return this.data;
}
public float getFloat()
{
return (float)this.data;
}
}

View file

@ -4,9 +4,7 @@ import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import proxy.util.MathHelper;
public class NBTTagFloat extends NBTBase.NBTPrimitive
public class NBTTagFloat extends NBTBase
{
/** The float value for the tag. */
private float data;
@ -72,34 +70,4 @@ public class NBTTagFloat extends NBTBase.NBTPrimitive
{
return super.hashCode() ^ Float.floatToIntBits(this.data);
}
public long getLong()
{
return (long)this.data;
}
public int getInt()
{
return MathHelper.floor_float(this.data);
}
public short getShort()
{
return (short)(MathHelper.floor_float(this.data) & 65535);
}
public byte getByte()
{
return (byte)(MathHelper.floor_float(this.data) & 255);
}
public double getDouble()
{
return (double)this.data;
}
public float getFloat()
{
return this.data;
}
}

View file

@ -4,7 +4,7 @@ import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
public class NBTTagInt extends NBTBase.NBTPrimitive
public class NBTTagInt extends NBTBase
{
/** The integer value for the tag. */
private int data;

View file

@ -169,85 +169,6 @@ public class NBTTagList extends NBTBase
return this.tagList.isEmpty();
}
/**
* Retrieves the NBTTagCompound at the specified index in the list
*/
public NBTTagCompound getCompoundTagAt(int i)
{
if (i >= 0 && i < this.tagList.size())
{
NBTBase nbtbase = (NBTBase)this.tagList.get(i);
return nbtbase.getId() == 10 ? (NBTTagCompound)nbtbase : new NBTTagCompound();
}
else
{
return new NBTTagCompound();
}
}
public int[] getIntArrayAt(int i)
{
if (i >= 0 && i < this.tagList.size())
{
NBTBase nbtbase = (NBTBase)this.tagList.get(i);
return nbtbase.getId() == 11 ? ((NBTTagIntArray)nbtbase).getIntArray() : new int[0];
}
else
{
return new int[0];
}
}
public double getDoubleAt(int i)
{
if (i >= 0 && i < this.tagList.size())
{
NBTBase nbtbase = (NBTBase)this.tagList.get(i);
return nbtbase.getId() == 6 ? ((NBTTagDouble)nbtbase).getDouble() : 0.0D;
}
else
{
return 0.0D;
}
}
public float getFloatAt(int i)
{
if (i >= 0 && i < this.tagList.size())
{
NBTBase nbtbase = (NBTBase)this.tagList.get(i);
return nbtbase.getId() == 5 ? ((NBTTagFloat)nbtbase).getFloat() : 0.0F;
}
else
{
return 0.0F;
}
}
/**
* Retrieves the tag String value at the specified index in the list
*/
public String getStringTagAt(int i)
{
if (i >= 0 && i < this.tagList.size())
{
NBTBase nbtbase = (NBTBase)this.tagList.get(i);
return nbtbase.getId() == 8 ? nbtbase.getString() : nbtbase.toString();
}
else
{
return "";
}
}
/**
* Get the tag at the given position
*/
public NBTBase get(int idx)
{
return (NBTBase)(idx >= 0 && idx < this.tagList.size() ? (NBTBase)this.tagList.get(idx) : new NBTTagEnd());
}
/**
* Returns the number of tags in the list.
*/

View file

@ -4,7 +4,7 @@ import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
public class NBTTagLong extends NBTBase.NBTPrimitive
public class NBTTagLong extends NBTBase
{
/** The long value for the tag. */
private long data;

View file

@ -4,7 +4,7 @@ import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
public class NBTTagShort extends NBTBase.NBTPrimitive
public class NBTTagShort extends NBTBase
{
/** The short value for the tag. */
private short data;

View file

@ -1,9 +1,7 @@
package proxy.network;
import proxy.util.ChatComponent;
public interface INetHandler {
void onDisconnect(NetworkManager connection, ChatComponent reason);
void onDisconnect(NetworkManager connection, String reason);
default void update(NetworkManager connection) {
}
}

View file

@ -3,8 +3,6 @@ package proxy.network;
import proxy.Proxy;
import proxy.packet.handshake.client.C00Handshake;
import proxy.packet.login.server.S00PacketDisconnect;
import proxy.util.ChatComponent;
import proxy.util.ChatComponentText;
public class NetHandlerHandshake implements INetHandler {
private final Proxy proxy;
@ -21,12 +19,12 @@ public class NetHandlerHandshake implements INetHandler {
this.connection.setConnectionState(EnumConnectionState.LOGIN);
if(packet.getProtocolVersion() > 47) {
ChatComponentText text = new ChatComponentText("Outdated server! I\'m still on 1.8.9");
String text = "Outdated server! I\'m still on 1.8.9";
this.connection.sendPacket(new S00PacketDisconnect(text));
this.connection.closeChannel(text);
}
else if(packet.getProtocolVersion() < 47) {
ChatComponentText text = new ChatComponentText("Outdated client! Please use 1.8.9");
String text = "Outdated client! Please use 1.8.9";
this.connection.sendPacket(new S00PacketDisconnect(text));
this.connection.closeChannel(text);
}
@ -46,6 +44,6 @@ public class NetHandlerHandshake implements INetHandler {
}
}
public void onDisconnect(NetworkManager connection, ChatComponent reason) {
public void onDisconnect(NetworkManager connection, String reason) {
}
}

View file

@ -8,8 +8,6 @@ import proxy.packet.login.client.C01PacketEncryptionResponse;
import proxy.packet.login.server.S00PacketDisconnect;
import proxy.packet.login.server.S02PacketLoginSuccess;
import proxy.packet.login.server.S03PacketEnableCompression;
import proxy.util.ChatComponent;
import proxy.util.ChatComponentText;
import proxy.util.Log;
public class NetHandlerLoginServer implements INetHandler {
@ -44,16 +42,15 @@ public class NetHandlerLoginServer implements INetHandler {
}
if(this.timer++ == 600) {
this.closeConnection("Took too long to log in");
this.disconnect("Took too long to log in");
}
}
public void closeConnection(String reason) {
public void disconnect(String reason) {
try {
Log.info("Disconnecting " + this.getConnectionInfo() + ": " + reason);
ChatComponentText text = new ChatComponentText(reason);
this.connection.sendPacket(new S00PacketDisconnect(text));
this.connection.closeChannel(text);
this.connection.sendPacket(new S00PacketDisconnect(reason));
this.connection.closeChannel(reason);
}
catch(Exception e) {
Log.error(e, "Error whilst disconnecting player");
@ -62,7 +59,7 @@ public class NetHandlerLoginServer implements INetHandler {
public void tryAcceptPlayer() {
if(this.proxy.isLoggedIn(this.username)) {
this.closeConnection("That username is already taken");
this.disconnect("That username is already taken");
return;
}
this.state = LoginState.DONE;
@ -81,7 +78,7 @@ public class NetHandlerLoginServer implements INetHandler {
handler.setupPlayer();
}
public void onDisconnect(NetworkManager connection, ChatComponent reason) {
public void onDisconnect(NetworkManager connection, String reason) {
Log.info(this.getConnectionInfo() + " lost connection: " + reason);
}
@ -95,7 +92,7 @@ public class NetHandlerLoginServer implements INetHandler {
throw new IllegalStateException("Unexpected hello packet");
this.username = packet.getProfile();
if(this.username.length() < 3 || this.username.length() > 16 || !isValidUser(this.username)) {
this.closeConnection("Invalid username");
this.disconnect("Invalid username");
return;
}
this.state = LoginState.WAITING;

View file

@ -110,8 +110,6 @@ import proxy.packet.play.server.S47PacketPlayerListHeaderFooter;
import proxy.packet.play.server.S48PacketResourcePackSend;
import proxy.packet.play.server.S49PacketUpdateEntityNBT;
import proxy.util.ChatColor;
import proxy.util.ChatComponent;
import proxy.util.ChatComponentText;
import proxy.util.User;
import proxy.util.Stack;
import proxy.util.Log;
@ -119,14 +117,14 @@ import proxy.util.Log;
public class NetHandlerPlayServer implements INetHandler {
public class ProxyLoginHandler implements INetHandler {
public void handleEncryptionRequest(S01PacketEncryptionRequest packetIn) {
NetHandlerPlayServer.this.server.closeChannel(new ChatComponentText("Online mode auth request received"));
NetHandlerPlayServer.this.kickPlayerFromServer("Server tried to authenticate, check if online-mode ist set to false");
NetHandlerPlayServer.this.server.closeChannel("Online mode auth request received");
NetHandlerPlayServer.this.disconnect("Server tried to authenticate, check if online-mode ist set to false");
}
public void handleLoginSuccess(S02PacketLoginSuccess packetIn) {
if(!NetHandlerPlayServer.this.username.equals(packetIn.getName()) || !Proxy.getOfflineUUID(NetHandlerPlayServer.this.username).equals(packetIn.getId())) {
NetHandlerPlayServer.this.server.closeChannel(new ChatComponentText("Different profile received"));
NetHandlerPlayServer.this.kickPlayerFromServer("Server returned a different profile, check if server or plugins tamper with profiles");
NetHandlerPlayServer.this.server.closeChannel("Different profile received");
NetHandlerPlayServer.this.disconnect("Server returned a different profile, check if server or plugins tamper with profiles");
}
NetHandlerPlayServer.this.server.setNetHandler(NetHandlerPlayServer.this);
NetHandlerPlayServer.this.server.setConnectionState(EnumConnectionState.PLAY);
@ -136,15 +134,15 @@ public class NetHandlerPlayServer implements INetHandler {
}
public void handleDisconnect(S00PacketDisconnect packetIn) {
NetHandlerPlayServer.this.server.closeChannel(packetIn.func_149603_c());
NetHandlerPlayServer.this.kickPlayerFromServer(packetIn.func_149603_c());
NetHandlerPlayServer.this.server.closeChannel("Kicked by server on login: " + packetIn.getReason());
NetHandlerPlayServer.this.disconnect("Kicked by server on login");
}
public void handleEnableCompression(S03PacketEnableCompression packetIn) {
NetHandlerPlayServer.this.server.setCompressionTreshold(packetIn.getCompressionTreshold());
}
public void onDisconnect(NetworkManager connection, ChatComponent reason) {
public void onDisconnect(NetworkManager connection, String reason) {
NetHandlerPlayServer.this.onDisconnect(connection, reason);
}
}
@ -227,7 +225,7 @@ public class NetHandlerPlayServer implements INetHandler {
this.server.processReceivedPackets();
}
catch(Throwable e) {
this.kickPlayerFromServer("Forward server error");
this.disconnect("Forward server error");
Log.error(e, "Error in connection for %s", this.username);
}
}
@ -245,14 +243,10 @@ public class NetHandlerPlayServer implements INetHandler {
this.server.sendPacket(packetIn);
}
public void kickPlayerFromServer(String reason) {
this.kickPlayerFromServer(new ChatComponentText(reason));
}
public void kickPlayerFromServer(final ChatComponent comp) {
this.client.sendPacket(new S40PacketDisconnect(comp), new GenericFutureListener<Future<? super Void>>() {
public void disconnect(final String reason) {
this.client.sendPacket(new S40PacketDisconnect(reason), new GenericFutureListener<Future<? super Void>>() {
public void operationComplete(Future<? super Void> p_operationComplete_1_) throws Exception {
NetHandlerPlayServer.this.client.closeChannel(comp);
NetHandlerPlayServer.this.client.closeChannel(reason);
}
});
this.client.disableAutoRead();
@ -271,12 +265,12 @@ public class NetHandlerPlayServer implements INetHandler {
conn = NetworkManager.createNetworkManagerAndConnect(InetAddress.getByName(IDN.toASCII(this.proxy.getForwardHost())), this.proxy.getForwardPort(), this.proxy.isUsingEPoll());
}
catch(UnknownHostException e) {
this.kickPlayerFromServer("Could not connect to server: unknown host, check if the hostname is correct");
this.disconnect("Could not connect to server: unknown host, check if the hostname is correct");
Log.error(e, "Could not connect to server");
return;
}
catch(Exception e) {
this.kickPlayerFromServer("Could not connect to server: connection failed, check if the server is running and reachable on this port");
this.disconnect("Could not connect to server: connection failed, check if the server is running and reachable on this port");
Log.error(e, "Could not connect to server");
return;
}
@ -312,9 +306,9 @@ public class NetHandlerPlayServer implements INetHandler {
}
}
public void onDisconnect(NetworkManager connection, ChatComponent reason) {
public void onDisconnect(NetworkManager connection, String reason) {
if(connection == this.server) {
this.kickPlayerFromServer(reason);
this.disconnect(reason);
Log.info("Server disconnected, kicking player %s", this.username);
}
if(connection == this.client) {
@ -334,7 +328,7 @@ public class NetHandlerPlayServer implements INetHandler {
private void handlePassword(String password) {
if(password.isEmpty()) {
if(this.wasClosed) {
this.kickPlayerFromServer("Login aborted");
this.disconnect("Login aborted");
}
else {
this.wasClosed = true;
@ -346,7 +340,7 @@ public class NetHandlerPlayServer implements INetHandler {
User stored = this.proxy.getUser(this.username);
if(stored == null) {
if(!this.proxy.canRegister()) {
this.kickPlayerFromServer("You are not whitelisted on this server");
this.disconnect("You are not whitelisted on this server");
}
else if(password.isEmpty() || password.length() < this.proxy.getMinimumPasswordLength()) {
this.setSign(ChatColor.DARK_RED + "" + ChatColor.UNDERLINE + "Too short" + ChatColor.DARK_RED + ", use", ChatColor.DARK_RED + "" + this.proxy.getMinimumPasswordLength() + "-32 characters");
@ -363,13 +357,13 @@ public class NetHandlerPlayServer implements INetHandler {
else {
if(!stored.checkPassword(password)) {
if(++this.passwordAttempts >= this.proxy.getMaximumPasswordAttempts())
this.kickPlayerFromServer("Too many password attempts");
this.disconnect("Too many password attempts");
else
this.setSign(ChatColor.DARK_RED + "" + ChatColor.UNDERLINE + "Wrong password", ChatColor.DARK_RED + "Please try again");
Log.info("%s failed password attempt %d/%d", this.username, this.passwordAttempts, this.proxy.getMaximumPasswordAttempts());
}
else if(this.proxy.isCheckingCase() && !stored.getName().equals(this.username)) {
this.kickPlayerFromServer("You used the wrong username casing, please use '" + stored.getName() + "' exactly");
this.disconnect("You used the wrong username casing, please use '" + stored.getName() + "' exactly");
Log.info("%s tried to use a different username casing", this.username);
}
else {
@ -382,20 +376,18 @@ public class NetHandlerPlayServer implements INetHandler {
public void processUpdateSign(C12PacketUpdateSign packetIn) {
if(!this.connected) {
PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.proxy);
if(!(packetIn.getLines()[0] instanceof ChatComponentText && packetIn.getLines()[1] instanceof ChatComponentText))
return;
String line1 = ((ChatComponentText)packetIn.getLines()[0]).getText();
String line2 = ((ChatComponentText)packetIn.getLines()[1]).getText();
if(line1.length() > 50 || line2.length() > 50 || !isValidString(line1) || !isValidString(line2))
String line1 = ChatColor.fromJsonString(packetIn.getLines()[0]);
String line2 = ChatColor.fromJsonString(packetIn.getLines()[1]);
if(line1 == null || line2 == null || line1.length() > 50 || line2.length() > 50 || !isValidString(line1) || !isValidString(line2))
return;
String password = line1 + line2;
this.handlePassword(password);
return;
}
ChatComponent[] lines = packetIn.getLines();
for(ChatComponent line : lines) {
if(line != null && (!(line instanceof ChatComponentText) || ((ChatComponentText)line).getText().length() > 50
|| !isValidString(((ChatComponentText)line).getText())))
String[] lines = packetIn.getLines();
for(String line : lines) {
String value = ChatColor.fromJsonString(line);
if(value == null || value.length() > 50 || !isValidString(value))
return;
}
this.sendToServer(packetIn);
@ -526,7 +518,8 @@ public class NetHandlerPlayServer implements INetHandler {
if(itemstack1 != null) {
NBTTagList pages = itemstack1.getTag().getTagList("pages", 8);
return;
if(pages.tagCount() > 50)
return;
}
}
catch(Exception exception3) {
@ -545,8 +538,11 @@ public class NetHandlerPlayServer implements INetHandler {
if(itemstack != null) {
String title = itemstack.getTag().getString("title");
if(title.length() > 50 || !isValidString(title))
return;
NBTTagList pages = itemstack.getTag().getTagList("pages", 8);
return;
if(pages.tagCount() > 50)
return;
}
}
catch(Exception exception4) {
@ -560,24 +556,26 @@ public class NetHandlerPlayServer implements INetHandler {
}
else if("MC|TrSel".equals(packetIn.getChannelName())) {
PacketBuffer packetbuffer = packetIn.getBufferData();
int i = packetbuffer.readInt();
int index = packetbuffer.readInt();
packetbuffer.release();
}
else if("MC|AdvCdm".equals(packetIn.getChannelName())) {
PacketBuffer packetbuffer = packetIn.getBufferData();
int j = packetbuffer.readByte();
int type = packetbuffer.readByte();
if(j == 0) {
if(type == 0) {
packetbuffer.readInt();
packetbuffer.readInt();
packetbuffer.readInt();
}
else if(j == 1) {
else if(type == 1) {
packetbuffer.readInt();
}
String s1 = packetbuffer.readStringFromBuffer(packetbuffer.readableBytes());
boolean flag = packetbuffer.readBoolean();
String command = packetbuffer.readStringFromBuffer(packetbuffer.readableBytes());
if(!isValidString(command))
return;
boolean track = packetbuffer.readBoolean();
packetbuffer.release();
}
else if("MC|Beacon".equals(packetIn.getChannelName())) {
@ -611,8 +609,9 @@ public class NetHandlerPlayServer implements INetHandler {
}
public void handleDisconnect(S40PacketDisconnect packetIn) {
this.server.closeChannel(packetIn.getReason());
this.kickPlayerFromServer(packetIn.getReason());
String reason = packetIn.getReason();
this.server.closeChannel("Disconnected by server: " + reason);
this.disconnect("Disconnected: '" + reason + "'");
}
public void handleJoinGame(S01PacketJoinGame packetIn) {

View file

@ -2,7 +2,6 @@ package proxy.network;
import proxy.packet.status.server.S00PacketServerInfo;
import proxy.packet.status.server.S01PacketPong;
import proxy.util.ChatComponent;
public class NetHandlerStatusClient implements INetHandler {
public void handleServerInfo(S00PacketServerInfo packetIn) {
@ -13,7 +12,7 @@ public class NetHandlerStatusClient implements INetHandler {
}
public void onDisconnect(NetworkManager connection, ChatComponent reason) {
public void onDisconnect(NetworkManager connection, String reason) {
}
}

View file

@ -5,11 +5,9 @@ import proxy.packet.status.client.C00PacketServerQuery;
import proxy.packet.status.client.C01PacketPing;
import proxy.packet.status.server.S00PacketServerInfo;
import proxy.packet.status.server.S01PacketPong;
import proxy.util.ChatComponent;
import proxy.util.ChatComponentText;
public class NetHandlerStatusServer implements INetHandler {
private static final ChatComponent EXIT_MESSAGE = new ChatComponentText("Status request has been handled.");
private static final String EXIT_MESSAGE = "Status request has been handled.";
private final Proxy proxy;
private final NetworkManager networkManager;
@ -21,7 +19,7 @@ public class NetHandlerStatusServer implements INetHandler {
this.networkManager = netManager;
}
public void onDisconnect(NetworkManager connection, ChatComponent reason) {
public void onDisconnect(NetworkManager connection, String reason) {
}
public void processServerQuery(C00PacketServerQuery packetIn) {

View file

@ -29,22 +29,20 @@ import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import proxy.util.ChatComponent;
import proxy.util.ChatComponentText;
import proxy.util.LazyLoadBase;
import proxy.util.LazyLoader;
import proxy.util.Log;
public class NetworkManager extends SimpleChannelInboundHandler<Packet>
{
public static final AttributeKey<EnumConnectionState> STATE = AttributeKey.<EnumConnectionState>valueOf("protocol");
public static final LazyLoadBase<NioEventLoopGroup> CLIENT_NIO_EVENTLOOP = new LazyLoadBase<NioEventLoopGroup>()
public static final LazyLoader<NioEventLoopGroup> CLIENT_NIO_EVENTLOOP = new LazyLoader<NioEventLoopGroup>()
{
protected NioEventLoopGroup load()
{
return new NioEventLoopGroup(0, (new ThreadFactoryBuilder()).setNameFormat("Netty Client IO #%d").setDaemon(true).build());
}
};
public static final LazyLoadBase<EpollEventLoopGroup> CLIENT_EPOLL_EVENTLOOP = new LazyLoadBase<EpollEventLoopGroup>()
public static final LazyLoader<EpollEventLoopGroup> CLIENT_EPOLL_EVENTLOOP = new LazyLoader<EpollEventLoopGroup>()
{
protected EpollEventLoopGroup load()
{
@ -58,7 +56,7 @@ public class NetworkManager extends SimpleChannelInboundHandler<Packet>
private Channel channel;
private SocketAddress socketAddress;
private INetHandler packetListener;
private ChatComponent terminationReason;
private String terminationReason;
private boolean disconnected;
public NetworkManager(EnumPacketDirection packetDirection)
@ -94,23 +92,23 @@ public class NetworkManager extends SimpleChannelInboundHandler<Packet>
public void channelInactive(ChannelHandlerContext p_channelInactive_1_) throws Exception
{
this.closeChannel(new ChatComponentText("End of stream"));
this.closeChannel("End of stream");
}
public void exceptionCaught(ChannelHandlerContext p_exceptionCaught_1_, Throwable p_exceptionCaught_2_) throws Exception
{
ChatComponentText chatcomponenttranslation;
String msg;
if (p_exceptionCaught_2_ instanceof TimeoutException)
{
chatcomponenttranslation = new ChatComponentText("Network timeout");
msg = "Network timeout";
}
else
{
chatcomponenttranslation = new ChatComponentText("Internal Exception: " + p_exceptionCaught_2_);
msg = "Internal Exception: " + p_exceptionCaught_2_;
}
this.closeChannel(chatcomponenttranslation);
this.closeChannel(msg);
}
protected void channelRead0(ChannelHandlerContext p_channelRead0_1_, Packet p_channelRead0_2_) throws Exception
@ -282,10 +280,7 @@ public class NetworkManager extends SimpleChannelInboundHandler<Packet>
return this.socketAddress;
}
/**
* Closes the channel, the parameter can be used for an exit message (not certain how it gets sent)
*/
public void closeChannel(ChatComponent message)
public void closeChannel(String message)
{
if (this.channel.isOpen())
{
@ -305,7 +300,7 @@ public class NetworkManager extends SimpleChannelInboundHandler<Packet>
{
final NetworkManager networkmanager = new NetworkManager(EnumPacketDirection.CLIENTBOUND);
Class <? extends SocketChannel > oclass;
LazyLoadBase <? extends EventLoopGroup > lazyloadbase;
LazyLoader <? extends EventLoopGroup > lazyloadbase;
if (Epoll.isAvailable() && useNativeTransport)
{
@ -358,7 +353,7 @@ public class NetworkManager extends SimpleChannelInboundHandler<Packet>
/**
* If this channel is closed, returns the exit message, null otherwise.
*/
public ChatComponent getExitMessage()
public String getExitMessage()
{
return this.terminationReason;
}
@ -421,7 +416,7 @@ public class NetworkManager extends SimpleChannelInboundHandler<Packet>
}
else if (this.getNetHandler() != null)
{
this.getNetHandler().onDisconnect(this, new ChatComponentText("Disconnected"));
this.getNetHandler().onDisconnect(this, "Disconnected");
}
}
else

View file

@ -23,7 +23,6 @@ import java.util.UUID;
import proxy.nbt.NBTSizeTracker;
import proxy.nbt.NBTTagCompound;
import proxy.util.Vec3;
import proxy.util.ChatComponent;
import proxy.util.Stack;
public class PacketBuffer extends ByteBuf
@ -77,14 +76,14 @@ public class PacketBuffer extends ByteBuf
this.writeLong(pos.getData());
}
public ChatComponent readChatComponent() throws IOException
public String readChatComponent() throws IOException
{
return ChatComponent.Serializer.jsonToComponent(this.readStringFromBuffer(32767));
return this.readStringFromBuffer(32767);
}
public void writeChatComponent(ChatComponent component) throws IOException
public void writeChatComponent(String json) throws IOException
{
this.writeString(ChatComponent.Serializer.componentToJson(component));
this.writeString(json);
}
public <T extends Enum<T>> T readEnumValue(Class<T> enumClass)

View file

@ -5,19 +5,19 @@ import java.io.IOException;
import proxy.network.NetHandlerPlayServer.ProxyLoginHandler;
import proxy.network.Packet;
import proxy.network.PacketBuffer;
import proxy.util.ChatComponent;
import proxy.util.ChatColor;
public class S00PacketDisconnect implements Packet<ProxyLoginHandler>
{
private ChatComponent reason;
private String reason;
public S00PacketDisconnect()
{
}
public S00PacketDisconnect(ChatComponent reasonIn)
public S00PacketDisconnect(String reasonIn)
{
this.reason = reasonIn;
this.reason = ChatColor.toJsonString(reasonIn);
}
/**
@ -44,8 +44,8 @@ public class S00PacketDisconnect implements Packet<ProxyLoginHandler>
handler.handleDisconnect(this);
}
public ChatComponent func_149603_c()
public String getReason()
{
return this.reason;
return ChatColor.getStringOrJson(this.reason);
}
}

View file

@ -6,12 +6,11 @@ import proxy.network.NetHandlerPlayServer;
import proxy.network.Packet;
import proxy.network.PacketBuffer;
import proxy.util.Vec3;
import proxy.util.ChatComponent;
public class C12PacketUpdateSign implements Packet<NetHandlerPlayServer>
{
private Vec3 pos;
private ChatComponent[] lines;
private String[] lines;
/**
* Reads the raw packet data from the data stream.
@ -19,13 +18,11 @@ public class C12PacketUpdateSign implements Packet<NetHandlerPlayServer>
public void readPacketData(PacketBuffer buf) throws IOException
{
this.pos = buf.readVector();
this.lines = new ChatComponent[4];
this.lines = new String[4];
for (int i = 0; i < 4; ++i)
{
String s = buf.readStringFromBuffer(384);
ChatComponent ichatcomponent = ChatComponent.Serializer.jsonToComponent(s);
this.lines[i] = ichatcomponent;
this.lines[i] = buf.readStringFromBuffer(384);
}
}
@ -38,9 +35,7 @@ public class C12PacketUpdateSign implements Packet<NetHandlerPlayServer>
for (int i = 0; i < 4; ++i)
{
ChatComponent ichatcomponent = this.lines[i];
String s = ChatComponent.Serializer.componentToJson(ichatcomponent);
buf.writeString(s);
buf.writeString(this.lines[i]);
}
}
@ -52,7 +47,7 @@ public class C12PacketUpdateSign implements Packet<NetHandlerPlayServer>
handler.processUpdateSign(this);
}
public ChatComponent[] getLines()
public String[] getLines()
{
return this.lines;
}

View file

@ -5,12 +5,11 @@ import java.io.IOException;
import proxy.network.NetHandlerPlayServer;
import proxy.network.Packet;
import proxy.network.PacketBuffer;
import proxy.util.ChatComponent;
import proxy.util.ChatComponentText;
import proxy.util.ChatColor;
public class S02PacketChat implements Packet<NetHandlerPlayServer>
{
private ChatComponent chatComponent;
private String chatComponent;
private byte type;
public S02PacketChat()
@ -19,7 +18,7 @@ public class S02PacketChat implements Packet<NetHandlerPlayServer>
public S02PacketChat(String message)
{
this.chatComponent = new ChatComponentText(message);
this.chatComponent = ChatColor.toJsonString(message);
this.type = 0;
}

View file

@ -8,7 +8,6 @@ import proxy.network.NetHandlerPlayServer;
import proxy.network.Packet;
import proxy.network.PacketBuffer;
import proxy.util.EntityData;
import proxy.util.MathHelper;
public class S0CPacketSpawnPlayer implements Packet<NetHandlerPlayServer>
{
@ -22,22 +21,6 @@ public class S0CPacketSpawnPlayer implements Packet<NetHandlerPlayServer>
private int currentItem;
private List<EntityData> field_148958_j;
public S0CPacketSpawnPlayer()
{
}
public S0CPacketSpawnPlayer(int id, UUID uuid, double x, double y, double z, float yaw, float pitch)
{
this.entityId = id;
this.playerId = uuid;
this.x = MathHelper.floor_double(x * 32.0D);
this.y = MathHelper.floor_double(y * 32.0D);
this.z = MathHelper.floor_double(z * 32.0D);
this.yaw = (byte)((int)(yaw * 256.0F / 360.0F));
this.pitch = (byte)((int)(pitch * 256.0F / 360.0F));
this.currentItem = 0;
}
/**
* Reads the raw packet data from the data stream.
*/

View file

@ -5,13 +5,12 @@ import java.io.IOException;
import proxy.network.NetHandlerPlayServer;
import proxy.network.Packet;
import proxy.network.PacketBuffer;
import proxy.util.ChatComponent;
public class S2DPacketOpenWindow implements Packet<NetHandlerPlayServer>
{
private int windowId;
private String inventoryType;
private ChatComponent windowTitle;
private String windowTitle;
private int slotCount;
private int entityId;

View file

@ -6,13 +6,12 @@ import proxy.network.NetHandlerPlayServer;
import proxy.network.Packet;
import proxy.network.PacketBuffer;
import proxy.util.Vec3;
import proxy.util.ChatComponent;
import proxy.util.ChatComponentText;
import proxy.util.ChatColor;
public class S33PacketUpdateSign implements Packet<NetHandlerPlayServer>
{
private Vec3 blockPos;
private ChatComponent[] lines;
private String[] lines;
public S33PacketUpdateSign() {
@ -20,7 +19,7 @@ public class S33PacketUpdateSign implements Packet<NetHandlerPlayServer>
public S33PacketUpdateSign(int x, int y, int z, String line1, String line2, String line3, String line4) {
this.blockPos = new Vec3(x, y, z);
this.lines = new ChatComponent[] {new ChatComponentText(line1), new ChatComponentText(line2), new ChatComponentText(line3), new ChatComponentText(line4)};
this.lines = new String[] {ChatColor.toJsonString(line1), ChatColor.toJsonString(line2), ChatColor.toJsonString(line3), ChatColor.toJsonString(line4)};
}
/**
@ -29,7 +28,7 @@ public class S33PacketUpdateSign implements Packet<NetHandlerPlayServer>
public void readPacketData(PacketBuffer buf) throws IOException
{
this.blockPos = buf.readVector();
this.lines = new ChatComponent[4];
this.lines = new String[4];
for (int i = 0; i < 4; ++i)
{

View file

@ -9,7 +9,6 @@ import java.util.List;
import proxy.network.NetHandlerPlayServer;
import proxy.network.Packet;
import proxy.network.PacketBuffer;
import proxy.util.ChatComponent;
import proxy.util.Profile;
import proxy.util.Property;
@ -18,17 +17,6 @@ public class S38PacketPlayerListItem implements Packet<NetHandlerPlayServer>
private S38PacketPlayerListItem.Action action;
private final List<S38PacketPlayerListItem.AddPlayerData> players = Lists.<S38PacketPlayerListItem.AddPlayerData>newArrayList();
public S38PacketPlayerListItem()
{
}
public S38PacketPlayerListItem(S38PacketPlayerListItem.Action actionIn, Profile profile, int ping, int mode, ChatComponent display)
{
this.action = actionIn;
this.players.add(new S38PacketPlayerListItem.AddPlayerData(profile, ping, mode, display));
}
/**
* Reads the raw packet data from the data stream.
*/
@ -42,7 +30,7 @@ public class S38PacketPlayerListItem implements Packet<NetHandlerPlayServer>
Profile gameprofile = null;
int k = 0;
int worldsettings$gametype = 0;
ChatComponent ichatcomponent = null;
String ichatcomponent = null;
switch (this.action)
{
@ -220,9 +208,9 @@ public class S38PacketPlayerListItem implements Packet<NetHandlerPlayServer>
private final int ping;
private final int gamemode;
private final Profile profile;
private final ChatComponent displayName;
private final String displayName;
public AddPlayerData(Profile profile, int pingIn, int gamemodeIn, ChatComponent displayNameIn)
public AddPlayerData(Profile profile, int pingIn, int gamemodeIn, String displayNameIn)
{
this.profile = profile;
this.ping = pingIn;
@ -245,7 +233,7 @@ public class S38PacketPlayerListItem implements Packet<NetHandlerPlayServer>
return this.gamemode;
}
public ChatComponent getDisplayName()
public String getDisplayName()
{
return this.displayName;
}

View file

@ -5,19 +5,19 @@ import java.io.IOException;
import proxy.network.NetHandlerPlayServer;
import proxy.network.Packet;
import proxy.network.PacketBuffer;
import proxy.util.ChatComponent;
import proxy.util.ChatColor;
public class S40PacketDisconnect implements Packet<NetHandlerPlayServer>
{
private ChatComponent reason;
private String reason;
public S40PacketDisconnect()
{
}
public S40PacketDisconnect(ChatComponent reasonIn)
public S40PacketDisconnect(String reasonIn)
{
this.reason = reasonIn;
this.reason = ChatColor.toJsonString(reasonIn);
}
/**
@ -44,8 +44,8 @@ public class S40PacketDisconnect implements Packet<NetHandlerPlayServer>
handler.handleDisconnect(this);
}
public ChatComponent getReason()
public String getReason()
{
return this.reason;
return ChatColor.getStringOrJson(this.reason);
}
}

View file

@ -5,39 +5,15 @@ import java.io.IOException;
import proxy.network.NetHandlerPlayServer;
import proxy.network.Packet;
import proxy.network.PacketBuffer;
import proxy.util.ChatComponent;
public class S45PacketTitle implements Packet<NetHandlerPlayServer>
{
private S45PacketTitle.Type type;
private ChatComponent message;
private String message;
private int fadeInTime;
private int displayTime;
private int fadeOutTime;
public S45PacketTitle()
{
}
public S45PacketTitle(S45PacketTitle.Type type, ChatComponent message)
{
this(type, message, -1, -1, -1);
}
public S45PacketTitle(int fadeInTime, int displayTime, int fadeOutTime)
{
this(S45PacketTitle.Type.TIMES, (ChatComponent)null, fadeInTime, displayTime, fadeOutTime);
}
public S45PacketTitle(S45PacketTitle.Type type, ChatComponent message, int fadeInTime, int displayTime, int fadeOutTime)
{
this.type = type;
this.message = message;
this.fadeInTime = fadeInTime;
this.displayTime = displayTime;
this.fadeOutTime = fadeOutTime;
}
/**
* Reads the raw packet data from the data stream.
*/

View file

@ -5,22 +5,11 @@ import java.io.IOException;
import proxy.network.NetHandlerPlayServer;
import proxy.network.Packet;
import proxy.network.PacketBuffer;
import proxy.util.ChatComponent;
public class S47PacketPlayerListHeaderFooter implements Packet<NetHandlerPlayServer>
{
private ChatComponent header;
private ChatComponent footer;
public S47PacketPlayerListHeaderFooter()
{
}
public S47PacketPlayerListHeaderFooter(ChatComponent headerIn, ChatComponent footerIn)
{
this.header = headerIn;
this.footer = footerIn;
}
private String header;
private String footer;
/**
* Reads the raw packet data from the data stream.

View file

@ -1,60 +1,41 @@
package proxy.packet.status.server;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.io.IOException;
import proxy.network.NetHandlerStatusClient;
import proxy.network.Packet;
import proxy.network.PacketBuffer;
import proxy.util.ChatComponent;
import proxy.util.ChatStyle;
import proxy.util.JsonEnumFactory;
import proxy.util.PlayerInfo;
import proxy.util.ServerInfo;
import proxy.util.VersionId;
public class S00PacketServerInfo implements Packet<NetHandlerStatusClient>
{
private static final Gson GSON = (new GsonBuilder()).registerTypeAdapter(VersionId.class, new VersionId.Serializer()).registerTypeAdapter(PlayerInfo.class, new PlayerInfo.Serializer()).registerTypeAdapter(ServerInfo.class, new ServerInfo.Serializer()).registerTypeHierarchyAdapter(ChatComponent.class, new ChatComponent.Serializer()).registerTypeHierarchyAdapter(ChatStyle.class, new ChatStyle.Serializer()).registerTypeAdapterFactory(new JsonEnumFactory()).create();
private ServerInfo response;
public class S00PacketServerInfo implements Packet<NetHandlerStatusClient> {
private String response;
public S00PacketServerInfo()
{
}
public S00PacketServerInfo() {
}
public S00PacketServerInfo(ServerInfo responseIn)
{
this.response = responseIn;
}
public S00PacketServerInfo(ServerInfo responseIn) {
this.response = responseIn.serialize();
}
/**
* Reads the raw packet data from the data stream.
*/
public void readPacketData(PacketBuffer buf) throws IOException
{
this.response = (ServerInfo)GSON.fromJson(buf.readStringFromBuffer(32767), ServerInfo.class);
}
/**
* Reads the raw packet data from the data stream.
*/
public void readPacketData(PacketBuffer buf) throws IOException {
this.response = buf.readStringFromBuffer(32767);
}
/**
* Writes the raw packet data to the data stream.
*/
public void writePacketData(PacketBuffer buf) throws IOException
{
buf.writeString(GSON.toJson((Object)this.response));
}
/**
* Writes the raw packet data to the data stream.
*/
public void writePacketData(PacketBuffer buf) throws IOException {
buf.writeString(this.response);
}
/**
* Passes this Packet on to the NetHandler for processing.
*/
public void processPacket(NetHandlerStatusClient handler)
{
handler.handleServerInfo(this);
}
public ServerInfo getResponse()
{
return this.response;
}
/**
* Passes this Packet on to the NetHandler for processing.
*/
public void processPacket(NetHandlerStatusClient handler) {
handler.handleServerInfo(this);
}
}

View file

@ -2,6 +2,10 @@ package proxy.util;
import java.util.regex.Pattern;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import com.google.gson.JsonPrimitive;
public enum ChatColor {
BLACK('0'),
DARK_BLUE('1'),
@ -33,6 +37,27 @@ public enum ChatColor {
public static String strip(String str) {
return str == null ? null : STRIP_PATTERN.matcher(str).replaceAll("");
}
public static String toJsonString(String text) {
return new JsonPrimitive(text).toString();
}
public static String fromJsonString(String json) {
JsonParser parser = new JsonParser();
JsonElement elem;
try {
elem = parser.parse(json);
}
catch(Throwable t) {
return null;
}
return elem.isJsonPrimitive() ? elem.getAsString() : null;
}
public static String getStringOrJson(String json) {
String str = fromJsonString(json);
return str == null ? "JSON:" + json : str;
}
private ChatColor(char code) {
this.value = "\u00a7" + code;

View file

@ -1,261 +0,0 @@
package proxy.util;
import com.google.common.collect.Lists;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import java.lang.reflect.Type;
import java.util.List;
import java.util.Map.Entry;
public abstract class ChatComponent
{
private List<ChatComponent> siblings = Lists.<ChatComponent>newArrayList();
private ChatStyle style;
public static class Serializer implements JsonDeserializer<ChatComponent>, JsonSerializer<ChatComponent>
{
private static final Gson GSON;
public ChatComponent deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException
{
if (p_deserialize_1_.isJsonPrimitive())
{
return new ChatComponentText(p_deserialize_1_.getAsString());
}
else if (!p_deserialize_1_.isJsonObject())
{
if (p_deserialize_1_.isJsonArray())
{
JsonArray jsonarray1 = p_deserialize_1_.getAsJsonArray();
ChatComponent ichatcomponent1 = null;
for (JsonElement jsonelement : jsonarray1)
{
ChatComponent ichatcomponent2 = this.deserialize(jsonelement, jsonelement.getClass(), p_deserialize_3_);
if (ichatcomponent1 == null)
{
ichatcomponent1 = ichatcomponent2;
}
else
{
ichatcomponent1.siblings.add(ichatcomponent2);
}
}
return ichatcomponent1;
}
else
{
throw new JsonParseException("Don\'t know how to turn " + p_deserialize_1_.toString() + " into a Component");
}
}
else
{
JsonObject jsonobject = p_deserialize_1_.getAsJsonObject();
ChatComponent ichatcomponent;
if (jsonobject.has("text"))
{
ichatcomponent = new ChatComponentText(jsonobject.get("text").getAsString());
}
else if (jsonobject.has("translate"))
{
String s = jsonobject.get("translate").getAsString();
if (jsonobject.has("with"))
{
JsonArray arr = jsonobject.getAsJsonArray("with");
Object[] args = new Object[arr.size()];
for (int z = 0; z < args.length; z++)
{
args[z] = this.deserialize(arr.get(z), p_deserialize_2_, p_deserialize_3_);
if (args[z] instanceof ChatComponentText)
{
ChatComponentText text = (ChatComponentText)args[z];
if ((((ChatComponent)text).style == null || ((ChatComponent)text).style.isEmpty()) && ((ChatComponent)text).siblings.isEmpty())
{
args[z] = text.getText();
}
}
}
ichatcomponent = new ChatComponentTranslation(s, args);
}
else
{
ichatcomponent = new ChatComponentTranslation(s);
}
}
else if (jsonobject.has("score"))
{
JsonObject jsonobject1 = jsonobject.getAsJsonObject("score");
if (!jsonobject1.has("name") || !jsonobject1.has("objective"))
{
throw new JsonParseException("A score component needs a least a name and an objective");
}
ichatcomponent = new ChatComponentScore(JsonUtils.getString(jsonobject1, "name"), JsonUtils.getString(jsonobject1, "objective"));
if (jsonobject1.has("value"))
{
((ChatComponentScore)ichatcomponent).setValue(JsonUtils.getString(jsonobject1, "value"));
}
}
else
{
if (!jsonobject.has("selector"))
{
throw new JsonParseException("Don\'t know how to turn " + p_deserialize_1_.toString() + " into a Component");
}
ichatcomponent = new ChatComponentSelector(JsonUtils.getString(jsonobject, "selector"));
}
if (jsonobject.has("extra"))
{
JsonArray jsonarray2 = jsonobject.getAsJsonArray("extra");
if (jsonarray2.size() <= 0)
{
throw new JsonParseException("Unexpected empty array of components");
}
for (int j = 0; j < jsonarray2.size(); ++j)
{
ichatcomponent.siblings.add(this.deserialize(jsonarray2.get(j), p_deserialize_2_, p_deserialize_3_));
}
}
ichatcomponent.style = (ChatStyle)p_deserialize_3_.deserialize(p_deserialize_1_, ChatStyle.class);
return ichatcomponent;
}
}
private void serializeChatStyle(ChatStyle style, JsonObject object, JsonSerializationContext ctx)
{
JsonElement jsonelement = ctx.serialize(style);
if (jsonelement.isJsonObject())
{
JsonObject jsonobject = (JsonObject)jsonelement;
for (Entry<String, JsonElement> entry : jsonobject.entrySet())
{
object.add((String)entry.getKey(), (JsonElement)entry.getValue());
}
}
}
public JsonElement serialize(ChatComponent p_serialize_1_, Type p_serialize_2_, JsonSerializationContext p_serialize_3_)
{
if (p_serialize_1_ instanceof ChatComponentText && (p_serialize_1_.style == null || p_serialize_1_.style.isEmpty()) && p_serialize_1_.siblings.isEmpty())
{
return new JsonPrimitive(((ChatComponentText)p_serialize_1_).getText());
}
else
{
JsonObject jsonobject = new JsonObject();
if (p_serialize_1_.style != null && !p_serialize_1_.style.isEmpty())
{
this.serializeChatStyle(p_serialize_1_.style, jsonobject, p_serialize_3_);
}
if (!p_serialize_1_.siblings.isEmpty())
{
JsonArray jsonarray = new JsonArray();
for (ChatComponent ichatcomponent : p_serialize_1_.siblings)
{
jsonarray.add(this.serialize((ChatComponent)ichatcomponent, ichatcomponent.getClass(), p_serialize_3_));
}
jsonobject.add("extra", jsonarray);
}
if (p_serialize_1_ instanceof ChatComponentText)
{
jsonobject.addProperty("text", ((ChatComponentText)p_serialize_1_).getText());
}
else if (p_serialize_1_ instanceof ChatComponentTranslation)
{
ChatComponentTranslation chatcomponenttranslation = (ChatComponentTranslation)p_serialize_1_;
jsonobject.addProperty("translate", chatcomponenttranslation.getKey());
if (chatcomponenttranslation.getArgs() != null && chatcomponenttranslation.getArgs().length > 0)
{
JsonArray jsonarray1 = new JsonArray();
for (Object object : chatcomponenttranslation.getArgs())
{
if (object instanceof ChatComponent)
{
jsonarray1.add(this.serialize((ChatComponent)((ChatComponent)object), object.getClass(), p_serialize_3_));
}
else
{
jsonarray1.add(new JsonPrimitive(String.valueOf(object)));
}
}
jsonobject.add("with", jsonarray1);
}
}
else if (p_serialize_1_ instanceof ChatComponentScore)
{
ChatComponentScore chatcomponentscore = (ChatComponentScore)p_serialize_1_;
JsonObject jsonobject1 = new JsonObject();
jsonobject1.addProperty("name", chatcomponentscore.getName());
jsonobject1.addProperty("objective", chatcomponentscore.getObjective());
jsonobject1.addProperty("value", chatcomponentscore.getValue());
jsonobject.add("score", jsonobject1);
}
else
{
if (!(p_serialize_1_ instanceof ChatComponentSelector))
{
throw new IllegalArgumentException("Don\'t know how to serialize " + p_serialize_1_ + " as a Component");
}
ChatComponentSelector chatcomponentselector = (ChatComponentSelector)p_serialize_1_;
jsonobject.addProperty("selector", chatcomponentselector.getSelector());
}
return jsonobject;
}
}
public static String componentToJson(ChatComponent component)
{
return GSON.toJson((Object)component);
}
public static ChatComponent jsonToComponent(String json)
{
return (ChatComponent)GSON.fromJson(json, ChatComponent.class);
}
static
{
GsonBuilder gsonbuilder = new GsonBuilder();
gsonbuilder.registerTypeHierarchyAdapter(ChatComponent.class, new ChatComponent.Serializer());
gsonbuilder.registerTypeHierarchyAdapter(ChatStyle.class, new ChatStyle.Serializer());
gsonbuilder.registerTypeAdapterFactory(new JsonEnumFactory());
GSON = gsonbuilder.create();
}
}
}

View file

@ -1,32 +0,0 @@
package proxy.util;
public class ChatComponentScore extends ChatComponent {
private final String name;
private final String objective;
private String value = "";
public ChatComponentScore(String name, String objective) {
this.name = name;
this.objective = objective;
}
public String getName() {
return this.name;
}
public String getObjective() {
return this.objective;
}
public void setValue(String value) {
this.value = value;
}
public String getValue() {
return this.value;
}
public String toString() {
return this.value;
}
}

View file

@ -1,17 +0,0 @@
package proxy.util;
public class ChatComponentSelector extends ChatComponent {
private final String selector;
public ChatComponentSelector(String selector) {
this.selector = selector;
}
public String getSelector() {
return this.selector;
}
public String toString() {
return this.selector;
}
}

View file

@ -1,17 +0,0 @@
package proxy.util;
public class ChatComponentText extends ChatComponent {
private final String text;
public ChatComponentText(String text) {
this.text = text;
}
public String getText() {
return this.text;
}
public String toString() {
return this.text;
}
}

View file

@ -1,27 +0,0 @@
package proxy.util;
public class ChatComponentTranslation extends ChatComponent {
private final String key;
private final Object[] args;
public ChatComponentTranslation(String key, Object... args) {
this.key = key;
this.args = args;
}
public String getKey() {
return this.key;
}
public Object[] getArgs() {
return this.args;
}
public String toString() {
StringBuilder sb = new StringBuilder(this.key);
for(Object arg : this.args) {
sb.append(' ').append(arg);
}
return sb.toString();
}
}

View file

@ -1,189 +0,0 @@
package proxy.util;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import java.lang.reflect.Type;
public class ChatStyle
{
private ChatColor color;
private Boolean bold;
private Boolean italic;
private Boolean underlined;
private Boolean strikethrough;
private Boolean obfuscated;
private ClickEvent chatClickEvent;
private HoverEvent chatHoverEvent;
private String insertion;
public boolean isEmpty()
{
return this.bold == null && this.italic == null && this.strikethrough == null && this.underlined == null && this.obfuscated == null && this.color == null && this.chatClickEvent == null && this.chatHoverEvent == null;
}
public static class Serializer implements JsonDeserializer<ChatStyle>, JsonSerializer<ChatStyle>
{
public ChatStyle deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException
{
if (p_deserialize_1_.isJsonObject())
{
ChatStyle chatstyle = new ChatStyle();
JsonObject jsonobject = p_deserialize_1_.getAsJsonObject();
if (jsonobject == null)
{
return null;
}
else
{
if (jsonobject.has("bold"))
{
chatstyle.bold = Boolean.valueOf(jsonobject.get("bold").getAsBoolean());
}
if (jsonobject.has("italic"))
{
chatstyle.italic = Boolean.valueOf(jsonobject.get("italic").getAsBoolean());
}
if (jsonobject.has("underlined"))
{
chatstyle.underlined = Boolean.valueOf(jsonobject.get("underlined").getAsBoolean());
}
if (jsonobject.has("strikethrough"))
{
chatstyle.strikethrough = Boolean.valueOf(jsonobject.get("strikethrough").getAsBoolean());
}
if (jsonobject.has("obfuscated"))
{
chatstyle.obfuscated = Boolean.valueOf(jsonobject.get("obfuscated").getAsBoolean());
}
if (jsonobject.has("color"))
{
chatstyle.color = (ChatColor)p_deserialize_3_.deserialize(jsonobject.get("color"), ChatColor.class);
}
if (jsonobject.has("insertion"))
{
chatstyle.insertion = jsonobject.get("insertion").getAsString();
}
if (jsonobject.has("clickEvent"))
{
JsonObject jsonobject1 = jsonobject.getAsJsonObject("clickEvent");
if (jsonobject1 != null)
{
JsonPrimitive jsonprimitive = jsonobject1.getAsJsonPrimitive("action");
ClickAction clickevent$action = jsonprimitive == null ? null : ClickAction.getByName(jsonprimitive.getAsString());
JsonPrimitive jsonprimitive1 = jsonobject1.getAsJsonPrimitive("value");
String s = jsonprimitive1 == null ? null : jsonprimitive1.getAsString();
if (clickevent$action != null && s != null && clickevent$action.isSerialized())
{
chatstyle.chatClickEvent = new ClickEvent(clickevent$action, s);
}
}
}
if (jsonobject.has("hoverEvent"))
{
JsonObject jsonobject2 = jsonobject.getAsJsonObject("hoverEvent");
if (jsonobject2 != null)
{
JsonPrimitive jsonprimitive2 = jsonobject2.getAsJsonPrimitive("action");
HoverAction hoverevent$action = jsonprimitive2 == null ? null : HoverAction.getByName(jsonprimitive2.getAsString());
ChatComponent ichatcomponent = (ChatComponent)p_deserialize_3_.deserialize(jsonobject2.get("value"), ChatComponent.class);
if (hoverevent$action != null && ichatcomponent != null && hoverevent$action.isSerialized())
{
chatstyle.chatHoverEvent = new HoverEvent(hoverevent$action, ichatcomponent);
}
}
}
return chatstyle;
}
}
else
{
return null;
}
}
public JsonElement serialize(ChatStyle p_serialize_1_, Type p_serialize_2_, JsonSerializationContext p_serialize_3_)
{
if (p_serialize_1_.isEmpty())
{
return null;
}
else
{
JsonObject jsonobject = new JsonObject();
if (p_serialize_1_.bold != null)
{
jsonobject.addProperty("bold", p_serialize_1_.bold);
}
if (p_serialize_1_.italic != null)
{
jsonobject.addProperty("italic", p_serialize_1_.italic);
}
if (p_serialize_1_.underlined != null)
{
jsonobject.addProperty("underlined", p_serialize_1_.underlined);
}
if (p_serialize_1_.strikethrough != null)
{
jsonobject.addProperty("strikethrough", p_serialize_1_.strikethrough);
}
if (p_serialize_1_.obfuscated != null)
{
jsonobject.addProperty("obfuscated", p_serialize_1_.obfuscated);
}
if (p_serialize_1_.color != null)
{
jsonobject.add("color", p_serialize_3_.serialize(p_serialize_1_.color));
}
if (p_serialize_1_.insertion != null)
{
jsonobject.add("insertion", p_serialize_3_.serialize(p_serialize_1_.insertion));
}
if (p_serialize_1_.chatClickEvent != null)
{
JsonObject jsonobject1 = new JsonObject();
jsonobject1.addProperty("action", p_serialize_1_.chatClickEvent.getAction().getName());
jsonobject1.addProperty("value", p_serialize_1_.chatClickEvent.getValue());
jsonobject.add("clickEvent", jsonobject1);
}
if (p_serialize_1_.chatHoverEvent != null)
{
JsonObject jsonobject2 = new JsonObject();
jsonobject2.addProperty("action", p_serialize_1_.chatHoverEvent.getAction().getName());
jsonobject2.add("value", p_serialize_3_.serialize(p_serialize_1_.chatHoverEvent.getValue()));
jsonobject.add("hoverEvent", jsonobject2);
}
return jsonobject;
}
}
}
}

View file

@ -1,42 +0,0 @@
package proxy.util;
import java.util.Map;
import com.google.common.collect.Maps;
public enum ClickAction {
OPEN_URL("open_url", true),
OPEN_FILE("open_file", false),
RUN_COMMAND("run_command", true),
TWITCH_USER_INFO("twitch_user_info", false),
SUGGEST_COMMAND("suggest_command", true),
CHANGE_PAGE("change_page", true);
private static final Map<String, ClickAction> LOOKUP = Maps.newHashMap();
private final boolean serialize;
private final String name;
static {
for(ClickAction action : values()) {
LOOKUP.put(action.name, action);
}
}
public static ClickAction getByName(String name) {
return LOOKUP.get(name);
}
private ClickAction(String name, boolean serialize) {
this.name = name;
this.serialize = serialize;
}
public boolean isSerialized() {
return this.serialize;
}
public String getName() {
return this.name;
}
}

View file

@ -1,19 +0,0 @@
package proxy.util;
public class ClickEvent {
private final ClickAction action;
private final String value;
public ClickEvent(ClickAction action, String value) {
this.action = action;
this.value = value;
}
public ClickAction getAction() {
return this.action;
}
public String getValue() {
return this.value;
}
}

View file

@ -1,40 +0,0 @@
package proxy.util;
import java.util.Map;
import com.google.common.collect.Maps;
public enum HoverAction {
SHOW_TEXT("show_text", true),
SHOW_ACHIEVEMENT("show_achievement", true),
SHOW_ITEM("show_item", true),
SHOW_ENTITY("show_entity", true);
private static final Map<String, HoverAction> LOOKUP = Maps.newHashMap();
private final boolean serialize;
private final String name;
static {
for(HoverAction action : values()) {
LOOKUP.put(action.name, action);
}
}
public static HoverAction getByName(String name) {
return LOOKUP.get(name);
}
private HoverAction(String name, boolean serialize) {
this.name = name;
this.serialize = serialize;
}
public boolean isSerialized() {
return this.serialize;
}
public String getName() {
return this.name;
}
}

View file

@ -1,19 +0,0 @@
package proxy.util;
public class HoverEvent {
private final HoverAction action;
private final ChatComponent value;
public HoverEvent(HoverAction action, ChatComponent value) {
this.action = action;
this.value = value;
}
public HoverAction getAction() {
return this.action;
}
public ChatComponent getValue() {
return this.value;
}
}

View file

@ -1,49 +0,0 @@
package proxy.util;
import com.google.common.collect.Maps;
import com.google.gson.Gson;
import com.google.gson.TypeAdapter;
import com.google.gson.TypeAdapterFactory;
import com.google.gson.reflect.TypeToken;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonToken;
import com.google.gson.stream.JsonWriter;
import java.io.IOException;
import java.util.Locale;
import java.util.Map;
public class JsonEnumFactory implements TypeAdapterFactory {
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
Class<T> clazz = (Class<T>)type.getRawType();
if(!clazz.isEnum())
return null;
final Map<String, T> map = Maps.newHashMap();
for(T t : clazz.getEnumConstants()) {
map.put(this.formatName(t), t);
}
return new TypeAdapter<T>() {
public void write(JsonWriter writer, T data) throws IOException {
if(data == null) {
writer.nullValue();
}
else {
writer.value(JsonEnumFactory.this.formatName(data));
}
}
public T read(JsonReader reader) throws IOException {
if(reader.peek() == JsonToken.NULL) {
reader.nextNull();
return (T)null;
}
else {
return (T)map.get(reader.nextString());
}
}
};
}
private String formatName(Object data) {
return data instanceof Enum ? ((Enum)data).name().toLowerCase(Locale.US) : data.toString().toLowerCase(Locale.US);
}
}

View file

@ -1,338 +0,0 @@
package proxy.util;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSyntaxException;
public class JsonUtils
{
/**
* Does the given JsonObject contain a string field with the given name?
*/
public static boolean isString(JsonObject p_151205_0_, String p_151205_1_)
{
return !isJsonPrimitive(p_151205_0_, p_151205_1_) ? false : p_151205_0_.getAsJsonPrimitive(p_151205_1_).isString();
}
/**
* Is the given JsonElement a string?
*/
public static boolean isString(JsonElement p_151211_0_)
{
return !p_151211_0_.isJsonPrimitive() ? false : p_151211_0_.getAsJsonPrimitive().isString();
}
public static boolean isBoolean(JsonObject p_180199_0_, String p_180199_1_)
{
return !isJsonPrimitive(p_180199_0_, p_180199_1_) ? false : p_180199_0_.getAsJsonPrimitive(p_180199_1_).isBoolean();
}
/**
* Does the given JsonObject contain an array field with the given name?
*/
public static boolean isJsonArray(JsonObject p_151202_0_, String p_151202_1_)
{
return !hasField(p_151202_0_, p_151202_1_) ? false : p_151202_0_.get(p_151202_1_).isJsonArray();
}
/**
* Does the given JsonObject contain a field with the given name whose type is primitive (String, Java primitive, or
* Java primitive wrapper)?
*/
public static boolean isJsonPrimitive(JsonObject p_151201_0_, String p_151201_1_)
{
return !hasField(p_151201_0_, p_151201_1_) ? false : p_151201_0_.get(p_151201_1_).isJsonPrimitive();
}
/**
* Does the given JsonObject contain a field with the given name?
*/
public static boolean hasField(JsonObject p_151204_0_, String p_151204_1_)
{
return p_151204_0_ == null ? false : p_151204_0_.get(p_151204_1_) != null;
}
/**
* Gets the string value of the given JsonElement. Expects the second parameter to be the name of the element's
* field if an error message needs to be thrown.
*/
public static String getString(JsonElement p_151206_0_, String p_151206_1_)
{
if (p_151206_0_.isJsonPrimitive())
{
return p_151206_0_.getAsString();
}
else
{
throw new JsonSyntaxException("Expected " + p_151206_1_ + " to be a string, was " + toString(p_151206_0_));
}
}
/**
* Gets the string value of the field on the JsonObject with the given name.
*/
public static String getString(JsonObject p_151200_0_, String p_151200_1_)
{
if (p_151200_0_.has(p_151200_1_))
{
return getString(p_151200_0_.get(p_151200_1_), p_151200_1_);
}
else
{
throw new JsonSyntaxException("Missing " + p_151200_1_ + ", expected to find a string");
}
}
/**
* Gets the string value of the field on the JsonObject with the given name, or the given default value if the field
* is missing.
*/
public static String getString(JsonObject p_151219_0_, String p_151219_1_, String p_151219_2_)
{
return p_151219_0_.has(p_151219_1_) ? getString(p_151219_0_.get(p_151219_1_), p_151219_1_) : p_151219_2_;
}
/**
* Gets the boolean value of the given JsonElement. Expects the second parameter to be the name of the element's
* field if an error message needs to be thrown.
*/
public static boolean getBoolean(JsonElement p_151216_0_, String p_151216_1_)
{
if (p_151216_0_.isJsonPrimitive())
{
return p_151216_0_.getAsBoolean();
}
else
{
throw new JsonSyntaxException("Expected " + p_151216_1_ + " to be a Boolean, was " + toString(p_151216_0_));
}
}
/**
* Gets the boolean value of the field on the JsonObject with the given name.
*/
public static boolean getBoolean(JsonObject p_151212_0_, String p_151212_1_)
{
if (p_151212_0_.has(p_151212_1_))
{
return getBoolean(p_151212_0_.get(p_151212_1_), p_151212_1_);
}
else
{
throw new JsonSyntaxException("Missing " + p_151212_1_ + ", expected to find a Boolean");
}
}
/**
* Gets the boolean value of the field on the JsonObject with the given name, or the given default value if the
* field is missing.
*/
public static boolean getBoolean(JsonObject p_151209_0_, String p_151209_1_, boolean p_151209_2_)
{
return p_151209_0_.has(p_151209_1_) ? getBoolean(p_151209_0_.get(p_151209_1_), p_151209_1_) : p_151209_2_;
}
/**
* Gets the float value of the given JsonElement. Expects the second parameter to be the name of the element's
* field if an error message needs to be thrown.
*/
public static float getFloat(JsonElement p_151220_0_, String p_151220_1_)
{
if (p_151220_0_.isJsonPrimitive() && p_151220_0_.getAsJsonPrimitive().isNumber())
{
return p_151220_0_.getAsFloat();
}
else
{
throw new JsonSyntaxException("Expected " + p_151220_1_ + " to be a Float, was " + toString(p_151220_0_));
}
}
/**
* Gets the float value of the field on the JsonObject with the given name.
*/
public static float getFloat(JsonObject p_151217_0_, String p_151217_1_)
{
if (p_151217_0_.has(p_151217_1_))
{
return getFloat(p_151217_0_.get(p_151217_1_), p_151217_1_);
}
else
{
throw new JsonSyntaxException("Missing " + p_151217_1_ + ", expected to find a Float");
}
}
/**
* Gets the float value of the field on the JsonObject with the given name, or the given default value if the field
* is missing.
*/
public static float getFloat(JsonObject p_151221_0_, String p_151221_1_, float p_151221_2_)
{
return p_151221_0_.has(p_151221_1_) ? getFloat(p_151221_0_.get(p_151221_1_), p_151221_1_) : p_151221_2_;
}
/**
* Gets the integer value of the given JsonElement. Expects the second parameter to be the name of the element's
* field if an error message needs to be thrown.
*/
public static int getInt(JsonElement p_151215_0_, String p_151215_1_)
{
if (p_151215_0_.isJsonPrimitive() && p_151215_0_.getAsJsonPrimitive().isNumber())
{
return p_151215_0_.getAsInt();
}
else
{
throw new JsonSyntaxException("Expected " + p_151215_1_ + " to be a Int, was " + toString(p_151215_0_));
}
}
/**
* Gets the integer value of the field on the JsonObject with the given name.
*/
public static int getInt(JsonObject p_151203_0_, String p_151203_1_)
{
if (p_151203_0_.has(p_151203_1_))
{
return getInt(p_151203_0_.get(p_151203_1_), p_151203_1_);
}
else
{
throw new JsonSyntaxException("Missing " + p_151203_1_ + ", expected to find a Int");
}
}
/**
* Gets the integer value of the field on the JsonObject with the given name, or the given default value if the
* field is missing.
*/
public static int getInt(JsonObject p_151208_0_, String p_151208_1_, int p_151208_2_)
{
return p_151208_0_.has(p_151208_1_) ? getInt(p_151208_0_.get(p_151208_1_), p_151208_1_) : p_151208_2_;
}
/**
* Gets the given JsonElement as a JsonObject. Expects the second parameter to be the name of the element's field
* if an error message needs to be thrown.
*/
public static JsonObject getJsonObject(JsonElement p_151210_0_, String p_151210_1_)
{
if (p_151210_0_.isJsonObject())
{
return p_151210_0_.getAsJsonObject();
}
else
{
throw new JsonSyntaxException("Expected " + p_151210_1_ + " to be a JsonObject, was " + toString(p_151210_0_));
}
}
public static JsonObject getJsonObject(JsonObject base, String key)
{
if (base.has(key))
{
return getJsonObject(base.get(key), key);
}
else
{
throw new JsonSyntaxException("Missing " + key + ", expected to find a JsonObject");
}
}
/**
* Gets the JsonObject field on the JsonObject with the given name, or the given default value if the field is
* missing.
*/
public static JsonObject getJsonObject(JsonObject p_151218_0_, String p_151218_1_, JsonObject p_151218_2_)
{
return p_151218_0_.has(p_151218_1_) ? getJsonObject(p_151218_0_.get(p_151218_1_), p_151218_1_) : p_151218_2_;
}
/**
* Gets the given JsonElement as a JsonArray. Expects the second parameter to be the name of the element's field if
* an error message needs to be thrown.
*/
public static JsonArray getJsonArray(JsonElement p_151207_0_, String p_151207_1_)
{
if (p_151207_0_.isJsonArray())
{
return p_151207_0_.getAsJsonArray();
}
else
{
throw new JsonSyntaxException("Expected " + p_151207_1_ + " to be a JsonArray, was " + toString(p_151207_0_));
}
}
/**
* Gets the JsonArray field on the JsonObject with the given name.
*/
public static JsonArray getJsonArray(JsonObject p_151214_0_, String p_151214_1_)
{
if (p_151214_0_.has(p_151214_1_))
{
return getJsonArray(p_151214_0_.get(p_151214_1_), p_151214_1_);
}
else
{
throw new JsonSyntaxException("Missing " + p_151214_1_ + ", expected to find a JsonArray");
}
}
/**
* Gets the JsonArray field on the JsonObject with the given name, or the given default value if the field is
* missing.
*/
public static JsonArray getJsonArray(JsonObject p_151213_0_, String p_151213_1_, JsonArray p_151213_2_)
{
return p_151213_0_.has(p_151213_1_) ? getJsonArray(p_151213_0_.get(p_151213_1_), p_151213_1_) : p_151213_2_;
}
/**
* Gets a human-readable description of the given JsonElement's type. For example: "a number (4)"
*/
public static String toString(JsonElement p_151222_0_)
{
String s = String.valueOf(p_151222_0_);
s = s.length() > 10 ? s.substring(0, 10) + "..." : s;
if (p_151222_0_ == null)
{
return "null (missing)";
}
else if (p_151222_0_.isJsonNull())
{
return "null (json)";
}
else if (p_151222_0_.isJsonArray())
{
return "an array (" + s + ")";
}
else if (p_151222_0_.isJsonObject())
{
return "an object (" + s + ")";
}
else
{
if (p_151222_0_.isJsonPrimitive())
{
JsonPrimitive jsonprimitive = p_151222_0_.getAsJsonPrimitive();
if (jsonprimitive.isNumber())
{
return "a number (" + s + ")";
}
if (jsonprimitive.isBoolean())
{
return "a boolean (" + s + ")";
}
}
return s;
}
}
}

View file

@ -1,6 +1,6 @@
package proxy.util;
public abstract class LazyLoadBase<T> {
public abstract class LazyLoader<T> {
private T value;
private boolean isLoaded = false;
@ -9,7 +9,6 @@ public abstract class LazyLoadBase<T> {
this.isLoaded = true;
this.value = this.load();
}
return this.value;
}

View file

@ -1,559 +0,0 @@
package proxy.util;
import java.util.Random;
import java.util.UUID;
public class MathHelper
{
public static final float SQRT_2 = sqrt_float(2.0F);
/**
* A table of sin values computed from 0 (inclusive) to 2*pi (exclusive), with steps of 2*PI / 65536.
*/
private static final float[] SIN_TABLE = new float[65536];
/**
* Though it looks like an array, this is really more like a mapping. Key (index of this array) is the upper 5 bits
* of the result of multiplying a 32-bit unsigned integer by the B(2, 5) De Bruijn sequence 0x077CB531. Value
* (value stored in the array) is the unique index (from the right) of the leftmost one-bit in a 32-bit unsigned
* integer that can cause the upper 5 bits to get that value. Used for highly optimized "find the log-base-2 of
* this number" calculations.
*/
private static final int[] multiplyDeBruijnBitPosition;
private static final double field_181163_d;
private static final double[] field_181164_e;
private static final double[] field_181165_f;
/**
* sin looked up in a table
*/
public static float sin(float p_76126_0_)
{
return SIN_TABLE[(int)(p_76126_0_ * 10430.378F) & 65535];
}
/**
* cos looked up in the sin table with the appropriate offset
*/
public static float cos(float value)
{
return SIN_TABLE[(int)(value * 10430.378F + 16384.0F) & 65535];
}
public static float sqrt_float(float value)
{
return (float)Math.sqrt((double)value);
}
public static float sqrt_double(double value)
{
return (float)Math.sqrt(value);
}
/**
* Returns the greatest integer less than or equal to the float argument
*/
public static int floor_float(float value)
{
int i = (int)value;
return value < (float)i ? i - 1 : i;
}
/**
* returns par0 cast as an int, and no greater than Integer.MAX_VALUE-1024
*/
public static int truncateDoubleToInt(double value)
{
return (int)(value + 1024.0D) - 1024;
}
/**
* Returns the greatest integer less than or equal to the double argument
*/
public static int floor_double(double value)
{
int i = (int)value;
return value < (double)i ? i - 1 : i;
}
/**
* Long version of floor_double
*/
public static long floor_double_long(double value)
{
long i = (long)value;
return value < (double)i ? i - 1L : i;
}
public static int func_154353_e(double value)
{
return (int)(value >= 0.0D ? value : -value + 1.0D);
}
public static float abs(float value)
{
return value >= 0.0F ? value : -value;
}
/**
* Returns the unsigned value of an int.
*/
public static int abs_int(int value)
{
return value >= 0 ? value : -value;
}
public static int ceiling_float_int(float value)
{
int i = (int)value;
return value > (float)i ? i + 1 : i;
}
public static int ceiling_double_int(double value)
{
int i = (int)value;
return value > (double)i ? i + 1 : i;
}
/**
* Returns the value of the first parameter, clamped to be within the lower and upper limits given by the second and
* third parameters.
*/
public static int clamp_int(int num, int min, int max)
{
return num < min ? min : (num > max ? max : num);
}
/**
* Returns the value of the first parameter, clamped to be within the lower and upper limits given by the second and
* third parameters
*/
public static float clamp_float(float num, float min, float max)
{
return num < min ? min : (num > max ? max : num);
}
public static double clamp_double(double num, double min, double max)
{
return num < min ? min : (num > max ? max : num);
}
public static double denormalizeClamp(double lowerBnd, double upperBnd, double slide)
{
return slide < 0.0D ? lowerBnd : (slide > 1.0D ? upperBnd : lowerBnd + (upperBnd - lowerBnd) * slide);
}
/**
* Maximum of the absolute value of two numbers.
*/
public static double abs_max(double p_76132_0_, double p_76132_2_)
{
if (p_76132_0_ < 0.0D)
{
p_76132_0_ = -p_76132_0_;
}
if (p_76132_2_ < 0.0D)
{
p_76132_2_ = -p_76132_2_;
}
return p_76132_0_ > p_76132_2_ ? p_76132_0_ : p_76132_2_;
}
/**
* Buckets an integer with specifed bucket sizes. Args: i, bucketSize
*/
public static int bucketInt(int p_76137_0_, int p_76137_1_)
{
return p_76137_0_ < 0 ? -((-p_76137_0_ - 1) / p_76137_1_) - 1 : p_76137_0_ / p_76137_1_;
}
public static int getRandomIntegerInRange(Random p_76136_0_, int p_76136_1_, int p_76136_2_)
{
return p_76136_1_ >= p_76136_2_ ? p_76136_1_ : p_76136_0_.nextInt(p_76136_2_ - p_76136_1_ + 1) + p_76136_1_;
}
public static float randomFloatClamp(Random p_151240_0_, float p_151240_1_, float p_151240_2_)
{
return p_151240_1_ >= p_151240_2_ ? p_151240_1_ : p_151240_0_.nextFloat() * (p_151240_2_ - p_151240_1_) + p_151240_1_;
}
public static double getRandomDoubleInRange(Random p_82716_0_, double p_82716_1_, double p_82716_3_)
{
return p_82716_1_ >= p_82716_3_ ? p_82716_1_ : p_82716_0_.nextDouble() * (p_82716_3_ - p_82716_1_) + p_82716_1_;
}
public static double average(long[] values)
{
long i = 0L;
for (long j : values)
{
i += j;
}
return (double)i / (double)values.length;
}
public static boolean epsilonEquals(float p_180185_0_, float p_180185_1_)
{
return abs(p_180185_1_ - p_180185_0_) < 1.0E-5F;
}
public static int normalizeAngle(int p_180184_0_, int p_180184_1_)
{
return (p_180184_0_ % p_180184_1_ + p_180184_1_) % p_180184_1_;
}
/**
* the angle is reduced to an angle between -180 and +180 by mod, and a 360 check
*/
public static float wrapAngleTo180_float(float value)
{
value = value % 360.0F;
if (value >= 180.0F)
{
value -= 360.0F;
}
if (value < -180.0F)
{
value += 360.0F;
}
return value;
}
/**
* the angle is reduced to an angle between -180 and +180 by mod, and a 360 check
*/
public static double wrapAngleTo180_double(double value)
{
value = value % 360.0D;
if (value >= 180.0D)
{
value -= 360.0D;
}
if (value < -180.0D)
{
value += 360.0D;
}
return value;
}
/**
* parses the string as integer or returns the second parameter if it fails
*/
public static int parseIntWithDefault(String p_82715_0_, int p_82715_1_)
{
try
{
return Integer.parseInt(p_82715_0_);
}
catch (Throwable var3)
{
return p_82715_1_;
}
}
/**
* parses the string as integer or returns the second parameter if it fails. this value is capped to par2
*/
public static int parseIntWithDefaultAndMax(String p_82714_0_, int p_82714_1_, int p_82714_2_)
{
return Math.max(p_82714_2_, parseIntWithDefault(p_82714_0_, p_82714_1_));
}
/**
* parses the string as double or returns the second parameter if it fails.
*/
public static double parseDoubleWithDefault(String p_82712_0_, double p_82712_1_)
{
try
{
return Double.parseDouble(p_82712_0_);
}
catch (Throwable var4)
{
return p_82712_1_;
}
}
public static double parseDoubleWithDefaultAndMax(String p_82713_0_, double p_82713_1_, double p_82713_3_)
{
return Math.max(p_82713_3_, parseDoubleWithDefault(p_82713_0_, p_82713_1_));
}
/**
* Returns the input value rounded up to the next highest power of two.
*/
public static int roundUpToPowerOfTwo(int value)
{
int i = value - 1;
i = i | i >> 1;
i = i | i >> 2;
i = i | i >> 4;
i = i | i >> 8;
i = i | i >> 16;
return i + 1;
}
/**
* Is the given value a power of two? (1, 2, 4, 8, 16, ...)
*/
private static boolean isPowerOfTwo(int value)
{
return value != 0 && (value & value - 1) == 0;
}
/**
* Uses a B(2, 5) De Bruijn sequence and a lookup table to efficiently calculate the log-base-two of the given
* value. Optimized for cases where the input value is a power-of-two. If the input value is not a power-of-two,
* then subtract 1 from the return value.
*/
private static int calculateLogBaseTwoDeBruijn(int value)
{
value = isPowerOfTwo(value) ? value : roundUpToPowerOfTwo(value);
return multiplyDeBruijnBitPosition[(int)((long)value * 125613361L >> 27) & 31];
}
/**
* Efficiently calculates the floor of the base-2 log of an integer value. This is effectively the index of the
* highest bit that is set. For example, if the number in binary is 0...100101, this will return 5.
*/
public static int calculateLogBaseTwo(int value)
{
return calculateLogBaseTwoDeBruijn(value) - (isPowerOfTwo(value) ? 0 : 1);
}
public static int roundUp(int p_154354_0_, int p_154354_1_)
{
if (p_154354_1_ == 0)
{
return 0;
}
else if (p_154354_0_ == 0)
{
return p_154354_1_;
}
else
{
if (p_154354_0_ < 0)
{
p_154354_1_ *= -1;
}
int i = p_154354_0_ % p_154354_1_;
return i == 0 ? p_154354_0_ : p_154354_0_ + p_154354_1_ - i;
}
}
public static int func_180183_b(float p_180183_0_, float p_180183_1_, float p_180183_2_)
{
return func_180181_b(floor_float(p_180183_0_ * 255.0F), floor_float(p_180183_1_ * 255.0F), floor_float(p_180183_2_ * 255.0F));
}
public static int func_180181_b(int p_180181_0_, int p_180181_1_, int p_180181_2_)
{
int lvt_3_1_ = (p_180181_0_ << 8) + p_180181_1_;
lvt_3_1_ = (lvt_3_1_ << 8) + p_180181_2_;
return lvt_3_1_;
}
public static int func_180188_d(int p_180188_0_, int p_180188_1_)
{
int i = (p_180188_0_ & 16711680) >> 16;
int j = (p_180188_1_ & 16711680) >> 16;
int k = (p_180188_0_ & 65280) >> 8;
int l = (p_180188_1_ & 65280) >> 8;
int i1 = (p_180188_0_ & 255) >> 0;
int j1 = (p_180188_1_ & 255) >> 0;
int k1 = (int)((float)i * (float)j / 255.0F);
int l1 = (int)((float)k * (float)l / 255.0F);
int i2 = (int)((float)i1 * (float)j1 / 255.0F);
return p_180188_0_ & -16777216 | k1 << 16 | l1 << 8 | i2;
}
public static double func_181162_h(double p_181162_0_)
{
return p_181162_0_ - Math.floor(p_181162_0_);
}
public static long getCoordinateRandom(int x, int y, int z)
{
long i = (long)(x * 3129871) ^ (long)z * 116129781L ^ (long)y;
i = i * i * 42317861L + i * 11L;
return i;
}
public static UUID getRandomUuid(Random rand)
{
long i = rand.nextLong() & -61441L | 16384L;
long j = rand.nextLong() & 4611686018427387903L | Long.MIN_VALUE;
return new UUID(i, j);
}
public static double func_181160_c(double p_181160_0_, double p_181160_2_, double p_181160_4_)
{
return (p_181160_0_ - p_181160_2_) / (p_181160_4_ - p_181160_2_);
}
public static double atan2(double p_181159_0_, double p_181159_2_)
{
double d0 = p_181159_2_ * p_181159_2_ + p_181159_0_ * p_181159_0_;
if (Double.isNaN(d0))
{
return Double.NaN;
}
else
{
boolean flag = p_181159_0_ < 0.0D;
if (flag)
{
p_181159_0_ = -p_181159_0_;
}
boolean flag1 = p_181159_2_ < 0.0D;
if (flag1)
{
p_181159_2_ = -p_181159_2_;
}
boolean flag2 = p_181159_0_ > p_181159_2_;
if (flag2)
{
double d1 = p_181159_2_;
p_181159_2_ = p_181159_0_;
p_181159_0_ = d1;
}
double d9 = func_181161_i(d0);
p_181159_2_ = p_181159_2_ * d9;
p_181159_0_ = p_181159_0_ * d9;
double d2 = field_181163_d + p_181159_0_;
int i = (int)Double.doubleToRawLongBits(d2);
double d3 = field_181164_e[i];
double d4 = field_181165_f[i];
double d5 = d2 - field_181163_d;
double d6 = p_181159_0_ * d4 - p_181159_2_ * d5;
double d7 = (6.0D + d6 * d6) * d6 * 0.16666666666666666D;
double d8 = d3 + d7;
if (flag2)
{
d8 = (Math.PI / 2D) - d8;
}
if (flag1)
{
d8 = Math.PI - d8;
}
if (flag)
{
d8 = -d8;
}
return d8;
}
}
public static double func_181161_i(double p_181161_0_)
{
double d0 = 0.5D * p_181161_0_;
long i = Double.doubleToRawLongBits(p_181161_0_);
i = 6910469410427058090L - (i >> 1);
p_181161_0_ = Double.longBitsToDouble(i);
p_181161_0_ = p_181161_0_ * (1.5D - d0 * p_181161_0_ * p_181161_0_);
return p_181161_0_;
}
public static int hsvToRGB(float p_181758_0_, float p_181758_1_, float p_181758_2_)
{
int i = (int)(p_181758_0_ * 6.0F) % 6;
float f = p_181758_0_ * 6.0F - (float)i;
float f1 = p_181758_2_ * (1.0F - p_181758_1_);
float f2 = p_181758_2_ * (1.0F - f * p_181758_1_);
float f3 = p_181758_2_ * (1.0F - (1.0F - f) * p_181758_1_);
float f4;
float f5;
float f6;
switch (i)
{
case 0:
f4 = p_181758_2_;
f5 = f3;
f6 = f1;
break;
case 1:
f4 = f2;
f5 = p_181758_2_;
f6 = f1;
break;
case 2:
f4 = f1;
f5 = p_181758_2_;
f6 = f3;
break;
case 3:
f4 = f1;
f5 = f2;
f6 = p_181758_2_;
break;
case 4:
f4 = f3;
f5 = f1;
f6 = p_181758_2_;
break;
case 5:
f4 = p_181758_2_;
f5 = f1;
f6 = f2;
break;
default:
throw new RuntimeException("Something went wrong when converting from HSV to RGB. Input was " + p_181758_0_ + ", " + p_181758_1_ + ", " + p_181758_2_);
}
int j = clamp_int((int)(f4 * 255.0F), 0, 255);
int k = clamp_int((int)(f5 * 255.0F), 0, 255);
int l = clamp_int((int)(f6 * 255.0F), 0, 255);
return j << 16 | k << 8 | l;
}
static
{
for (int i = 0; i < 65536; ++i)
{
SIN_TABLE[i] = (float)Math.sin((double)i * Math.PI * 2.0D / 65536.0D);
}
multiplyDeBruijnBitPosition = new int[] {0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8, 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9};
field_181163_d = Double.longBitsToDouble(4805340802404319232L);
field_181164_e = new double[257];
field_181165_f = new double[257];
for (int j = 0; j < 257; ++j)
{
double d0 = (double)j / 256.0D;
double d1 = Math.asin(d0);
field_181165_f[j] = Math.cos(d1);
field_181164_e[j] = d1;
}
}
}

View file

@ -1,78 +0,0 @@
package proxy.util;
import java.lang.reflect.Type;
import java.util.UUID;
import com.google.gson.JsonArray;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
public class PlayerInfo {
private final int capacity;
private final int online;
private Profile[] list;
public PlayerInfo(int capacity, int online) {
this.capacity = capacity;
this.online = online;
}
public int getCapacity() {
return this.capacity;
}
public int getOnline() {
return this.online;
}
public Profile[] getList() {
return this.list;
}
public void setList(Profile[] list) {
this.list = list;
}
public static class Serializer implements JsonDeserializer<PlayerInfo>, JsonSerializer<PlayerInfo> {
public PlayerInfo deserialize(JsonElement elem, Type type, JsonDeserializationContext context) throws JsonParseException {
JsonObject obj = JsonUtils.getJsonObject(elem, "players");
PlayerInfo info = new PlayerInfo(JsonUtils.getInt(obj, "max"), JsonUtils.getInt(obj, "online"));
if(JsonUtils.isJsonArray(obj, "sample")) {
JsonArray arr = JsonUtils.getJsonArray(obj, "sample");
if(arr.size() > 0) {
Profile[] list = new Profile[arr.size()];
for(int z = 0; z < list.length; z++) {
JsonObject profile = JsonUtils.getJsonObject(arr.get(z), "player[" + z + "]");
String id = JsonUtils.getString(profile, "id");
list[z] = new Profile(UUID.fromString(id), JsonUtils.getString(profile, "name"));
}
info.setList(list);
}
}
return info;
}
public JsonElement serialize(PlayerInfo info, Type type, JsonSerializationContext context) {
JsonObject obj = new JsonObject();
obj.addProperty("max", info.getCapacity());
obj.addProperty("online", info.getOnline());
if(info.getList() != null && info.getList().length > 0) {
JsonArray arr = new JsonArray();
for(int z = 0; z < info.getList().length; z++) {
JsonObject profile = new JsonObject();
UUID id = info.getList()[z].getId();
profile.addProperty("id", id == null ? "" : id.toString());
profile.addProperty("name", info.getList()[z].getName());
arr.add(profile);
}
obj.add("sample", arr);
}
return obj;
}
}
}

View file

@ -2,10 +2,13 @@ package proxy.util;
import java.util.UUID;
import com.google.common.collect.LinkedHashMultimap;
import com.google.common.collect.Multimap;
public class Profile {
private final UUID id;
private final String name;
private final PropertyMap properties = new PropertyMap();
private final Multimap<String, Property> properties = LinkedHashMultimap.create();
private boolean legacy;
public Profile(UUID id, String name) {
@ -21,7 +24,7 @@ public class Profile {
return this.name;
}
public PropertyMap getProperties() {
public Multimap<String, Property> getProperties() {
return this.properties;
}
}

View file

@ -1,67 +0,0 @@
package proxy.util;
import com.google.common.collect.ForwardingMultimap;
import com.google.common.collect.LinkedHashMultimap;
import com.google.common.collect.Multimap;
import com.google.gson.JsonArray;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import java.lang.reflect.Type;
import java.util.Map.Entry;
public class PropertyMap extends ForwardingMultimap<String, Property> {
private final Multimap<String, Property> properties = LinkedHashMultimap.create();
protected Multimap<String, Property> delegate() {
return this.properties;
}
public static class Serializer implements JsonSerializer<PropertyMap>, JsonDeserializer<PropertyMap> {
public PropertyMap deserialize(JsonElement elem, Type type, JsonDeserializationContext context) throws JsonParseException {
PropertyMap properties = new PropertyMap();
if(elem instanceof JsonObject) {
JsonObject obj = (JsonObject)elem;
for(Entry<String, JsonElement> entry : obj.entrySet()) {
if(entry.getValue() instanceof JsonArray) {
for(JsonElement element : (JsonArray)entry.getValue()) {
properties.put(entry.getKey(), new Property(entry.getKey(), element.getAsString()));
}
}
}
}
else if(elem instanceof JsonArray) {
for(JsonElement element : (JsonArray)elem) {
if(element instanceof JsonObject) {
JsonObject obj = (JsonObject)element;
String name = obj.getAsJsonPrimitive("name").getAsString();
String value = obj.getAsJsonPrimitive("value").getAsString();
if(obj.has("signature"))
properties.put(name, new Property(name, value, obj.getAsJsonPrimitive("signature").getAsString()));
else
properties.put(name, new Property(name, value));
}
}
}
return properties;
}
public JsonElement serialize(PropertyMap properties, Type type, JsonSerializationContext context) {
JsonArray arr = new JsonArray();
for(Property property : properties.values()) {
JsonObject obj = new JsonObject();
obj.addProperty("name", property.getName());
obj.addProperty("value", property.getValue());
if(property.getSignature() != null)
obj.addProperty("signature", property.getSignature());
arr.add(obj);
}
return arr;
}
}
}

View file

@ -1,78 +1,83 @@
package proxy.util;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import java.lang.reflect.Type;
import proxy.Proxy;
import java.util.UUID;
public class ServerInfo {
private ChatComponent motd;
private PlayerInfo info;
private VersionId version;
private static final Gson GSON = new GsonBuilder().create();
private final String name;
private final int protocol;
private String motd = "";
private int capacity;
private int online;
private Profile[] list;
private String icon;
public ChatComponent getMotd() {
return this.motd;
public ServerInfo(String name, int protocol) {
this.name = name;
this.protocol = protocol;
}
public void setMotd(ChatComponent motd) {
public void setMotd(String motd) {
this.motd = motd;
}
public PlayerInfo getInfo() {
return this.info;
public void setCapacity(int capacity) {
this.capacity = capacity;
}
public void setInfo(PlayerInfo info) {
this.info = info;
public void setOnline(int online) {
this.online = online;
}
public VersionId getVersion() {
return this.version;
}
public void setVersion(VersionId version) {
this.version = version;
public void setList(String[] lines) {
if(lines == null) {
this.list = null;
}
else {
this.list = new Profile[Math.min(lines.length, 12)];
for(int z = 0; z < this.list.length; z++) {
this.list[z] = new Profile(Proxy.getOfflineUUID(lines[z]), lines[z]);
}
}
}
public void setIcon(String icon) {
this.icon = icon;
}
public String getIcon() {
return this.icon;
}
public static class Serializer implements JsonDeserializer<ServerInfo>, JsonSerializer<ServerInfo> {
public ServerInfo deserialize(JsonElement elem, Type type, JsonDeserializationContext context) throws JsonParseException {
JsonObject obj = JsonUtils.getJsonObject(elem, "status");
ServerInfo status = new ServerInfo();
if(obj.has("description"))
status.setMotd((ChatComponent)context.deserialize(obj.get("description"), ChatComponent.class));
if(obj.has("players"))
status.setInfo((PlayerInfo)context.deserialize(obj.get("players"), PlayerInfo.class));
if(obj.has("version"))
status.setVersion((VersionId)context.deserialize(obj.get("version"), VersionId.class));
if(obj.has("favicon"))
status.setIcon(JsonUtils.getString(obj, "favicon"));
return status;
}
public JsonElement serialize(ServerInfo status, Type type, JsonSerializationContext context) {
JsonObject obj = new JsonObject();
if(status.getMotd() != null)
obj.add("description", context.serialize(status.getMotd()));
if(status.getInfo() != null)
obj.add("players", context.serialize(status.getInfo()));
if(status.getVersion() != null)
obj.add("version", context.serialize(status.getVersion()));
if(status.getIcon() != null)
obj.addProperty("favicon", status.getIcon());
return obj;
public String serialize() {
JsonObject obj = new JsonObject();
obj.addProperty("description", this.motd == null ? "" : this.motd);
JsonObject info = new JsonObject();
info.addProperty("max", this.capacity);
info.addProperty("online", this.online);
if(this.list != null && this.list.length > 0) {
JsonArray arr = new JsonArray();
for(int z = 0; z < this.list.length; z++) {
JsonObject profile = new JsonObject();
UUID id = this.list[z].getId();
profile.addProperty("id", id == null ? "" : id.toString());
profile.addProperty("name", this.list[z].getName());
arr.add(profile);
}
info.add("sample", arr);
}
obj.add("players", info);
JsonObject version = new JsonObject();
version.addProperty("name", this.name);
version.addProperty("protocol", this.protocol);
obj.add("version", version);
if(this.icon != null)
obj.addProperty("favicon", this.icon);
return GSON.toJson(obj);
}
}

View file

@ -1,43 +0,0 @@
package proxy.util;
import java.lang.reflect.Type;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
public class VersionId {
private final String name;
private final int protocol;
public VersionId(String name, int protocol) {
this.name = name;
this.protocol = protocol;
}
public String getName() {
return this.name;
}
public int getProtocol() {
return this.protocol;
}
public static class Serializer implements JsonDeserializer<VersionId>, JsonSerializer<VersionId> {
public VersionId deserialize(JsonElement elem, Type type, JsonDeserializationContext context) throws JsonParseException {
JsonObject obj = JsonUtils.getJsonObject(elem, "version");
return new VersionId(JsonUtils.getString(obj, "name"), JsonUtils.getInt(obj, "protocol"));
}
public JsonElement serialize(VersionId version, Type type, JsonSerializationContext context) {
JsonObject obj = new JsonObject();
obj.addProperty("name", version.getName());
obj.addProperty("protocol", (Number)Integer.valueOf(version.getProtocol()));
return obj;
}
}
}