3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-08 17:20:24 +01:00

Merge remote-tracking branch 'origin/master' into dev

Dieser Commit ist enthalten in:
KennyTV 2021-06-21 14:58:38 +02:00
Commit aed1a63a77
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 6BE3B555EBC5982B
13 geänderte Dateien mit 70 neuen und 83 gelöschten Zeilen

Datei anzeigen

@ -22,6 +22,7 @@
*/ */
package com.viaversion.viaversion.api.configuration; package com.viaversion.viaversion.api.configuration;
import com.google.gson.JsonElement;
import it.unimi.dsi.fastutil.ints.IntSet; import it.unimi.dsi.fastutil.ints.IntSet;
public interface ViaVersionConfig { public interface ViaVersionConfig {
@ -414,4 +415,11 @@ public interface ViaVersionConfig {
* @return true if enabled * @return true if enabled
*/ */
boolean isForcedUse1_17ResourcePack(); boolean isForcedUse1_17ResourcePack();
/**
* Get the message that is sent when a user displays a resource pack prompt.
*
* @return cached serialized component
*/
JsonElement get1_17ResourcePackPrompt();
} }

Datei anzeigen

@ -90,8 +90,8 @@ public interface UserConnection {
void addEntityTracker(Class<? extends Protocol> protocolClass, EntityTracker tracker); void addEntityTracker(Class<? extends Protocol> protocolClass, EntityTracker tracker);
/** /**
* Clear all the stored objects. * Clear stored objects and entity trackers.
* Used for bungee when switching servers. * Used for Bungee when switching servers.
*/ */
void clearStoredObjects(); void clearStoredObjects();

Datei anzeigen

@ -19,6 +19,7 @@ package com.viaversion.viaversion.bukkit.listeners.protocol1_9to1_8;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
@ -43,18 +44,20 @@ public class PaperPatch extends ViaBukkitListener {
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onPlace(BlockPlaceEvent e) { public void onPlace(BlockPlaceEvent e) {
if (isOnPipe(e.getPlayer())) { 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(); Material block = e.getBlockPlaced().getType();
if (isPlacable(block)) { if (isPlacable(block)) {
return; return;
} }
if (location.getBlock().equals(e.getBlock())) { Location location = e.getPlayer().getLocation();
Block locationBlock = location.getBlock();
if (locationBlock.equals(e.getBlock())) {
e.setCancelled(true); e.setCancelled(true);
} else { } else {
if (location.getBlock().getRelative(BlockFace.UP).equals(e.getBlock())) { if (locationBlock.getRelative(BlockFace.UP).equals(e.getBlock())) {
e.setCancelled(true); e.setCancelled(true);
} else { } else {
Location diff = location.clone().subtract(e.getBlock().getLocation().add(0.5D, 0, 0.5D));
// Within radius of block // Within radius of block
if (Math.abs(diff.getX()) <= 0.8 && Math.abs(diff.getZ()) <= 0.8D) { if (Math.abs(diff.getX()) <= 0.8 && Math.abs(diff.getZ()) <= 0.8D) {
// Are they on the edge / shifting ish // Are they on the edge / shifting ish

Datei anzeigen

@ -117,11 +117,20 @@ public class BukkitViaLoader implements ViaPlatformLoader {
} }
} }
if ((Bukkit.getVersion().toLowerCase(Locale.ROOT).contains("paper") if (serverProtocolVersion < ProtocolVersion.v1_12.getVersion() && !Boolean.getBoolean("com.viaversion.ignorePaperBlockPlacePatch")) {
|| Bukkit.getVersion().toLowerCase(Locale.ROOT).contains("taco") boolean paper = true;
|| Bukkit.getVersion().toLowerCase(Locale.ROOT).contains("torch")) try {
&& serverProtocolVersion < ProtocolVersion.v1_12.getVersion()) { Class.forName("org.github.paperspigot.PaperSpigotConfig"); // Paper 1.8 ?
storeListener(new PaperPatch(plugin)).register(); } 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 */ /* Providers */

Datei anzeigen

@ -17,6 +17,7 @@
*/ */
package com.viaversion.viaversion.configuration; package com.viaversion.viaversion.configuration;
import com.google.gson.JsonElement;
import com.viaversion.viaversion.api.configuration.ViaVersionConfig; import com.viaversion.viaversion.api.configuration.ViaVersionConfig;
import com.viaversion.viaversion.util.Config; import com.viaversion.viaversion.util.Config;
import it.unimi.dsi.fastutil.ints.IntOpenHashSet; import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
@ -75,6 +76,7 @@ public abstract class AbstractViaConfig extends Config implements ViaVersionConf
private boolean instantRespawn; private boolean instantRespawn;
private boolean ignoreLongChannelNames; private boolean ignoreLongChannelNames;
private boolean forcedUse1_17ResourcePack; private boolean forcedUse1_17ResourcePack;
private JsonElement resourcePack1_17PromptMessage;
protected AbstractViaConfig(File configFile) { protected AbstractViaConfig(File configFile) {
super(configFile); super(configFile);
@ -136,6 +138,7 @@ public abstract class AbstractViaConfig extends Config implements ViaVersionConf
instantRespawn = getBoolean("use-1_15-instant-respawn", false); instantRespawn = getBoolean("use-1_15-instant-respawn", false);
ignoreLongChannelNames = getBoolean("ignore-long-1_16-channel-names", true); ignoreLongChannelNames = getBoolean("ignore-long-1_16-channel-names", true);
forcedUse1_17ResourcePack = getBoolean("forced-use-1_17-resource-pack", false); forcedUse1_17ResourcePack = getBoolean("forced-use-1_17-resource-pack", false);
resourcePack1_17PromptMessage = getSerializedComponent("resource-pack-1_17-prompt");
} }
@Override @Override
@ -414,4 +417,9 @@ public abstract class AbstractViaConfig extends Config implements ViaVersionConf
public boolean isForcedUse1_17ResourcePack() { public boolean isForcedUse1_17ResourcePack() {
return forcedUse1_17ResourcePack; return forcedUse1_17ResourcePack;
} }
@Override
public JsonElement get1_17ResourcePackPrompt() {
return resourcePack1_17PromptMessage;
}
} }

Datei anzeigen

@ -114,6 +114,7 @@ public class UserConnectionImpl implements UserConnection {
@Override @Override
public void clearStoredObjects() { public void clearStoredObjects() {
storedObjects.clear(); storedObjects.clear();
entityTrackers.clear();
} }
@Override @Override

Datei anzeigen

@ -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.EntityPackets;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.packets.InventoryPackets; 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.packets.WorldPackets;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.storage.InventoryTracker1_16;
import com.viaversion.viaversion.rewriter.ComponentRewriter; import com.viaversion.viaversion.rewriter.ComponentRewriter;
import com.viaversion.viaversion.api.minecraft.RegistryType; import com.viaversion.viaversion.api.minecraft.RegistryType;
import com.viaversion.viaversion.rewriter.SoundRewriter; import com.viaversion.viaversion.rewriter.SoundRewriter;
@ -276,7 +275,6 @@ public class Protocol1_16To1_15_2 extends AbstractProtocol<ClientboundPackets1_1
@Override @Override
public void init(UserConnection userConnection) { public void init(UserConnection userConnection) {
userConnection.addEntityTracker(this.getClass(), new EntityTrackerBase(userConnection, Entity1_16Types.PLAYER)); userConnection.addEntityTracker(this.getClass(), new EntityTrackerBase(userConnection, Entity1_16Types.PLAYER));
userConnection.put(new InventoryTracker1_16());
} }
@Override @Override

Datei anzeigen

@ -26,6 +26,7 @@ import com.github.steveice10.opennbt.tag.builtin.LongTag;
import com.github.steveice10.opennbt.tag.builtin.StringTag; import com.github.steveice10.opennbt.tag.builtin.StringTag;
import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.minecraft.entities.Entity1_16Types; import com.viaversion.viaversion.api.minecraft.entities.Entity1_16Types;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler; import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper; import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
@ -34,9 +35,7 @@ import com.viaversion.viaversion.api.type.types.version.Types1_16;
import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15; 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.ClientboundPackets1_16;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.Protocol1_16To1_15_2; 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.metadata.MetadataRewriter1_16To1_15_2; import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.metadata.MetadataRewriter1_16To1_15_2;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.storage.InventoryTracker1_16;
import java.util.UUID; import java.util.UUID;
@ -267,18 +266,5 @@ public class EntityPackets {
}); });
} }
}); });
protocol.registerServerbound(ServerboundPackets1_16.ANIMATION, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
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();
}
});
}
});
} }
} }

