From 9ee8e6efa70a8940c823e3b44ec78643eafa724b Mon Sep 17 00:00:00 2001 From: creeper123123321 Date: Sun, 9 Dec 2018 13:18:40 -0200 Subject: [PATCH 1/7] Velocity and maybe better version detector --- all/pom.xml | 6 ++ .../api/ViaBackwardsPlatform.java | 17 ++-- pom.xml | 1 + .../nl/matsv/viabackwards/SpongePlugin.java | 19 ++--- velocity/pom.xml | 83 +++++++++++++++++++ .../viabackwards/velocity/VersionInfo.java | 15 ++++ .../nl/matsv/viabackwards/VelocityPlugin.java | 51 ++++++++++++ 7 files changed, 172 insertions(+), 20 deletions(-) create mode 100644 velocity/pom.xml create mode 100644 velocity/src/main/java-templates/nl/matsv/viabackwards/velocity/VersionInfo.java create mode 100644 velocity/src/main/java/nl/matsv/viabackwards/VelocityPlugin.java diff --git a/all/pom.xml b/all/pom.xml index 7db043b3..0cee5e97 100644 --- a/all/pom.xml +++ b/all/pom.xml @@ -81,5 +81,11 @@ viabackwards-sponge ${project.parent.version} + + + nl.matsv + viabackwards-velocity + ${project.parent.version} + \ No newline at end of file diff --git a/core/src/main/java/nl/matsv/viabackwards/api/ViaBackwardsPlatform.java b/core/src/main/java/nl/matsv/viabackwards/api/ViaBackwardsPlatform.java index baf9d722..c68094ca 100644 --- a/core/src/main/java/nl/matsv/viabackwards/api/ViaBackwardsPlatform.java +++ b/core/src/main/java/nl/matsv/viabackwards/api/ViaBackwardsPlatform.java @@ -12,15 +12,15 @@ package nl.matsv.viabackwards.api; import nl.matsv.viabackwards.ViaBackwards; import nl.matsv.viabackwards.protocol.protocol1_10to1_11.Protocol1_10To1_11; +import nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.Protocol1_11_1To1_12; import nl.matsv.viabackwards.protocol.protocol1_11to1_11_1.Protocol1_11To1_11_1; import nl.matsv.viabackwards.protocol.protocol1_12_1to1_12_2.Protocol1_12_1To1_12_2; -import nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.Protocol1_11_1To1_12; import nl.matsv.viabackwards.protocol.protocol1_12to1_12_1.Protocol1_12To1_12_1; import nl.matsv.viabackwards.protocol.protocol1_9_4to1_10.Protocol1_9_4To1_10; import us.myles.ViaVersion.api.protocol.ProtocolRegistry; import us.myles.ViaVersion.api.protocol.ProtocolVersion; +import us.myles.ViaVersion.update.Version; -import java.lang.reflect.Field; import java.util.Collections; import java.util.logging.Logger; @@ -48,21 +48,22 @@ public interface ViaBackwardsPlatform { */ Logger getLogger(); - // TODO remove or better implement later default boolean isOutdated() { + String minimumVVVersion = "2.0.0"; boolean upToDate = false; try { - Class clazz = Class.forName("us.myles.ViaVersion.api.protocol.ProtocolVersion"); - Field v1_12_2 = clazz.getField("v1_12_2"); + Class vvVersionInfo = Class.forName("us.myles.ViaVersion.sponge.VersionInfo"); + String vvVersion = (String) vvVersionInfo.getField("VERSION").get(null); - upToDate = (v1_12_2 != null); - } catch (ClassNotFoundException | NoSuchFieldException ignored) { + upToDate = (vvVersion != null + && new Version(vvVersion).compareTo(new Version(minimumVVVersion + "--")) >= 0); + } catch (ClassNotFoundException | NoSuchFieldException | IllegalAccessException ignored) { } if (!upToDate) { getLogger().severe("================================"); getLogger().severe("YOUR VIAVERSION IS OUTDATED"); - getLogger().severe("PLEASE USE THE LATEST VERSION"); + getLogger().severe("PLEASE USE VIAVERSION " + minimumVVVersion + " OR NEWER"); getLogger().severe("LINK: https://viaversion.com"); getLogger().severe("VIABACKWARDS WILL NOW DISABLE"); getLogger().severe("================================"); diff --git a/pom.xml b/pom.xml index 9a000266..e1d7713f 100644 --- a/pom.xml +++ b/pom.xml @@ -28,6 +28,7 @@ bukkit bungee sponge + velocity all diff --git a/sponge/src/main/java/nl/matsv/viabackwards/SpongePlugin.java b/sponge/src/main/java/nl/matsv/viabackwards/SpongePlugin.java index 39fb6b9b..090ea4df 100644 --- a/sponge/src/main/java/nl/matsv/viabackwards/SpongePlugin.java +++ b/sponge/src/main/java/nl/matsv/viabackwards/SpongePlugin.java @@ -11,14 +11,14 @@ package nl.matsv.viabackwards; import com.google.inject.Inject; +import lombok.Getter; import nl.matsv.viabackwards.api.ViaBackwardsPlatform; import nl.matsv.viabackwards.sponge.VersionInfo; import org.spongepowered.api.event.Listener; import org.spongepowered.api.event.Order; -import org.spongepowered.api.event.game.state.GameAboutToStartServerEvent; +import org.spongepowered.api.event.game.state.GameInitializationEvent; import org.spongepowered.api.plugin.Dependency; import org.spongepowered.api.plugin.Plugin; -import org.spongepowered.api.plugin.PluginContainer; import us.myles.ViaVersion.sponge.util.LoggerWrapper; import java.util.logging.Logger; @@ -31,26 +31,21 @@ import java.util.logging.Logger; dependencies = {@Dependency(id = "viaversion")} ) public class SpongePlugin implements ViaBackwardsPlatform { + @Getter private Logger logger; @Inject - private PluginContainer container; + private org.slf4j.Logger loggerSlf4j; @Listener(order = Order.LATE) - public void onServerStart(GameAboutToStartServerEvent e) { + public void onGameStart(GameInitializationEvent e) { // Setup Logger - this.logger = new LoggerWrapper(container.getLogger()); + this.logger = new LoggerWrapper(loggerSlf4j); // Init! this.init(); } - @Override - public Logger getLogger() { - return logger; - } - - // TODO check how to for sponge, site was offline @Override public void disable() { - + // Not possible } } diff --git a/velocity/pom.xml b/velocity/pom.xml new file mode 100644 index 00000000..ff974ef4 --- /dev/null +++ b/velocity/pom.xml @@ -0,0 +1,83 @@ + + + + + + viabackwards-parent + nl.matsv + 2.4.0-SNAPSHOT + + 4.0.0 + + viabackwards-velocity + + + + + . + true + src/main/resources/ + + * + + + + + + + org.codehaus.mojo + templating-maven-plugin + 1.0.0 + + + filter-src + + filter-sources + + + + + + + + + + velocity-maven-repo + Velocity maven repo + https://repo.velocitypowered.com/snapshots/ + + true + + + true + + + + + + + + nl.matsv + viabackwards-core + ${project.parent.version} + + + + + com.velocitypowered + velocity-api + 1.0-SNAPSHOT + provided + + + \ No newline at end of file diff --git a/velocity/src/main/java-templates/nl/matsv/viabackwards/velocity/VersionInfo.java b/velocity/src/main/java-templates/nl/matsv/viabackwards/velocity/VersionInfo.java new file mode 100644 index 00000000..f12f184f --- /dev/null +++ b/velocity/src/main/java-templates/nl/matsv/viabackwards/velocity/VersionInfo.java @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2016 Matsv + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package nl.matsv.viabackwards.velocity; + +public class VersionInfo { + public static final String VERSION = "${project.version}"; +} diff --git a/velocity/src/main/java/nl/matsv/viabackwards/VelocityPlugin.java b/velocity/src/main/java/nl/matsv/viabackwards/VelocityPlugin.java new file mode 100644 index 00000000..f20d6f58 --- /dev/null +++ b/velocity/src/main/java/nl/matsv/viabackwards/VelocityPlugin.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2016 Matsv + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package nl.matsv.viabackwards; + +import com.google.inject.Inject; +import com.velocitypowered.api.event.PostOrder; +import com.velocitypowered.api.event.Subscribe; +import com.velocitypowered.api.event.proxy.ProxyInitializeEvent; +import com.velocitypowered.api.plugin.Dependency; +import com.velocitypowered.api.plugin.Plugin; +import lombok.Getter; +import nl.matsv.viabackwards.api.ViaBackwardsPlatform; +import nl.matsv.viabackwards.velocity.VersionInfo; +import us.myles.ViaVersion.sponge.util.LoggerWrapper; + +import java.util.logging.Logger; + +@Plugin(id = "viabackwards", + name = "ViaBackwards", + version = VersionInfo.VERSION, + authors = {"Matsv"}, + description = "Allow older Minecraft versions to connect to an newer server version.", + dependencies = {@Dependency(id = "viaversion")} +) +public class VelocityPlugin implements ViaBackwardsPlatform { + @Getter + private Logger logger; + @Inject + private org.slf4j.Logger loggerSlf4j; + + @Subscribe(order = PostOrder.LATE) + public void onProxyStart(ProxyInitializeEvent e) { + // Setup Logger + this.logger = new LoggerWrapper(loggerSlf4j); + // Init! + this.init(); + } + + @Override + public void disable() { + // Not possible + } +} From 29f1f3ea7ccb0d351694a7ccadf63002ea5510a8 Mon Sep 17 00:00:00 2001 From: Matsv Date: Sun, 27 Jan 2019 13:01:24 +0100 Subject: [PATCH 2/7] =?UTF-8?q?=E2=9C=A8=20Reformat=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/EntityTypeMapping.java | 28 ++-- .../data/NamedSoundMapping.java | 28 ++-- .../data/PaintingMapping.java | 70 +++++----- .../data/SoundMapping.java | 54 ++++---- .../packets/BlockItemPackets1_13.java | 44 +++--- .../packets/PlayerPacket1_13.java | 30 ++-- .../packets/SoundPackets1_13.java | 130 +++++++++--------- 7 files changed, 192 insertions(+), 192 deletions(-) diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/data/EntityTypeMapping.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/data/EntityTypeMapping.java index e3ba3962..bf77e218 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/data/EntityTypeMapping.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/data/EntityTypeMapping.java @@ -8,20 +8,20 @@ import java.util.Map; import java.util.Optional; public class EntityTypeMapping { - private static Map entityTypes = new HashMap<>(); + private static Map entityTypes = new HashMap<>(); - static { - try { - Field field = EntityTypeRewriter.class.getDeclaredField("entityTypes"); - field.setAccessible(true); - Map entityTypes = (Map) field.get(null); - entityTypes.forEach((type1_12, type1_13) -> EntityTypeMapping.entityTypes.put(type1_13, type1_12)); - } catch (NoSuchFieldException | IllegalAccessException ex) { - ex.printStackTrace(); - } - } + static { + try { + Field field = EntityTypeRewriter.class.getDeclaredField("entityTypes"); + field.setAccessible(true); + Map entityTypes = (Map) field.get(null); + entityTypes.forEach((type1_12, type1_13) -> EntityTypeMapping.entityTypes.put(type1_13, type1_12)); + } catch (NoSuchFieldException | IllegalAccessException ex) { + ex.printStackTrace(); + } + } - public static Optional getOldId(int type1_13) { - return Optional.ofNullable(entityTypes.get(type1_13)); - } + public static Optional getOldId(int type1_13) { + return Optional.ofNullable(entityTypes.get(type1_13)); + } } diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/data/NamedSoundMapping.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/data/NamedSoundMapping.java index e6f167d9..5788fee2 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/data/NamedSoundMapping.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/data/NamedSoundMapping.java @@ -7,20 +7,20 @@ import java.util.HashMap; import java.util.Map; public class NamedSoundMapping { - private static Map sounds = new HashMap<>(); + private static Map sounds = new HashMap<>(); - static { - try { - Field field = NamedSoundRewriter.class.getDeclaredField("oldToNew"); - field.setAccessible(true); - Map sounds = (Map) field.get(null); - sounds.forEach((sound1_12, sound1_13) -> NamedSoundMapping.sounds.put(sound1_13, sound1_12)); - } catch (NoSuchFieldException | IllegalAccessException ex) { - ex.printStackTrace(); - } - } + static { + try { + Field field = NamedSoundRewriter.class.getDeclaredField("oldToNew"); + field.setAccessible(true); + Map sounds = (Map) field.get(null); + sounds.forEach((sound1_12, sound1_13) -> NamedSoundMapping.sounds.put(sound1_13, sound1_12)); + } catch (NoSuchFieldException | IllegalAccessException ex) { + ex.printStackTrace(); + } + } - public static String getOldId(String sound1_13) { - return sounds.get(sound1_13); - } + public static String getOldId(String sound1_13) { + return sounds.get(sound1_13); + } } diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/data/PaintingMapping.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/data/PaintingMapping.java index bfb85bd7..578ed5f9 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/data/PaintingMapping.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/data/PaintingMapping.java @@ -4,42 +4,42 @@ import java.util.HashMap; import java.util.Map; public class PaintingMapping { - private static Map paintings = new HashMap<>(); + private static Map paintings = new HashMap<>(); - public static void init() { - add("kebab"); - add("aztec"); - add("alban"); - add("aztec2"); - add("bomb"); - add("plant"); - add("wasteland"); - add("pool"); - add("courbet"); - add("sea"); - add("sunset"); - add("creebet"); - add("wanderer"); - add("graham"); - add("match"); - add("bust"); - add("stage"); - add("void"); - add("skullandroses"); - add("wither"); - add("fighters"); - add("pointer"); - add("pigscene"); - add("burningskull"); - add("skeleton"); - add("donkeykong"); - } + public static void init() { + add("kebab"); + add("aztec"); + add("alban"); + add("aztec2"); + add("bomb"); + add("plant"); + add("wasteland"); + add("pool"); + add("courbet"); + add("sea"); + add("sunset"); + add("creebet"); + add("wanderer"); + add("graham"); + add("match"); + add("bust"); + add("stage"); + add("void"); + add("skullandroses"); + add("wither"); + add("fighters"); + add("pointer"); + add("pigscene"); + add("burningskull"); + add("skeleton"); + add("donkeykong"); + } - private static void add(String motive) { - paintings.put(paintings.size(), motive); - } + private static void add(String motive) { + paintings.put(paintings.size(), motive); + } - public static String getStringId(int id) { - return paintings.getOrDefault(id, "kebab"); - } + public static String getStringId(int id) { + return paintings.getOrDefault(id, "kebab"); + } } diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/data/SoundMapping.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/data/SoundMapping.java index 99fa1628..c9096b01 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/data/SoundMapping.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/data/SoundMapping.java @@ -9,36 +9,36 @@ import java.util.Arrays; import static us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.MappingData.loadData; public class SoundMapping { - private static short[] sounds = new short[662]; + private static short[] sounds = new short[662]; - public static void init() { - JsonObject mapping1_12 = loadData("mapping-1.12.json"); - JsonObject mapping1_13 = loadData("mapping-1.13.json"); + public static void init() { + JsonObject mapping1_12 = loadData("mapping-1.12.json"); + JsonObject mapping1_13 = loadData("mapping-1.13.json"); - Arrays.fill(sounds, (short) -1); - mapIdentifiers(sounds, mapping1_13.getAsJsonArray("sounds"), mapping1_12.getAsJsonArray("sounds")); - } + Arrays.fill(sounds, (short) -1); + mapIdentifiers(sounds, mapping1_13.getAsJsonArray("sounds"), mapping1_12.getAsJsonArray("sounds")); + } - private static void mapIdentifiers(short[] output, JsonArray oldIdentifiers, JsonArray newIdentifiers) { - for (int i = 0; i < oldIdentifiers.size(); i++) { - JsonElement v = oldIdentifiers.get(i); - Integer index = findIndex(newIdentifiers, v.getAsString()); - if (index == null) continue; //There will be missing sounds, since we are goind backwards - output[i] = index.shortValue(); - } - } + private static void mapIdentifiers(short[] output, JsonArray oldIdentifiers, JsonArray newIdentifiers) { + for (int i = 0; i < oldIdentifiers.size(); i++) { + JsonElement v = oldIdentifiers.get(i); + Integer index = findIndex(newIdentifiers, v.getAsString()); + if (index == null) continue; //There will be missing sounds, since we are goind backwards + output[i] = index.shortValue(); + } + } - private static Integer findIndex(JsonArray array, String value) { - for (int i = 0; i < array.size(); i++) { - JsonElement v = array.get(i); - if (v.getAsString().equals(value)) { - return i; - } - } - return null; - } + private static Integer findIndex(JsonArray array, String value) { + for (int i = 0; i < array.size(); i++) { + JsonElement v = array.get(i); + if (v.getAsString().equals(value)) { + return i; + } + } + return null; + } - public static int getOldSound(int newSound) { - return newSound >= sounds.length ? -1 : sounds[newSound]; - } + public static int getOldSound(int newSound) { + return newSound >= sounds.length ? -1 : sounds[newSound]; + } } diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java index 27c70239..2e211f3c 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java @@ -195,7 +195,7 @@ public class BlockItemPackets1_13 extends BlockItemRewriter iterator = lore.iterator(); - while(iterator.hasNext()){ + while (iterator.hasNext()) { oldLore.add(iterator.next().clone()); } display.put(oldLore); @@ -692,10 +692,10 @@ public class BlockItemPackets1_13 extends BlockItemRewriter iterator = lore.iterator(); - while(iterator.hasNext()){ + while (iterator.hasNext()) { oldLore.add(iterator.next().clone()); } display.put(oldLore); @@ -833,10 +833,10 @@ public class BlockItemPackets1_13 extends BlockItemRewriter iterator = oldLore.iterator(); - while (iterator.hasNext()){ + while (iterator.hasNext()) { loreTag.add(iterator.next()); } display.remove("Lore"); @@ -877,10 +877,10 @@ public class BlockItemPackets1_13 extends BlockItemRewriter iterator = noMapped.iterator(); - while (iterator.hasNext()){ + while (iterator.hasNext()) { enchantments.add(iterator.next()); } } @@ -905,10 +905,10 @@ public class BlockItemPackets1_13 extends BlockItemRewriter iterator = noMapped.iterator(); - while (iterator.hasNext()){ + while (iterator.hasNext()) { newStoredEnch.add(iterator.next()); } } @@ -1018,7 +1018,7 @@ public class BlockItemPackets1_13 extends BlockItemRewriter { wrapper.write(Type.STRING, "MC|TrList"); wrapper.passthrough(Type.INT); //Passthrough Window ID - int size = wrapper.passthrough(Type.UNSIGNED_BYTE); - for (int i = 0; i < size; i++) { - //Input Item - Item input = wrapper.read(Type.FLAT_ITEM); - wrapper.write(Type.ITEM, getProtocol().getBlockItemPackets().handleItemToClient(input)); - //Output Item - Item output = wrapper.read(Type.FLAT_ITEM); - wrapper.write(Type.ITEM, getProtocol().getBlockItemPackets().handleItemToClient(output)); + int size = wrapper.passthrough(Type.UNSIGNED_BYTE); + for (int i = 0; i < size; i++) { + //Input Item + Item input = wrapper.read(Type.FLAT_ITEM); + wrapper.write(Type.ITEM, getProtocol().getBlockItemPackets().handleItemToClient(input)); + //Output Item + Item output = wrapper.read(Type.FLAT_ITEM); + wrapper.write(Type.ITEM, getProtocol().getBlockItemPackets().handleItemToClient(output)); - boolean secondItem = wrapper.passthrough(Type.BOOLEAN); //Has second item - if (secondItem) { - //Second Item - Item second = wrapper.read(Type.FLAT_ITEM); - wrapper.write(Type.ITEM, getProtocol().getBlockItemPackets().handleItemToClient(second)); - } + boolean secondItem = wrapper.passthrough(Type.BOOLEAN); //Has second item + if (secondItem) { + //Second Item + Item second = wrapper.read(Type.FLAT_ITEM); + wrapper.write(Type.ITEM, getProtocol().getBlockItemPackets().handleItemToClient(second)); + } wrapper.passthrough(Type.BOOLEAN); //Trade disabled wrapper.passthrough(Type.INT); //Number of tools uses @@ -158,7 +158,7 @@ public class PlayerPacket1_13 extends Rewriter { String match = wrapper.read(Type.STRING); wrapper.write(Type.STRING, (start == 0 ? "/" : "") + match); // Ignore tooltip - if (wrapper.read(Type.BOOLEAN)) wrapper.read(Type.STRING); + if (wrapper.read(Type.BOOLEAN)) wrapper.read(Type.STRING); } } }); diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/SoundPackets1_13.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/SoundPackets1_13.java index c82a4221..acc31982 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/SoundPackets1_13.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/SoundPackets1_13.java @@ -11,76 +11,76 @@ import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.packets.State; public class SoundPackets1_13 extends Rewriter { - private static final String[] SOUND_SOURCES = {"master", "music", "record", "weather", "block", "hostile", "neutral", "player", "ambient", "voice"}; + private static final String[] SOUND_SOURCES = {"master", "music", "record", "weather", "block", "hostile", "neutral", "player", "ambient", "voice"}; - @Override - protected void registerPackets(Protocol1_12_2To1_13 protocol) { + @Override + protected void registerPackets(Protocol1_12_2To1_13 protocol) { - //Named Sound Event - protocol.out(State.PLAY, 0x1A, 0x19, new PacketRemapper() { - @Override - public void registerMap() { - map(Type.STRING); - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) throws Exception { - String newSound = wrapper.get(Type.STRING, 0); - String oldSound = NamedSoundMapping.getOldId(newSound); - if (oldSound != null) { - wrapper.set(Type.STRING, 0, oldSound); - } - } - }); - } - }); + //Named Sound Event + protocol.out(State.PLAY, 0x1A, 0x19, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.STRING); + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + String newSound = wrapper.get(Type.STRING, 0); + String oldSound = NamedSoundMapping.getOldId(newSound); + if (oldSound != null) { + wrapper.set(Type.STRING, 0, oldSound); + } + } + }); + } + }); - //Stop Sound - protocol.out(State.PLAY, 0x4C, 0x18, new PacketRemapper() { - @Override - public void registerMap() { - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) throws Exception { - wrapper.write(Type.STRING, "MC|StopSound"); - byte flags = wrapper.read(Type.BYTE); - String source; - if ((flags & 0x01) != 0) { - source = SOUND_SOURCES[wrapper.read(Type.VAR_INT)]; - } else { - source = ""; - } - String sound = (flags & 0x02) != 0 ? wrapper.read(Type.STRING) : ""; + //Stop Sound + protocol.out(State.PLAY, 0x4C, 0x18, new PacketRemapper() { + @Override + public void registerMap() { + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + wrapper.write(Type.STRING, "MC|StopSound"); + byte flags = wrapper.read(Type.BYTE); + String source; + if ((flags & 0x01) != 0) { + source = SOUND_SOURCES[wrapper.read(Type.VAR_INT)]; + } else { + source = ""; + } + String sound = (flags & 0x02) != 0 ? wrapper.read(Type.STRING) : ""; - wrapper.write(Type.STRING, source); - wrapper.write(Type.STRING, sound); - } - }); - } - }); + wrapper.write(Type.STRING, source); + wrapper.write(Type.STRING, sound); + } + }); + } + }); - //Sound Effect - protocol.out(State.PLAY, 0x4D, 0x49, new PacketRemapper() { - @Override - public void registerMap() { - map(Type.VAR_INT); - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) throws Exception { - int newSound = wrapper.get(Type.VAR_INT, 0); - int oldSound = SoundMapping.getOldSound(newSound); - if (oldSound == -1) { - wrapper.cancel(); - } else { - wrapper.set(Type.VAR_INT, 0, oldSound); - } - } - }); - } - }); - } + //Sound Effect + protocol.out(State.PLAY, 0x4D, 0x49, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.VAR_INT); + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + int newSound = wrapper.get(Type.VAR_INT, 0); + int oldSound = SoundMapping.getOldSound(newSound); + if (oldSound == -1) { + wrapper.cancel(); + } else { + wrapper.set(Type.VAR_INT, 0, oldSound); + } + } + }); + } + }); + } - @Override - protected void registerRewrites() { + @Override + protected void registerRewrites() { - } + } } From 8477e20725c38e7e4a1d91525910cf0403fe5046 Mon Sep 17 00:00:00 2001 From: Matsv Date: Sun, 27 Jan 2019 14:06:48 +0100 Subject: [PATCH 3/7] =?UTF-8?q?=E2=99=BB=20Rewrite=20Entity=201.13.1=20the?= =?UTF-8?q?=20ViaBackwards=20way=20&=20remove=20incorrect=20metadata=20&?= =?UTF-8?q?=201.13=20rewrite?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../packets/EntityPackets1_13.java | 7 +- .../MetadataRewriter.java | 48 --- .../Protocol1_13To1_13_1.java | 18 +- .../packets/EntityPackets.java | 288 +++++++++++++++--- .../packets/WorldPackets.java | 36 --- 5 files changed, 261 insertions(+), 136 deletions(-) delete mode 100644 core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/MetadataRewriter.java diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/EntityPackets1_13.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/EntityPackets1_13.java index a36b0261..ec4fa3db 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/EntityPackets1_13.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/EntityPackets1_13.java @@ -465,13 +465,8 @@ public class EntityPackets1_13 extends EntityRewriter { // Remove boat splash timer registerMetaHandler().filter(EntityType.BOAT, 12).removed(); - //Remove shooter UUID - registerMetaHandler().filter(EntityType.ABSTRACT_ARROW, true, 7).removed(); - - registerMetaHandler().filter(EntityType.SPECTRAL_ARROW, 8).handleIndexChange(7); - // Remove Trident special loyalty level - registerMetaHandler().filter(EntityType.TRIDENT, 8).removed(); + registerMetaHandler().filter(EntityType.TRIDENT, 7).removed(); // Handle new wolf colors registerMetaHandler().filter(EntityType.WOLF, 17).handle(e -> { diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/MetadataRewriter.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/MetadataRewriter.java deleted file mode 100644 index 72ebe475..00000000 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/MetadataRewriter.java +++ /dev/null @@ -1,48 +0,0 @@ -package nl.matsv.viabackwards.protocol.protocol1_13to1_13_1; - -import nl.matsv.viabackwards.protocol.protocol1_13to1_13_1.packets.InventoryPackets; -import us.myles.ViaVersion.api.Via; -import us.myles.ViaVersion.api.data.UserConnection; -import us.myles.ViaVersion.api.entities.Entity1_13Types; -import us.myles.ViaVersion.api.entities.Entity1_13Types.EntityType; -import us.myles.ViaVersion.api.minecraft.item.Item; -import us.myles.ViaVersion.api.minecraft.metadata.Metadata; -import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_13; - -import java.util.ArrayList; -import java.util.List; - -public class MetadataRewriter { - - public static void handleMetadata(int entityId, Entity1_13Types.EntityType type, List metadatas, UserConnection connection) { - for (Metadata metadata : new ArrayList<>(metadatas)) { - try { - // 1.13 changed item to flat item (no data) - if (metadata.getMetaType() == MetaType1_13.Slot) { - InventoryPackets.toClient((Item) metadata.getValue()); - } else if (metadata.getMetaType() == MetaType1_13.BlockID) { - // Convert to new block id - int data = (int) metadata.getValue(); - metadata.setValue(Protocol1_13To1_13_1.getNewBlockStateId(data)); - } - if (type == null) continue; - if (type.isOrHasParent(Entity1_13Types.EntityType.MINECART_ABSTRACT) && metadata.getId() == 9) { - // New block format - int data = (int) metadata.getValue(); - metadata.setValue(Protocol1_13To1_13_1.getNewBlockStateId(data)); - } - if(type.is(EntityType.ITEM)){ - - } - } catch (Exception e) { - metadatas.remove(metadata); - if (!Via.getConfig().isSuppressMetadataErrors() || Via.getManager().isDebug()) { - Via.getPlatform().getLogger().warning("An error occurred with entity metadata handler"); - Via.getPlatform().getLogger().warning("Metadata: " + metadata); - e.printStackTrace(); - } - } - } - } - -} diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/Protocol1_13To1_13_1.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/Protocol1_13To1_13_1.java index 7992037e..d2e0e2bf 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/Protocol1_13To1_13_1.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/Protocol1_13To1_13_1.java @@ -1,6 +1,7 @@ package nl.matsv.viabackwards.protocol.protocol1_13to1_13_1; import nl.matsv.viabackwards.api.BackwardsProtocol; +import nl.matsv.viabackwards.api.entities.storage.EntityTracker; import nl.matsv.viabackwards.protocol.protocol1_13to1_13_1.packets.EntityPackets; import nl.matsv.viabackwards.protocol.protocol1_13to1_13_1.packets.InventoryPackets; import nl.matsv.viabackwards.protocol.protocol1_13to1_13_1.packets.WorldPackets; @@ -12,14 +13,13 @@ import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.remapper.ValueTransformer; import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.packets.State; -import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage.EntityTracker; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; public class Protocol1_13To1_13_1 extends BackwardsProtocol { @Override protected void registerPackets() { - EntityPackets.register(this); + new EntityPackets().register(this); InventoryPackets.register(this); WorldPackets.register(this); @@ -214,9 +214,15 @@ public class Protocol1_13To1_13_1 extends BackwardsProtocol { } @Override - public void init(UserConnection userConnection) { - userConnection.put(new EntityTracker(userConnection)); - if (!userConnection.has(ClientWorld.class)) - userConnection.put(new ClientWorld(userConnection)); + public void init(UserConnection user) { + // Register EntityTracker if it doesn't exist yet. + if (!user.has(EntityTracker.class)) + user.put(new EntityTracker(user)); + + // Init protocol in EntityTracker + user.get(EntityTracker.class).initProtocol(this); + + if (!user.has(ClientWorld.class)) + user.put(new ClientWorld(user)); } } diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/EntityPackets.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/EntityPackets.java index d1eb8d2a..e99a5edc 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/EntityPackets.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/EntityPackets.java @@ -1,25 +1,30 @@ package nl.matsv.viabackwards.protocol.protocol1_13to1_13_1.packets; -import com.google.common.base.Optional; -import nl.matsv.viabackwards.protocol.protocol1_13to1_13_1.MetadataRewriter; +import nl.matsv.viabackwards.ViaBackwards; +import nl.matsv.viabackwards.api.entities.storage.MetaStorage; +import nl.matsv.viabackwards.api.entities.types.EntityType1_12; +import nl.matsv.viabackwards.api.entities.types.EntityType1_13; +import nl.matsv.viabackwards.api.entities.types.EntityType1_13.EntityType; +import nl.matsv.viabackwards.api.rewriters.EntityRewriter; import nl.matsv.viabackwards.protocol.protocol1_13to1_13_1.Protocol1_13To1_13_1; import us.myles.ViaVersion.api.PacketWrapper; -import us.myles.ViaVersion.api.entities.Entity1_13Types; -import us.myles.ViaVersion.api.entities.Entity1_13Types.EntityType; -import us.myles.ViaVersion.api.protocol.Protocol; +import us.myles.ViaVersion.api.minecraft.item.Item; +import us.myles.ViaVersion.api.minecraft.metadata.Metadata; +import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_13; import us.myles.ViaVersion.api.remapper.PacketHandler; import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.types.version.Types1_13; import us.myles.ViaVersion.packets.State; -import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage.EntityTracker; +import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; -public class EntityPackets { +public class EntityPackets extends EntityRewriter { - public static void register(Protocol protocol) { + @Override + protected void registerPackets(Protocol1_13To1_13_1 protocol) { - //spawn entity - protocol.registerOutgoing(State.PLAY, 0x0, 0x0, new PacketRemapper() { + // Spawn Object + protocol.out(State.PLAY, 0x00, 0x00, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Entity id @@ -32,28 +37,74 @@ public class EntityPackets { map(Type.BYTE); // 7 - Yaw map(Type.INT); // 8 - Data - // Track Entity handler(new PacketHandler() { @Override public void handle(PacketWrapper wrapper) throws Exception { int entityId = wrapper.get(Type.VAR_INT, 0); byte type = wrapper.get(Type.BYTE, 0); - Entity1_13Types.EntityType entType = Entity1_13Types.getTypeFromId(type, true); - - if (entType != null) { - if (entType.is(Entity1_13Types.EntityType.FALLING_BLOCK)) { - int data = wrapper.get(Type.INT, 0); - wrapper.set(Type.INT, 0, Protocol1_13To1_13_1.getNewBlockStateId(data)); - } + EntityType entType = EntityType1_13.getTypeFromId(type, true); + if (entType == null) { + ViaBackwards.getPlatform().getLogger().warning("Could not find 1.13 entity type " + type); + return; } - // Register Type ID - wrapper.user().get(EntityTracker.class).addEntity(entityId, entType); + + // Rewrite falling block + if (entType.is(EntityType.FALLING_BLOCK)) { + int data = wrapper.get(Type.INT, 0); + wrapper.set(Type.INT, 0, Protocol1_13To1_13_1.getNewBlockStateId(data)); + } + + // Track Entity + addTrackedEntity( + wrapper.user(), + entityId, + entType + ); } }); } }); - // Spawn mob packet - protocol.registerOutgoing(State.PLAY, 0x3, 0x3, new PacketRemapper() { + + // Spawn Experience Orb + protocol.out(State.PLAY, 0x01, 0x01, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.VAR_INT); + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + addTrackedEntity( + wrapper.user(), + wrapper.get(Type.VAR_INT, 0), + EntityType.XP_ORB + ); + } + }); + } + }); + + // Spawn Global Entity + protocol.out(State.PLAY, 0x02, 0x02, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.VAR_INT); + map(Type.BYTE); + + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + addTrackedEntity( + wrapper.user(), + wrapper.get(Type.VAR_INT, 0), + EntityType.LIGHTNING_BOLT + ); + } + }); + } + }); + + // Spawn Mob + protocol.out(State.PLAY, 0x3, 0x3, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Entity ID @@ -70,25 +121,47 @@ public class EntityPackets { map(Type.SHORT); // 11 - Velocity Z map(Types1_13.METADATA_LIST); // 12 - Metadata + // Track Entity handler(new PacketHandler() { @Override public void handle(PacketWrapper wrapper) throws Exception { - int entityId = wrapper.get(Type.VAR_INT, 0); int type = wrapper.get(Type.VAR_INT, 1); - Entity1_13Types.EntityType entType = Entity1_13Types.getTypeFromId(type, false); + EntityType entityType = EntityType1_13.getTypeFromId(type, false); + addTrackedEntity( + wrapper.user(), + wrapper.get(Type.VAR_INT, 0), + entityType + ); + } + }); - // Register Type ID - wrapper.user().get(EntityTracker.class).addEntity(entityId, entType); + // Rewrite Metadata + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + MetaStorage storage = new MetaStorage(wrapper.get(Types1_13.METADATA_LIST, 0)); + handleMeta( + wrapper.user(), + wrapper.get(Type.VAR_INT, 0), + storage + ); - MetadataRewriter.handleMetadata(entityId, entType, wrapper.get(Types1_13.METADATA_LIST, 0), wrapper.user()); + // Don't handle new ids / base meta since it's not used for this version + + // Rewrite Metadata + wrapper.set( + Types1_13.METADATA_LIST, + 0, + storage.getMetaDataList() + ); } }); } }); // Spawn player packet - protocol.registerOutgoing(State.PLAY, 0x05, 0x05, new PacketRemapper() { + protocol.out(State.PLAY, 0x05, 0x05, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Entity ID @@ -100,21 +173,107 @@ public class EntityPackets { map(Type.BYTE); // 6 - Pitch map(Types1_13.METADATA_LIST); // 7 - Metadata + // Track Entity handler(new PacketHandler() { @Override public void handle(PacketWrapper wrapper) throws Exception { - int entityId = wrapper.get(Type.VAR_INT, 0); + addTrackedEntity( + wrapper.user(), + wrapper.get(Type.VAR_INT, 0), + EntityType.PLAYER + ); + } + }); - Entity1_13Types.EntityType entType = Entity1_13Types.EntityType.PLAYER; - // Register Type ID - wrapper.user().get(EntityTracker.class).addEntity(entityId, entType); - MetadataRewriter.handleMetadata(entityId, entType, wrapper.get(Types1_13.METADATA_LIST, 0), wrapper.user()); + // Rewrite Metadata + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + wrapper.set( + Types1_13.METADATA_LIST, + 0, + handleMeta( + wrapper.user(), + wrapper.get(Type.VAR_INT, 0), + new MetaStorage(wrapper.get(Types1_13.METADATA_LIST, 0)) + ).getMetaDataList() + ); } }); } }); + + //Spawn Painting + protocol.out(State.PLAY, 0x04, 0x04, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.VAR_INT); + map(Type.UUID); + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + addTrackedEntity( + wrapper.user(), + wrapper.get(Type.VAR_INT, 0), + EntityType.PAINTING + ); + } + }); + } + }); + + // Join Game + protocol.registerOutgoing(State.PLAY, 0x25, 0x25, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.INT); // 0 - Entity ID + map(Type.UNSIGNED_BYTE); // 1 - Gamemode + map(Type.INT); // 2 - Dimension + + // Track Entity + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + addTrackedEntity( + wrapper.user(), + wrapper.get(Type.INT, 0), + EntityType1_12.EntityType.PLAYER + ); + } + }); + + // Save dimension + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + ClientWorld clientChunks = wrapper.user().get(ClientWorld.class); + int dimensionId = wrapper.get(Type.INT, 1); + clientChunks.setEnvironment(dimensionId); + } + }); + } + }); + + // Respawn + protocol.out(State.PLAY, 0x38, 0x38, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.INT); // 0 - Dimension ID\ + + // Save dimension + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + ClientWorld clientWorld = wrapper.user().get(ClientWorld.class); + int dimensionId = wrapper.get(Type.INT, 0); + clientWorld.setEnvironment(dimensionId); + } + }); + } + }); + // Destroy entities - protocol.registerOutgoing(State.PLAY, 0x35, 0x35, new PacketRemapper() { + protocol.out(State.PLAY, 0x35, 0x35, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT_ARRAY); // 0 - Entity IDS @@ -123,7 +282,7 @@ public class EntityPackets { @Override public void handle(PacketWrapper wrapper) throws Exception { for (int entity : wrapper.get(Type.VAR_INT_ARRAY, 0)) - wrapper.user().get(EntityTracker.class).removeEntity(entity); + getEntityTracker(wrapper.user()).removeEntity(entity); } }); } @@ -131,22 +290,71 @@ public class EntityPackets { // Metadata packet - protocol.registerOutgoing(State.PLAY, 0x3F, 0x3F, new PacketRemapper() { + protocol.out(State.PLAY, 0x3F, 0x3F, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Entity ID map(Types1_13.METADATA_LIST); // 1 - Metadata list + handler(new PacketHandler() { @Override public void handle(PacketWrapper wrapper) throws Exception { - int entityId = wrapper.get(Type.VAR_INT, 0); - - Optional type = wrapper.user().get(EntityTracker.class).get(entityId); - MetadataRewriter.handleMetadata(entityId, type.orNull(), wrapper.get(Types1_13.METADATA_LIST, 0), wrapper.user()); + wrapper.set( + Types1_13.METADATA_LIST, + 0, + handleMeta( + wrapper.user(), + wrapper.get(Type.VAR_INT, 0), + new MetaStorage(wrapper.get(Types1_13.METADATA_LIST, 0)) + ).getMetaDataList() + ); } }); } }); } + @Override + protected void registerRewrites() { + + // Rewrite items & blocks + registerMetaHandler().handle(e -> { + Metadata meta = e.getData(); + + if (meta.getMetaType() == MetaType1_13.Slot) { + InventoryPackets.toClient((Item) meta.getValue()); + } else if (meta.getMetaType() == MetaType1_13.BlockID) { + // Convert to new block id + int data = (int) meta.getValue(); + meta.setValue(Protocol1_13To1_13_1.getNewBlockStateId(data)); + } + + return meta; + }); + + // Remove shooter UUID + registerMetaHandler(). + filter(EntityType.ABSTRACT_ARROW, true, 7) + .removed(); + + // Move colors to old position + registerMetaHandler().filter(EntityType.SPECTRAL_ARROW, 8) + .handleIndexChange(7); + + // Move loyalty level to old position + registerMetaHandler().filter(EntityType.TRIDENT, 8) + .handleIndexChange(7); + + // Rewrite Minecart blocks + registerMetaHandler() + .filter(EntityType.MINECART_ABSTRACT, true, 9) + .handle(e -> { + Metadata meta = e.getData(); + + int data = (int) meta.getValue(); + meta.setValue(Protocol1_13To1_13_1.getNewBlockStateId(data)); + + return meta; + }); + } } diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/WorldPackets.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/WorldPackets.java index aa0029ff..a36ed077 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/WorldPackets.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/WorldPackets.java @@ -118,42 +118,6 @@ public class WorldPackets { } }); - //join game - protocol.registerOutgoing(State.PLAY, 0x25, 0x25, new PacketRemapper() { - @Override - public void registerMap() { - map(Type.INT); // 0 - Entity ID - map(Type.UNSIGNED_BYTE); // 1 - Gamemode - map(Type.INT); // 2 - Dimension - - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) throws Exception { - // Store the player - ClientWorld clientChunks = wrapper.user().get(ClientWorld.class); - int dimensionId = wrapper.get(Type.INT, 1); - clientChunks.setEnvironment(dimensionId); - } - }); - } - }); - - //respawn - protocol.registerOutgoing(State.PLAY, 0x38, 0x38, new PacketRemapper() { - @Override - public void registerMap() { - map(Type.INT); // 0 - Dimension ID - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) throws Exception { - ClientWorld clientWorld = wrapper.user().get(ClientWorld.class); - int dimensionId = wrapper.get(Type.INT, 0); - clientWorld.setEnvironment(dimensionId); - } - }); - } - }); - //spawn particle protocol.registerOutgoing(State.PLAY, 0x24, 0x24, new PacketRemapper() { @Override From 58b8f4004b3c5c67855cc4c3d384c96338db6f8b Mon Sep 17 00:00:00 2001 From: Matsv Date: Sun, 27 Jan 2019 14:16:05 +0100 Subject: [PATCH 4/7] :paperclip: Rename 1.13.1 classes --- .../Protocol1_13To1_13_1.java | 18 +++++++++--------- ...tyPackets.java => EntityPackets1_13_1.java} | 4 ++-- ...ackets.java => InventoryPackets1_13_1.java} | 2 +- ...rldPackets.java => WorldPackets1_13_1.java} | 6 +++--- 4 files changed, 15 insertions(+), 15 deletions(-) rename core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/{EntityPackets.java => EntityPackets1_13_1.java} (98%) rename core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/{InventoryPackets.java => InventoryPackets1_13_1.java} (99%) rename core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/{WorldPackets.java => WorldPackets1_13_1.java} (97%) diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/Protocol1_13To1_13_1.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/Protocol1_13To1_13_1.java index d2e0e2bf..1704d890 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/Protocol1_13To1_13_1.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/Protocol1_13To1_13_1.java @@ -2,9 +2,9 @@ package nl.matsv.viabackwards.protocol.protocol1_13to1_13_1; import nl.matsv.viabackwards.api.BackwardsProtocol; import nl.matsv.viabackwards.api.entities.storage.EntityTracker; -import nl.matsv.viabackwards.protocol.protocol1_13to1_13_1.packets.EntityPackets; -import nl.matsv.viabackwards.protocol.protocol1_13to1_13_1.packets.InventoryPackets; -import nl.matsv.viabackwards.protocol.protocol1_13to1_13_1.packets.WorldPackets; +import nl.matsv.viabackwards.protocol.protocol1_13to1_13_1.packets.EntityPackets1_13_1; +import nl.matsv.viabackwards.protocol.protocol1_13to1_13_1.packets.InventoryPackets1_13_1; +import nl.matsv.viabackwards.protocol.protocol1_13to1_13_1.packets.WorldPackets1_13_1; import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.minecraft.item.Item; @@ -19,9 +19,9 @@ public class Protocol1_13To1_13_1 extends BackwardsProtocol { @Override protected void registerPackets() { - new EntityPackets().register(this); - InventoryPackets.register(this); - WorldPackets.register(this); + new EntityPackets1_13_1().register(this); + InventoryPackets1_13_1.register(this); + WorldPackets1_13_1.register(this); //Tab complete registerIncoming(State.PLAY, 0x05, 0x05, new PacketRemapper() { @@ -47,7 +47,7 @@ public class Protocol1_13To1_13_1 extends BackwardsProtocol { handler(new PacketHandler() { @Override public void handle(PacketWrapper wrapper) throws Exception { - InventoryPackets.toServer(wrapper.get(Type.FLAT_ITEM, 0)); + InventoryPackets1_13_1.toServer(wrapper.get(Type.FLAT_ITEM, 0)); wrapper.write(Type.VAR_INT, 0); } }); @@ -128,7 +128,7 @@ public class Protocol1_13To1_13_1 extends BackwardsProtocol { wrapper.passthrough(Type.STRING); // Title wrapper.passthrough(Type.STRING); // Description Item icon = wrapper.passthrough(Type.FLAT_ITEM); - InventoryPackets.toClient(icon); + InventoryPackets1_13_1.toClient(icon); wrapper.passthrough(Type.VAR_INT); // Frame type int flags = wrapper.passthrough(Type.INT); // Flags if ((flags & 1) != 0) @@ -169,7 +169,7 @@ public class Protocol1_13To1_13_1 extends BackwardsProtocol { wrapper.passthrough(Type.STRING); Integer[] items = wrapper.passthrough(Type.VAR_INT_ARRAY); for (int j = 0; j < items.length; j++) { - items[j] = InventoryPackets.getOldItemId(items[j]); + items[j] = InventoryPackets1_13_1.getOldItemId(items[j]); } } } diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/EntityPackets.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/EntityPackets1_13_1.java similarity index 98% rename from core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/EntityPackets.java rename to core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/EntityPackets1_13_1.java index e99a5edc..984c7478 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/EntityPackets.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/EntityPackets1_13_1.java @@ -18,7 +18,7 @@ import us.myles.ViaVersion.api.type.types.version.Types1_13; import us.myles.ViaVersion.packets.State; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; -public class EntityPackets extends EntityRewriter { +public class EntityPackets1_13_1 extends EntityRewriter { @Override protected void registerPackets(Protocol1_13To1_13_1 protocol) { @@ -322,7 +322,7 @@ public class EntityPackets extends EntityRewriter { Metadata meta = e.getData(); if (meta.getMetaType() == MetaType1_13.Slot) { - InventoryPackets.toClient((Item) meta.getValue()); + InventoryPackets1_13_1.toClient((Item) meta.getValue()); } else if (meta.getMetaType() == MetaType1_13.BlockID) { // Convert to new block id int data = (int) meta.getValue(); diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/InventoryPackets.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/InventoryPackets1_13_1.java similarity index 99% rename from core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/InventoryPackets.java rename to core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/InventoryPackets1_13_1.java index 32c5c3fb..058037e7 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/InventoryPackets.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/InventoryPackets1_13_1.java @@ -8,7 +8,7 @@ import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.packets.State; -public class InventoryPackets { +public class InventoryPackets1_13_1 { public static void register(Protocol protocol) { diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/WorldPackets.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/WorldPackets1_13_1.java similarity index 97% rename from core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/WorldPackets.java rename to core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/WorldPackets1_13_1.java index a36ed077..2d3dc3fa 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/WorldPackets.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13to1_13_1/packets/WorldPackets1_13_1.java @@ -13,7 +13,7 @@ import us.myles.ViaVersion.packets.State; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.types.Chunk1_13Type; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; -public class WorldPackets { +public class WorldPackets1_13_1 { public static void register(Protocol protocol) { //Chunk @@ -109,7 +109,7 @@ public class WorldPackets { int id = wrapper.get(Type.INT, 0); int data = wrapper.get(Type.INT, 1); if (id == 1010) { // Play record - wrapper.set(Type.INT, 1, data = InventoryPackets.getNewItemId(data)); + wrapper.set(Type.INT, 1, data = InventoryPackets1_13_1.getNewItemId(data)); } else if (id == 2001) { // Block break + block break sound wrapper.set(Type.INT, 1, data = Protocol1_13To1_13_1.getNewBlockStateId(data)); } @@ -140,7 +140,7 @@ public class WorldPackets { int data = wrapper.passthrough(Type.VAR_INT); wrapper.set(Type.VAR_INT, 0, Protocol1_13To1_13_1.getNewBlockStateId(data)); } else if (id == 27) { - InventoryPackets.toClient(wrapper.passthrough(Type.FLAT_ITEM)); + InventoryPackets1_13_1.toClient(wrapper.passthrough(Type.FLAT_ITEM)); } } }); From 9b7a4b79f7614db779ed86b9c84e7529e9ab1f38 Mon Sep 17 00:00:00 2001 From: Matsv Date: Sun, 27 Jan 2019 14:25:27 +0100 Subject: [PATCH 5/7] :paperclip: Rename 1.13.2 classes --- .../Protocol1_13_1To1_13_2.java | 12 ++++++------ .../{EntityPackets.java => EntityPackets1_13_2.java} | 2 +- ...ntoryPackets.java => InventoryPackets1_13_2.java} | 2 +- .../{WorldPackets.java => WorldPackets1_13_2.java} | 3 ++- 4 files changed, 10 insertions(+), 9 deletions(-) rename core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_1to1_13_2/packets/{EntityPackets.java => EntityPackets1_13_2.java} (99%) rename core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_1to1_13_2/packets/{InventoryPackets.java => InventoryPackets1_13_2.java} (99%) rename core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_1to1_13_2/packets/{WorldPackets.java => WorldPackets1_13_2.java} (97%) diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_1to1_13_2/Protocol1_13_1To1_13_2.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_1to1_13_2/Protocol1_13_1To1_13_2.java index d724dce7..33f7af9e 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_1to1_13_2/Protocol1_13_1To1_13_2.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_1to1_13_2/Protocol1_13_1To1_13_2.java @@ -1,6 +1,9 @@ package nl.matsv.viabackwards.protocol.protocol1_13_1to1_13_2; import nl.matsv.viabackwards.api.BackwardsProtocol; +import nl.matsv.viabackwards.protocol.protocol1_13_1to1_13_2.packets.EntityPackets1_13_2; +import nl.matsv.viabackwards.protocol.protocol1_13_1to1_13_2.packets.InventoryPackets1_13_2; +import nl.matsv.viabackwards.protocol.protocol1_13_1to1_13_2.packets.WorldPackets1_13_2; import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.minecraft.item.Item; @@ -8,17 +11,14 @@ import us.myles.ViaVersion.api.remapper.PacketHandler; import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.packets.State; -import nl.matsv.viabackwards.protocol.protocol1_13_1to1_13_2.packets.EntityPackets; -import nl.matsv.viabackwards.protocol.protocol1_13_1to1_13_2.packets.InventoryPackets; -import nl.matsv.viabackwards.protocol.protocol1_13_1to1_13_2.packets.WorldPackets; public class Protocol1_13_1To1_13_2 extends BackwardsProtocol { @Override protected void registerPackets() { - InventoryPackets.register(this); - WorldPackets.register(this); - EntityPackets.register(this); + InventoryPackets1_13_2.register(this); + WorldPackets1_13_2.register(this); + EntityPackets1_13_2.register(this); //Edit Book registerIncoming(State.PLAY, 0x0B, 0x0B, new PacketRemapper() { diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_1to1_13_2/packets/EntityPackets.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_1to1_13_2/packets/EntityPackets1_13_2.java similarity index 99% rename from core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_1to1_13_2/packets/EntityPackets.java rename to core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_1to1_13_2/packets/EntityPackets1_13_2.java index ad4ecd2d..000800c1 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_1to1_13_2/packets/EntityPackets.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_1to1_13_2/packets/EntityPackets1_13_2.java @@ -12,7 +12,7 @@ import us.myles.ViaVersion.api.type.types.version.Types1_13; import us.myles.ViaVersion.api.type.types.version.Types1_13_2; import us.myles.ViaVersion.packets.State; -public class EntityPackets { +public class EntityPackets1_13_2 { public static void register(Protocol protocol) { diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_1to1_13_2/packets/InventoryPackets.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_1to1_13_2/packets/InventoryPackets1_13_2.java similarity index 99% rename from core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_1to1_13_2/packets/InventoryPackets.java rename to core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_1to1_13_2/packets/InventoryPackets1_13_2.java index ecd88eec..44a44b48 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_1to1_13_2/packets/InventoryPackets.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_1to1_13_2/packets/InventoryPackets1_13_2.java @@ -7,7 +7,7 @@ import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.packets.State; -public class InventoryPackets { +public class InventoryPackets1_13_2 { public static void register(Protocol protocol) { diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_1to1_13_2/packets/WorldPackets.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_1to1_13_2/packets/WorldPackets1_13_2.java similarity index 97% rename from core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_1to1_13_2/packets/WorldPackets.java rename to core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_1to1_13_2/packets/WorldPackets1_13_2.java index 9fc17e0a..92d31a2e 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_1to1_13_2/packets/WorldPackets.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_1to1_13_2/packets/WorldPackets1_13_2.java @@ -7,7 +7,7 @@ import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.packets.State; -public class WorldPackets { +public class WorldPackets1_13_2 { public static void register(Protocol protocol) { //spawn particle @@ -24,6 +24,7 @@ public class WorldPackets { map(Type.FLOAT); // 7 - Offset Z map(Type.FLOAT); // 8 - Particle Data map(Type.INT); // 9 - Particle Count + handler(new PacketHandler() { @Override public void handle(PacketWrapper wrapper) throws Exception { From ff68a5182aa931499576ffdc563627dc1237486d Mon Sep 17 00:00:00 2001 From: Gerrygames Date: Mon, 28 Jan 2019 14:45:52 +0100 Subject: [PATCH 6/7] fix ConcurrentModificationException --- .../protocol1_12_2to1_13/packets/BlockItemPackets1_13.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java index 2e211f3c..e95b096f 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java @@ -634,7 +634,7 @@ public class BlockItemPackets1_13 extends BlockItemRewriter lore = new ArrayList<>(); - for (Tag enchantmentEntry : enchantments) { + for (Tag enchantmentEntry : enchantments.clone()) { if (enchantmentEntry instanceof CompoundTag) { CompoundTag enchEntry = new CompoundTag(""); String newId = (String) ((CompoundTag) enchantmentEntry).get("id").getValue(); From 9e12a199cf86d0ca3c5fc91e90d4ef3d2c515ddd Mon Sep 17 00:00:00 2001 From: creeper123123321 Date: Sat, 2 Feb 2019 17:19:30 -0200 Subject: [PATCH 7/7] Login plugin request and response --- .../packets/PlayerPacket1_13.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/PlayerPacket1_13.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/PlayerPacket1_13.java index a096b02e..7a49b6fa 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/PlayerPacket1_13.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/PlayerPacket1_13.java @@ -9,6 +9,7 @@ import us.myles.ViaVersion.api.minecraft.Position; import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.api.remapper.PacketHandler; import us.myles.ViaVersion.api.remapper.PacketRemapper; +import us.myles.ViaVersion.api.remapper.ValueCreator; import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.packets.State; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ChatRewriter; @@ -17,6 +18,25 @@ import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.packets.InventoryPacke public class PlayerPacket1_13 extends Rewriter { @Override protected void registerPackets(Protocol1_12_2To1_13 protocol) { + // Login Plugin Request + protocol.out(State.LOGIN, 0x04, -1, new PacketRemapper() { + @Override + public void registerMap() { + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper packetWrapper) throws Exception { + packetWrapper.cancel(); + packetWrapper.create(0x02, new ValueCreator() { // Plugin response + @Override + public void write(PacketWrapper newWrapper) throws Exception { + newWrapper.write(Type.VAR_INT, packetWrapper.read(Type.VAR_INT)); // Packet id + newWrapper.write(Type.BOOLEAN, false); // Success + } + }).sendToServer(Protocol1_12_2To1_13.class); + } + }); + } + }); //Plugin Message protocol.out(State.PLAY, 0x19, 0x18, new PacketRemapper() {