diff --git a/api/src/main/java/com/viaversion/viaversion/api/configuration/ViaVersionConfig.java b/api/src/main/java/com/viaversion/viaversion/api/configuration/ViaVersionConfig.java index 801b07a48..f4f2a5668 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/configuration/ViaVersionConfig.java +++ b/api/src/main/java/com/viaversion/viaversion/api/configuration/ViaVersionConfig.java @@ -22,6 +22,7 @@ */ package com.viaversion.viaversion.api.configuration; +import com.google.gson.JsonElement; import it.unimi.dsi.fastutil.ints.IntSet; public interface ViaVersionConfig { @@ -414,4 +415,11 @@ public interface ViaVersionConfig { * @return true if enabled */ boolean isForcedUse1_17ResourcePack(); + + /** + * Get the message that is sent when a user displays a resource pack prompt. + * + * @return cached serialized component + */ + JsonElement get1_17ResourcePackPrompt(); } diff --git a/api/src/main/java/com/viaversion/viaversion/api/connection/UserConnection.java b/api/src/main/java/com/viaversion/viaversion/api/connection/UserConnection.java index e35990000..ebab009d4 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/connection/UserConnection.java +++ b/api/src/main/java/com/viaversion/viaversion/api/connection/UserConnection.java @@ -90,8 +90,8 @@ public interface UserConnection { void addEntityTracker(Class protocolClass, EntityTracker tracker); /** - * Clear all the stored objects. - * Used for bungee when switching servers. + * Clear stored objects and entity trackers. + * Used for Bungee when switching servers. */ void clearStoredObjects(); diff --git a/bukkit-legacy/src/main/java/com/viaversion/viaversion/bukkit/listeners/protocol1_9to1_8/PaperPatch.java b/bukkit-legacy/src/main/java/com/viaversion/viaversion/bukkit/listeners/protocol1_9to1_8/PaperPatch.java index ae032b3c9..29c133fb5 100644 --- a/bukkit-legacy/src/main/java/com/viaversion/viaversion/bukkit/listeners/protocol1_9to1_8/PaperPatch.java +++ b/bukkit-legacy/src/main/java/com/viaversion/viaversion/bukkit/listeners/protocol1_9to1_8/PaperPatch.java @@ -19,6 +19,7 @@ package com.viaversion.viaversion.bukkit.listeners.protocol1_9to1_8; import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -43,18 +44,20 @@ public class PaperPatch extends ViaBukkitListener { @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) public void onPlace(BlockPlaceEvent e) { if (isOnPipe(e.getPlayer())) { - Location location = e.getPlayer().getLocation(); - Location diff = location.clone().subtract(e.getBlock().getLocation().add(0.5D, 0, 0.5D)); Material block = e.getBlockPlaced().getType(); if (isPlacable(block)) { return; } - if (location.getBlock().equals(e.getBlock())) { + Location location = e.getPlayer().getLocation(); + Block locationBlock = location.getBlock(); + + if (locationBlock.equals(e.getBlock())) { e.setCancelled(true); } else { - if (location.getBlock().getRelative(BlockFace.UP).equals(e.getBlock())) { + if (locationBlock.getRelative(BlockFace.UP).equals(e.getBlock())) { e.setCancelled(true); } else { + Location diff = location.clone().subtract(e.getBlock().getLocation().add(0.5D, 0, 0.5D)); // Within radius of block if (Math.abs(diff.getX()) <= 0.8 && Math.abs(diff.getZ()) <= 0.8D) { // Are they on the edge / shifting ish diff --git a/bukkit/src/main/java/com/viaversion/viaversion/bukkit/platform/BukkitViaLoader.java b/bukkit/src/main/java/com/viaversion/viaversion/bukkit/platform/BukkitViaLoader.java index 162a8560c..7bfd9759b 100644 --- a/bukkit/src/main/java/com/viaversion/viaversion/bukkit/platform/BukkitViaLoader.java +++ b/bukkit/src/main/java/com/viaversion/viaversion/bukkit/platform/BukkitViaLoader.java @@ -117,11 +117,20 @@ public class BukkitViaLoader implements ViaPlatformLoader { } } - if ((Bukkit.getVersion().toLowerCase(Locale.ROOT).contains("paper") - || Bukkit.getVersion().toLowerCase(Locale.ROOT).contains("taco") - || Bukkit.getVersion().toLowerCase(Locale.ROOT).contains("torch")) - && serverProtocolVersion < ProtocolVersion.v1_12.getVersion()) { - storeListener(new PaperPatch(plugin)).register(); + if (serverProtocolVersion < ProtocolVersion.v1_12.getVersion() && !Boolean.getBoolean("com.viaversion.ignorePaperBlockPlacePatch")) { + boolean paper = true; + try { + Class.forName("org.github.paperspigot.PaperSpigotConfig"); // Paper 1.8 ? + } catch (ClassNotFoundException ignored) { + try { + Class.forName("com.destroystokyo.paper.PaperConfig"); // Paper 1.9+ ? + } catch (ClassNotFoundException alsoIgnored) { + paper = false; // Definitely not Paper + } + } + if (paper) { + storeListener(new PaperPatch(plugin)).register(); + } } /* Providers */ diff --git a/common/src/main/java/com/viaversion/viaversion/configuration/AbstractViaConfig.java b/common/src/main/java/com/viaversion/viaversion/configuration/AbstractViaConfig.java index b704bd689..f4a76d02a 100644 --- a/common/src/main/java/com/viaversion/viaversion/configuration/AbstractViaConfig.java +++ b/common/src/main/java/com/viaversion/viaversion/configuration/AbstractViaConfig.java @@ -17,6 +17,7 @@ */ package com.viaversion.viaversion.configuration; +import com.google.gson.JsonElement; import com.viaversion.viaversion.api.configuration.ViaVersionConfig; import com.viaversion.viaversion.util.Config; import it.unimi.dsi.fastutil.ints.IntOpenHashSet; @@ -75,6 +76,7 @@ public abstract class AbstractViaConfig extends Config implements ViaVersionConf private boolean instantRespawn; private boolean ignoreLongChannelNames; private boolean forcedUse1_17ResourcePack; + private JsonElement resourcePack1_17PromptMessage; protected AbstractViaConfig(File configFile) { super(configFile); @@ -136,6 +138,7 @@ public abstract class AbstractViaConfig extends Config implements ViaVersionConf instantRespawn = getBoolean("use-1_15-instant-respawn", false); ignoreLongChannelNames = getBoolean("ignore-long-1_16-channel-names", true); forcedUse1_17ResourcePack = getBoolean("forced-use-1_17-resource-pack", false); + resourcePack1_17PromptMessage = getSerializedComponent("resource-pack-1_17-prompt"); } @Override @@ -414,4 +417,9 @@ public abstract class AbstractViaConfig extends Config implements ViaVersionConf public boolean isForcedUse1_17ResourcePack() { return forcedUse1_17ResourcePack; } + + @Override + public JsonElement get1_17ResourcePackPrompt() { + return resourcePack1_17PromptMessage; + } } diff --git a/common/src/main/java/com/viaversion/viaversion/connection/UserConnectionImpl.java b/common/src/main/java/com/viaversion/viaversion/connection/UserConnectionImpl.java index ce94d0127..385c8fbc8 100644 --- a/common/src/main/java/com/viaversion/viaversion/connection/UserConnectionImpl.java +++ b/common/src/main/java/com/viaversion/viaversion/connection/UserConnectionImpl.java @@ -114,6 +114,7 @@ public class UserConnectionImpl implements UserConnection { @Override public void clearStoredObjects() { storedObjects.clear(); + entityTrackers.clear(); } @Override diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16to1_15_2/Protocol1_16To1_15_2.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16to1_15_2/Protocol1_16To1_15_2.java index 5c45d7969..f71ee4c34 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16to1_15_2/Protocol1_16To1_15_2.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16to1_15_2/Protocol1_16To1_15_2.java @@ -39,7 +39,6 @@ import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.metadata.Metadat import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.packets.EntityPackets; import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.packets.InventoryPackets; import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.packets.WorldPackets; -import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.storage.InventoryTracker1_16; import com.viaversion.viaversion.rewriter.ComponentRewriter; import com.viaversion.viaversion.api.minecraft.RegistryType; import com.viaversion.viaversion.rewriter.SoundRewriter; @@ -276,7 +275,6 @@ public class Protocol1_16To1_15_2 extends AbstractProtocol { - InventoryTracker1_16 inventoryTracker = wrapper.user().get(InventoryTracker1_16.class); - // Don't send an arm swing if the player is switching between inventories. - if (inventoryTracker.getInventory() != -1) { - wrapper.cancel(); - } - }); - } - }); } } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16to1_15_2/packets/InventoryPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16to1_15_2/packets/InventoryPackets.java index 91b887207..9a9e18fb3 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16to1_15_2/packets/InventoryPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16to1_15_2/packets/InventoryPackets.java @@ -25,14 +25,16 @@ import com.github.steveice10.opennbt.tag.builtin.NumberTag; import com.github.steveice10.opennbt.tag.builtin.StringTag; import com.github.steveice10.opennbt.tag.builtin.Tag; import com.viaversion.viaversion.api.minecraft.item.Item; +import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; +import com.viaversion.viaversion.api.protocol.remapper.PacketHandler; import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper; import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.types.UUIDIntArrayType; import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.data.RecipeRewriter1_14; import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15; +import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.ClientboundPackets1_16; import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.Protocol1_16To1_15_2; import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.ServerboundPackets1_16; -import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.storage.InventoryTracker1_16; import com.viaversion.viaversion.rewriter.ItemRewriter; import java.util.UUID; @@ -45,6 +47,15 @@ public class InventoryPackets extends ItemRewriter { @Override public void registerPackets() { + // clear cursor item to prevent client to try dropping it during navigation between multiple inventories causing arm swing + PacketHandler cursorRemapper = wrapper -> { + PacketWrapper clearPacket = wrapper.create(ClientboundPackets1_16.SET_SLOT); + clearPacket.write(Type.UNSIGNED_BYTE, (short)-1); + clearPacket.write(Type.SHORT, (short)-1); + clearPacket.write(Type.FLAT_VAR_INT_ITEM, null); + clearPacket.send(Protocol1_16To1_15_2.class); + }; + protocol.registerClientbound(ClientboundPackets1_15.OPEN_WINDOW, new PacketRemapper() { @Override public void registerMap() { @@ -53,26 +64,19 @@ public class InventoryPackets extends ItemRewriter { map(Type.COMPONENT); // Window Title handler(wrapper -> { - InventoryTracker1_16 inventoryTracker = wrapper.user().get(InventoryTracker1_16.class); - int windowId = wrapper.get(Type.VAR_INT, 0); int windowType = wrapper.get(Type.VAR_INT, 1); if (windowType >= 20) { // smithing added with id 20 wrapper.set(Type.VAR_INT, 1, ++windowType); } - inventoryTracker.setInventory((short) windowId); }); + handler(cursorRemapper); } }); protocol.registerClientbound(ClientboundPackets1_15.CLOSE_WINDOW, new PacketRemapper() { @Override public void registerMap() { - map(Type.UNSIGNED_BYTE); - - handler(wrapper -> { - InventoryTracker1_16 inventoryTracker = wrapper.user().get(InventoryTracker1_16.class); - inventoryTracker.setInventory((short) -1); - }); + handler(cursorRemapper); } }); @@ -119,18 +123,6 @@ public class InventoryPackets extends ItemRewriter { registerClickWindow(ServerboundPackets1_16.CLICK_WINDOW, Type.FLAT_VAR_INT_ITEM); registerCreativeInvAction(ServerboundPackets1_16.CREATIVE_INVENTORY_ACTION, Type.FLAT_VAR_INT_ITEM); - protocol.registerServerbound(ServerboundPackets1_16.CLOSE_WINDOW, new PacketRemapper() { - @Override - public void registerMap() { - map(Type.UNSIGNED_BYTE); - - handler(wrapper -> { - InventoryTracker1_16 inventoryTracker = wrapper.user().get(InventoryTracker1_16.class); - inventoryTracker.setInventory((short) -1); - }); - } - }); - protocol.registerServerbound(ServerboundPackets1_16.EDIT_BOOK, new PacketRemapper() { @Override public void registerMap() { diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16to1_15_2/storage/InventoryTracker1_16.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16to1_15_2/storage/InventoryTracker1_16.java deleted file mode 100644 index 9320582c6..000000000 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16to1_15_2/storage/InventoryTracker1_16.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion - * Copyright (C) 2016-2021 ViaVersion and contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package com.viaversion.viaversion.protocols.protocol1_16to1_15_2.storage; - -import com.viaversion.viaversion.api.connection.StorableObject; - -public class InventoryTracker1_16 implements StorableObject { - private short inventory = -1; - - public short getInventory() { - return this.inventory; - } - - public void setInventory(short inventory) { - this.inventory = inventory; - } -} diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_17to1_16_4/Protocol1_17To1_16_4.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_17to1_16_4/Protocol1_17To1_16_4.java index 5abb2a8b3..6b96ad3f9 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_17to1_16_4/Protocol1_17To1_16_4.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_17to1_16_4/Protocol1_17To1_16_4.java @@ -102,7 +102,7 @@ public final class Protocol1_17To1_16_4 extends AbstractProtocol(); } } + + public @Nullable JsonElement getSerializedComponent(String key) { + final Object o = this.config.get(key); + if (o != null && !((String) o).isEmpty()) { + return GsonComponentSerializer.gson().serializeToTree(LegacyComponentSerializer.legacySection().deserialize((String) o)); + } else { + return null; + } + } } diff --git a/common/src/main/resources/assets/viaversion/config.yml b/common/src/main/resources/assets/viaversion/config.yml index a4869da2c..593117d2d 100644 --- a/common/src/main/resources/assets/viaversion/config.yml +++ b/common/src/main/resources/assets/viaversion/config.yml @@ -153,6 +153,8 @@ ignore-long-1_16-channel-names: true # # Force 1.17+ client to accept the server resource pack; they will automatically disconnect if they decline. forced-use-1_17-resource-pack: false +# The message to be displayed at the prompt when the 1.17+ client receives the server resource pack. +resource-pack-1_17-prompt: '' # #----------------------------------------------------------# # 1.9+ CLIENTS ON 1.8 SERVERS OPTIONS #