From 740ebc0c1df756181c8e433b6f713d2bf13adb95 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 3 Feb 2023 17:59:58 +0100 Subject: [PATCH 01/42] Add click callback for REntityServer --- .../src/de/steamwar/entity/REntityServer.java | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java b/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java index 70a5fee..5359b4a 100644 --- a/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java +++ b/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java @@ -19,8 +19,10 @@ package de.steamwar.entity; +import com.comphenix.tinyprotocol.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; import de.steamwar.core.Core; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -33,7 +35,9 @@ import org.bukkit.event.player.PlayerQuitEvent; import java.util.HashMap; import java.util.HashSet; import java.util.Set; +import java.util.concurrent.atomic.AtomicReference; import java.util.function.BiConsumer; +import java.util.function.BiFunction; import java.util.function.Consumer; @@ -42,13 +46,41 @@ public class REntityServer implements Listener { private static final HashSet emptyEntities = new HashSet<>(0); private static final HashSet emptyPlayers = new HashSet<>(0); + private static final Class useEntity = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInUseEntity"); + private static final Reflection.FieldAccessor useEntityTarget = Reflection.getField(useEntity, int.class, 0); + private static final Reflection.FieldAccessor useEntityAction = Reflection.getField(useEntity, int.class, 1); + + private final HashMap entityMap = new HashMap<>(); private final HashMap> entities = new HashMap<>(); private final HashMap> players = new HashMap<>(); private final HashMap lastLocation = new HashMap<>(); private final HashMap viewDistance = new HashMap<>(); + private EntityActionListener callback = null; + + private BiFunction filter = (player, packet) -> { + if (callback == null) return packet; + int target = useEntityTarget.get(packet); + if (!entityMap.containsKey(target)) return packet; + + REntity entity = entityMap.get(target); + int action = useEntityAction.get(packet); + if (action == 2) action = 0; + int finalAction = action; + + Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> { + callback.onAction(player, entity, finalAction == 0 ? EntityAction.INTERACT : EntityAction.ATTACK); + }, 0); + return null; + }; + public REntityServer() { Core.getInstance().getServer().getPluginManager().registerEvents(this, Core.getInstance()); + TinyProtocol.instance.addFilter(useEntity, filter); + } + + public void setCallback(EntityActionListener callback) { + this.callback = callback; } public void addPlayer(Player player) { @@ -64,6 +96,7 @@ public class REntityServer implements Listener { } public void close() { + TinyProtocol.instance.removeFilter(useEntity, filter); for(Player player : lastLocation.keySet().toArray(new Player[0])) { removePlayer(player); } @@ -71,6 +104,7 @@ public class REntityServer implements Listener { } void addEntity(REntity entity) { + entityMap.put(entity.entityId, entity); addEntityToChunk(entity); entity.spawn(packet -> updateEntity(entity, packet)); } @@ -104,6 +138,7 @@ public class REntityServer implements Listener { void removeEntity(REntity entity) { entity.despawn(packet -> updateEntity(entity, packet)); removeEntityFromChunk(entity); + entityMap.put(entity.entityId, entity); } private void addEntityToChunk(REntity entity) { @@ -226,4 +261,13 @@ public class REntityServer implements Listener { private long chunkToId(int x, int z) { return ((long) x << 32) + z; } + + public enum EntityAction { + INTERACT, + ATTACK, + } + + public interface EntityActionListener { + void onAction(Player player, REntity entity, EntityAction action); + } } From 6c461fc38f5b77a8c93038cbffa9437bbf9f3b39 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 4 Feb 2023 11:55:36 +0100 Subject: [PATCH 02/42] Hotfix CommonCore (CommandFramework) --- CommonCore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CommonCore b/CommonCore index 9ea02eb..89b0c14 160000 --- a/CommonCore +++ b/CommonCore @@ -1 +1 @@ -Subproject commit 9ea02ebcd4620e7baa6980cd88e1a4dabd59e50c +Subproject commit 89b0c14da664589a7c9699d73bf72028cdf9dd0d From 495e33b195ee85d24ad347f7811468a407adf500 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 4 Feb 2023 14:37:04 +0100 Subject: [PATCH 03/42] Rebuild --- SpigotCore_Main/src/de/steamwar/entity/REntityServer.java | 1 - 1 file changed, 1 deletion(-) diff --git a/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java b/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java index 5359b4a..f0cf1eb 100644 --- a/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java +++ b/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java @@ -35,7 +35,6 @@ import org.bukkit.event.player.PlayerQuitEvent; import java.util.HashMap; import java.util.HashSet; import java.util.Set; -import java.util.concurrent.atomic.AtomicReference; import java.util.function.BiConsumer; import java.util.function.BiFunction; import java.util.function.Consumer; From b2122d24e8271ef3ad700db87d5d634cf53809a8 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 4 Feb 2023 14:39:28 +0100 Subject: [PATCH 04/42] Fix removeEntity --- SpigotCore_Main/src/de/steamwar/entity/REntityServer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java b/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java index f0cf1eb..68b2a11 100644 --- a/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java +++ b/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java @@ -137,7 +137,7 @@ public class REntityServer implements Listener { void removeEntity(REntity entity) { entity.despawn(packet -> updateEntity(entity, packet)); removeEntityFromChunk(entity); - entityMap.put(entity.entityId, entity); + entityMap.remove(entity.entityId); } private void addEntityToChunk(REntity entity) { From b1dea856fc602ecee1601b2f97a48de75b375ce5 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 4 Feb 2023 18:20:40 +0100 Subject: [PATCH 05/42] Add REntity x,y,z getters --- .../src/de/steamwar/entity/REntity.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/SpigotCore_Main/src/de/steamwar/entity/REntity.java b/SpigotCore_Main/src/de/steamwar/entity/REntity.java index d6ace1a..2d95c9b 100644 --- a/SpigotCore_Main/src/de/steamwar/entity/REntity.java +++ b/SpigotCore_Main/src/de/steamwar/entity/REntity.java @@ -20,13 +20,17 @@ package de.steamwar.entity; import com.comphenix.tinyprotocol.Reflection; -import de.steamwar.core.*; +import de.steamwar.core.BountifulWrapper; +import de.steamwar.core.Core; +import de.steamwar.core.FlatteningWrapper; +import de.steamwar.core.ProtocolWrapper; import it.unimi.dsi.fastutil.ints.IntArrayList; import it.unimi.dsi.fastutil.ints.IntList; import lombok.Getter; import org.bukkit.Location; import org.bukkit.entity.EntityType; import org.bukkit.inventory.ItemStack; +import org.bukkit.util.Vector; import java.util.*; import java.util.function.Consumer; @@ -214,6 +218,18 @@ public class REntity { } } + public double getX() { + return x; + } + + public double getY() { + return y; + } + + public double getZ() { + return z; + } + private static int spawnPacketOffset() { switch (Core.getVersion()) { case 8: From b5a9b3d068dc27bac29e94ba608173bc1a21e7ea Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 4 Feb 2023 19:56:04 +0100 Subject: [PATCH 06/42] Fix pr stuff --- SpigotCore_Main/src/de/steamwar/entity/REntityServer.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java b/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java index 68b2a11..7ebb46a 100644 --- a/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java +++ b/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java @@ -67,9 +67,9 @@ public class REntityServer implements Listener { if (action == 2) action = 0; int finalAction = action; - Bukkit.getScheduler().runTaskLater(Core.getInstance(), () -> { + Bukkit.getScheduler().runTask(Core.getInstance(), () -> { callback.onAction(player, entity, finalAction == 0 ? EntityAction.INTERACT : EntityAction.ATTACK); - }, 0); + }); return null; }; From c02d7c2c7d975b3e94f1438f41e7a8ea1ae259e7 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 4 Feb 2023 20:24:24 +0100 Subject: [PATCH 07/42] Fix pr stuff --- .../src/de/steamwar/entity/REntityServer.java | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java b/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java index 7ebb46a..ecc59c7 100644 --- a/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java +++ b/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java @@ -35,6 +35,7 @@ import org.bukkit.event.player.PlayerQuitEvent; import java.util.HashMap; import java.util.HashSet; import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; import java.util.function.BiConsumer; import java.util.function.BiFunction; import java.util.function.Consumer; @@ -49,7 +50,7 @@ public class REntityServer implements Listener { private static final Reflection.FieldAccessor useEntityTarget = Reflection.getField(useEntity, int.class, 0); private static final Reflection.FieldAccessor useEntityAction = Reflection.getField(useEntity, int.class, 1); - private final HashMap entityMap = new HashMap<>(); + private final ConcurrentHashMap entityMap = new ConcurrentHashMap<>(); private final HashMap> entities = new HashMap<>(); private final HashMap> players = new HashMap<>(); private final HashMap lastLocation = new HashMap<>(); @@ -60,26 +61,23 @@ public class REntityServer implements Listener { private BiFunction filter = (player, packet) -> { if (callback == null) return packet; int target = useEntityTarget.get(packet); - if (!entityMap.containsKey(target)) return packet; - REntity entity = entityMap.get(target); - int action = useEntityAction.get(packet); - if (action == 2) action = 0; - int finalAction = action; + if (entity == null) return packet; + EntityAction action = useEntityAction.get(packet) == 1 ? EntityAction.ATTACK : EntityAction.INTERACT; Bukkit.getScheduler().runTask(Core.getInstance(), () -> { - callback.onAction(player, entity, finalAction == 0 ? EntityAction.INTERACT : EntityAction.ATTACK); + callback.onAction(player, entity, action); }); return null; }; public REntityServer() { Core.getInstance().getServer().getPluginManager().registerEvents(this, Core.getInstance()); - TinyProtocol.instance.addFilter(useEntity, filter); } public void setCallback(EntityActionListener callback) { this.callback = callback; + TinyProtocol.instance.addFilter(useEntity, filter); } public void addPlayer(Player player) { From e39e128aa69635c2c4c888c5fbd86c7d5602d092 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 5 Feb 2023 19:17:25 +0100 Subject: [PATCH 08/42] prevent double filter --- SpigotCore_Main/src/de/steamwar/entity/REntityServer.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java b/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java index ecc59c7..a718c41 100644 --- a/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java +++ b/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java @@ -76,8 +76,11 @@ public class REntityServer implements Listener { } public void setCallback(EntityActionListener callback) { + boolean uninitialized = this.callback == null; this.callback = callback; - TinyProtocol.instance.addFilter(useEntity, filter); + + if(uninitialized) + TinyProtocol.instance.addFilter(useEntity, filter); } public void addPlayer(Player player) { From ca4c31a353afc7df63a6fd1ba4bdf503d4c88344 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Wed, 8 Feb 2023 21:29:11 +0100 Subject: [PATCH 09/42] Hotfix REntityServer --- SpigotCore_Main/src/de/steamwar/entity/REntityServer.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java b/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java index e0ea912..5987112 100644 --- a/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java +++ b/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java @@ -23,7 +23,6 @@ import com.comphenix.tinyprotocol.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; import de.steamwar.core.Core; import de.steamwar.core.FlatteningWrapper; -import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -49,7 +48,7 @@ public class REntityServer implements Listener { private static final Class useEntity = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInUseEntity"); private static final Reflection.FieldAccessor useEntityTarget = Reflection.getField(useEntity, int.class, 0); - private static final Reflection.FieldAccessor useEntityAction = Reflection.getField(useEntity, int.class, 1); + //private static final Reflection.FieldAccessor useEntityAction = Reflection.getField(useEntity, int.class, 1); private final ConcurrentHashMap entityMap = new ConcurrentHashMap<>(); private final HashMap> entities = new HashMap<>(); @@ -65,10 +64,10 @@ public class REntityServer implements Listener { REntity entity = entityMap.get(target); if (entity == null) return packet; - EntityAction action = useEntityAction.get(packet) == 1 ? EntityAction.ATTACK : EntityAction.INTERACT; + /*EntityAction action = useEntityAction.get(packet) == 1 ? EntityAction.ATTACK : EntityAction.INTERACT; Bukkit.getScheduler().runTask(Core.getInstance(), () -> { callback.onAction(player, entity, action); - }); + });*/ return null; }; From 4efd305bf90c0d8fca28e165440bad306f3a0419 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Wed, 8 Feb 2023 21:44:11 +0100 Subject: [PATCH 10/42] Add debug output --- SpigotCore_Main/src/de/steamwar/techhider/TechHider.java | 1 + 1 file changed, 1 insertion(+) diff --git a/SpigotCore_Main/src/de/steamwar/techhider/TechHider.java b/SpigotCore_Main/src/de/steamwar/techhider/TechHider.java index 36e70b3..9373a76 100644 --- a/SpigotCore_Main/src/de/steamwar/techhider/TechHider.java +++ b/SpigotCore_Main/src/de/steamwar/techhider/TechHider.java @@ -49,6 +49,7 @@ public class TechHider { private static final Reflection.MethodInvoker getBlockByBlockData = Reflection.getTypedMethod(iBlockData, null, block); private static final Reflection.MethodInvoker getMaterialByBlock = Reflection.getTypedMethod(craftMagicNumbers, "getMaterial", Material.class, block); public static boolean iBlockDataHidden(Set obfuscate, Object iBlockData) { + System.out.println(iBlockData.getClass() + " " + getBlockByBlockData.invoke(iBlockData).getClass()); return obfuscate.contains((Material) getMaterialByBlock.invoke(null, getBlockByBlockData.invoke(iBlockData))); } From 22f598753e8f5dfb28594b5c27dfe061365f2df1 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Wed, 8 Feb 2023 21:52:07 +0100 Subject: [PATCH 11/42] Fix getTypedMethod recursion --- SpigotCore_Main/src/com/comphenix/tinyprotocol/Reflection.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SpigotCore_Main/src/com/comphenix/tinyprotocol/Reflection.java b/SpigotCore_Main/src/com/comphenix/tinyprotocol/Reflection.java index c3100b2..fc1e8c1 100644 --- a/SpigotCore_Main/src/com/comphenix/tinyprotocol/Reflection.java +++ b/SpigotCore_Main/src/com/comphenix/tinyprotocol/Reflection.java @@ -251,7 +251,7 @@ public final class Reflection { // Search in every superclass if (clazz.getSuperclass() != null) - return getMethod(clazz.getSuperclass(), methodName, params); + return getTypedMethod(clazz.getSuperclass(), methodName, returnType, params); throw new IllegalStateException(String.format("Unable to find method %s (%s).", methodName, Arrays.asList(params))); } From 76d16a2c0301c5e016e75a39500374fd23ae79c4 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Wed, 8 Feb 2023 21:52:24 +0100 Subject: [PATCH 12/42] Remove debug code --- SpigotCore_Main/src/de/steamwar/techhider/TechHider.java | 1 - 1 file changed, 1 deletion(-) diff --git a/SpigotCore_Main/src/de/steamwar/techhider/TechHider.java b/SpigotCore_Main/src/de/steamwar/techhider/TechHider.java index 9373a76..36e70b3 100644 --- a/SpigotCore_Main/src/de/steamwar/techhider/TechHider.java +++ b/SpigotCore_Main/src/de/steamwar/techhider/TechHider.java @@ -49,7 +49,6 @@ public class TechHider { private static final Reflection.MethodInvoker getBlockByBlockData = Reflection.getTypedMethod(iBlockData, null, block); private static final Reflection.MethodInvoker getMaterialByBlock = Reflection.getTypedMethod(craftMagicNumbers, "getMaterial", Material.class, block); public static boolean iBlockDataHidden(Set obfuscate, Object iBlockData) { - System.out.println(iBlockData.getClass() + " " + getBlockByBlockData.invoke(iBlockData).getClass()); return obfuscate.contains((Material) getMaterialByBlock.invoke(null, getBlockByBlockData.invoke(iBlockData))); } From 61341b815f8b17d6947cb2a751af59c0a57f6e09 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Wed, 8 Feb 2023 22:28:42 +0100 Subject: [PATCH 13/42] Fix EntityTypes --- .../src/de/steamwar/core/FlatteningWrapper14.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/SpigotCore_14/src/de/steamwar/core/FlatteningWrapper14.java b/SpigotCore_14/src/de/steamwar/core/FlatteningWrapper14.java index e650a29..8996475 100644 --- a/SpigotCore_14/src/de/steamwar/core/FlatteningWrapper14.java +++ b/SpigotCore_14/src/de/steamwar/core/FlatteningWrapper14.java @@ -22,6 +22,7 @@ package de.steamwar.core; import com.comphenix.tinyprotocol.Reflection; import org.bukkit.Bukkit; import org.bukkit.Material; +import org.bukkit.NamespacedKey; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -325,9 +326,13 @@ public class FlatteningWrapper14 implements FlatteningWrapper.IFlatteningWrapper return displayName != null ? Optional.of(ChatWrapper.impl.stringToChatComponent(displayName)) : Optional.empty(); } - private static final Reflection.FieldAccessor spawnType = Reflection.getField(ProtocolWrapper.spawnPacket, Reflection.getClass("{nms.world.entity}.EntityTypes"), 0); + private static final Class registryBlocks = Reflection.getClass("{nms.core}.RegistryBlocks"); + private static final Class entityTypes = Reflection.getClass("{nms.world.entity}.EntityTypes"); + private static final Object entityTypesRegistry = Reflection.getField(Reflection.getClass("{nms.core}.IRegistry"), registryBlocks, 0, entityTypes).get(null); + private static final Reflection.MethodInvoker get = Reflection.getMethod(registryBlocks, null, Reflection.getClass("{nms.resources}.MinecraftKey")); + private static final Reflection.FieldAccessor spawnType = Reflection.getField(ProtocolWrapper.spawnPacket, entityTypes, 0); private static final Reflection.FieldAccessor spawnLivingType = Core.getVersion() > 19 ? spawnType : Reflection.getField(ProtocolWrapper.spawnLivingPacket, int.class, 1); - private static final Reflection.MethodInvoker getEntityTypes = Reflection.getMethod("{obc}.util.CraftMagicNumbers", "getEntityTypes", EntityType.class); + private static final Reflection.MethodInvoker toMinecraft = Reflection.getMethod("{obc}.util.CraftNamespacedKey", "toMinecraft", NamespacedKey.class); private static final Map types = new HashMap<>(); static { types.put(EntityType.ARMOR_STAND, 1); @@ -335,9 +340,9 @@ public class FlatteningWrapper14 implements FlatteningWrapper.IFlatteningWrapper @Override public void setSpawnPacketType(Object packet, EntityType type) { if(type.isAlive()) { - spawnLivingType.set(packet, Core.getVersion() > 18 ? getEntityTypes.invoke(null, type) : types.get(type)); + spawnLivingType.set(packet, Core.getVersion() > 18 ? get.invoke(entityTypesRegistry, toMinecraft.invoke(null, type.getKey())) : types.get(type)); } else { - spawnType.set(packet, getEntityTypes.invoke(null, type)); + spawnType.set(packet, get.invoke(entityTypesRegistry, toMinecraft.invoke(null, type.getKey()))); } } From c032f55d2e140f4654815d3c21c8f5c4d2fc1154 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 10 Feb 2023 16:20:43 +0100 Subject: [PATCH 14/42] Fix REntityServer click listener --- .../src/de/steamwar/entity/REntityServer.java | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java b/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java index ecc59c7..df18398 100644 --- a/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java +++ b/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java @@ -47,8 +47,17 @@ public class REntityServer implements Listener { private static final HashSet emptyPlayers = new HashSet<>(0); private static final Class useEntity = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInUseEntity"); + private static final Class useEntityEnumAction = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInUseEntity$EnumEntityUseAction"); private static final Reflection.FieldAccessor useEntityTarget = Reflection.getField(useEntity, int.class, 0); - private static final Reflection.FieldAccessor useEntityAction = Reflection.getField(useEntity, int.class, 1); + private static final Reflection.FieldAccessor useEntityAction = (Reflection.FieldAccessor) Reflection.getField(useEntity, useEntityEnumAction, 0); + private static final Reflection.MethodInvoker useEntityGetAction; + static { + if (useEntityEnumAction.isEnum()) { + useEntityGetAction = null; + } else { + useEntityGetAction = Reflection.getMethod(useEntity, "a"); + } + } private final ConcurrentHashMap entityMap = new ConcurrentHashMap<>(); private final HashMap> entities = new HashMap<>(); @@ -64,7 +73,15 @@ public class REntityServer implements Listener { REntity entity = entityMap.get(target); if (entity == null) return packet; - EntityAction action = useEntityAction.get(packet) == 1 ? EntityAction.ATTACK : EntityAction.INTERACT; + Object entityAction = useEntityAction.get(packet); + int entityActionOrdinal; + if (useEntityEnumAction.isEnum()) { + entityActionOrdinal = ((Enum) entityAction).ordinal(); + } else { + entityActionOrdinal = ((Enum) useEntityGetAction.invoke(entityAction)).ordinal(); + } + + EntityAction action = entityActionOrdinal == 1 ? EntityAction.ATTACK : EntityAction.INTERACT; Bukkit.getScheduler().runTask(Core.getInstance(), () -> { callback.onAction(player, entity, action); }); From 91e2a9a619cc44950ffae528d55779bef23c5d46 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Thu, 16 Feb 2023 13:53:05 +0100 Subject: [PATCH 15/42] Hotfix: SchematicSelector --- .../src/de/steamwar/inventory/SchematicSelector.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java b/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java index e57ef68..ed3f856 100644 --- a/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java +++ b/SpigotCore_Main/src/de/steamwar/inventory/SchematicSelector.java @@ -163,7 +163,7 @@ public class SchematicSelector { } if(!singleDirOpen) { if(NodeMember.getNodeMember(parent.getId(), user.getId()) != null) { - return Optional.ofNullable(SchematicNode.byIdAndUser(user, parent.getId())).flatMap(SchematicNode::getOptionalParent).map(integer -> SchematicNode.byIdAndUser(user, integer)).orElse(null); + return NodeMember.getNodeMember(parent.getId(), user.getId()).getParent().map(integer -> SchematicNode.byIdAndUser(user, integer)).orElse(null); } else { return getParent(parent).orElse(null); } From c3087948b528bc28d277bab36c76d3db379c7fb9 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 17 Feb 2023 15:11:53 +0100 Subject: [PATCH 16/42] Anti NoCom DOS --- .../src/de/steamwar/core/Core.java | 7 ++- .../de/steamwar/core/events/AntiNocom.java | 50 +++++++++++++++++++ 2 files changed, 53 insertions(+), 4 deletions(-) create mode 100644 SpigotCore_Main/src/de/steamwar/core/events/AntiNocom.java diff --git a/SpigotCore_Main/src/de/steamwar/core/Core.java b/SpigotCore_Main/src/de/steamwar/core/Core.java index ff0d555..d1e6949 100644 --- a/SpigotCore_Main/src/de/steamwar/core/Core.java +++ b/SpigotCore_Main/src/de/steamwar/core/Core.java @@ -22,10 +22,7 @@ package de.steamwar.core; import com.comphenix.tinyprotocol.TinyProtocol; import de.steamwar.command.*; import de.steamwar.core.authlib.AuthlibInjector; -import de.steamwar.core.events.ChattingEvent; -import de.steamwar.core.events.PartialChunkFixer; -import de.steamwar.core.events.PlayerJoinedEvent; -import de.steamwar.core.events.WorldLoadEvent; +import de.steamwar.core.events.*; import de.steamwar.message.Message; import de.steamwar.network.NetworkReceiver; import de.steamwar.network.handlers.ServerDataHandler; @@ -99,6 +96,8 @@ public class Core extends JavaPlugin{ AuthlibInjector.inject(); TinyProtocol.init(); + new AntiNocom(); + if(Core.getVersion() < 17 && Bukkit.getPluginManager().getPlugin("ViaVersion") != null) new PartialChunkFixer(); diff --git a/SpigotCore_Main/src/de/steamwar/core/events/AntiNocom.java b/SpigotCore_Main/src/de/steamwar/core/events/AntiNocom.java new file mode 100644 index 0000000..cb509ad --- /dev/null +++ b/SpigotCore_Main/src/de/steamwar/core/events/AntiNocom.java @@ -0,0 +1,50 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.core.events; + +import com.comphenix.tinyprotocol.Reflection; +import com.comphenix.tinyprotocol.TinyProtocol; +import de.steamwar.core.Core; +import de.steamwar.sql.SWException; +import de.steamwar.techhider.ProtocolUtils; +import de.steamwar.techhider.TechHider; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +public class AntiNocom { + + public AntiNocom() { + TinyProtocol.instance.addFilter(blockDig, this::onDig); + } + + private static final Class blockDig = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInBlockDig"); + private static final Reflection.FieldAccessor digPosition = Reflection.getField(blockDig, TechHider.blockPosition, 0); + private Object onDig(Player player, Object packet) { + Object pos = digPosition.get(packet); + int x = TechHider.blockPositionX.get(pos); + int z = TechHider.blockPositionZ.get(pos); + if(!player.getWorld().isChunkLoaded(ProtocolUtils.posToChunk(x), ProtocolUtils.posToChunk(z))) { + Bukkit.getScheduler().runTask(Core.getInstance(), () -> player.kickPlayer(null)); + SWException.log(player.getName() + " kicked for digging an unloaded block (potential NoCom-DOS attack)", ""); + return null; + } + return packet; + } +} From d3c27dd0f291af06ea088c353e6086caf7e068cf Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 17 Feb 2023 15:31:37 +0100 Subject: [PATCH 17/42] Add more debug code --- SpigotCore_Main/src/de/steamwar/core/events/AntiNocom.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SpigotCore_Main/src/de/steamwar/core/events/AntiNocom.java b/SpigotCore_Main/src/de/steamwar/core/events/AntiNocom.java index cb509ad..63b289c 100644 --- a/SpigotCore_Main/src/de/steamwar/core/events/AntiNocom.java +++ b/SpigotCore_Main/src/de/steamwar/core/events/AntiNocom.java @@ -42,7 +42,7 @@ public class AntiNocom { int z = TechHider.blockPositionZ.get(pos); if(!player.getWorld().isChunkLoaded(ProtocolUtils.posToChunk(x), ProtocolUtils.posToChunk(z))) { Bukkit.getScheduler().runTask(Core.getInstance(), () -> player.kickPlayer(null)); - SWException.log(player.getName() + " kicked for digging an unloaded block (potential NoCom-DOS attack)", ""); + SWException.log(player.getName() + " kicked for digging an unloaded block (potential NoCom-DOS attack)", x + " " + z); return null; } return packet; From 022b0983b6f9f45ab59f95b8fb8cc9c15ad0079c Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 17 Feb 2023 15:34:08 +0100 Subject: [PATCH 18/42] Fix NoCom detection (dropping blocks) --- SpigotCore_Main/src/de/steamwar/core/events/AntiNocom.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SpigotCore_Main/src/de/steamwar/core/events/AntiNocom.java b/SpigotCore_Main/src/de/steamwar/core/events/AntiNocom.java index 63b289c..aea52b2 100644 --- a/SpigotCore_Main/src/de/steamwar/core/events/AntiNocom.java +++ b/SpigotCore_Main/src/de/steamwar/core/events/AntiNocom.java @@ -40,7 +40,7 @@ public class AntiNocom { Object pos = digPosition.get(packet); int x = TechHider.blockPositionX.get(pos); int z = TechHider.blockPositionZ.get(pos); - if(!player.getWorld().isChunkLoaded(ProtocolUtils.posToChunk(x), ProtocolUtils.posToChunk(z))) { + if((x != 0 || z != 0) && !player.getWorld().isChunkLoaded(ProtocolUtils.posToChunk(x), ProtocolUtils.posToChunk(z))) { Bukkit.getScheduler().runTask(Core.getInstance(), () -> player.kickPlayer(null)); SWException.log(player.getName() + " kicked for digging an unloaded block (potential NoCom-DOS attack)", x + " " + z); return null; From efbed65ab43d5c82a3669161c1f3fcf7a5042d8d Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 18 Feb 2023 14:07:00 +0100 Subject: [PATCH 19/42] Update CommonCore --- CommonCore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CommonCore b/CommonCore index 89b0c14..aa70f42 160000 --- a/CommonCore +++ b/CommonCore @@ -1 +1 @@ -Subproject commit 89b0c14da664589a7c9699d73bf72028cdf9dd0d +Subproject commit aa70f423d87e9f6534ad2dd1f20a5122179c423f From 0a90cabf191b060db8e4b44964ac9669b3f90925 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 19 Feb 2023 21:27:37 +0100 Subject: [PATCH 20/42] Expand AntiNocom --- .../de/steamwar/core/events/AntiNocom.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/SpigotCore_Main/src/de/steamwar/core/events/AntiNocom.java b/SpigotCore_Main/src/de/steamwar/core/events/AntiNocom.java index aea52b2..7cdf31f 100644 --- a/SpigotCore_Main/src/de/steamwar/core/events/AntiNocom.java +++ b/SpigotCore_Main/src/de/steamwar/core/events/AntiNocom.java @@ -28,10 +28,45 @@ import de.steamwar.techhider.TechHider; import org.bukkit.Bukkit; import org.bukkit.entity.Player; +import java.util.function.Function; + public class AntiNocom { public AntiNocom() { TinyProtocol.instance.addFilter(blockDig, this::onDig); + + if(Core.getVersion() > 8) { + registerUseItem(); + } + } + + private void registerUseItem() { + Class useItem = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInUseItem"); + + Function getPosition; + if(Core.getVersion() > 12) { + Class movingObjectPositionBlock = Reflection.getClass("{nms.world.phys}.MovingObjectPositionBlock"); + Reflection.FieldAccessor useItemPosition = Reflection.getField(useItem, movingObjectPositionBlock, 0); + Reflection.FieldAccessor movingBlockPosition = Reflection.getField(movingObjectPositionBlock, TechHider.blockPosition, 0); + + getPosition = (packet) -> movingBlockPosition.get(useItemPosition.get(packet)); + } else { + getPosition = Reflection.getField(blockDig, TechHider.blockPosition, 0)::get; + } + + TinyProtocol.instance.addFilter(useItem, (player, packet) -> { + Object pos = getPosition.apply(packet); + int x = TechHider.blockPositionX.get(pos); + int z = TechHider.blockPositionZ.get(pos); + + if(!player.getWorld().isChunkLoaded(ProtocolUtils.posToChunk(x), ProtocolUtils.posToChunk(z))) { + Bukkit.getScheduler().runTask(Core.getInstance(), () -> player.kickPlayer(null)); + SWException.log(player.getName() + " kicked for using item on unloaded block (potential NoCom-DOS attack)", x + " " + z); + return null; + } + + return packet; + }); } private static final Class blockDig = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInBlockDig"); From 3f4372d9a355ea045ad75b3bf082c407430a8147 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 20 Feb 2023 21:30:48 +0100 Subject: [PATCH 21/42] Fix AntiNocom 1.9-1.12 --- SpigotCore_Main/src/de/steamwar/core/events/AntiNocom.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SpigotCore_Main/src/de/steamwar/core/events/AntiNocom.java b/SpigotCore_Main/src/de/steamwar/core/events/AntiNocom.java index 7cdf31f..0799523 100644 --- a/SpigotCore_Main/src/de/steamwar/core/events/AntiNocom.java +++ b/SpigotCore_Main/src/de/steamwar/core/events/AntiNocom.java @@ -51,7 +51,7 @@ public class AntiNocom { getPosition = (packet) -> movingBlockPosition.get(useItemPosition.get(packet)); } else { - getPosition = Reflection.getField(blockDig, TechHider.blockPosition, 0)::get; + getPosition = Reflection.getField(useItem, TechHider.blockPosition, 0)::get; } TinyProtocol.instance.addFilter(useItem, (player, packet) -> { From be593a7d947f3c9cfe76ed179420e1ed94b8ddd0 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 21 Feb 2023 10:00:40 +0100 Subject: [PATCH 22/42] Fix spawn Armorstand --- SpigotCore_14/src/de/steamwar/core/FlatteningWrapper14.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SpigotCore_14/src/de/steamwar/core/FlatteningWrapper14.java b/SpigotCore_14/src/de/steamwar/core/FlatteningWrapper14.java index 8996475..e0eb2ea 100644 --- a/SpigotCore_14/src/de/steamwar/core/FlatteningWrapper14.java +++ b/SpigotCore_14/src/de/steamwar/core/FlatteningWrapper14.java @@ -331,7 +331,7 @@ public class FlatteningWrapper14 implements FlatteningWrapper.IFlatteningWrapper private static final Object entityTypesRegistry = Reflection.getField(Reflection.getClass("{nms.core}.IRegistry"), registryBlocks, 0, entityTypes).get(null); private static final Reflection.MethodInvoker get = Reflection.getMethod(registryBlocks, null, Reflection.getClass("{nms.resources}.MinecraftKey")); private static final Reflection.FieldAccessor spawnType = Reflection.getField(ProtocolWrapper.spawnPacket, entityTypes, 0); - private static final Reflection.FieldAccessor spawnLivingType = Core.getVersion() > 19 ? spawnType : Reflection.getField(ProtocolWrapper.spawnLivingPacket, int.class, 1); + private static final Reflection.FieldAccessor spawnLivingType = Core.getVersion() > 18 ? spawnType : Reflection.getField(ProtocolWrapper.spawnLivingPacket, int.class, 1); private static final Reflection.MethodInvoker toMinecraft = Reflection.getMethod("{obc}.util.CraftNamespacedKey", "toMinecraft", NamespacedKey.class); private static final Map types = new HashMap<>(); static { From 4f24fe862dde3401b961097205f0919b093c31db Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 21 Feb 2023 10:15:52 +0100 Subject: [PATCH 23/42] Fix REntity initialization --- SpigotCore_Main/src/de/steamwar/entity/RArmorStand.java | 3 ++- SpigotCore_Main/src/de/steamwar/entity/REntity.java | 4 +--- .../src/de/steamwar/entity/RFallingBlockEntity.java | 1 + SpigotCore_Main/src/de/steamwar/entity/RPlayer.java | 1 + 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/entity/RArmorStand.java b/SpigotCore_Main/src/de/steamwar/entity/RArmorStand.java index 5513d2b..369754a 100644 --- a/SpigotCore_Main/src/de/steamwar/entity/RArmorStand.java +++ b/SpigotCore_Main/src/de/steamwar/entity/RArmorStand.java @@ -52,8 +52,9 @@ public class RArmorStand extends REntity { private final Size size; public RArmorStand(REntityServer server, Location location, Size size) { - super(server, EntityType.ARMOR_STAND, location); + super(server, EntityType.ARMOR_STAND, location, 0); this.size = size; + server.addEntity(this); } @Override diff --git a/SpigotCore_Main/src/de/steamwar/entity/REntity.java b/SpigotCore_Main/src/de/steamwar/entity/REntity.java index 5d01b40..83dc391 100644 --- a/SpigotCore_Main/src/de/steamwar/entity/REntity.java +++ b/SpigotCore_Main/src/de/steamwar/entity/REntity.java @@ -30,7 +30,6 @@ import lombok.Getter; import org.bukkit.Location; import org.bukkit.entity.EntityType; import org.bukkit.inventory.ItemStack; -import org.bukkit.util.Vector; import java.util.*; import java.util.function.Consumer; @@ -77,6 +76,7 @@ public class REntity { public REntity(REntityServer server, EntityType entityType, Location location) { this(server,entityType,location,0); + server.addEntity(this); } protected REntity(REntityServer server, EntityType entityType, Location location,int objectData) { @@ -101,8 +101,6 @@ public class REntity { this.isGlowing = false; this.objectData = objectData; - - server.addEntity(this); } public void move(Location location) { diff --git a/SpigotCore_Main/src/de/steamwar/entity/RFallingBlockEntity.java b/SpigotCore_Main/src/de/steamwar/entity/RFallingBlockEntity.java index b436997..b17fefa 100644 --- a/SpigotCore_Main/src/de/steamwar/entity/RFallingBlockEntity.java +++ b/SpigotCore_Main/src/de/steamwar/entity/RFallingBlockEntity.java @@ -29,5 +29,6 @@ public class RFallingBlockEntity extends REntity{ public RFallingBlockEntity(REntityServer server, Location location, Material material) { super(server, EntityType.FALLING_BLOCK, location, BlockIds.impl.materialToId(material) >> (Core.getVersion() <= 12 ? 4 : 0)); + server.addEntity(this); } } diff --git a/SpigotCore_Main/src/de/steamwar/entity/RPlayer.java b/SpigotCore_Main/src/de/steamwar/entity/RPlayer.java index fa6d513..c862db6 100644 --- a/SpigotCore_Main/src/de/steamwar/entity/RPlayer.java +++ b/SpigotCore_Main/src/de/steamwar/entity/RPlayer.java @@ -79,6 +79,7 @@ public class RPlayer extends REntity { super(server, EntityType.PLAYER, uuid, location,0); this.name = name; //team.addEntry(name); + server.addEntity(this); } @Override From afb7f1c69841e7b1e44d388e090bd8193ac2203a Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Tue, 21 Feb 2023 13:24:32 +0100 Subject: [PATCH 24/42] Seperate SchematicData --- CommonCore | 2 +- .../src/de/steamwar/sql/SchematicData.java | 44 +++---------------- 2 files changed, 7 insertions(+), 39 deletions(-) diff --git a/CommonCore b/CommonCore index aa70f42..e52e9c5 160000 --- a/CommonCore +++ b/CommonCore @@ -1 +1 @@ -Subproject commit aa70f423d87e9f6534ad2dd1f20a5122179c423f +Subproject commit e52e9c5ccd8ef9b87ce06d4eeeaaa4044afa89b5 diff --git a/SpigotCore_Main/src/de/steamwar/sql/SchematicData.java b/SpigotCore_Main/src/de/steamwar/sql/SchematicData.java index 87b6708..ecbf86a 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/SchematicData.java +++ b/SpigotCore_Main/src/de/steamwar/sql/SchematicData.java @@ -36,11 +36,6 @@ import java.util.zip.GZIPInputStream; public class SchematicData { - static { - new SqlTypeMapper<>(PipedInputStream.class, "BLOB", (rs, identifier) -> { throw new SecurityException("PipedInputStream is write only datatype"); }, PreparedStatement::setBinaryStream); - new SqlTypeMapper<>(ByteArrayInputStream.class, "BLOB", (rs, identifier) -> { throw new SecurityException("ByteArrayInputStream is write only datatype"); }, PreparedStatement::setBinaryStream); - } - public static Clipboard clipboardFromStream(InputStream is, boolean schemFormat) { try { return WorldEditWrapper.impl.getClipboard(is, schemFormat); @@ -49,42 +44,20 @@ public class SchematicData { } } - private static final Statement updateDatabase = new Statement("UPDATE SchematicNode SET NodeData = ?, NodeFormat = ? WHERE NodeId = ?"); - private static final Statement selSchemData = new Statement("SELECT NodeData FROM SchematicNode WHERE NodeId = ?"); - - private final SchematicNode node; + private final NodeData data; public SchematicData(SchematicNode node) { - this.node = node; + this.data = NodeData.get(node); if(node.isDir()) throw new SecurityException("Node is Directory"); } - public InputStream schemData() throws IOException { - try { - return selSchemData.select(rs -> { - rs.next(); - Blob schemData = rs.getBlob("NodeData"); - if(schemData == null) { - throw new SecurityException("SchemData is null"); - } - try { - return new GZIPInputStream(schemData.getBinaryStream()); - } catch (IOException e) { - throw new SecurityException("SchemData is wrong", e); - } - }, node.getId()); - } catch (Exception e) { - throw new IOException(e); - } - } - public Clipboard load() throws IOException, NoClipboardException { - return WorldEditWrapper.impl.getClipboard(schemData(), node.getSchemFormat()); + return WorldEditWrapper.impl.getClipboard(data.schemData(), data.getNodeFormat()); } public void loadToPlayer(Player player) throws IOException, NoClipboardException { - WorldEditWrapper.impl.setPlayerClipboard(player, schemData(), node.getSchemFormat()); + WorldEditWrapper.impl.setPlayerClipboard(player, data.schemData(), data.getNodeFormat()); } public void saveFromPlayer(Player player) throws IOException, NoClipboardException { @@ -92,16 +65,11 @@ public class SchematicData { } public void saveFromPlayer(Player player, boolean newFormat) throws IOException, NoClipboardException { - saveFromStream(WorldEditWrapper.impl.getPlayerClipboard(player, newFormat), newFormat); + data.saveFromStream(WorldEditWrapper.impl.getPlayerClipboard(player, newFormat), newFormat); } @Deprecated public void saveFromBytes(byte[] bytes, boolean newFormat) { - saveFromStream(new ByteArrayInputStream(bytes), newFormat); - } - - public void saveFromStream(InputStream blob, boolean newFormat) { - updateDatabase.update(blob, newFormat, node.getId()); - node.setNodeFormat(newFormat); + data.saveFromStream(new ByteArrayInputStream(bytes), newFormat); } } From 833e6f58184880317e5ad4c338f96af8ee17030e Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 23 Feb 2023 11:03:36 +0100 Subject: [PATCH 25/42] Fix stuff from merge --- SpigotCore_Main/src/de/steamwar/entity/REntityServer.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java b/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java index df18398..f40e3a9 100644 --- a/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java +++ b/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java @@ -22,6 +22,7 @@ package de.steamwar.entity; import com.comphenix.tinyprotocol.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; import de.steamwar.core.Core; +import de.steamwar.core.FlatteningWrapper; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.Player; @@ -93,8 +94,11 @@ public class REntityServer implements Listener { } public void setCallback(EntityActionListener callback) { + boolean uninitialized = this.callback == null; this.callback = callback; - TinyProtocol.instance.addFilter(useEntity, filter); + + if(uninitialized) + TinyProtocol.instance.addFilter(useEntity, filter); } public void addPlayer(Player player) { @@ -261,7 +265,7 @@ public class REntityServer implements Listener { } private int viewRadius(Player player) { - return player.getClientViewDistance() / 2; + return FlatteningWrapper.impl.getViewDistance(player) / 2; } private long entityToId(REntity entity) { From 26f267cc287105a7438a5ccd58811bac2439c772 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 23 Feb 2023 14:26:16 +0100 Subject: [PATCH 26/42] Update CommonCore --- CommonCore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CommonCore b/CommonCore index aa70f42..95b46f3 160000 --- a/CommonCore +++ b/CommonCore @@ -1 +1 @@ -Subproject commit aa70f423d87e9f6534ad2dd1f20a5122179c423f +Subproject commit 95b46f3a9a83eb63f5770552134967a1921ae159 From ad9b2465ee7140696b56eb1710b2205e2b032642 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 23 Feb 2023 16:59:36 +0100 Subject: [PATCH 27/42] Simplify REntityFilter --- .../src/de/steamwar/entity/REntityServer.java | 37 +++++++------------ 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java b/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java index f40e3a9..7c60ad4 100644 --- a/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java +++ b/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java @@ -40,6 +40,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.function.BiConsumer; import java.util.function.BiFunction; import java.util.function.Consumer; +import java.util.function.Function; public class REntityServer implements Listener { @@ -48,15 +49,16 @@ public class REntityServer implements Listener { private static final HashSet emptyPlayers = new HashSet<>(0); private static final Class useEntity = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInUseEntity"); - private static final Class useEntityEnumAction = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInUseEntity$EnumEntityUseAction"); private static final Reflection.FieldAccessor useEntityTarget = Reflection.getField(useEntity, int.class, 0); - private static final Reflection.FieldAccessor useEntityAction = (Reflection.FieldAccessor) Reflection.getField(useEntity, useEntityEnumAction, 0); - private static final Reflection.MethodInvoker useEntityGetAction; + private static final Class useEntityEnumAction = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInUseEntity$EnumEntityUseAction"); + private static final Reflection.FieldAccessor useEntityAction = Reflection.getField(useEntity, useEntityEnumAction, 0); + private static final Function getEntityAction; static { - if (useEntityEnumAction.isEnum()) { - useEntityGetAction = null; + if(Core.getVersion() > 15) { + Reflection.MethodInvoker useEntityGetAction = Reflection.getMethod(useEntity, "a"); + getEntityAction = value -> ((Enum) useEntityGetAction.invoke(value)).ordinal(); } else { - useEntityGetAction = Reflection.getMethod(useEntity, "a"); + getEntityAction = value -> ((Enum) value).ordinal(); } } @@ -68,24 +70,13 @@ public class REntityServer implements Listener { private EntityActionListener callback = null; - private BiFunction filter = (player, packet) -> { - if (callback == null) return packet; - int target = useEntityTarget.get(packet); - REntity entity = entityMap.get(target); - if (entity == null) return packet; + private final BiFunction filter = (player, packet) -> { + REntity entity = entityMap.get(useEntityTarget.get(packet)); + if (entity == null) + return packet; - Object entityAction = useEntityAction.get(packet); - int entityActionOrdinal; - if (useEntityEnumAction.isEnum()) { - entityActionOrdinal = ((Enum) entityAction).ordinal(); - } else { - entityActionOrdinal = ((Enum) useEntityGetAction.invoke(entityAction)).ordinal(); - } - - EntityAction action = entityActionOrdinal == 1 ? EntityAction.ATTACK : EntityAction.INTERACT; - Bukkit.getScheduler().runTask(Core.getInstance(), () -> { - callback.onAction(player, entity, action); - }); + EntityAction action = getEntityAction.apply(useEntityAction.get(packet)) == 1 ? EntityAction.ATTACK : EntityAction.INTERACT; + Bukkit.getScheduler().runTask(Core.getInstance(), () -> callback.onAction(player, entity, action)); return null; }; From 1fbc3c883568569293aadca331a42ffefbcbebca Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 23 Feb 2023 17:01:12 +0100 Subject: [PATCH 28/42] Fix build --- .../src/de/steamwar/core/events/PlayerJoinedEvent.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/core/events/PlayerJoinedEvent.java b/SpigotCore_Main/src/de/steamwar/core/events/PlayerJoinedEvent.java index aae2000..fe342bd 100644 --- a/SpigotCore_Main/src/de/steamwar/core/events/PlayerJoinedEvent.java +++ b/SpigotCore_Main/src/de/steamwar/core/events/PlayerJoinedEvent.java @@ -35,10 +35,7 @@ public class PlayerJoinedEvent implements Listener{ @EventHandler(priority = EventPriority.LOWEST) private void onJoin(PlayerJoinEvent event) { Player player = event.getPlayer(); - if(!Statement.productionDatabase()) { - SteamwarUser.createOrUpdateUsername(player.getUniqueId(), player.getName()); - } - SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + SteamwarUser user = Statement.productionDatabase() ? SteamwarUser.get(player.getUniqueId()) : SteamwarUser.getOrCreate(player.getUniqueId(), player.getName(), uuid -> {}, (oldName, newName) -> {}); if(user.getUserGroup() != UserGroup.Member) { UserGroup group = user.getUserGroup(); From 4ec767e9225cad64e3386bcc12a6c1635eec456a Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 23 Feb 2023 17:20:55 +0100 Subject: [PATCH 29/42] Hotfix SWUser Init --- CommonCore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CommonCore b/CommonCore index 95b46f3..3778d6c 160000 --- a/CommonCore +++ b/CommonCore @@ -1 +1 @@ -Subproject commit 95b46f3a9a83eb63f5770552134967a1921ae159 +Subproject commit 3778d6c1f943bb87025e4a3ab23f76c25e6325b6 From 5e6b86f2ba0dded68a4589ac76285e1a17e07137 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 23 Feb 2023 17:22:38 +0100 Subject: [PATCH 30/42] Hotfix REntityServer --- SpigotCore_Main/src/de/steamwar/entity/REntityServer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java b/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java index 7c60ad4..d01a64f 100644 --- a/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java +++ b/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java @@ -55,7 +55,7 @@ public class REntityServer implements Listener { private static final Function getEntityAction; static { if(Core.getVersion() > 15) { - Reflection.MethodInvoker useEntityGetAction = Reflection.getMethod(useEntity, "a"); + Reflection.MethodInvoker useEntityGetAction = Reflection.getMethod(useEntityEnumAction, "a"); getEntityAction = value -> ((Enum) useEntityGetAction.invoke(value)).ordinal(); } else { getEntityAction = value -> ((Enum) value).ordinal(); From 02d756137e437f0f2a6fd228eb030505469ce341 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 23 Feb 2023 17:56:25 +0100 Subject: [PATCH 31/42] Fix Memory Leak --- .../src/de/steamwar/entity/REntityServer.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java b/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java index d01a64f..b2bec15 100644 --- a/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java +++ b/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java @@ -197,11 +197,18 @@ public class REntityServer implements Listener { @EventHandler public void onQuit(PlayerQuitEvent e) { Player player = e.getPlayer(); + viewDistance.remove(player); Location location = lastLocation.remove(player); if(location == null) return; - forChunkInView(player, location, (x, z) -> players.get(chunkToId(x, z)).remove(player)); + forChunkInView(player, location, (x, z) -> { + long id = chunkToId(x, z); + Set playersInChunk = players.get(id); + playersInChunk.remove(player); + if(playersInChunk.isEmpty()) + players.remove(id); + }); } private void onMissing(Set of, Set in, Consumer> packetProvider) { @@ -237,7 +244,12 @@ public class REntityServer implements Listener { private void removePlayerFromChunk(Player player, int x, int z) { long id = chunkToId(x, z); - players.get(id).remove(player); + + Set playersInChunk = players.get(id); + playersInChunk.remove(player); + if(playersInChunk.isEmpty()) + players.remove(id); + for(REntity entity : entities.getOrDefault(id, emptyEntities)) { entity.despawn(packet -> TinyProtocol.instance.sendPacket(player, packet)); } From 40d52d23550c4e8d9cee6533cf053fc8bb85c329 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 23 Feb 2023 18:01:17 +0100 Subject: [PATCH 32/42] Fix Memory Leak2 --- SpigotCore_Main/src/de/steamwar/entity/REntityServer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java b/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java index b2bec15..1ed4c6f 100644 --- a/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java +++ b/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java @@ -197,7 +197,6 @@ public class REntityServer implements Listener { @EventHandler public void onQuit(PlayerQuitEvent e) { Player player = e.getPlayer(); - viewDistance.remove(player); Location location = lastLocation.remove(player); if(location == null) return; @@ -209,6 +208,7 @@ public class REntityServer implements Listener { if(playersInChunk.isEmpty()) players.remove(id); }); + viewDistance.remove(player); } private void onMissing(Set of, Set in, Consumer> packetProvider) { From f9c204877baa977c6073fef840284e3a3bc2013d Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Thu, 23 Feb 2023 18:19:38 +0100 Subject: [PATCH 33/42] Add License Header --- CommonCore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CommonCore b/CommonCore index d22bb36..9c6a7cf 160000 --- a/CommonCore +++ b/CommonCore @@ -1 +1 @@ -Subproject commit d22bb36fc348fae373713b83235cef67010cf020 +Subproject commit 9c6a7cf07dd25d1a4f12c4451373927d413dd9f4 From 6e147f8d6342b6160053b67f07e7cb922d612c71 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Fri, 24 Feb 2023 09:22:02 +0100 Subject: [PATCH 34/42] Fix Queries --- CommonCore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CommonCore b/CommonCore index 9c6a7cf..9c15c0c 160000 --- a/CommonCore +++ b/CommonCore @@ -1 +1 @@ -Subproject commit 9c6a7cf07dd25d1a4f12c4451373927d413dd9f4 +Subproject commit 9c15c0ccfeb40032bc48e89cd2af434b7e83b53d From 56e9d55d12c8c88fe174c73b1eaa75c1f9ef40f5 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Fri, 24 Feb 2023 09:31:09 +0100 Subject: [PATCH 35/42] Fix Queries --- CommonCore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CommonCore b/CommonCore index 9c15c0c..178c96e 160000 --- a/CommonCore +++ b/CommonCore @@ -1 +1 @@ -Subproject commit 9c15c0ccfeb40032bc48e89cd2af434b7e83b53d +Subproject commit 178c96e7c6e4fe7e7833194c976d2289340c31f3 From 02a38a7f455f36fc44133ee9653a5441347f2762 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Fri, 24 Feb 2023 10:24:36 +0100 Subject: [PATCH 36/42] Add BIS --- CommonCore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CommonCore b/CommonCore index 178c96e..aa91584 160000 --- a/CommonCore +++ b/CommonCore @@ -1 +1 @@ -Subproject commit 178c96e7c6e4fe7e7833194c976d2289340c31f3 +Subproject commit aa91584a1e361f5b466f4e359462051d5e065da3 From af5d3a5bcc0838520769e3203a9102b94102f8c5 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 24 Feb 2023 10:38:39 +0100 Subject: [PATCH 37/42] Update CommonCore --- CommonCore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CommonCore b/CommonCore index aa91584..fe09afd 160000 --- a/CommonCore +++ b/CommonCore @@ -1 +1 @@ -Subproject commit aa91584a1e361f5b466f4e359462051d5e065da3 +Subproject commit fe09afdb34242696944ffd214322151ec19c76dd From 8530ffc4381473654afa6c2cde33dd63e6ba6740 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 24 Feb 2023 13:36:41 +0100 Subject: [PATCH 38/42] Update CommonCore --- CommonCore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CommonCore b/CommonCore index fe09afd..38457db 160000 --- a/CommonCore +++ b/CommonCore @@ -1 +1 @@ -Subproject commit fe09afdb34242696944ffd214322151ec19c76dd +Subproject commit 38457db0141d34e6f9f133e70bc3061b8a3d3e5a From 8cd9764e9df5f5e22988d2ecb92fcae2a0f3fc13 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 24 Feb 2023 17:01:29 +0100 Subject: [PATCH 39/42] Supress Recipe Discover popup --- .../core/RecipeDiscoverWrapper14.java | 30 +++++++++++++++++++ .../steamwar/core/RecipeDiscoverWrapper8.java | 24 +++++++++++++++ .../src/de/steamwar/core/Core.java | 24 ++++++++------- .../steamwar/core/RecipeDiscoverWrapper.java | 26 ++++++++++++++++ 4 files changed, 93 insertions(+), 11 deletions(-) create mode 100644 SpigotCore_14/src/de/steamwar/core/RecipeDiscoverWrapper14.java create mode 100644 SpigotCore_8/src/de/steamwar/core/RecipeDiscoverWrapper8.java create mode 100644 SpigotCore_Main/src/de/steamwar/core/RecipeDiscoverWrapper.java diff --git a/SpigotCore_14/src/de/steamwar/core/RecipeDiscoverWrapper14.java b/SpigotCore_14/src/de/steamwar/core/RecipeDiscoverWrapper14.java new file mode 100644 index 0000000..93e050d --- /dev/null +++ b/SpigotCore_14/src/de/steamwar/core/RecipeDiscoverWrapper14.java @@ -0,0 +1,30 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.core; + +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerRecipeDiscoverEvent; + +public class RecipeDiscoverWrapper14 implements RecipeDiscoverWrapper { + @EventHandler + public void onRecipeDiscover(PlayerRecipeDiscoverEvent e) { + e.setCancelled(true); + } +} diff --git a/SpigotCore_8/src/de/steamwar/core/RecipeDiscoverWrapper8.java b/SpigotCore_8/src/de/steamwar/core/RecipeDiscoverWrapper8.java new file mode 100644 index 0000000..59faa4c --- /dev/null +++ b/SpigotCore_8/src/de/steamwar/core/RecipeDiscoverWrapper8.java @@ -0,0 +1,24 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.core; + +public class RecipeDiscoverWrapper8 implements RecipeDiscoverWrapper { + // Event not available pre flattening +} diff --git a/SpigotCore_Main/src/de/steamwar/core/Core.java b/SpigotCore_Main/src/de/steamwar/core/Core.java index d1e6949..7d3a30d 100644 --- a/SpigotCore_Main/src/de/steamwar/core/Core.java +++ b/SpigotCore_Main/src/de/steamwar/core/Core.java @@ -31,6 +31,7 @@ import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.internal.Statement; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; +import org.bukkit.event.Listener; import org.bukkit.plugin.java.JavaPlugin; import java.io.BufferedReader; @@ -81,32 +82,33 @@ public class Core extends JavaPlugin{ return tabCompleter.apply(sender, s); } }); - Bukkit.getScheduler().runTaskTimer(this, TabCompletionCache::invalidateOldEntries, 20, 20); - Bukkit.getPluginManager().registerEvents(new CaseInsensitiveCommandsListener(), this); - Bukkit.getPluginManager().registerEvents(new PlayerJoinedEvent(), this); - Bukkit.getPluginManager().registerEvents(new ChattingEvent(), this); - Bukkit.getPluginManager().registerEvents(new WorldLoadEvent(), this); - if(!Statement.productionDatabase()) { - Bukkit.getPluginManager().registerEvents(LocaleChangeWrapper.impl, this); + for(Listener listener : new Listener[]{new CaseInsensitiveCommandsListener(), new PlayerJoinedEvent(), new ChattingEvent(), new WorldLoadEvent(), RecipeDiscoverWrapper.impl}) { + getServer().getPluginManager().registerEvents(listener, this); } + if(!Statement.productionDatabase()) { + getServer().getPluginManager().registerEvents(LocaleChangeWrapper.impl, this); + } + getServer().getMessenger().registerIncomingPluginChannel(this, "sw:bridge", new NetworkReceiver()); getServer().getMessenger().registerOutgoingPluginChannel(this, "sw:bridge"); + if(Core.getVersion() < 19) AuthlibInjector.inject(); - TinyProtocol.init(); + TinyProtocol.init(); new AntiNocom(); if(Core.getVersion() < 17 && Bukkit.getPluginManager().getPlugin("ViaVersion") != null) new PartialChunkFixer(); - Bukkit.getScheduler().runTaskTimer(Core.getInstance(), SteamwarUser::clear, 72000, 72000); - Bukkit.getScheduler().runTaskTimer(Core.getInstance(), SchematicNode::clear, 20L * 30, 20L * 30); - if(Core.getVersion() >= 19) new ServerDataHandler(); + Bukkit.getScheduler().runTaskTimer(this, TabCompletionCache::invalidateOldEntries, 20, 20); + Bukkit.getScheduler().runTaskTimer(Core.getInstance(), SteamwarUser::clear, 72000, 72000); + Bukkit.getScheduler().runTaskTimer(Core.getInstance(), SchematicNode::clear, 20L * 30, 20L * 30); + try { getLogger().log(Level.INFO, "Running on: " + new BufferedReader(new InputStreamReader(Runtime.getRuntime().exec("hostname").getInputStream())).readLine()); } catch (IOException e) { diff --git a/SpigotCore_Main/src/de/steamwar/core/RecipeDiscoverWrapper.java b/SpigotCore_Main/src/de/steamwar/core/RecipeDiscoverWrapper.java new file mode 100644 index 0000000..0d6b9da --- /dev/null +++ b/SpigotCore_Main/src/de/steamwar/core/RecipeDiscoverWrapper.java @@ -0,0 +1,26 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2023 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.core; + +import org.bukkit.event.Listener; + +public interface RecipeDiscoverWrapper extends Listener { + RecipeDiscoverWrapper impl = VersionDependent.getVersionImpl(Core.getInstance()); +} From 75ee59810fce56ebe462354514bba1902787ae2b Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 24 Feb 2023 17:28:02 +0100 Subject: [PATCH 40/42] Fix chat disconnects --- SpigotCore_9/build.gradle | 2 ++ SpigotCore_9/src/de/steamwar/core/BountifulWrapper9.java | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/SpigotCore_9/build.gradle b/SpigotCore_9/build.gradle index 4585a01..8e81844 100644 --- a/SpigotCore_9/build.gradle +++ b/SpigotCore_9/build.gradle @@ -43,6 +43,8 @@ sourceSets { } dependencies { + compileOnly 'com.viaversion:viaversion-api:4.3.1' + compileOnly project(":SpigotCore_Main") compileOnly project(":SpigotCore_8") diff --git a/SpigotCore_9/src/de/steamwar/core/BountifulWrapper9.java b/SpigotCore_9/src/de/steamwar/core/BountifulWrapper9.java index 97fe828..5602d9a 100644 --- a/SpigotCore_9/src/de/steamwar/core/BountifulWrapper9.java +++ b/SpigotCore_9/src/de/steamwar/core/BountifulWrapper9.java @@ -20,6 +20,7 @@ package de.steamwar.core; import com.comphenix.tinyprotocol.Reflection; +import com.viaversion.viaversion.api.Via; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.BaseComponent; import org.bukkit.Sound; @@ -36,6 +37,9 @@ public class BountifulWrapper9 implements BountifulWrapper.IBountifulWrapper { @Override public void sendMessage(Player player, ChatMessageType type, BaseComponent... msg) { + if(type == ChatMessageType.CHAT && Via.getAPI().getPlayerVersion(player.getUniqueId()) >= 759) + type = ChatMessageType.SYSTEM; + player.spigot().sendMessage(type, msg); } From c4a294b18628d59ee3584075ac2a0f6389c3b9b2 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 24 Feb 2023 20:38:37 +0100 Subject: [PATCH 41/42] Fix double and tripple click of REntityServer --- .../src/de/steamwar/entity/REntityServer.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java b/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java index 1ed4c6f..32a7efc 100644 --- a/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java +++ b/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java @@ -69,14 +69,22 @@ public class REntityServer implements Listener { private final HashMap viewDistance = new HashMap<>(); private EntityActionListener callback = null; + private final Set playersThatClicked = new HashSet<>(); private final BiFunction filter = (player, packet) -> { REntity entity = entityMap.get(useEntityTarget.get(packet)); if (entity == null) return packet; + if (playersThatClicked.contains(player)) + return null; + + playersThatClicked.add(player); EntityAction action = getEntityAction.apply(useEntityAction.get(packet)) == 1 ? EntityAction.ATTACK : EntityAction.INTERACT; - Bukkit.getScheduler().runTask(Core.getInstance(), () -> callback.onAction(player, entity, action)); + Bukkit.getScheduler().runTask(Core.getInstance(), () -> { + playersThatClicked.remove(player); + callback.onAction(player, entity, action); + }); return null; }; From 1eba896c9527a3186608a25d33e4101319e0c65c Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 24 Feb 2023 20:43:09 +0100 Subject: [PATCH 42/42] Make Set concurrent --- SpigotCore_Main/src/de/steamwar/entity/REntityServer.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java b/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java index 32a7efc..667bcce 100644 --- a/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java +++ b/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java @@ -33,6 +33,7 @@ import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerQuitEvent; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Set; @@ -69,7 +70,7 @@ public class REntityServer implements Listener { private final HashMap viewDistance = new HashMap<>(); private EntityActionListener callback = null; - private final Set playersThatClicked = new HashSet<>(); + private final Set playersThatClicked = Collections.synchronizedSet(new HashSet<>()); private final BiFunction filter = (player, packet) -> { REntity entity = entityMap.get(useEntityTarget.get(packet));