Datei anzeigen

@ -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.StringTag;
import com.github.steveice10.opennbt.tag.builtin.Tag; import com.github.steveice10.opennbt.tag.builtin.Tag;
import com.viaversion.viaversion.api.minecraft.item.Item; 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.protocol.remapper.PacketRemapper;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.UUIDIntArrayType; 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_14to1_13_2.data.RecipeRewriter1_14;
import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15; 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.Protocol1_16To1_15_2;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.ServerboundPackets1_16; 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 com.viaversion.viaversion.rewriter.ItemRewriter;
import java.util.UUID; import java.util.UUID;
@ -45,6 +47,15 @@ public class InventoryPackets extends ItemRewriter<Protocol1_16To1_15_2> {
@Override @Override
public void registerPackets() { 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() { protocol.registerClientbound(ClientboundPackets1_15.OPEN_WINDOW, new PacketRemapper() {
@Override @Override
public void registerMap() { public void registerMap() {
@ -53,26 +64,19 @@ public class InventoryPackets extends ItemRewriter<Protocol1_16To1_15_2> {
map(Type.COMPONENT); // Window Title map(Type.COMPONENT); // Window Title
handler(wrapper -> { 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); int windowType = wrapper.get(Type.VAR_INT, 1);
if (windowType >= 20) { // smithing added with id 20 if (windowType >= 20) { // smithing added with id 20
wrapper.set(Type.VAR_INT, 1, ++windowType); wrapper.set(Type.VAR_INT, 1, ++windowType);
} }
inventoryTracker.setInventory((short) windowId);
}); });
handler(cursorRemapper);
} }
}); });
protocol.registerClientbound(ClientboundPackets1_15.CLOSE_WINDOW, new PacketRemapper() { protocol.registerClientbound(ClientboundPackets1_15.CLOSE_WINDOW, new PacketRemapper() {
@Override @Override
public void registerMap() { public void registerMap() {
map(Type.UNSIGNED_BYTE); handler(cursorRemapper);
handler(wrapper -> {
InventoryTracker1_16 inventoryTracker = wrapper.user().get(InventoryTracker1_16.class);
inventoryTracker.setInventory((short) -1);
});
} }
}); });
@ -119,18 +123,6 @@ public class InventoryPackets extends ItemRewriter<Protocol1_16To1_15_2> {
registerClickWindow(ServerboundPackets1_16.CLICK_WINDOW, Type.FLAT_VAR_INT_ITEM); registerClickWindow(ServerboundPackets1_16.CLICK_WINDOW, Type.FLAT_VAR_INT_ITEM);
registerCreativeInvAction(ServerboundPackets1_16.CREATIVE_INVENTORY_ACTION, 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() { protocol.registerServerbound(ServerboundPackets1_16.EDIT_BOOK, new PacketRemapper() {
@Override @Override
public void registerMap() { public void registerMap() {

Datei anzeigen

@ -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 <http://www.gnu.org/licenses/>.
*/
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;
}
}

Datei anzeigen

@ -102,7 +102,7 @@ public final class Protocol1_17To1_16_4 extends AbstractProtocol<ClientboundPack
wrapper.passthrough(Type.STRING); wrapper.passthrough(Type.STRING);
wrapper.passthrough(Type.STRING); wrapper.passthrough(Type.STRING);
wrapper.write(Type.BOOLEAN, Via.getConfig().isForcedUse1_17ResourcePack()); // Required wrapper.write(Type.BOOLEAN, Via.getConfig().isForcedUse1_17ResourcePack()); // Required
wrapper.write(Type.OPTIONAL_COMPONENT, null); // Prompt message wrapper.write(Type.OPTIONAL_COMPONENT, Via.getConfig().get1_17ResourcePackPrompt()); // Prompt message
}); });
} }
}); });

Datei anzeigen

@ -17,7 +17,10 @@
*/ */
package com.viaversion.viaversion.util; package com.viaversion.viaversion.util;
import com.google.gson.JsonElement;
import com.viaversion.viaversion.api.configuration.ConfigurationProvider; import com.viaversion.viaversion.api.configuration.ConfigurationProvider;
import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
import org.yaml.snakeyaml.DumperOptions; import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.Yaml;
@ -207,4 +210,13 @@ public abstract class Config implements ConfigurationProvider {
return new ArrayList<>(); return new ArrayList<>();
} }
} }
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;
}
}
} }

Datei anzeigen

@ -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. # Force 1.17+ client to accept the server resource pack; they will automatically disconnect if they decline.
forced-use-1_17-resource-pack: false 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 # # 1.9+ CLIENTS ON 1.8 SERVERS OPTIONS #