From 44907b3e8dcadcf3b99896952df56d3312ccbd0a Mon Sep 17 00:00:00 2001 From: Myles Date: Mon, 7 Mar 2016 11:09:43 +0000 Subject: [PATCH] Add /viaversion autoteam to toggle auto teaming for 1.8 colliding. --- .../commands/ViaVersionCommand.java | 9 +++++++++ .../transformers/OutgoingTransformer.java | 20 ++++--------------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/main/java/us/myles/ViaVersion/commands/ViaVersionCommand.java b/src/main/java/us/myles/ViaVersion/commands/ViaVersionCommand.java index 34fdbbfb3..1e53ce862 100644 --- a/src/main/java/us/myles/ViaVersion/commands/ViaVersionCommand.java +++ b/src/main/java/us/myles/ViaVersion/commands/ViaVersionCommand.java @@ -28,6 +28,7 @@ public class ViaVersionCommand implements CommandExecutor { sender.sendMessage(color("&aViaVersion &c" + ViaVersion.getInstance().getVersion())); sender.sendMessage(color("&6Commands:")); sender.sendMessage(color("&2/viaversion list &7- &6Shows lists of all 1.9 clients and 1.8 clients.")); + sender.sendMessage(color("&2/viaversion autoteam &7- &6Toggle automatically teaming to prevent colliding.")); sender.sendMessage(color("&2/viaversion dontbugme &7- &6Toggle checking for updates.")); } else if (args.length == 1) { if (args[0].equalsIgnoreCase("list")) { @@ -54,6 +55,14 @@ public class ViaVersionCommand implements CommandExecutor { plugin.saveConfig(); sender.sendMessage(color("&6We will " + (newValue ? "&anotify you about updates." : "&cnot tell you about updates."))); } + if (args[0].equalsIgnoreCase("autoteam")) { + boolean newValue = !plugin.getConfig().getBoolean("auto-team", true); + plugin.getConfig().set("auto-team", newValue); + plugin.saveConfig(); + sender.sendMessage(color("&6We will " + (newValue ? "&aautomatically team players" : "&cno longer auto team players"))); + sender.sendMessage(color("&6All players will need to re-login for the change to take place.")); + + } } } diff --git a/src/main/java/us/myles/ViaVersion/transformers/OutgoingTransformer.java b/src/main/java/us/myles/ViaVersion/transformers/OutgoingTransformer.java index fd5f81e7b..af763f0ea 100644 --- a/src/main/java/us/myles/ViaVersion/transformers/OutgoingTransformer.java +++ b/src/main/java/us/myles/ViaVersion/transformers/OutgoingTransformer.java @@ -37,6 +37,7 @@ public class OutgoingTransformer { private final ConnectionInfo info; private final ViaVersionPlugin plugin = (ViaVersionPlugin) ViaVersion.getInstance(); private boolean cancel = false; + private boolean autoTeam = false; private Map uuidMap = new HashMap(); private Map clientEntityTypes = new HashMap(); @@ -550,6 +551,7 @@ public class OutgoingTransformer { output.writeBytes(input); // send fake team if (plugin.isAutoTeam()) { + autoTeam = true; sendTeamPacket(true); } return; @@ -627,7 +629,7 @@ public class OutgoingTransformer { for (int i = 0; i < count; i++) { String name = PacketUtil.readString(input); - if (plugin.isAutoTeam() && name.equalsIgnoreCase(info.getUsername())) { + if (autoTeam && name.equalsIgnoreCase(info.getUsername())) { if (mode == 4) { // since removing add to auto team plugin.run(new Runnable() { @@ -748,21 +750,7 @@ public class OutgoingTransformer { } output.writeBytes(input); } - private void sendCreateTeam() { - ByteBuf buf = info.getChannel().alloc().buffer(); - PacketUtil.writeVarInt(PacketType.PLAY_TEAM.getNewPacketID(), buf); - PacketUtil.writeString("viaversion", buf); - buf.writeByte(0); // make team - PacketUtil.writeString("viaversion", buf); - PacketUtil.writeString("", buf); // prefix - PacketUtil.writeString("", buf); // suffix - buf.writeByte(0); // friendly fire - PacketUtil.writeString("", buf); // nametags - PacketUtil.writeString("never", buf); // collision rule :) - buf.writeByte(0); // color - PacketUtil.writeVarInt(0, buf); // player count - info.sendRawPacket(buf); - } + private void sendTeamPacket(boolean b) { ByteBuf buf = info.getChannel().alloc().buffer(); PacketUtil.writeVarInt(PacketType.PLAY_TEAM.getNewPacketID(), buf);