diff --git a/proxy/src/main/java/proxy/Proxy.java b/proxy/src/main/java/proxy/Proxy.java index 82b97da..dcab6c3 100755 --- a/proxy/src/main/java/proxy/Proxy.java +++ b/proxy/src/main/java/proxy/Proxy.java @@ -75,8 +75,6 @@ import proxy.handler.HandshakeHandler; import proxy.handler.ProxyHandler; import proxy.handler.Handler.ThreadQuickExitException; import proxy.network.Connection; -import proxy.packet.C01PacketChatMessage; -import proxy.packet.S02PacketChat; import proxy.packet.S38PacketPlayerListItem; import proxy.packet.S38PacketPlayerListItem.Action; import proxy.packet.S40PacketDisconnect; @@ -324,7 +322,8 @@ public class Proxy { final String cmd = line; Proxy.this.schedule(new Runnable() { public void run() { - Proxy.this.run(null, cmd); + String msg = Formatter.filterSpaces(cmd); + Proxy.this.runCommand(null, msg.isEmpty() ? new String[] {"phelp"} : msg.split(" "), msg); } }); } @@ -630,39 +629,9 @@ public class Proxy { this.register(new CommandSave()); this.register(new CommandSeed()); - for(String cmd : new String[] {"?", "about", "ban", "ban-ip", "banlist", "icanhasbukkit", "me", "pardon", "pardon-ip", "pl", "plugins", "restart", "rl", "say", "scoreboard", "stop", "tell", "tellraw", "timings", "title", "toggledownfall", "trigger", "ver", "version", "whitelist", "clone", "debug", "fill", "testfor", "testforblock", "testforblocks", "setidletimeout", "stats", "save-off", "save-on", "save-all", "spreadplayers"}) { + for(String cmd : new String[] {"?", "about", "ban", "ban-ip", "banlist", "icanhasbukkit", "me", "pardon", "pardon-ip", "pl", "plugins", "restart", "rl", "say", "scoreboard", "stop", "tell", "tellraw", "timings", "title", "toggledownfall", "trigger", "ver", "version", "whitelist", "clone", "debug", "fill", "testfor", "testforblock", "testforblocks", "setidletimeout", "stats", "save-off", "save-on", "save-all"}) { this.register(new CommandDummy(cmd)); } - - this.register(new CommandPass("achievement", " [player]", "Gives takes achievements to players or takes them")); - this.register(new CommandPass("blockdata", " ", "Sets data of a tile entity")); - this.register(new CommandPass("clear", "[player] [item] [data] [maxCount] [dataTag]", "Clears items in the inventory of a player")); - this.register(new CommandPass("defaultgamemode", "", "Sets the default game mode of the server")); - this.register(new CommandPass("deop", "", "Removes a player from the operator list")); - this.register(new CommandPass("difficulty", "", "Sets the difficulty of the server")); - this.register(new CommandPass("effect", " [seconds] [amplifier] [hideParticles] OR /effect clear", "Gives entities status effects or removes them")); - this.register(new CommandPass("enchant", " [level]", "Enchants the item in the hand of a player")); - this.register(new CommandPass("entitydata", " ", "Sets data of an entity")); - this.register(new CommandPass("execute", " OR /execute detect ", "Runs a command as another entity")); - this.register(new CommandPass("gamemode", " [player]", "Sets the gamemode of a player")); - this.register(new CommandPass("gamerule", " [value]", "Sets a gamerule of the server")); - this.register(new CommandPass("give", " [amount] [data] [dataTag]", "Gives an item to a player")); - this.register(new CommandPass("kill", "[player|entity]", "Kills entities")); - this.register(new CommandPass("op", "", "Adds a player to the operator list")); - this.register(new CommandPass("particle", " [count] [mode]", "Displays particle effects to players")); - this.register(new CommandPass("playsound", " [x] [y] [z] [volume] [pitch] [minimumVolume]", "Plays sound effects to players")); - this.register(new CommandPass("replaceitem", " ...", "Replaces an item in the inventory of an entity")); - this.register(new CommandPass("setblock", " [dataValue] [oldBlockHandling] [dataTag]", "Sets a block in the world")); - this.register(new CommandPass("setworldspawn", "[ ]", "Sets the spawn point of the world")); - this.register(new CommandPass("spawnpoint", "[player] [ ]", "Sets the spawn point of a player")); - this.register(new CommandPass("summon", " [x] [y] [z] [dataTag]", "Creates a new entity")); - this.register(new CommandPass("time", " ", "Sets the time of the world or displays it")); - this.register(new CommandPass("tp", "[target player] OR /tp [target player] [ ]", "Teleports entities to antother entity or a position")); - this.register(new CommandPass("weather", " [duration in seconds]", "Changes the current weather of the world")); - this.register(new CommandPass("worldborder", " ...", "Sets parameters of the world border")); - this.register(new CommandPass("xp", " [player] OR /xp L [player]", "Gives experience to player or takes it")); - - this.register(new CommandPass("tps", null, "Displays the current ticks per second of the server")); } public Map getCommands() { @@ -697,7 +666,7 @@ public class Proxy { this.running = false; } - private boolean runCommand(ProxyHandler player, String[] args, String line) { + public boolean runCommand(ProxyHandler player, String[] args, String line) { if(args.length == 0) return false; Command cmd = this.commands.get(args[0].toLowerCase(Locale.US)); @@ -742,82 +711,4 @@ public class Proxy { } return true; } - - public void run(ProxyHandler player, String line) { - String msg = Formatter.filterSpaces(line); - if(msg.isEmpty()) - return; - if(msg.startsWith("/")) { - msg = msg.substring(1); - String[] args = msg.split(" "); - if(args[0].indexOf(':') != -1) { - if(player != null) - player.sendToServer(new C01PacketChatMessage("/")); - return; - } - if(!this.runCommand(player, args, msg) && player != null) - player.sendToServer(new C01PacketChatMessage(line)); - } - else { - msg = String.format(Formatter.BLUE + "%s" + Formatter.DARK_GRAY + ": " + Formatter.GRAY + "%s", player != null ? player.getUsername() : "#CONSOLE#", line); - this.sendPacket(new S02PacketChat(msg, false)); - Log.info(Formatter.strip(msg)); - } - } - - private List getCompletions(ProxyHandler player, String[] args, String[] serverMatches) { - if(args.length <= 1) - return null; - Command cmd = this.commands.get(args[0].toLowerCase(Locale.US)); - if(cmd == null) - return null; - List list = Lists.newArrayList(); - if(!cmd.canUse(player)) - return list; - String[] argv = new String[args.length - 1]; - System.arraycopy(args, 1, argv, 0, argv.length); - Iterable comps = cmd.complete(this, player, argv, serverMatches); - if(comps == null) - return list; - String param = args[args.length - 1]; - for(String comp : comps) { - if(comp.regionMatches(true, 0, param, 0, param.length())) - list.add(comp); - } - return list; - } - - public List complete(ProxyHandler player, String completion, String[] serverMatches) { - List list = null; - if(completion.startsWith("/")) { - if(completion.indexOf(' ') == -1) { - list = completion.indexOf(':') != -1 ? Lists.newArrayList() : Lists.newArrayList(serverMatches); - for(Iterator iter = list.iterator(); iter.hasNext();) { - String cmd = iter.next(); - if(cmd.isEmpty() || cmd.indexOf(':') != -1 || this.commands.containsKey(cmd.substring(1).toLowerCase(Locale.US))) - iter.remove(); - } - for(Command cmd : this.commands.values()) { - String command = "/" + cmd.getName(); - if(cmd.canUse(player) && command.regionMatches(true, 0, completion, 0, completion.length())) - list.add(command); - } - Collections.sort(list); - } - else { - String[] args = completion.substring(1).split(" ", -1); - list = args[0].indexOf(':') != -1 ? Lists.newArrayList() : this.getCompletions(player, args, serverMatches); - } - } - else { - String[] args = completion.split(" ", -1); - String param = args[args.length - 1]; - list = Lists.newArrayList(); - for(ProxyHandler plr : this.players.values()) { - if(plr.getUsername().regionMatches(true, 0, param, 0, param.length())) - list.add(plr.getUsername()); - } - } - return list; - } } diff --git a/proxy/src/main/java/proxy/command/Command.java b/proxy/src/main/java/proxy/command/Command.java index 05eda9a..1504bfd 100644 --- a/proxy/src/main/java/proxy/command/Command.java +++ b/proxy/src/main/java/proxy/command/Command.java @@ -12,7 +12,7 @@ public abstract class Command { return null; } public abstract void run(Proxy proxy, ProxyHandler player, String[] args); - public Iterable complete(Proxy proxy, ProxyHandler player, String[] args, String[] serverMatches) { + public Iterable complete(Proxy proxy, ProxyHandler player, String[] args) { return null; } public int getRedactedLogArg(int args) { diff --git a/proxy/src/main/java/proxy/command/CommandAdmin.java b/proxy/src/main/java/proxy/command/CommandAdmin.java index a012f4d..67c6033 100644 --- a/proxy/src/main/java/proxy/command/CommandAdmin.java +++ b/proxy/src/main/java/proxy/command/CommandAdmin.java @@ -47,7 +47,7 @@ public class CommandAdmin extends Command { sendInfo(player, "%s is now an admin", user.getUsername()); } - public Iterable complete(Proxy proxy, ProxyHandler player, String[] args, String[] serverMatches) { + public Iterable complete(Proxy proxy, ProxyHandler player, String[] args) { return args.length == 1 ? Collections2.filter(proxy.getUserNames(), user -> !proxy.getUser(user).isAdmin()) : null; } } diff --git a/proxy/src/main/java/proxy/command/CommandDelete.java b/proxy/src/main/java/proxy/command/CommandDelete.java index 07a104d..f80e448 100644 --- a/proxy/src/main/java/proxy/command/CommandDelete.java +++ b/proxy/src/main/java/proxy/command/CommandDelete.java @@ -33,7 +33,7 @@ public class CommandDelete extends Command { sendInfo(player, "The profile of %s was deleted", user.getUsername()); } - public Iterable complete(Proxy proxy, ProxyHandler player, String[] args, String[] serverMatches) { + public Iterable complete(Proxy proxy, ProxyHandler player, String[] args) { return args.length == 1 ? (player == null ? proxy.getUserNames() : Collections2.filter(proxy.getUserNames(), user -> !proxy.getUser(user).isAdmin())) : null; } } diff --git a/proxy/src/main/java/proxy/command/CommandHelp.java b/proxy/src/main/java/proxy/command/CommandHelp.java index 6555c4b..0ac503c 100644 --- a/proxy/src/main/java/proxy/command/CommandHelp.java +++ b/proxy/src/main/java/proxy/command/CommandHelp.java @@ -10,20 +10,20 @@ import proxy.util.Formatter; public class CommandHelp extends Command { public String getName() { - return "help"; + return "phelp"; } public String getHelp() { - return "Displays proxy and server command help"; + return "Displays proxy command help"; } public String getArgs() { return "[command]"; } - private static String formatCommand(Command cmd) { + private static String formatCommand(Command cmd, boolean prefix) { String args = cmd.getArgs(); - return Formatter.DARK_GRAY + "/" + Formatter.AQUA + cmd.getName() + (args == null || args.isEmpty() ? "" : Formatter.GREEN + " " + args) + return (prefix ? Formatter.DARK_GRAY + "/" : "") + Formatter.AQUA + cmd.getName() + (args == null || args.isEmpty() ? "" : Formatter.GREEN + " " + args) + Formatter.GRAY + " - " + Formatter.YELLOW + cmd.getHelp(); } @@ -31,7 +31,7 @@ public class CommandHelp extends Command { if(args.length == 0) { for(Command cmd : proxy.getCommands().values()) { if(cmd.canUse(player)) - sendMessage(player, formatCommand(cmd)); + sendMessage(player, formatCommand(cmd, player != null)); } return; } @@ -40,10 +40,10 @@ public class CommandHelp extends Command { throw new RunException("Command '%s' not found", args[0]); if(!cmd.canUse(player)) throw new RunException("Command '%s' can not be used", args[0]); - sendMessage(player, formatCommand(cmd)); + sendMessage(player, formatCommand(cmd, player != null)); } - public Iterable complete(Proxy proxy, ProxyHandler player, String[] args, String[] serverMatches) { + public Iterable complete(Proxy proxy, ProxyHandler player, String[] args) { return args.length == 1 ? Collections2.filter(proxy.getCommands().keySet(), name -> proxy.getCommands().get(name).canUse(player)) : null; } } diff --git a/proxy/src/main/java/proxy/command/CommandKick.java b/proxy/src/main/java/proxy/command/CommandKick.java index d7bf3c1..588f515 100644 --- a/proxy/src/main/java/proxy/command/CommandKick.java +++ b/proxy/src/main/java/proxy/command/CommandKick.java @@ -32,7 +32,7 @@ public class CommandKick extends Command { plr.disconnect(args.length <= 1 ? "Kicked from server" : Formatter.joinSpace(1, args)); } - public Iterable complete(Proxy proxy, ProxyHandler player, String[] args, String[] serverMatches) { + public Iterable complete(Proxy proxy, ProxyHandler player, String[] args) { return args.length == 1 ? (player == null ? proxy.getPlayerNames() : Collections2.filter(proxy.getPlayerNames(), name -> !proxy.getPlayer(name).isAdmin())) : null; } } diff --git a/proxy/src/main/java/proxy/command/CommandPass.java b/proxy/src/main/java/proxy/command/CommandPass.java deleted file mode 100644 index ef8c5c3..0000000 --- a/proxy/src/main/java/proxy/command/CommandPass.java +++ /dev/null @@ -1,44 +0,0 @@ -package proxy.command; - -import com.google.common.collect.Lists; - -import proxy.Proxy; -import proxy.handler.ProxyHandler; -import proxy.packet.C01PacketChatMessage; -import proxy.util.Formatter; - -public class CommandPass extends Command { - private final String name; - private final String args; - private final String help; - - public CommandPass(String name, String args, String help) { - this.name = name; - this.args = args; - this.help = help; - } - - public String getName() { - return this.name; - } - - public String getArgs() { - return this.args; - } - - public String getHelp() { - return this.help; - } - - public boolean canUse(ProxyHandler player) { - return player != null && super.canUse(player); - } - - public void run(Proxy proxy, ProxyHandler player, String[] args) { - player.sendToServer(new C01PacketChatMessage("/" + this.name + (args.length != 0 ? " " + Formatter.joinSpace(0, args) : ""))); - } - - public Iterable complete(Proxy proxy, ProxyHandler player, String[] args, String[] serverMatches) { - return Lists.newArrayList(serverMatches); - } -} diff --git a/proxy/src/main/java/proxy/command/CommandPing.java b/proxy/src/main/java/proxy/command/CommandPing.java index d2e5c31..1a39857 100644 --- a/proxy/src/main/java/proxy/command/CommandPing.java +++ b/proxy/src/main/java/proxy/command/CommandPing.java @@ -28,7 +28,7 @@ public class CommandPing extends Command { sendInfo(player, (plr == player ? "Your latency" : "Latency of %s") + ": %d ms", plr == player ? plr.getPing() : plr.getUsername(), plr.getPing()); } - public Iterable complete(Proxy proxy, ProxyHandler player, String[] args, String[] serverMatches) { + public Iterable complete(Proxy proxy, ProxyHandler player, String[] args) { return args.length == 1 && (player == null || player.hasPermission(Permissions.PING_OTHERS)) ? proxy.getPlayerNames() : null; } } diff --git a/proxy/src/main/java/proxy/command/CommandRevoke.java b/proxy/src/main/java/proxy/command/CommandRevoke.java index c564628..6ce070a 100644 --- a/proxy/src/main/java/proxy/command/CommandRevoke.java +++ b/proxy/src/main/java/proxy/command/CommandRevoke.java @@ -38,7 +38,7 @@ public class CommandRevoke extends Command { sendInfo(player, "%s is no longer an admin", user.getUsername()); } - public Iterable complete(Proxy proxy, ProxyHandler player, String[] args, String[] serverMatches) { + public Iterable complete(Proxy proxy, ProxyHandler player, String[] args) { return args.length == 1 ? Collections2.filter(proxy.getUserNames(), user -> proxy.getUser(user).isAdmin()) : null; } } diff --git a/proxy/src/main/java/proxy/handler/ProxyHandler.java b/proxy/src/main/java/proxy/handler/ProxyHandler.java index 748277e..ff58c23 100755 --- a/proxy/src/main/java/proxy/handler/ProxyHandler.java +++ b/proxy/src/main/java/proxy/handler/ProxyHandler.java @@ -1,16 +1,21 @@ package proxy.handler; -import io.netty.buffer.Unpooled; import io.netty.util.concurrent.Future; import io.netty.util.concurrent.GenericFutureListener; import java.net.IDN; import java.net.InetAddress; import java.net.UnknownHostException; +import java.util.Collections; +import java.util.Iterator; import java.util.List; +import java.util.Locale; import java.util.concurrent.atomic.AtomicInteger; +import com.google.common.collect.Lists; + import proxy.Proxy; +import proxy.command.Command; import proxy.network.Connection; import proxy.network.Packet; import proxy.network.PacketBuffer; @@ -137,11 +142,10 @@ public class ProxyHandler extends User implements Handler { public void setupPlayer(int id) { this.spoofedId = id; this.sendToClient(new S01PacketJoinGame(id, true)); - this.sendToClient(new S3FPacketCustomPayload("MC|Brand", (new PacketBuffer(Unpooled.buffer())).writeString(Proxy.NAME))); this.sendToClient(new S03PacketTimeUpdate(3000L, false)); this.sendToClient(new S26PacketMapChunkBulk(0, 64, 0)); this.sendToClient(new S08PacketPlayerPosLook(0.5, 65.0, 0.5, 0.0f, 0.0f)); - // this.sendMessage(Formatter.DARK_PURPLE + "Welcome %s, please log in using the sign gui ...", this.username); + this.sendMessage(Formatter.DARK_PURPLE + "Welcome %s, please log in using the sign gui ...", this.username); } public void sendMessage(String message) { @@ -378,23 +382,59 @@ public class ProxyHandler extends User implements Handler { this.sendToServer(packetIn); } + public List getCompletions(String[] args) { + if(args.length <= 1) + return null; + Command cmd = this.proxy.getCommands().get(args[0].toLowerCase(Locale.US)); + if(cmd == null) + return null; + List list = Lists.newArrayList(); + if(!cmd.canUse(this)) + return list; + String[] argv = new String[args.length - 1]; + System.arraycopy(args, 1, argv, 0, argv.length); + Iterable comps = cmd.complete(this.proxy, this, argv); + if(comps == null) + return list; + String param = args[args.length - 1]; + for(String comp : comps) { + if(comp.regionMatches(true, 0, param, 0, param.length())) + list.add(comp); + } + return list; + } + public void processChatMessage(C01PacketChatMessage packetIn) { if(this.connected) { Handler.syncToMain(packetIn, this, this.proxy); String msg = packetIn.getMessage(); if(!isValidString(msg)) return; - this.proxy.run(this, msg); + msg = Formatter.filterSpaces(msg); + if(msg.isEmpty()) + return; + if(msg.startsWith("/")) { + msg = msg.substring(1); + String[] args = msg.split(" "); + if(args[0].indexOf(':') != -1) { + this.sendToServer(new C01PacketChatMessage("/")); + return; + } + if(!this.proxy.runCommand(this, args, msg)) + this.sendToServer(packetIn); + } + else { + msg = String.format(Formatter.BLUE + "%s" + Formatter.DARK_GRAY + ": " + Formatter.GRAY + "%s", this.username, packetIn.getMessage()); + this.proxy.sendPacket(new S02PacketChat(msg, false)); + Log.info(Formatter.strip(msg)); + } } } public void processTabComplete(C14PacketTabComplete packetIn) { if(this.connected) { Handler.syncToMain(packetIn, this, this.proxy); - String msg = packetIn.getMessage(); - if(!isValidString(msg)) - return; - this.completion = msg; + this.completion = packetIn.getMessage(); this.sendToServer(packetIn); } } @@ -405,7 +445,36 @@ public class ProxyHandler extends User implements Handler { this.sendToClient(new S3APacketTabComplete(new String[0])); return; } - List list = this.proxy.complete(this, this.completion, packetIn.getMatches()); + List list = null; + if(this.completion.startsWith("/")) { + if(this.completion.indexOf(' ') == -1) { + list = this.completion.indexOf(':') != -1 ? Lists.newArrayList() : Lists.newArrayList(packetIn.getMatches()); + for(Iterator iter = list.iterator(); iter.hasNext();) { + String cmd = iter.next(); + if(cmd.isEmpty() || cmd.indexOf(':') != -1 || this.proxy.getCommands().containsKey(cmd.substring(1).toLowerCase(Locale.US))) + iter.remove(); + } + for(Command cmd : this.proxy.getCommands().values()) { + String command = "/" + cmd.getName(); + if(cmd.canUse(this) && command.regionMatches(true, 0, this.completion, 0, this.completion.length())) + list.add(command); + } + Collections.sort(list); + } + else { + String[] args = this.completion.substring(1).split(" ", -1); + list = args[0].indexOf(':') != -1 ? Lists.newArrayList() : this.getCompletions(args); + } + } + else { + String[] args = this.completion.split(" ", -1); + String param = args[args.length - 1]; + list = Lists.newArrayList(); + for(ProxyHandler player : this.proxy.getPlayers()) { + if(player.getUsername().regionMatches(true, 0, param, 0, param.length())) + list.add(player.getUsername()); + } + } this.sendToClient(list != null ? new S3APacketTabComplete(list.toArray(new String[list.size()])) : packetIn); this.completion = null; } @@ -518,6 +587,8 @@ public class ProxyHandler extends User implements Handler { finally { packetbuffer.release(); } + + return; } else if("MC|BSign".equals(packetIn.getChannelName())) { PacketBuffer packetbuffer = packetIn.getBufferData(); @@ -539,6 +610,8 @@ public class ProxyHandler extends User implements Handler { finally { packetbuffer.release(); } + + return; } else if("MC|TrSel".equals(packetIn.getChannelName())) { PacketBuffer packetbuffer = packetIn.getBufferData(); @@ -824,6 +897,10 @@ public class ProxyHandler extends User implements Handler { this.sendToClient(packetIn); } + public void handleTitle(S45PacketTitle packetIn) { + this.sendToClient(packetIn); + } + public void handleRemoveEntityEffect(S1EPacketRemoveEntityEffect packetIn) { this.sendToClient(packetIn.replaceEntityId(this.realId, this.spoofedId)); } @@ -841,8 +918,7 @@ public class ProxyHandler extends User implements Handler { } public void handleCustomPayload(S3FPacketCustomPayload packetIn) { - if("MC|TrList".equals(packetIn.getChannelName()) || "MC|BOpen".equals(packetIn.getChannelName())) - this.sendToClient(packetIn); + this.sendToClient(packetIn); } public void handleParticles(S2APacketParticles packetIn) { diff --git a/proxy/src/main/java/proxy/packet/S45PacketTitle.java b/proxy/src/main/java/proxy/packet/S45PacketTitle.java index 5abc005..d962708 100755 --- a/proxy/src/main/java/proxy/packet/S45PacketTitle.java +++ b/proxy/src/main/java/proxy/packet/S45PacketTitle.java @@ -6,39 +6,94 @@ import proxy.handler.ProxyHandler; import proxy.network.Packet; import proxy.network.PacketBuffer; -public class S45PacketTitle implements Packet { - private static enum Type { - TITLE, SUBTITLE, TIMES, CLEAR, RESET; - } +public class S45PacketTitle implements Packet +{ + private S45PacketTitle.Type type; + private String message; + private int fadeInTime; + private int displayTime; + private int fadeOutTime; - private Type type; - private String message; - private int fadeInTime; - private int displayTime; - private int fadeOutTime; + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.type = (S45PacketTitle.Type)buf.readEnumValue(S45PacketTitle.Type.class); - public void readPacketData(PacketBuffer buf) throws IOException { - this.type = buf.readEnumValue(Type.class); - if(this.type == Type.TITLE || this.type == Type.SUBTITLE) - this.message = buf.readChatComponent(); - else if(this.type == Type.TIMES) { - this.fadeInTime = buf.readInt(); - this.displayTime = buf.readInt(); - this.fadeOutTime = buf.readInt(); - } - } + if (this.type == S45PacketTitle.Type.TITLE || this.type == S45PacketTitle.Type.SUBTITLE) + { + this.message = buf.readChatComponent(); + } - public void writePacketData(PacketBuffer buf) throws IOException { - buf.writeEnumValue(this.type); - if(this.type == Type.TITLE || this.type == Type.SUBTITLE) - buf.writeChatComponent(this.message); - else if(this.type == Type.TIMES) { - buf.writeInt(this.fadeInTime); - buf.writeInt(this.displayTime); - buf.writeInt(this.fadeOutTime); - } - } + if (this.type == S45PacketTitle.Type.TIMES) + { + this.fadeInTime = buf.readInt(); + this.displayTime = buf.readInt(); + this.fadeOutTime = buf.readInt(); + } + } - public void processPacket(ProxyHandler handler) { - } + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeEnumValue(this.type); + + if (this.type == S45PacketTitle.Type.TITLE || this.type == S45PacketTitle.Type.SUBTITLE) + { + buf.writeChatComponent(this.message); + } + + if (this.type == S45PacketTitle.Type.TIMES) + { + buf.writeInt(this.fadeInTime); + buf.writeInt(this.displayTime); + buf.writeInt(this.fadeOutTime); + } + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(ProxyHandler handler) + { + handler.handleTitle(this); + } + + public static enum Type + { + TITLE, + SUBTITLE, + TIMES, + CLEAR, + RESET; + + public static S45PacketTitle.Type byName(String name) + { + for (S45PacketTitle.Type s45packettitle$type : values()) + { + if (s45packettitle$type.name().equalsIgnoreCase(name)) + { + return s45packettitle$type; + } + } + + return TITLE; + } + + public static String[] getNames() + { + String[] astring = new String[values().length]; + int i = 0; + + for (S45PacketTitle.Type s45packettitle$type : values()) + { + astring[i++] = s45packettitle$type.name().toLowerCase(); + } + + return astring; + } + } }