diff --git a/BauSystem/BauSystem_15/src/de/steamwar/bausystem/utils/NMSWrapper15.java b/BauSystem/BauSystem_15/src/de/steamwar/bausystem/utils/NMSWrapper15.java index 3b56be55..b479e5d3 100644 --- a/BauSystem/BauSystem_15/src/de/steamwar/bausystem/utils/NMSWrapper15.java +++ b/BauSystem/BauSystem_15/src/de/steamwar/bausystem/utils/NMSWrapper15.java @@ -19,27 +19,21 @@ package de.steamwar.bausystem.utils; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import de.steamwar.bausystem.features.util.NoClipCommand; import net.minecraft.server.v1_15_R1.*; -import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.craftbukkit.v1_15_R1.entity.CraftEntity; import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack; import org.bukkit.entity.Player; -import org.bukkit.entity.TNTPrimed; import org.bukkit.inventory.ItemStack; -import java.util.ArrayList; import java.util.List; -import java.util.function.LongSupplier; public class NMSWrapper15 implements NMSWrapper { - private static final Reflection.FieldAccessor playerGameMode = Reflection.getField(PlayerInteractManager.class, EnumGamemode.class, 0); + private static final Reflection.Field playerGameMode = Reflection.getField(PlayerInteractManager.class, EnumGamemode.class, 0); @Override @SuppressWarnings("deprecation") @@ -63,7 +57,7 @@ public class NMSWrapper15 implements NMSWrapper { player.updateInventory(); } - private static final Reflection.FieldAccessor gameStateChangeReason = Reflection.getField(NoClipCommand.gameStateChange, int.class, 0); + private static final Reflection.Field gameStateChangeReason = Reflection.getField(NoClipCommand.gameStateChange, int.class, 0); @Override public void setGameStateChangeReason(Object packet) { @@ -120,12 +114,12 @@ public class NMSWrapper15 implements NMSWrapper { return invalid; } - private final Class explosionPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutExplosion"); - private final Reflection.FieldAccessor a = Reflection.getField(explosionPacket, double.class, 0); - private final Reflection.FieldAccessor b = Reflection.getField(explosionPacket, double.class, 1); - private final Reflection.FieldAccessor c = Reflection.getField(explosionPacket, double.class, 2); - private final Reflection.FieldAccessor d = Reflection.getField(explosionPacket, float.class, 0); - private final Reflection.FieldAccessor e = Reflection.getField(explosionPacket, List.class, 0); + private final Class explosionPacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundExplodePacket"); + private final Reflection.Field a = Reflection.getField(explosionPacket, double.class, 0); + private final Reflection.Field b = Reflection.getField(explosionPacket, double.class, 1); + private final Reflection.Field c = Reflection.getField(explosionPacket, double.class, 2); + private final Reflection.Field d = Reflection.getField(explosionPacket, float.class, 0); + private final Reflection.Field e = Reflection.getField(explosionPacket, List.class, 0); @Override public Object resetExplosionKnockback(Object packet) { diff --git a/BauSystem/BauSystem_15/src/de/steamwar/bausystem/utils/PlayerMovementWrapper15.java b/BauSystem/BauSystem_15/src/de/steamwar/bausystem/utils/PlayerMovementWrapper15.java index 12f80cdb..f290f7dd 100644 --- a/BauSystem/BauSystem_15/src/de/steamwar/bausystem/utils/PlayerMovementWrapper15.java +++ b/BauSystem/BauSystem_15/src/de/steamwar/bausystem/utils/PlayerMovementWrapper15.java @@ -19,12 +19,9 @@ package de.steamwar.bausystem.utils; -import com.comphenix.tinyprotocol.Reflection; -import de.steamwar.bausystem.utils.PlayerMovementWrapper; +import de.steamwar.Reflection; import net.minecraft.server.v1_15_R1.EntityPlayer; import net.minecraft.server.v1_15_R1.PacketPlayInFlying; -import net.minecraft.server.v1_15_R1.PacketPlayOutEntity; -import net.minecraft.server.v1_15_R1.PacketPlayOutEntityTeleport; import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer; import org.bukkit.entity.Player; diff --git a/BauSystem/BauSystem_18/src/de/steamwar/bausystem/utils/NMSWrapper18.java b/BauSystem/BauSystem_18/src/de/steamwar/bausystem/utils/NMSWrapper18.java index c12ce0af..9763858e 100644 --- a/BauSystem/BauSystem_18/src/de/steamwar/bausystem/utils/NMSWrapper18.java +++ b/BauSystem/BauSystem_18/src/de/steamwar/bausystem/utils/NMSWrapper18.java @@ -19,36 +19,26 @@ package de.steamwar.bausystem.utils; -import com.comphenix.tinyprotocol.Reflection; -import com.comphenix.tinyprotocol.TinyProtocol; +import de.steamwar.Reflection; import de.steamwar.bausystem.features.util.NoClipCommand; -import net.minecraft.SystemUtils; import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; -import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.game.*; import net.minecraft.server.level.PlayerInteractManager; import net.minecraft.world.level.EnumGamemode; -import net.minecraft.world.phys.Vec3D; -import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.craftbukkit.v1_18_R2.entity.CraftEntity; import org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack; import org.bukkit.entity.Player; -import org.bukkit.entity.TNTPrimed; import org.bukkit.inventory.ItemStack; -import java.util.ArrayList; import java.util.List; -import java.util.function.LongSupplier; public class NMSWrapper18 implements NMSWrapper { - private static final Reflection.FieldAccessor playerGameMode = Reflection.getField(PlayerInteractManager.class, EnumGamemode.class, 0); + private static final Reflection.Field playerGameMode = Reflection.getField(PlayerInteractManager.class, EnumGamemode.class, 0); @Override @SuppressWarnings("deprecation") @@ -73,7 +63,7 @@ public class NMSWrapper18 implements NMSWrapper { player.updateInventory(); } - private static final Reflection.FieldAccessor gameStateChangeReason = Reflection.getField(NoClipCommand.gameStateChange, PacketPlayOutGameStateChange.a.class, 12); + private static final Reflection.Field gameStateChangeReason = Reflection.getField(NoClipCommand.gameStateChange, PacketPlayOutGameStateChange.a.class, 12); @Override public void setGameStateChangeReason(Object packet) { @@ -130,12 +120,12 @@ public class NMSWrapper18 implements NMSWrapper { return invalid; } - private final Class explosionPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutExplosion"); - private final Reflection.FieldAccessor a = Reflection.getField(explosionPacket, double.class, 0); - private final Reflection.FieldAccessor b = Reflection.getField(explosionPacket, double.class, 1); - private final Reflection.FieldAccessor c = Reflection.getField(explosionPacket, double.class, 2); - private final Reflection.FieldAccessor d = Reflection.getField(explosionPacket, float.class, 0); - private final Reflection.FieldAccessor e = Reflection.getField(explosionPacket, List.class, 0); + private final Class explosionPacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundExplodePacket"); + private final Reflection.Field a = Reflection.getField(explosionPacket, double.class, 0); + private final Reflection.Field b = Reflection.getField(explosionPacket, double.class, 1); + private final Reflection.Field c = Reflection.getField(explosionPacket, double.class, 2); + private final Reflection.Field d = Reflection.getField(explosionPacket, float.class, 0); + private final Reflection.Field e = Reflection.getField(explosionPacket, List.class, 0); @Override public Object resetExplosionKnockback(Object packet) { diff --git a/BauSystem/BauSystem_18/src/de/steamwar/bausystem/utils/PlayerMovementWrapper18.java b/BauSystem/BauSystem_18/src/de/steamwar/bausystem/utils/PlayerMovementWrapper18.java index d1e186d2..0f1ba669 100644 --- a/BauSystem/BauSystem_18/src/de/steamwar/bausystem/utils/PlayerMovementWrapper18.java +++ b/BauSystem/BauSystem_18/src/de/steamwar/bausystem/utils/PlayerMovementWrapper18.java @@ -19,8 +19,7 @@ package de.steamwar.bausystem.utils; -import com.comphenix.tinyprotocol.Reflection; -import de.steamwar.bausystem.utils.PlayerMovementWrapper; +import de.steamwar.Reflection; import net.minecraft.network.protocol.game.PacketPlayInFlying; import net.minecraft.server.level.EntityPlayer; import org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer; diff --git a/BauSystem/BauSystem_19/src/de/steamwar/bausystem/utils/NMSWrapper19.java b/BauSystem/BauSystem_19/src/de/steamwar/bausystem/utils/NMSWrapper19.java index ecdc33be..748cf86d 100644 --- a/BauSystem/BauSystem_19/src/de/steamwar/bausystem/utils/NMSWrapper19.java +++ b/BauSystem/BauSystem_19/src/de/steamwar/bausystem/utils/NMSWrapper19.java @@ -19,37 +19,26 @@ package de.steamwar.bausystem.utils; -import com.comphenix.tinyprotocol.Reflection; -import com.comphenix.tinyprotocol.TinyProtocol; +import de.steamwar.Reflection; import de.steamwar.bausystem.features.util.NoClipCommand; -import net.minecraft.SystemUtils; import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; -import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.game.*; -import net.minecraft.network.syncher.DataWatcher; import net.minecraft.server.level.PlayerInteractManager; import net.minecraft.world.level.EnumGamemode; -import net.minecraft.world.phys.Vec3D; -import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.craftbukkit.v1_19_R2.entity.CraftEntity; import org.bukkit.craftbukkit.v1_19_R2.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_19_R2.inventory.CraftItemStack; import org.bukkit.entity.Player; -import org.bukkit.entity.TNTPrimed; import org.bukkit.inventory.ItemStack; -import java.util.ArrayList; import java.util.List; -import java.util.function.LongSupplier; public class NMSWrapper19 implements NMSWrapper { - private static final Reflection.FieldAccessor playerGameMode = Reflection.getField(PlayerInteractManager.class, EnumGamemode.class, 0); + private static final Reflection.Field playerGameMode = Reflection.getField(PlayerInteractManager.class, EnumGamemode.class, 0); @Override @SuppressWarnings("deprecation") @@ -73,7 +62,7 @@ public class NMSWrapper19 implements NMSWrapper { player.updateInventory(); } - private static final Reflection.FieldAccessor gameStateChangeReason = Reflection.getField(NoClipCommand.gameStateChange, PacketPlayOutGameStateChange.a.class, 12); + private static final Reflection.Field gameStateChangeReason = Reflection.getField(NoClipCommand.gameStateChange, PacketPlayOutGameStateChange.a.class, 12); @Override public void setGameStateChangeReason(Object packet) { @@ -130,12 +119,12 @@ public class NMSWrapper19 implements NMSWrapper { return invalid; } - private final Class explosionPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutExplosion"); - private final Reflection.FieldAccessor a = Reflection.getField(explosionPacket, double.class, 0); - private final Reflection.FieldAccessor b = Reflection.getField(explosionPacket, double.class, 1); - private final Reflection.FieldAccessor c = Reflection.getField(explosionPacket, double.class, 2); - private final Reflection.FieldAccessor d = Reflection.getField(explosionPacket, float.class, 0); - private final Reflection.FieldAccessor e = Reflection.getField(explosionPacket, List.class, 0); + private final Class explosionPacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundExplodePacket"); + private final Reflection.Field a = Reflection.getField(explosionPacket, double.class, 0); + private final Reflection.Field b = Reflection.getField(explosionPacket, double.class, 1); + private final Reflection.Field c = Reflection.getField(explosionPacket, double.class, 2); + private final Reflection.Field d = Reflection.getField(explosionPacket, float.class, 0); + private final Reflection.Field e = Reflection.getField(explosionPacket, List.class, 0); @Override public Object resetExplosionKnockback(Object packet) { diff --git a/BauSystem/BauSystem_19/src/de/steamwar/bausystem/utils/PlayerMovementWrapper19.java b/BauSystem/BauSystem_19/src/de/steamwar/bausystem/utils/PlayerMovementWrapper19.java index 9815023c..af152ea5 100644 --- a/BauSystem/BauSystem_19/src/de/steamwar/bausystem/utils/PlayerMovementWrapper19.java +++ b/BauSystem/BauSystem_19/src/de/steamwar/bausystem/utils/PlayerMovementWrapper19.java @@ -19,17 +19,12 @@ package de.steamwar.bausystem.utils; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import net.minecraft.network.protocol.game.PacketPlayInFlying; import net.minecraft.server.level.EntityPlayer; -import org.bukkit.Location; import org.bukkit.craftbukkit.v1_19_R2.entity.CraftPlayer; import org.bukkit.entity.Player; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; - public class PlayerMovementWrapper19 implements PlayerMovementWrapper { @Override diff --git a/BauSystem/BauSystem_20/src/de/steamwar/bausystem/utils/NMSWrapper20.java b/BauSystem/BauSystem_20/src/de/steamwar/bausystem/utils/NMSWrapper20.java index 1cb81892..1cc09e56 100644 --- a/BauSystem/BauSystem_20/src/de/steamwar/bausystem/utils/NMSWrapper20.java +++ b/BauSystem/BauSystem_20/src/de/steamwar/bausystem/utils/NMSWrapper20.java @@ -19,7 +19,7 @@ package de.steamwar.bausystem.utils; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import de.steamwar.bausystem.features.util.NoClipCommand; import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagCompound; @@ -40,7 +40,7 @@ import java.util.List; public class NMSWrapper20 implements NMSWrapper { - private static final Reflection.FieldAccessor playerGameMode = Reflection.getField(PlayerInteractManager.class, EnumGamemode.class, 0); + private static final Reflection.Field playerGameMode = Reflection.getField(PlayerInteractManager.class, EnumGamemode.class, 0); @Override @SuppressWarnings("deprecation") @@ -64,7 +64,7 @@ public class NMSWrapper20 implements NMSWrapper { player.updateInventory(); } - private static final Reflection.FieldAccessor gameStateChangeReason = Reflection.getField(NoClipCommand.gameStateChange, PacketPlayOutGameStateChange.a.class, 12); + private static final Reflection.Field gameStateChangeReason = Reflection.getField(NoClipCommand.gameStateChange, PacketPlayOutGameStateChange.a.class, 12); @Override public void setGameStateChangeReason(Object packet) { @@ -121,12 +121,12 @@ public class NMSWrapper20 implements NMSWrapper { return invalid; } - private final Class explosionPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutExplosion"); - private final Reflection.FieldAccessor a = Reflection.getField(explosionPacket, double.class, 0); - private final Reflection.FieldAccessor b = Reflection.getField(explosionPacket, double.class, 1); - private final Reflection.FieldAccessor c = Reflection.getField(explosionPacket, double.class, 2); - private final Reflection.FieldAccessor d = Reflection.getField(explosionPacket, float.class, 0); - private final Reflection.FieldAccessor e = Reflection.getField(explosionPacket, List.class, 0); + private final Class explosionPacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundExplodePacket"); + private final Reflection.Field a = Reflection.getField(explosionPacket, double.class, 0); + private final Reflection.Field b = Reflection.getField(explosionPacket, double.class, 1); + private final Reflection.Field c = Reflection.getField(explosionPacket, double.class, 2); + private final Reflection.Field d = Reflection.getField(explosionPacket, float.class, 0); + private final Reflection.Field e = Reflection.getField(explosionPacket, List.class, 0); @Override public Object resetExplosionKnockback(Object packet) { diff --git a/BauSystem/BauSystem_20/src/de/steamwar/bausystem/utils/PlayerMovementWrapper20.java b/BauSystem/BauSystem_20/src/de/steamwar/bausystem/utils/PlayerMovementWrapper20.java index 75701471..f7866a4a 100644 --- a/BauSystem/BauSystem_20/src/de/steamwar/bausystem/utils/PlayerMovementWrapper20.java +++ b/BauSystem/BauSystem_20/src/de/steamwar/bausystem/utils/PlayerMovementWrapper20.java @@ -19,18 +19,12 @@ package de.steamwar.bausystem.utils; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import net.minecraft.network.protocol.game.PacketPlayInFlying; -import net.minecraft.network.protocol.game.PacketPlayOutEntityTeleport; import net.minecraft.server.level.EntityPlayer; -import org.bukkit.Location; import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer; import org.bukkit.entity.Player; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; - public class PlayerMovementWrapper20 implements PlayerMovementWrapper { @Override diff --git a/BauSystem/BauSystem_21/src/de/steamwar/bausystem/utils/NMSWrapper21.java b/BauSystem/BauSystem_21/src/de/steamwar/bausystem/utils/NMSWrapper21.java index 1c3ce035..e6308e43 100644 --- a/BauSystem/BauSystem_21/src/de/steamwar/bausystem/utils/NMSWrapper21.java +++ b/BauSystem/BauSystem_21/src/de/steamwar/bausystem/utils/NMSWrapper21.java @@ -19,7 +19,7 @@ package de.steamwar.bausystem.utils; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import de.steamwar.bausystem.features.util.NoClipCommand; import net.minecraft.core.component.DataComponents; import net.minecraft.nbt.NBTBase; @@ -45,7 +45,7 @@ import java.util.Optional; public class NMSWrapper21 implements NMSWrapper { - private static final Reflection.FieldAccessor playerInteractManager = Reflection.getField(EntityPlayer.class, null, PlayerInteractManager.class); + private static final Reflection.Field playerInteractManager = Reflection.getField(EntityPlayer.class, null, PlayerInteractManager.class); @Override public void setInternalGameMode(Player player, GameMode gameMode) { @@ -68,14 +68,14 @@ public class NMSWrapper21 implements NMSWrapper { player.updateInventory(); } - private static final Reflection.FieldAccessor gameStateChangeReason = Reflection.getField(NoClipCommand.gameStateChange, PacketPlayOutGameStateChange.a.class, 12); + private static final Reflection.Field gameStateChangeReason = Reflection.getField(NoClipCommand.gameStateChange, PacketPlayOutGameStateChange.a.class, 12); @Override public void setGameStateChangeReason(Object packet) { gameStateChangeReason.set(packet, PacketPlayOutGameStateChange.d); } - private static final Reflection.FieldAccessor playerAbilities = Reflection.getField(EntityHuman.class, null, PlayerAbilities.class); + private static final Reflection.Field playerAbilities = Reflection.getField(EntityHuman.class, null, PlayerAbilities.class); @Override public void setPlayerBuildAbilities(Player player) { diff --git a/BauSystem/BauSystem_Main/build.gradle.kts b/BauSystem/BauSystem_Main/build.gradle.kts index 8f46699d..5b8f0a89 100644 --- a/BauSystem/BauSystem_Main/build.gradle.kts +++ b/BauSystem/BauSystem_Main/build.gradle.kts @@ -38,7 +38,6 @@ dependencies { compileOnly(libs.spigotapi) compileOnly(libs.axiom) compileOnly(libs.authlib) - compileOnly(libs.viaapi) compileOnly(libs.fawe18) diff --git a/BauSystem/BauSystem_Main/src/BauSystem.properties b/BauSystem/BauSystem_Main/src/BauSystem.properties index c9116dce..929d0c67 100644 --- a/BauSystem/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem/BauSystem_Main/src/BauSystem.properties @@ -1013,6 +1013,4 @@ XRAY_OFF=§cXray deactivated COLORREPLACE_HELP=§8//§ecolorreplace §8[§7color§8] §8[§7color§8] §8- §7Replace all blocks of one color with another TYPEREPLACE_HELP=§8//§etypereplace §8[§7type§8] §8[§7type§8] §8- §7Replace all blocks of one type with another # Schematic -SCHEMATIC_GUI_ITEM=§eSchematics -#VersionAnnouncer -SERVER_VERSION=§7This server runs on Minecraft version §e{0} \ No newline at end of file +SCHEMATIC_GUI_ITEM=§eSchematics \ No newline at end of file diff --git a/BauSystem/BauSystem_Main/src/BauSystem_de.properties b/BauSystem/BauSystem_Main/src/BauSystem_de.properties index 45e60f84..4cb20d95 100644 --- a/BauSystem/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem/BauSystem_Main/src/BauSystem_de.properties @@ -954,6 +954,4 @@ XRAY_OFF=§cXray deaktiviert COLORREPLACE_HELP=§8//§ecolorreplace §8[§7color§8] §8[§7color§8] §8- §7Ersetzt eine Farbe mit einer anderen TYPEREPLACE_HELP=§8//§etyreplace §8[§7type§8] §8[§7type§8] §8- §7Ersetzt einen Blockgruppe mit einer anderen # Schematics -SCHEMATIC_GUI_ITEM=§eSchematics -#VersionAnnouncer -SERVER_VERSION=§7Dieser Server läuft auf Minecraft-Version §e{0} \ No newline at end of file +SCHEMATIC_GUI_ITEM=§eSchematics \ No newline at end of file diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracer.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracer.java index 9f641e65..c1e08fcf 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracer.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracer.java @@ -19,7 +19,7 @@ package de.steamwar.bausystem.features.observer; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import de.steamwar.bausystem.region.Point; import org.bukkit.Location; import org.bukkit.Material; @@ -170,7 +170,7 @@ public class ObserverTracer { } } - private static final Class craftPoweredRail = Reflection.getClass("{obc}.block.impl.CraftPoweredRail"); + private static final Class craftPoweredRail = Reflection.getClass("org.bukkit.craftbukkit.block.impl.CraftPoweredRail"); private boolean checkAllowed(Block block, BlockData blockData) { if (checkMaterial(block)) return true; if (block.getType() == Material.BELL) { diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/script/event/EventListener.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/script/event/EventListener.java index 3eb099aa..4c5feada 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/script/event/EventListener.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/script/event/EventListener.java @@ -24,7 +24,6 @@ import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.features.script.ScriptRunner; import de.steamwar.bausystem.features.script.lua.SteamWarGlobalLuaPlugin; import de.steamwar.bausystem.features.script.lua.libs.StorageLib; -import de.steamwar.bausystem.features.tpslimit.TPSUtils; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.utils.RegionExtensionType; import de.steamwar.bausystem.region.utils.RegionType; @@ -32,7 +31,6 @@ import de.steamwar.core.TrickyTrialsWrapper; import de.steamwar.linkage.Linked; import org.bukkit.Bukkit; import org.bukkit.Material; -import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -72,9 +70,10 @@ public class EventListener implements Listener { @EventHandler(priority = EventPriority.HIGH) public void onPlayerQuit(PlayerQuitEvent event) { + if(Permission.BUILD.hasPermission(event.getPlayer())) { + ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.SelfLeave, LuaValue.NIL, event); + } StorageLib.removePlayer(event.getPlayer()); - if(!Permission.BUILD.hasPermission(event.getPlayer())) return; - ScriptRunner.callEvent(event.getPlayer(), SteamWarGlobalLuaPlugin.EventType.SelfLeave, LuaValue.NIL, event); } @EventHandler(priority = EventPriority.HIGH) diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java index a7664158..de9dae3f 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCursor.java @@ -19,7 +19,7 @@ package de.steamwar.bausystem.features.simulator; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; @@ -72,9 +72,9 @@ import java.util.stream.Collectors; public class SimulatorCursor implements Listener { private final World WORLD = Bukkit.getWorlds().get(0); - private Class position = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInFlying$PacketPlayInPosition"); - private Class look = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInFlying$PacketPlayInLook"); - private Class positionLook = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInFlying$PacketPlayInPositionLook"); + private Class position = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$Pos"); + private Class look = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$Rot"); + private Class positionLook = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$PosRot"); private Map cursorType = Collections.synchronizedMap(new HashMap<>()); private Map cursors = Collections.synchronizedMap(new HashMap<>()); diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/SmartPlaceListener.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/SmartPlaceListener.java index 10916beb..75b3f8b7 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/SmartPlaceListener.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/SmartPlaceListener.java @@ -19,7 +19,7 @@ package de.steamwar.bausystem.features.smartplace; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; @@ -81,7 +81,7 @@ public class SmartPlaceListener implements Listener { IGNORED.remove(Material.BARRIER); } - private static final Class useItem = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInUseItem"); + private static final Class useItem = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundUseItemOnPacket"); private static final Set SMART_PLACING = new HashSet<>(); private static final Set WAS_EXECUTED = new HashSet<>(); diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/PacketCache.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/PacketCache.java index e9076382..a53bd819 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/PacketCache.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/PacketCache.java @@ -19,7 +19,7 @@ package de.steamwar.bausystem.features.tpslimit; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; import de.steamwar.core.BountifulWrapper; import de.steamwar.core.ChatWrapper; @@ -45,18 +45,18 @@ class PacketCache { private static Set entities = new HashSet<>(); private static BukkitTask task = null; - private static Class vec3dClass = Reflection.getClass("{nms.world.phys}.Vec3D"); - private static Reflection.FieldAccessor zeroVec3d = (Reflection.FieldAccessor) Reflection.getField(vec3dClass, vec3dClass, 0); + private static Class vec3dClass = Reflection.getClass("net.minecraft.world.phys.Vec3"); + private static Reflection.Field zeroVec3d = (Reflection.Field) Reflection.getField(vec3dClass, vec3dClass, 0); private static Object ZERO_VEC3D = zeroVec3d.get(null); - private static Class velocityPacketClass = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityVelocity"); - private static Reflection.ConstructorInvoker velocityPacketConstructor = Reflection.getConstructor(velocityPacketClass, int.class, vec3dClass); + private static Class velocityPacketClass = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundSetEntityMotionPacket"); + private static Reflection.Constructor velocityPacketConstructor = Reflection.getConstructor(velocityPacketClass, int.class, vec3dClass); - private static Class teleportPacketClass = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityTeleport"); - private static Class entityClass = Reflection.getClass("{nms.world.entity}.Entity"); - private static Reflection.ConstructorInvoker teleportPacketConstructor = Reflection.getConstructor(teleportPacketClass, entityClass); + private static Class teleportPacketClass = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket"); + private static Class entityClass = Reflection.getClass("net.minecraft.world.entity.Entity"); + private static Reflection.Constructor teleportPacketConstructor = Reflection.getConstructor(teleportPacketClass, entityClass); - private static Class craftEntityClass = Reflection.getClass("{obc}.entity.CraftEntity"); - private static Reflection.MethodInvoker getHandle = Reflection.getMethod(craftEntityClass, "getHandle"); + private static Class craftEntityClass = Reflection.getClass("org.bukkit.craftbukkit.entity.CraftEntity"); + private static Reflection.Method getHandle = Reflection.getMethod(craftEntityClass, "getHandle"); private static Object noGravityDataWatcher = BountifulWrapper.impl.getDataWatcherObject(5, Boolean.class); private static Object fuseDataWatcher = BountifulWrapper.impl.getDataWatcherObject(8, Integer.class); diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSFreezeUtils.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSFreezeUtils.java index 34981161..cb79f6fb 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSFreezeUtils.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSFreezeUtils.java @@ -19,7 +19,7 @@ package de.steamwar.bausystem.features.tpslimit; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import lombok.Getter; import lombok.experimental.UtilityClass; import org.bukkit.Bukkit; @@ -28,11 +28,11 @@ import org.bukkit.World; @UtilityClass public class TPSFreezeUtils { - private static Reflection.FieldAccessor fieldAccessor; + private static Reflection.Field fieldAccessor; @Getter private static final boolean canFreeze; - private static final Reflection.MethodInvoker getWorldHandle = Reflection.getTypedMethod(Reflection.getClass("{obc}.CraftWorld"), "getHandle", null); + private static final Reflection.Method getWorldHandle = Reflection.getTypedMethod(Reflection.getClass("org.bukkit.craftbukkit.CraftWorld"), "getHandle", null); @Getter private static boolean frozen = false; @@ -40,9 +40,9 @@ public class TPSFreezeUtils { private static final World world = Bukkit.getWorlds().get(0); static { - Reflection.FieldAccessor fieldAccessor; + Reflection.Field fieldAccessor; try { - fieldAccessor = Reflection.getField(Reflection.getClass("{nms.server.level}.WorldServer"), "freezed", boolean.class); + fieldAccessor = Reflection.getField(Reflection.getClass("net.minecraft.server.level.ServerLevel"), "freezed", boolean.class); } catch (IllegalArgumentException e) { fieldAccessor = null; } diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitUtils.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitUtils.java index cdc38f2d..29068ace 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitUtils.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitUtils.java @@ -19,15 +19,12 @@ package de.steamwar.bausystem.features.tpslimit; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; -import de.steamwar.bausystem.SWUtils; import de.steamwar.bausystem.utils.PlayerMovementWrapper; import de.steamwar.core.Core; -import de.steamwar.core.TPSWatcher; import lombok.experimental.UtilityClass; import org.bukkit.Bukkit; -import org.bukkit.World; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitTask; @@ -104,8 +101,8 @@ public class TPSLimitUtils { } */ - private static final Class position = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInFlying$PacketPlayInPosition"); - private static final Class positionLook = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInFlying$PacketPlayInPositionLook"); + private static final Class position = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$Pos"); + private static final Class positionLook = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$PosRot"); static { BiFunction positionSetter = (player, o) -> { if (tpsLimiter != null) { diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/util/NoClipCommand.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/util/NoClipCommand.java index 867ad83d..03055780 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/util/NoClipCommand.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/util/NoClipCommand.java @@ -19,7 +19,7 @@ package de.steamwar.bausystem.features.util; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; import com.mojang.authlib.GameProfile; import de.steamwar.bausystem.BauSystem; @@ -49,15 +49,15 @@ import java.util.function.BiFunction; @Linked public class NoClipCommand extends SWCommand implements Listener { - public static final Class gameStateChange = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutGameStateChange"); - private static final Reflection.FieldAccessor floatFieldAccessor = Reflection.getField(gameStateChange, float.class, 0); + public static final Class gameStateChange = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundGameEventPacket"); + private static final Reflection.Field floatFieldAccessor = Reflection.getField(gameStateChange, float.class, 0); - private static final Class position = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInFlying$PacketPlayInPosition"); - private static final Class positionLook = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInFlying$PacketPlayInPositionLook"); - private static final Class useItem = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInUseItem"); - private static final Class blockDig = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInBlockDig"); - private static final Class windowClick = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInWindowClick"); - private static final Class setSlotStack = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInSetCreativeSlot"); + private static final Class position = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$Pos"); + private static final Class positionLook = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$PosRot"); + private static final Class useItem = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundUseItemOnPacket"); + private static final Class blockDig = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundPlayerActionPacket"); + private static final Class windowClick = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundContainerClickPacket"); + private static final Class setSlotStack = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundSetCreativeModeSlotPacket"); @Getter private static final List NOCLIPS = new ArrayList<>(); diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/AntiCursorReCentering.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/AntiCursorReCentering.java index ff04aa5f..46206a6c 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/AntiCursorReCentering.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/AntiCursorReCentering.java @@ -19,7 +19,7 @@ package de.steamwar.bausystem.features.world; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; import de.steamwar.bausystem.BauSystem; import de.steamwar.linkage.Linked; @@ -32,7 +32,7 @@ public class AntiCursorReCentering implements Enable { @Override public void enable() { - Class closeWindow = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutCloseWindow"); + Class closeWindow = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundContainerClosePacket"); TinyProtocol.instance.addFilter(closeWindow, (player, object) -> { if (player.getOpenInventory().getTopInventory().getType() == InventoryType.CRAFTING) { return object; diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/NoCreativeKnockback.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/NoCreativeKnockback.java index 19417ec2..be950c60 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/NoCreativeKnockback.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/NoCreativeKnockback.java @@ -19,7 +19,7 @@ package de.steamwar.bausystem.features.world; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; import de.steamwar.bausystem.utils.NMSWrapper; import de.steamwar.linkage.Linked; @@ -29,7 +29,7 @@ import org.bukkit.GameMode; public class NoCreativeKnockback { public NoCreativeKnockback() { - TinyProtocol.instance.addFilter(Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutExplosion"), (player, o) -> { + TinyProtocol.instance.addFilter(Reflection.getClass("net.minecraft.network.protocol.game.ClientboundExplodePacket"), (player, o) -> { if (player.getGameMode() != GameMode.CREATIVE) return o; return NMSWrapper.impl.resetExplosionKnockback(o); }); diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/SignEditFrom20.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/SignEditFrom20.java index 1ccfb014..df4164aa 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/SignEditFrom20.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/SignEditFrom20.java @@ -19,7 +19,7 @@ package de.steamwar.bausystem.features.world; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; @@ -48,21 +48,21 @@ import org.bukkit.util.Vector; @MinVersion(20) public class SignEditFrom20 implements Listener { - private static final Class blockPosition = Reflection.getClass("{nms.core}.BlockPosition"); - private static final Class craftBlock = Reflection.getClass("{obc}.block.CraftBlock"); - private static final Class craftWorld = Reflection.getClass("{obc}.CraftWorld"); - private static final Class generatorAccess = Reflection.getClass("{nms.world.level}.GeneratorAccess"); - private static final Reflection.MethodInvoker getPosition = Reflection.getTypedMethod(craftBlock, "getPosition", blockPosition); - private static final Reflection.MethodInvoker getWorldHandle = Reflection.getTypedMethod(craftWorld, "getHandle", null); - private static final Reflection.MethodInvoker at = Reflection.getTypedMethod(craftBlock, "at", craftBlock, generatorAccess, blockPosition); + private static final Class blockPosition = Reflection.getClass("net.minecraft.core.BlockPos"); + private static final Class craftBlock = Reflection.getClass("org.bukkit.craftbukkit.block.CraftBlock"); + private static final Class craftWorld = Reflection.getClass("org.bukkit.craftbukkit.CraftWorld"); + private static final Class generatorAccess = Reflection.getClass("net.minecraft.world.level.LevelAccessor"); + private static final Reflection.Method getPosition = Reflection.getTypedMethod(craftBlock, "getPosition", blockPosition); + private static final Reflection.Method getWorldHandle = Reflection.getTypedMethod(craftWorld, "getHandle", null); + private static final Reflection.Method at = Reflection.getTypedMethod(craftBlock, "at", craftBlock, generatorAccess, blockPosition); - private static final Class openSign = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutOpenSignEditor"); - private static final Reflection.FieldAccessor blockPositionFieldAccessor = Reflection.getField(openSign, blockPosition, 0); - private static final Reflection.FieldAccessor sideFieldAccessor = Reflection.getField(openSign, boolean.class, 0); + private static final Class openSign = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundOpenSignEditorPacket"); + private static final Reflection.Field blockPositionFieldAccessor = Reflection.getField(openSign, blockPosition, 0); + private static final Reflection.Field sideFieldAccessor = Reflection.getField(openSign, boolean.class, 0); - private static final Class updateSign = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInUpdateSign"); - private static final Reflection.FieldAccessor getBlockPositionFieldAccessor = Reflection.getField(updateSign, blockPosition, 0); - private static final Reflection.FieldAccessor stringFieldAccessor = Reflection.getField(updateSign, String[].class, 0); + private static final Class updateSign = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundSignUpdatePacket"); + private static final Reflection.Field getBlockPositionFieldAccessor = Reflection.getField(updateSign, blockPosition, 0); + private static final Reflection.Field stringFieldAccessor = Reflection.getField(updateSign, String[].class, 0); @EventHandler public void editSign(PlayerInteractEvent event) { diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/SignEditUntil19.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/SignEditUntil19.java index 7aebd4e9..94b78f84 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/SignEditUntil19.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/world/SignEditUntil19.java @@ -19,7 +19,7 @@ package de.steamwar.bausystem.features.world; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; @@ -40,20 +40,20 @@ import org.bukkit.event.player.PlayerInteractEvent; @MaxVersion(19) public class SignEditUntil19 implements Listener { - private static final Class blockPosition = Reflection.getClass("{nms.core}.BlockPosition"); - private static final Class craftBlock = Reflection.getClass("{obc}.block.CraftBlock"); - private static final Class craftWorld = Reflection.getClass("{obc}.CraftWorld"); - private static final Class generatorAccess = Reflection.getClass("{nms.world.level}.GeneratorAccess"); - private static final Reflection.MethodInvoker getPosition = Reflection.getTypedMethod(craftBlock, "getPosition", blockPosition); - private static final Reflection.MethodInvoker getWorldHandle = Reflection.getTypedMethod(craftWorld, "getHandle", null); - private static final Reflection.MethodInvoker at = Reflection.getTypedMethod(craftBlock, "at", craftBlock, generatorAccess, blockPosition); + private static final Class blockPosition = Reflection.getClass("net.minecraft.core.BlockPos"); + private static final Class craftBlock = Reflection.getClass("org.bukkit.craftbukkit.block.CraftBlock"); + private static final Class craftWorld = Reflection.getClass("org.bukkit.craftbukkit.CraftWorld"); + private static final Class generatorAccess = Reflection.getClass("net.minecraft.world.level.LevelAccessor"); + private static final Reflection.Method getPosition = Reflection.getTypedMethod(craftBlock, "getPosition", blockPosition); + private static final Reflection.Method getWorldHandle = Reflection.getTypedMethod(craftWorld, "getHandle", null); + private static final Reflection.Method at = Reflection.getTypedMethod(craftBlock, "at", craftBlock, generatorAccess, blockPosition); - private static final Class openSign = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutOpenSignEditor"); - private static final Reflection.FieldAccessor blockPositionFieldAccessor = Reflection.getField(openSign, blockPosition, 0); + private static final Class openSign = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundOpenSignEditorPacket"); + private static final Reflection.Field blockPositionFieldAccessor = Reflection.getField(openSign, blockPosition, 0); - private static final Class updateSign = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInUpdateSign"); - private static final Reflection.FieldAccessor getBlockPositionFieldAccessor = Reflection.getField(updateSign, blockPosition, 0); - private static final Reflection.FieldAccessor stringFieldAccessor = Reflection.getField(updateSign, String[].class, 0); + private static final Class updateSign = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundSignUpdatePacket"); + private static final Reflection.Field getBlockPositionFieldAccessor = Reflection.getField(updateSign, blockPosition, 0); + private static final Reflection.Field stringFieldAccessor = Reflection.getField(updateSign, String[].class, 0); @EventHandler public void editSign(PlayerInteractEvent event) { diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/xray/XrayCommand.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/xray/XrayCommand.java index 59e88ec5..cad5b633 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/xray/XrayCommand.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/xray/XrayCommand.java @@ -19,7 +19,7 @@ package de.steamwar.bausystem.features.xray; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.techhider.TechHiderCommand; @@ -108,8 +108,8 @@ public class XrayCommand extends SWCommand implements Listener, ScoreboardElemen }); } - private static final Class position = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInFlying$PacketPlayInPosition"); - private static final Class positionLook = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInFlying$PacketPlayInPositionLook"); + private static final Class position = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$Pos"); + private static final Class positionLook = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$PosRot"); { BiFunction positionSetter = (player, o) -> { diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/PlaceItemUtils.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/PlaceItemUtils.java index bec908a6..3202c88e 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/PlaceItemUtils.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/PlaceItemUtils.java @@ -19,7 +19,7 @@ package de.steamwar.bausystem.utils; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.experimental.UtilityClass; @@ -81,12 +81,12 @@ public class PlaceItemUtils { .collect(Collectors.toSet()); } - private static final Class blockPosition = Reflection.getClass("{nms.core}.BlockPosition"); - private static final Reflection.ConstructorInvoker blockPositionConstructor = Reflection.getConstructor(blockPosition, int.class, int.class, int.class); - private static final Class craftBlock = Reflection.getClass("{obc}.block.CraftBlockState"); - private static final Class craftWorld = Reflection.getClass("{obc}.CraftWorld"); - private static final Reflection.FieldAccessor positionAccessor = Reflection.getField(craftBlock, blockPosition, 0); - private static final Reflection.FieldAccessor worldAccessor = Reflection.getField(craftBlock, craftWorld, 0); + private static final Class blockPosition = Reflection.getClass("net.minecraft.core.BlockPos"); + private static final Reflection.Constructor blockPositionConstructor = Reflection.getConstructor(blockPosition, int.class, int.class, int.class); + private static final Class craftBlock = Reflection.getClass("org.bukkit.craftbukkit.block.CraftBlockState"); + private static final Class craftWorld = Reflection.getClass("org.bukkit.craftbukkit.CraftWorld"); + private static final Reflection.Field positionAccessor = Reflection.getField(craftBlock, blockPosition, 0); + private static final Reflection.Field worldAccessor = Reflection.getField(craftBlock, craftWorld, 0); /** * Attempt to place an {@link ItemStack} the {@link Player} is holding against a {@link Block} inside the World. diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/PlayerMovementWrapper.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/PlayerMovementWrapper.java index 15aea7f0..b0cebfdd 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/PlayerMovementWrapper.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/PlayerMovementWrapper.java @@ -19,17 +19,16 @@ package de.steamwar.bausystem.utils; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import de.steamwar.bausystem.BauSystem; import de.steamwar.core.BountifulWrapper; -import de.steamwar.core.Core; import de.steamwar.core.VersionDependent; import de.steamwar.entity.REntity; import org.bukkit.entity.Player; public interface PlayerMovementWrapper { Class teleportPacket = REntity.teleportPacket; - Reflection.FieldAccessor teleportEntity = REntity.teleportEntity; + Reflection.Field teleportEntity = REntity.teleportEntity; BountifulWrapper.PositionSetter teleportPosition = REntity.teleportPosition; PlayerMovementWrapper impl = VersionDependent.getVersionImpl(BauSystem.getInstance()); diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/VersionAnnouncer.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/VersionAnnouncer.java deleted file mode 100644 index ee9e91be..00000000 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/VersionAnnouncer.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2024 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.bausystem.utils; - -import com.viaversion.viaversion.api.Via; -import com.viaversion.viaversion.api.ViaAPI; -import de.steamwar.bausystem.BauSystem; -import de.steamwar.linkage.Linked; -import net.md_5.bungee.api.ChatMessageType; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerJoinEvent; - -@Linked -public class VersionAnnouncer implements Listener { - - private final String versionString = Bukkit.getBukkitVersion().split("-", 2)[0]; - - @SuppressWarnings("unchecked") - private final ViaAPI via = Via.getAPI(); - - @EventHandler - public void onJoin(PlayerJoinEvent event) { - Player player = event.getPlayer(); - if(via.getServerVersion().supportedVersions().contains(via.getPlayerVersion(player))) - return; - - BauSystem.MESSAGE.sendPrefixless("SERVER_VERSION", player, ChatMessageType.ACTION_BAR, versionString); - } -} diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/WorldEditUtils.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/WorldEditUtils.java index 4d20f346..3fef4e48 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/WorldEditUtils.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/utils/WorldEditUtils.java @@ -19,7 +19,7 @@ package de.steamwar.bausystem.utils; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.IncompleteRegionException; import com.sk89q.worldedit.LocalSession; @@ -100,7 +100,7 @@ public class WorldEditUtils { .getSessionManager() .get(BukkitAdapter.adapt(player)); - Reflection.ConstructorInvoker constructorInvoker = Reflection.getConstructor(clazz, com.sk89q.worldedit.world.World.class); + Reflection.Constructor constructorInvoker = Reflection.getConstructor(clazz, com.sk89q.worldedit.world.World.class); RegionSelector regionSelector = (RegionSelector) constructorInvoker.invoke(BukkitAdapter.adapt(player.getWorld())); localSession.setRegionSelector(BukkitAdapter.adapt(player.getWorld()), regionSelector); diff --git a/BauSystem/BauSystem_Main/src/plugin.yml b/BauSystem/BauSystem_Main/src/plugin.yml index 53585eaa..71b08d95 100644 --- a/BauSystem/BauSystem_Main/src/plugin.yml +++ b/BauSystem/BauSystem_Main/src/plugin.yml @@ -2,8 +2,6 @@ name: BauSystem authors: [ Lixfel, YoyoNow, Chaoscaot, Zeanon, D4rkr34lm ] version: "2.0" depend: [ WorldEdit, SpigotCore ] -softdepend: - - ViaVersion load: POSTWORLD main: de.steamwar.bausystem.BauSystem api-version: "1.13" diff --git a/BauSystem/build.gradle.kts b/BauSystem/build.gradle.kts index 7a02ffa7..712238c8 100644 --- a/BauSystem/build.gradle.kts +++ b/BauSystem/build.gradle.kts @@ -1,7 +1,7 @@ /* * This file is a part of the SteamWar software. * - * Copyright (C) 2024 SteamWar.de-Serverteam + * Copyright (C) 2024 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 diff --git a/CommandFramework/build.gradle.kts b/CommandFramework/build.gradle.kts index 61fbf34e..7fcb7845 100644 --- a/CommandFramework/build.gradle.kts +++ b/CommandFramework/build.gradle.kts @@ -1,7 +1,7 @@ /* * This file is a part of the SteamWar software. * - * Copyright (C) 2024 SteamWar.de-Serverteam + * Copyright (C) 2024 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 diff --git a/CommonCore/SQL/src/de/steamwar/sql/Fight.java b/CommonCore/SQL/src/de/steamwar/sql/Fight.java index efa230d2..66efbef9 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/Fight.java +++ b/CommonCore/SQL/src/de/steamwar/sql/Fight.java @@ -35,8 +35,9 @@ import java.util.stream.Collectors; public class Fight { private static final Table table = new Table<>(Fight.class); - private static final SelectStatement getPage = new SelectStatement<>(table, "SELECT f.*, (b.NodeId IS NULL OR b.AllowReplay) AND (r.NodeId IS NULL OR r.AllowReplay) AS ReplayAllowed, (SELECT COUNT(1) FROM Replay WHERE Replay.FightID = f.FightID) as ReplayAvailable FROM Fight f LEFT OUTER JOIN SchematicNode b ON f.BlueSchem = b.NodeId LEFT OUTER JOIN SchematicNode r ON f.RedSchem = r.NodeId ORDER BY FightID DESC LIMIT ?, ?"); + private static final SelectStatement getPage = new SelectStatement<>(table, "SELECT f.*, (b.NodeId IS NULL OR b.AllowReplay) AND (r.NodeId IS NULL OR r.AllowReplay) AS ReplayAllowed FROM Fight f LEFT OUTER JOIN SchematicNode b ON f.BlueSchem = b.NodeId LEFT OUTER JOIN SchematicNode r ON f.RedSchem = r.NodeId ORDER BY FightID DESC LIMIT ?, ?"); private static final Statement insert = table.insertFields(true, "GameMode", "Server", "StartTime", "Duration", "BlueLeader", "RedLeader", "BlueSchem", "RedSchem", "Win", "WinCondition"); + private static final Statement updateReplayAvailable = table.update(Table.PRIMARY, "ReplayAvailable"); public static List getPage(int page, int elementsPerPage) { List fights = getPage.listSelect(page * elementsPerPage, elementsPerPage); @@ -54,6 +55,10 @@ public class Fight { return insert.insertGetKey(gamemode, server, starttime, duration, blueleader, redleader, blueschem, redschem, win, wincondition); } + public static void markReplayAvailable(int fightID) { + updateReplayAvailable.update(true, fightID); + } + @Getter @Field(keys = {Table.PRIMARY}, autoincrement = true) private final int fightID; @@ -80,10 +85,10 @@ public class Fight { private final int win; @Field private final String wincondition; + @Field + private final boolean replayAvailable; @Field // Virtual field for easy select private final boolean replayAllowed; - @Field // Virtual field for easy select - private final boolean replayAvailable; @Getter private final List bluePlayers = new ArrayList<>(); diff --git a/CommonCore/SQL/src/de/steamwar/sql/NodeData.java b/CommonCore/SQL/src/de/steamwar/sql/NodeData.java index 52743811..0de6c6c5 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/NodeData.java +++ b/CommonCore/SQL/src/de/steamwar/sql/NodeData.java @@ -28,12 +28,15 @@ import java.sql.PreparedStatement; import java.util.zip.GZIPInputStream; @AllArgsConstructor +@Getter public class NodeData { 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); new SqlTypeMapper<>(BufferedInputStream.class, "BLOB", (rs, identifier) -> { throw new SecurityException("BufferedInputStream is write only datatype"); }, PreparedStatement::setBinaryStream); + + SqlTypeMapper.ordinalEnumMapper(SchematicFormat.class); } private static final Table table = new Table<>(NodeData.class); @@ -48,19 +51,18 @@ public class NodeData { throw new IllegalArgumentException("Node is a directory"); return get.select(rs -> { if(rs.next()) { - return new NodeData(node.getId(), rs.getBoolean("NodeFormat")); + return new NodeData(node.getId(), SchematicFormat.values()[rs.getInt("NodeFormat")]); } else { - return new NodeData(node.getId(), false); + return new NodeData(node.getId(), SchematicFormat.MCEDIT); } }, node); } - @Getter @Field(keys = {Table.PRIMARY}) private final int nodeId; @Field - private boolean nodeFormat; + private SchematicFormat nodeFormat; public InputStream schemData() throws IOException { try { @@ -81,12 +83,18 @@ public class NodeData { } } - public void saveFromStream(InputStream blob, boolean newFormat) { + public void saveFromStream(InputStream blob, SchematicFormat newFormat) { updateDatabase.update(nodeId, newFormat, blob); nodeFormat = newFormat; } - public boolean getNodeFormat() { - return nodeFormat; + @AllArgsConstructor + @Getter + public enum SchematicFormat { + MCEDIT(".schematic"), + SPONGE_V2(".schem"), + SPONGE_V3(".schem"); + + private final String fileEnding; } } diff --git a/CommonCore/SQL/src/de/steamwar/sql/NodeDownload.java b/CommonCore/SQL/src/de/steamwar/sql/NodeDownload.java index b3792b63..71cf83f4 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/NodeDownload.java +++ b/CommonCore/SQL/src/de/steamwar/sql/NodeDownload.java @@ -35,7 +35,7 @@ import java.time.Instant; public class NodeDownload { private static final char[] HEX = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; - private static final String LINK_BASE = "https://steamwar.de/download.php?schem="; + private static final String LINK_BASE = "https://api.steamwar.de/download/"; private static final Table table = new Table<>(NodeDownload.class); private static final Statement insert = table.insertFields("NodeId", "Link"); diff --git a/CommonCore/SQL/src/de/steamwar/sql/Replay.java b/CommonCore/SQL/src/de/steamwar/sql/Replay.java deleted file mode 100644 index a90e2392..00000000 --- a/CommonCore/SQL/src/de/steamwar/sql/Replay.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 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.sql; - -import de.steamwar.sql.internal.*; -import lombok.AllArgsConstructor; -import lombok.Getter; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.StandardCopyOption; -import java.sql.SQLException; - -@AllArgsConstructor -public class Replay { - - static { - new SqlTypeMapper<>(File.class, "BLOB", (rs, identifier) -> { - try { - File file = File.createTempFile("replay", ".replay"); - file.deleteOnExit(); - Files.copy(rs.getBinaryStream(identifier), file.toPath(), StandardCopyOption.REPLACE_EXISTING); - return file; - } catch (IOException e) { - throw new SQLException(e); - } - }, (st, index, value) -> { - try { - st.setBinaryStream(index, new FileInputStream(value)); - } catch (FileNotFoundException e) { - throw new SQLException(e); - } - }); - } - - private static final Table table = new Table<>(Replay.class); - private static final SelectStatement get = table.select(Table.PRIMARY); - - public static final Statement insert = table.insertAll(); - - public static Replay get(int fightID) { - return get.select(fightID); - } - - public static void save(int fightID, File file) { - insert.update(fightID, file); - } - - @Field(keys = {Table.PRIMARY}) - private final int fightID; - @Getter - @Field - private final File replay; -} diff --git a/CommonCore/SQL/src/de/steamwar/sql/SchematicNode.java b/CommonCore/SQL/src/de/steamwar/sql/SchematicNode.java index 3df740da..bece8549 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/SchematicNode.java +++ b/CommonCore/SQL/src/de/steamwar/sql/SchematicNode.java @@ -375,11 +375,10 @@ public class SchematicNode { return nodeType == null; } - @Deprecated - public boolean getSchemFormat() { + public String getFileEnding() { if(isDir()) throw new SecurityException("Node is Directory"); - return NodeData.get(this).getNodeFormat(); + return NodeData.get(this).getNodeFormat().getFileEnding(); } public int getRank() { diff --git a/CommonCore/SQL/src/de/steamwar/sql/SteamwarUser.java b/CommonCore/SQL/src/de/steamwar/sql/SteamwarUser.java index d5b87b6e..d4bed21c 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/SteamwarUser.java +++ b/CommonCore/SQL/src/de/steamwar/sql/SteamwarUser.java @@ -29,7 +29,6 @@ import java.security.SecureRandom; import java.security.spec.InvalidKeySpecException; import java.sql.Timestamp; import java.util.*; -import java.util.function.BiConsumer; import java.util.function.Consumer; import java.util.logging.Level; import java.util.stream.Collectors; @@ -122,13 +121,12 @@ public class SteamwarUser { return byDiscord.select(discordId); } - public static SteamwarUser getOrCreate(UUID uuid, String name, Consumer newPlayer, BiConsumer nameUpdate) { + public static SteamwarUser getOrCreate(UUID uuid, String name, Consumer newPlayer) { SteamwarUser user = get(uuid); if (user != null) { if (!user.userName.equals(name)) { updateName.update(name, user.id); - nameUpdate.accept(user.userName, name); user.userName = name; } @@ -359,6 +357,10 @@ public class SteamwarUser { } } + public boolean hasPassword() { + return this.password != null; + } + private byte[] generateHash(String password, byte[] salt) throws InvalidKeySpecException { PBEKeySpec spec = new PBEKeySpec(password.toCharArray(), salt, 65536, 512); diff --git a/CommonCore/SQL/src/de/steamwar/sql/internal/Statement.java b/CommonCore/SQL/src/de/steamwar/sql/internal/Statement.java index 3d6a49b2..2621da6b 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/internal/Statement.java +++ b/CommonCore/SQL/src/de/steamwar/sql/internal/Statement.java @@ -62,7 +62,7 @@ public class Statement implements AutoCloseable { String user = properties.getProperty("user"); String password = properties.getProperty("password"); - PRODUCTION_DATABASE = "core".equals(properties.getProperty("database")); + PRODUCTION_DATABASE = "production".equals(properties.getProperty("database")); MAX_CONNECTIONS = SQLConfig.impl.maxConnections(); conProvider = () -> { try { diff --git a/FightSystem/FightSystem_14/src/de/steamwar/fightsystem/utils/BlockIdWrapper14.java b/FightSystem/FightSystem_14/src/de/steamwar/fightsystem/utils/BlockIdWrapper14.java index 5030cb04..93b4a811 100644 --- a/FightSystem/FightSystem_14/src/de/steamwar/fightsystem/utils/BlockIdWrapper14.java +++ b/FightSystem/FightSystem_14/src/de/steamwar/fightsystem/utils/BlockIdWrapper14.java @@ -19,7 +19,7 @@ package de.steamwar.fightsystem.utils; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import de.steamwar.core.Core; import de.steamwar.fightsystem.Config; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; @@ -33,32 +33,32 @@ import java.util.Map; public class BlockIdWrapper14 implements BlockIdWrapper { - private static final Class chunkProviderServer = Reflection.getClass("{nms.server.level}.ChunkProviderServer"); - private static final Reflection.MethodInvoker getChunkProvider = Reflection.getTypedMethod(worldServer, null, chunkProviderServer); - private static final Class playerChunkMap = Reflection.getClass("{nms.server.level}.PlayerChunkMap"); - private static final Reflection.FieldAccessor getPlayerChunkMap = Reflection.getField(chunkProviderServer, playerChunkMap, 0); - private static final Reflection.FieldAccessor entityTrackers = Core.getVersion() > 15 ? Reflection.getField(playerChunkMap, Int2ObjectMap.class, 0) : Reflection.getField(playerChunkMap, org.bukkit.craftbukkit.libs.it.unimi.dsi.fastutil.ints.Int2ObjectMap.class, 0); - private static final Class block = Reflection.getClass("{nms.world.level.block}.Block"); - private static final Class iBlockData = Reflection.getClass("{nms.world.level.block.state}.IBlockData"); - private static final Class blockPosition = Reflection.getClass("{nms.core}.BlockPosition"); + private static final Class chunkProviderServer = Reflection.getClass("net.minecraft.server.level.ServerChunkCache"); + private static final Reflection.Method getChunkProvider = Reflection.getTypedMethod(worldServer, null, chunkProviderServer); + private static final Class playerChunkMap = Reflection.getClass("net.minecraft.server.level.ChunkMap"); + private static final Reflection.Field getPlayerChunkMap = Reflection.getField(chunkProviderServer, playerChunkMap, 0); + private static final Reflection.Field entityTrackers = Core.getVersion() > 15 ? Reflection.getField(playerChunkMap, Int2ObjectMap.class, 0) : Reflection.getField(playerChunkMap, org.bukkit.craftbukkit.libs.it.unimi.dsi.fastutil.ints.Int2ObjectMap.class, 0); + private static final Class block = Reflection.getClass("net.minecraft.world.level.block.Block"); + private static final Class iBlockData = Reflection.getClass("net.minecraft.world.level.block.state.BlockState"); + private static final Class blockPosition = Reflection.getClass("net.minecraft.core.BlockPos"); private final Map trackers; public BlockIdWrapper14() { trackers = entityTrackers.get(getPlayerChunkMap.get(getChunkProvider.invoke(getWorldHandle.invoke(Config.world)))); } - private static final Reflection.MethodInvoker getCombinedId = Reflection.getTypedMethod(block, null, int.class, iBlockData); - private static final Reflection.MethodInvoker getNMS = Reflection.getTypedMethod(Reflection.getClass("{obc}.block.CraftBlock"), "getNMS", iBlockData); + private static final Reflection.Method getCombinedId = Reflection.getTypedMethod(block, null, int.class, iBlockData); + private static final Reflection.Method getNMS = Reflection.getTypedMethod(Reflection.getClass("org.bukkit.craftbukkit.block.CraftBlock"), "getNMS", iBlockData); @Override public int blockToId(Block block) { return (int) getCombinedId.invoke(null, getNMS.invoke(block)); } - private static final Reflection.MethodInvoker getByCombinedId = Reflection.getTypedMethod(block, null, iBlockData, int.class); - private static final Reflection.ConstructorInvoker newBlockPosition = Reflection.getConstructor(blockPosition, int.class, int.class, int.class); - private static final Reflection.MethodInvoker getTypeAndData = Reflection.getMethod(worldServer, null, blockPosition, iBlockData, int.class); - private static final Reflection.MethodInvoker removeTileEntity = Reflection.getMethod(worldServer, Core.getVersion() > 15 ? "m" : "removeTileEntity", blockPosition); - private static final Reflection.MethodInvoker flagDirty = Reflection.getMethod(chunkProviderServer, null, blockPosition); + private static final Reflection.Method getByCombinedId = Reflection.getTypedMethod(block, null, iBlockData, int.class); + private static final Reflection.Constructor newBlockPosition = Reflection.getConstructor(blockPosition, int.class, int.class, int.class); + private static final Reflection.Method getTypeAndData = Reflection.getMethod(worldServer, null, blockPosition, iBlockData, int.class); + private static final Reflection.Method removeTileEntity = Reflection.getMethod(worldServer, Core.getVersion() > 15 ? "m" : "removeTileEntity", blockPosition); + private static final Reflection.Method flagDirty = Reflection.getMethod(chunkProviderServer, null, blockPosition); @Override public void setBlock(World world, int x, int y, int z, int blockState) { Object blockData = getByCombinedId.invoke(null, blockState); @@ -70,8 +70,8 @@ public class BlockIdWrapper14 implements BlockIdWrapper { flagDirty.invoke(getChunkProvider.invoke(nworld), pos); } - private static final Class entityTracker = Reflection.getClass("{nms.server.level}.PlayerChunkMap$EntityTracker"); - private static final Reflection.MethodInvoker updatePlayer = Reflection.getMethod(entityTracker, Core.getVersion() > 15 ? "b" : "updatePlayer", entityPlayer); + private static final Class entityTracker = Reflection.getClass("net.minecraft.server.level.ChunkMap$TrackedEntity"); + private static final Reflection.Method updatePlayer = Reflection.getMethod(entityTracker, Core.getVersion() > 15 ? "b" : "updatePlayer", entityPlayer); @Override public void trackEntity(Player player, Entity entity) { Object tracker = trackers.get(entity.getEntityId()); @@ -79,7 +79,7 @@ public class BlockIdWrapper14 implements BlockIdWrapper { updatePlayer.invoke(tracker, getPlayer.invoke(player)); } - private static final Reflection.MethodInvoker clearPlayer = Reflection.getMethod(entityTracker, Core.getVersion() > 15 ? "a" : "clear", entityPlayer); + private static final Reflection.Method clearPlayer = Reflection.getMethod(entityTracker, Core.getVersion() > 15 ? "a" : "clear", entityPlayer); @Override public void untrackEntity(Player player, Entity entity) { Object tracker = trackers.get(entity.getEntityId()); @@ -87,8 +87,8 @@ public class BlockIdWrapper14 implements BlockIdWrapper { clearPlayer.invoke(tracker, getPlayer.invoke(player)); } - private static final Reflection.MethodInvoker getMaterialByBlock = Reflection.getTypedMethod(Reflection.getClass("{obc}.util.CraftMagicNumbers"), "getMaterial", Material.class, block); - private static final Reflection.MethodInvoker getBlockByBlockData = Reflection.getTypedMethod(iBlockData, null, block); + private static final Reflection.Method getMaterialByBlock = Reflection.getTypedMethod(Reflection.getClass("org.bukkit.craftbukkit.util.CraftMagicNumbers"), "getMaterial", Material.class, block); + private static final Reflection.Method getBlockByBlockData = Reflection.getTypedMethod(iBlockData, null, block); @Override public Material idToMaterial(int blockState) { return (Material)getMaterialByBlock.invoke(null, getBlockByBlockData.invoke(getByCombinedId.invoke(null, blockState))); diff --git a/FightSystem/FightSystem_14/src/de/steamwar/fightsystem/utils/WorldeditWrapper14.java b/FightSystem/FightSystem_14/src/de/steamwar/fightsystem/utils/WorldeditWrapper14.java index 288b89e8..9a0ae4b5 100644 --- a/FightSystem/FightSystem_14/src/de/steamwar/fightsystem/utils/WorldeditWrapper14.java +++ b/FightSystem/FightSystem_14/src/de/steamwar/fightsystem/utils/WorldeditWrapper14.java @@ -42,6 +42,7 @@ import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockTypes; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; +import de.steamwar.sql.NodeData; import de.steamwar.sql.SchematicData; import de.steamwar.sql.SchematicNode; import org.bukkit.DyeColor; @@ -144,6 +145,6 @@ public class WorldeditWrapper14 implements WorldeditWrapper { throw new SecurityException(e); } - new SchematicData(schem).saveFromBytes(outputStream.toByteArray(), true); + new SchematicData(schem).saveFromBytes(outputStream.toByteArray(), NodeData.SchematicFormat.SPONGE_V2); } } diff --git a/FightSystem/FightSystem_18/build.gradle.kts b/FightSystem/FightSystem_18/build.gradle.kts index b140d148..b5d694ed 100644 --- a/FightSystem/FightSystem_18/build.gradle.kts +++ b/FightSystem/FightSystem_18/build.gradle.kts @@ -31,5 +31,6 @@ dependencies { compileOnly(libs.nms18) compileOnly(libs.fawe18) + compileOnly(libs.authlib) compileOnly(libs.fastutil) } diff --git a/FightSystem/FightSystem_18/src/de/steamwar/fightsystem/utils/BlockIdWrapper18.java b/FightSystem/FightSystem_18/src/de/steamwar/fightsystem/utils/BlockIdWrapper18.java index c229353a..992dd451 100644 --- a/FightSystem/FightSystem_18/src/de/steamwar/fightsystem/utils/BlockIdWrapper18.java +++ b/FightSystem/FightSystem_18/src/de/steamwar/fightsystem/utils/BlockIdWrapper18.java @@ -19,24 +19,29 @@ package de.steamwar.fightsystem.utils; -import com.comphenix.tinyprotocol.Reflection; +import com.comphenix.tinyprotocol.TinyProtocol; +import com.mojang.authlib.GameProfile; +import de.steamwar.core.ProtocolWrapper; +import de.steamwar.fightsystem.FightSystem; +import org.bukkit.GameMode; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; -import java.util.*; - public class BlockIdWrapper18 extends BlockIdWrapper14 { - private static final Reflection.FieldAccessor hiddenEntities = Reflection.getField(Reflection.getClass("{obc}.entity.CraftPlayer"), Map.class, 0, UUID.class, Set.class); @Override public void trackEntity(Player player, Entity entity) { - hiddenEntities.get(player).remove(entity.getUniqueId()); - super.trackEntity(player, entity); + if(entity instanceof Player) + TinyProtocol.instance.sendPacket(player, ProtocolWrapper.impl.playerInfoPacketConstructor(ProtocolWrapper.PlayerInfoAction.REMOVE, new GameProfile(entity.getUniqueId(), entity.getName()), GameMode.CREATIVE)); + + player.showEntity(FightSystem.getPlugin(), entity); } @Override public void untrackEntity(Player player, Entity entity) { - hiddenEntities.get(player).put(entity.getUniqueId(), new HashSet<>(1)); - super.untrackEntity(player, entity); + player.hideEntity(FightSystem.getPlugin(), entity); + + if(entity instanceof Player) + TinyProtocol.instance.sendPacket(player, ProtocolWrapper.impl.playerInfoPacketConstructor(ProtocolWrapper.PlayerInfoAction.ADD, new GameProfile(entity.getUniqueId(), entity.getName()), GameMode.CREATIVE)); } } diff --git a/FightSystem/FightSystem_18/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper18.java b/FightSystem/FightSystem_18/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper18.java index 72c14f8f..8fa8e7de 100644 --- a/FightSystem/FightSystem_18/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper18.java +++ b/FightSystem/FightSystem_18/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper18.java @@ -19,7 +19,7 @@ package de.steamwar.fightsystem.utils; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import de.steamwar.fightsystem.Config; import net.minecraft.server.level.WorldServer; import net.minecraft.world.level.chunk.Chunk; @@ -33,9 +33,9 @@ import java.util.stream.StreamSupport; public class CraftbukkitWrapper18 implements CraftbukkitWrapper { - private static final Reflection.MethodInvoker getWorld = Reflection.getMethod(Reflection.getClass("{obc}.CraftWorld"), "getHandle"); - private static final Reflection.MethodInvoker getChunk = Reflection.getTypedMethod(net.minecraft.world.level.World.class, null, Chunk.class, int.class, int.class); - private static final Reflection.MethodInvoker getChunkSections = Reflection.getTypedMethod(Chunk.class, null, ChunkSection[].class); + private static final Reflection.Method getWorld = Reflection.getMethod(Reflection.getClass("org.bukkit.craftbukkit.CraftWorld"), "getHandle"); + private static final Reflection.Method getChunk = Reflection.getTypedMethod(net.minecraft.world.level.World.class, null, Chunk.class, int.class, int.class); + private static final Reflection.Method getChunkSections = Reflection.getTypedMethod(Chunk.class, null, ChunkSection[].class); private ChunkSection[] getChunkSections(World world, int x, int z) { return (ChunkSection[]) getChunkSections.invoke(getChunk.invoke(getWorld.invoke(world), x, z)); } @@ -46,7 +46,7 @@ public class CraftbukkitWrapper18 implements CraftbukkitWrapper { System.arraycopy(getChunkSections(backup, x, z), 0, sections, 0, sections.length); } - private static final Reflection.MethodInvoker getEntity = Reflection.getTypedMethod(Reflection.getClass("{obc}.entity.CraftEntity"), "getHandle", net.minecraft.world.entity.Entity.class); + private static final Reflection.Method getEntity = Reflection.getTypedMethod(Reflection.getClass("org.bukkit.craftbukkit.entity.CraftEntity"), "getHandle", net.minecraft.world.entity.Entity.class); protected net.minecraft.world.entity.Entity getEntity(Entity e) { return (net.minecraft.world.entity.Entity) getEntity.invoke(e); } @@ -56,8 +56,8 @@ public class CraftbukkitWrapper18 implements CraftbukkitWrapper { return getEntity(e).ce(); } - private static final Reflection.MethodInvoker getWorldEntities = Reflection.getTypedMethod(WorldServer.class, null, LevelEntityGetter.class); - private static final Reflection.MethodInvoker getIterable = Reflection.getTypedMethod(LevelEntityGetter.class, null, Iterable.class); + private static final Reflection.Method getWorldEntities = Reflection.getTypedMethod(WorldServer.class, null, LevelEntityGetter.class); + private static final Reflection.Method getIterable = Reflection.getTypedMethod(LevelEntityGetter.class, null, Iterable.class); @Override public Stream entityIterator() { return StreamSupport.stream(((Iterable) getIterable.invoke(getWorldEntities.invoke(getWorld.invoke(Config.world)))).spliterator(), false); diff --git a/FightSystem/FightSystem_18/src/de/steamwar/fightsystem/utils/HullHiderWrapper18.java b/FightSystem/FightSystem_18/src/de/steamwar/fightsystem/utils/HullHiderWrapper18.java index af5f83a1..9cee390f 100644 --- a/FightSystem/FightSystem_18/src/de/steamwar/fightsystem/utils/HullHiderWrapper18.java +++ b/FightSystem/FightSystem_18/src/de/steamwar/fightsystem/utils/HullHiderWrapper18.java @@ -19,7 +19,7 @@ package de.steamwar.fightsystem.utils; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import de.steamwar.fightsystem.Config; import it.unimi.dsi.fastutil.shorts.Short2ObjectArrayMap; import net.minecraft.core.BlockPosition; @@ -33,7 +33,7 @@ import java.util.List; public class HullHiderWrapper18 implements HullHiderWrapper { - private static final Reflection.MethodInvoker getState = Reflection.getTypedMethod(Reflection.getClass("{obc}.block.data.CraftBlockData"), "getState", IBlockData.class); + private static final Reflection.Method getState = Reflection.getTypedMethod(Reflection.getClass("org.bukkit.craftbukkit.block.data.CraftBlockData"), "getState", IBlockData.class); @Override public Object generateBlockChangePacket(List changes) { Object[] blockdata = new Object[changes.size()]; diff --git a/FightSystem/FightSystem_8/src/de/steamwar/fightsystem/utils/BlockIdWrapper8.java b/FightSystem/FightSystem_8/src/de/steamwar/fightsystem/utils/BlockIdWrapper8.java index 402f8e60..5d06a7be 100644 --- a/FightSystem/FightSystem_8/src/de/steamwar/fightsystem/utils/BlockIdWrapper8.java +++ b/FightSystem/FightSystem_8/src/de/steamwar/fightsystem/utils/BlockIdWrapper8.java @@ -19,7 +19,7 @@ package de.steamwar.fightsystem.utils; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import de.steamwar.fightsystem.Config; import org.bukkit.Material; import org.bukkit.World; @@ -29,10 +29,10 @@ import org.bukkit.entity.Player; public class BlockIdWrapper8 implements BlockIdWrapper { - private static final Class entityTracker = Reflection.getClass("{nms}.EntityTracker"); - private static final Reflection.FieldAccessor getEntityTracker = Reflection.getField(worldServer, entityTracker, 0); - private static final Class intHashMap = Reflection.getClass("{nms}.IntHashMap"); - private static final Reflection.FieldAccessor getTrackedEntities = Reflection.getField(entityTracker, intHashMap, 0); + private static final Class entityTracker = Reflection.getClass("net.minecraft.EntityTracker"); + private static final Reflection.Field getEntityTracker = Reflection.getField(worldServer, entityTracker, 0); + private static final Class intHashMap = Reflection.getClass("net.minecraft.IntHashMap"); + private static final Reflection.Field getTrackedEntities = Reflection.getField(entityTracker, intHashMap, 0); private final Object trackers; public BlockIdWrapper8() { @@ -54,9 +54,9 @@ public class BlockIdWrapper8 implements BlockIdWrapper { world.getBlockAt(x, y, z).setTypeIdAndData(blockState >> 4, (byte)(blockState & 0b1111), false); } - private static final Class entityTrackerEntry = Reflection.getClass("{nms}.EntityTrackerEntry"); - private static final Reflection.MethodInvoker get = Reflection.getTypedMethod(intHashMap, "get", Object.class, int.class); - private static final Reflection.MethodInvoker updatePlayer = Reflection.getMethod(entityTrackerEntry, "updatePlayer", entityPlayer); + private static final Class entityTrackerEntry = Reflection.getClass("net.minecraft.EntityTrackerEntry"); + private static final Reflection.Method get = Reflection.getTypedMethod(intHashMap, "get", Object.class, int.class); + private static final Reflection.Method updatePlayer = Reflection.getMethod(entityTrackerEntry, "updatePlayer", entityPlayer); @Override public void trackEntity(Player player, Entity entity) { Object tracker = get.invoke(trackers, entity.getEntityId()); @@ -64,7 +64,7 @@ public class BlockIdWrapper8 implements BlockIdWrapper { updatePlayer.invoke(tracker, getPlayer.invoke(player)); } - private static final Reflection.MethodInvoker clearPlayer = Reflection.getMethod(entityTrackerEntry, "a", entityPlayer); + private static final Reflection.Method clearPlayer = Reflection.getMethod(entityTrackerEntry, "a", entityPlayer); @Override public void untrackEntity(Player player, Entity entity) { Object tracker = get.invoke(trackers, entity.getEntityId()); diff --git a/FightSystem/FightSystem_8/src/de/steamwar/fightsystem/utils/HullHiderWrapper8.java b/FightSystem/FightSystem_8/src/de/steamwar/fightsystem/utils/HullHiderWrapper8.java index af56e404..03647c5e 100644 --- a/FightSystem/FightSystem_8/src/de/steamwar/fightsystem/utils/HullHiderWrapper8.java +++ b/FightSystem/FightSystem_8/src/de/steamwar/fightsystem/utils/HullHiderWrapper8.java @@ -19,15 +19,15 @@ package de.steamwar.fightsystem.utils; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import de.steamwar.fightsystem.Config; import java.util.List; public class HullHiderWrapper8 implements HullHiderWrapper { - private static final Reflection.ConstructorInvoker newMultiBlockChange = Reflection.getConstructor("{nms}.PacketPlayOutMultiBlockChange", int.class, short[].class, Reflection.getClass("{nms}.Chunk")); - private static final Reflection.MethodInvoker getHandle = Reflection.getMethod("{obc}.CraftChunk", "getHandle"); + private static final Reflection.Constructor newMultiBlockChange = Reflection.getConstructor("net.minecraft.PacketPlayOutMultiBlockChange", int.class, short[].class, Reflection.getClass("net.minecraft.Chunk")); + private static final Reflection.Method getHandle = Reflection.getMethod("org.bukkit.craftbukkit.CraftChunk", "getHandle"); @Override public Object generateBlockChangePacket(List changes) { Hull.IntVector chunk = changes.get(0); diff --git a/FightSystem/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldeditWrapper8.java b/FightSystem/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldeditWrapper8.java index 19854db8..018552f2 100644 --- a/FightSystem/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldeditWrapper8.java +++ b/FightSystem/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldeditWrapper8.java @@ -39,6 +39,7 @@ import com.sk89q.worldedit.session.ClipboardHolder; import com.sk89q.worldedit.world.World; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; +import de.steamwar.sql.NodeData; import de.steamwar.sql.SchematicData; import de.steamwar.sql.SchematicNode; import org.bukkit.DyeColor; @@ -142,6 +143,6 @@ public class WorldeditWrapper8 implements WorldeditWrapper { throw new SecurityException(e); } - new SchematicData(schem).saveFromBytes(outputStream.toByteArray(), false); + new SchematicData(schem).saveFromBytes(outputStream.toByteArray(), NodeData.SchematicFormat.MCEDIT); } } diff --git a/FightSystem/FightSystem_9/src/de/steamwar/fightsystem/utils/BountifulWrapper9.java b/FightSystem/FightSystem_9/src/de/steamwar/fightsystem/utils/BountifulWrapper9.java index 96cc9436..48017755 100644 --- a/FightSystem/FightSystem_9/src/de/steamwar/fightsystem/utils/BountifulWrapper9.java +++ b/FightSystem/FightSystem_9/src/de/steamwar/fightsystem/utils/BountifulWrapper9.java @@ -19,7 +19,7 @@ package de.steamwar.fightsystem.utils; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.listener.Recording; @@ -43,9 +43,9 @@ import java.util.Map; public class BountifulWrapper9 implements BountifulWrapper { - private static final Class enumHand = Reflection.getClass("{nms.world}.EnumHand"); + private static final Class enumHand = Reflection.getClass("net.minecraft.world.InteractionHand"); private static final Object mainHand = enumHand.getEnumConstants()[0]; - private static final Reflection.FieldAccessor blockPlaceHand = Reflection.getField(Recording.blockPlacePacket, enumHand, 0); + private static final Reflection.Field blockPlaceHand = Reflection.getField(Recording.blockPlacePacket, enumHand, 0); @Override public boolean mainHand(Object packet) { diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/AIManager.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/AIManager.java index 2cb13f65..3950a201 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/AIManager.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/ai/AIManager.java @@ -19,7 +19,7 @@ package de.steamwar.fightsystem.ai; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.fight.FightTeam; diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/Commands.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/Commands.java index b880fa6d..cff729df 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/Commands.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/commands/Commands.java @@ -19,7 +19,7 @@ package de.steamwar.fightsystem.commands; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.Fight; @@ -39,7 +39,7 @@ import org.bukkit.entity.Player; @UtilityClass public class Commands { - private static final Reflection.FieldAccessor commandMap = Reflection.getField("{obc}.CraftServer", "commandMap", SimpleCommandMap.class); + private static final Reflection.Field commandMap = Reflection.getField("org.bukkit.craftbukkit.CraftServer", "commandMap", SimpleCommandMap.class); public static void injectCommand(Command cmd) { commandMap.get(Bukkit.getServer()).register("FightSystem", cmd); } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/Kit.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/Kit.java index e3829099..db97aa27 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/Kit.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/fight/Kit.java @@ -19,7 +19,7 @@ package de.steamwar.fightsystem.fight; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.commands.Commands; @@ -215,11 +215,11 @@ public class Kit { return !normal.isEnchantmentInKit(stack) && !stack.getEnchantments().isEmpty(); } - private static final Class itemStack = Reflection.getClass("{nms.world.item}.ItemStack"); - private static final Reflection.MethodInvoker asNMSCopy = Reflection.getTypedMethod(Reflection.getClass("{obc}.inventory.CraftItemStack"), "asNMSCopy", itemStack, ItemStack.class); - private static final Class nbtTagCompound = Reflection.getClass("{nms.nbt}.NBTTagCompound"); - private static final Reflection.MethodInvoker getTag = Reflection.getTypedMethod(itemStack, null, nbtTagCompound); - private static final Reflection.MethodInvoker getKeys = Reflection.getTypedMethod(nbtTagCompound, null, Set.class); + private static final Class itemStack = Reflection.getClass("net.minecraft.world.item.ItemStack"); + private static final Reflection.Method asNMSCopy = Reflection.getTypedMethod(Reflection.getClass("org.bukkit.craftbukkit.inventory.CraftItemStack"), "asNMSCopy", itemStack, ItemStack.class); + private static final Class nbtTagCompound = Reflection.getClass("net.minecraft.nbt.CompoundTag"); + private static final Reflection.Method getTag = Reflection.getTypedMethod(itemStack, null, nbtTagCompound); + private static final Reflection.Method getKeys = Reflection.getTypedMethod(nbtTagCompound, null, Set.class); public static boolean hasItems(ItemStack stack) { Set keys = new HashSet<>((Set) getKeys.invoke(getTag.invoke(asNMSCopy.invoke(null, stack)))); keys.remove("Enchantments"); diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArrowStopper.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArrowStopper.java index 3fd7f7dc..361b86b6 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArrowStopper.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArrowStopper.java @@ -19,7 +19,7 @@ package de.steamwar.fightsystem.listener; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentTask; @@ -41,7 +41,7 @@ public class ArrowStopper { new StateDependentTask(Config.TechhiderActive, FightState.Running, this::run, 1, 1); } - private static final Class entityArrow = Reflection.getClass("{nms.world.entity.projectile}.EntityArrow"); + private static final Class entityArrow = Reflection.getClass("net.minecraft.world.entity.projectile.AbstractArrow"); private void run() { Recording.iterateOverEntities(entityArrow::isInstance, entity -> { Projectile arrow = (Projectile) entity; diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/ClickAnalyzer.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/ClickAnalyzer.java index 73e2afa9..d4bd10dc 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/ClickAnalyzer.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/ClickAnalyzer.java @@ -19,7 +19,7 @@ package de.steamwar.fightsystem.listener; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; import de.steamwar.core.Core; import de.steamwar.fightsystem.Config; @@ -43,7 +43,7 @@ public class ClickAnalyzer { public ClickAnalyzer() { TinyProtocol.instance.addFilter(Recording.blockPlacePacket, this::onBlockPlace); if(Core.getVersion() > 8) - TinyProtocol.instance.addFilter(Reflection.getClass("{nms.network.protocol.game}.PacketPlayInUseItem"), this::onBlockPlace); + TinyProtocol.instance.addFilter(Reflection.getClass("net.minecraft.network.protocol.game.ServerboundUseItemOnPacket"), this::onBlockPlace); } public Object onBlockPlace(Player player, Object packet) { diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/Recording.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/Recording.java index b4040b74..117962eb 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/Recording.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/listener/Recording.java @@ -19,7 +19,7 @@ package de.steamwar.fightsystem.listener; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; import de.steamwar.core.TrickyTrialsWrapper; import de.steamwar.fightsystem.ArenaMode; @@ -77,8 +77,8 @@ public class Recording implements Listener { return fp == null || !fp.isLiving() || FightState.getFightState() == FightState.SPECTATE; } - public static final Class primedTnt = Reflection.getClass("{nms.world.entity.item}.EntityTNTPrimed"); - private static final Reflection.MethodInvoker getBukkitEntity = Reflection.getTypedMethod(Reflection.getClass("{nms.world.entity}.Entity"), "getBukkitEntity", null); + public static final Class primedTnt = Reflection.getClass("net.minecraft.world.entity.item.PrimedTnt"); + private static final Reflection.Method getBukkitEntity = Reflection.getTypedMethod(Reflection.getClass("net.minecraft.world.entity.Entity"), "getBukkitEntity", null); public static void iterateOverEntities(Predicate filter, Consumer consumer) { CraftbukkitWrapper.impl.entityIterator().filter(filter).map(entity -> (Entity) getBukkitEntity.invoke(entity)).forEach(consumer); } @@ -129,9 +129,9 @@ public class Recording implements Listener { GlobalRecorder.getInstance().entitySpeed(entity); } - private static final Class blockDigPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInBlockDig"); + private static final Class blockDigPacket = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundPlayerActionPacket"); private static final Class playerDigType = blockDigPacket.getDeclaredClasses()[0]; - private static final Reflection.FieldAccessor blockDigType = Reflection.getField(blockDigPacket, playerDigType, 0); + private static final Reflection.Field blockDigType = Reflection.getField(blockDigPacket, playerDigType, 0); private static final Object releaseUseItem = playerDigType.getEnumConstants()[5]; private Object blockDig(Player p, Object packet) { if(!isNotSent(p) && blockDigType.get(packet) == releaseUseItem) @@ -139,7 +139,7 @@ public class Recording implements Listener { return packet; } - public static final Class blockPlacePacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInBlockPlace"); + public static final Class blockPlacePacket = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundUseItemPacket"); private Object blockPlace(Player p, Object packet) { boolean mainHand = BountifulWrapper.impl.mainHand(packet); if(!isNotSent(p) && BountifulWrapper.impl.bowInHand(mainHand, p)) diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/FileSource.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/FileSource.java index 2fcaa59e..9e1a05ea 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/FileSource.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/FileSource.java @@ -20,15 +20,18 @@ package de.steamwar.fightsystem.record; import de.steamwar.fightsystem.Config; -import de.steamwar.sql.Replay; import java.io.File; -import java.io.FileInputStream; import java.io.IOException; +import java.nio.file.Files; import java.util.zip.GZIPInputStream; public class FileSource extends PacketSource { + public static File replayFile(int fightId) { + return new File("/mnt/storage/replays", fightId + ".replay"); + } + public static void startReplay() { if(Config.replayserver()) { try { @@ -41,7 +44,7 @@ public class FileSource extends PacketSource { if(Config.ReplayID > 0) { try { - new FileSource(Replay.get(Config.ReplayID).getReplay()); + new FileSource(replayFile(Config.ReplayID)); } catch (IOException e) { throw new SecurityException("Could not start replay", e); } @@ -49,7 +52,7 @@ public class FileSource extends PacketSource { } public FileSource(File fightFile) throws IOException { - super(new GZIPInputStream(new FileInputStream(fightFile))); + super(new GZIPInputStream(Files.newInputStream(fightFile.toPath()))); new PacketProcessor(this); } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java index 825c5eb6..47efc09d 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java @@ -22,6 +22,7 @@ package de.steamwar.fightsystem.record; import com.sk89q.worldedit.extent.clipboard.Clipboard; import de.steamwar.core.Core; import de.steamwar.core.TrickyTrialsWrapper; +import de.steamwar.core.WorldEditWrapper; import de.steamwar.entity.REntity; import de.steamwar.entity.REntityServer; import de.steamwar.entity.RPlayer; @@ -523,7 +524,7 @@ public class PacketProcessor implements Listener { public void close() { // FAWE 1.12 calls close... } - }, Core.getVersion() > 12); + }, WorldEditWrapper.impl.getNativeFormat()); execSync(() -> team.pasteSchem(schemId, clipboard)); } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/BlockIdWrapper.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/BlockIdWrapper.java index 354ff9fd..a8f5d226 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/BlockIdWrapper.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/BlockIdWrapper.java @@ -19,7 +19,7 @@ package de.steamwar.fightsystem.utils; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import de.steamwar.core.VersionDependent; import de.steamwar.fightsystem.FightSystem; import org.bukkit.Material; @@ -29,12 +29,12 @@ import org.bukkit.entity.Entity; import org.bukkit.entity.Player; public interface BlockIdWrapper { - Class worldServer = Reflection.getClass("{nms.server.level}.WorldServer"); - Reflection.MethodInvoker getWorldHandle = Reflection.getTypedMethod(Reflection.getClass("{obc}.CraftWorld"), "getHandle", worldServer); + Class worldServer = Reflection.getClass("net.minecraft.server.level.ServerLevel"); + Reflection.Method getWorldHandle = Reflection.getTypedMethod(Reflection.getClass("org.bukkit.craftbukkit.CraftWorld"), "getHandle", worldServer); - Class craftPlayer = Reflection.getClass("{obc}.entity.CraftPlayer"); - Class entityPlayer = Reflection.getClass("{nms.server.level}.EntityPlayer"); - Reflection.MethodInvoker getPlayer = Reflection.getTypedMethod(craftPlayer, "getHandle", entityPlayer); + Class craftPlayer = Reflection.getClass("org.bukkit.craftbukkit.entity.CraftPlayer"); + Class entityPlayer = Reflection.getClass("net.minecraft.server.level.ServerPlayer"); + Reflection.Method getPlayer = Reflection.getTypedMethod(craftPlayer, "getHandle", entityPlayer); BlockIdWrapper impl = VersionDependent.getVersionImpl(FightSystem.getPlugin()); diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightStatistics.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightStatistics.java index 1f46a3a8..ae9a56ac 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightStatistics.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightStatistics.java @@ -27,23 +27,25 @@ import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightPlayer; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.record.FileRecorder; +import de.steamwar.fightsystem.record.FileSource; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.OneShotStateDependent; import de.steamwar.fightsystem.winconditions.Wincondition; import de.steamwar.network.NetworkSender; import de.steamwar.network.packets.common.FightEndsPacket; -import de.steamwar.sql.Replay; import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SteamwarUser; import lombok.Getter; import org.bukkit.Bukkit; +import java.nio.file.Files; import java.sql.Timestamp; import java.time.Instant; import java.util.logging.Level; import java.util.stream.Collectors; import static de.steamwar.sql.Fight.create; +import static de.steamwar.sql.Fight.markReplayAvailable; public class FightStatistics { @@ -124,11 +126,9 @@ public class FightStatistics { Config.EventKampf.setFight(fightId); } - try { - Replay.save(fightId, FileRecorder.getFile()); - } catch (Exception e) { - Bukkit.getLogger().log(Level.INFO, "Failed to save replay", e); - } + Files.move(FileRecorder.getFile().toPath(), FileSource.replayFile(fightId).toPath()); + + markReplayAvailable(fightId); } catch (Exception e) { Bukkit.getLogger().log(Level.SEVERE, "Failed to save statistics", e); } diff --git a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java index c613a4ab..455b960d 100644 --- a/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java +++ b/FightSystem/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java @@ -19,7 +19,7 @@ package de.steamwar.fightsystem.utils; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; import de.steamwar.core.Core; import de.steamwar.entity.REntity; @@ -71,10 +71,10 @@ public class HullHider implements Listener { packetHiders.put(packetPlayOutWorldEvent, this::worldEventHider); packetHiders.put(packetPlayOutExplosion, this::explosionHider); - posHiderGenerator("{nms.network.protocol.game}.PacketPlayOutWorldParticles", Core.getVersion() >= 18 ? double.class : float.class, 1.0); - posHiderGenerator("{nms.network.protocol.game}.PacketPlayOutNamedSoundEffect", int.class, 8.0); + posHiderGenerator("net.minecraft.network.protocol.game.ClientboundLevelParticlesPacket", Core.getVersion() >= 18 ? double.class : float.class, 1.0); + posHiderGenerator("net.minecraft.network.protocol.game.ClientboundSoundPacket", int.class, 8.0); if(Core.getVersion() >= 9 && Core.getVersion() < 18) - posHiderGenerator("{nms.network.protocol.game}.PacketPlayOutCustomSoundEffect", int.class, 8.0); + posHiderGenerator("net.minecraft.network.protocol.game.PacketPlayOutCustomSoundEffect", int.class, 8.0); new StateDependentListener(TechHiderWrapper.ENABLED, FightState.Schem, this); new StateDependent(TechHiderWrapper.ENABLED, FightState.Schem) { @@ -198,16 +198,16 @@ public class HullHider implements Listener { } - private static final Class packetPlayOutWorldEvent = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutWorldEvent"); - private static final Reflection.FieldAccessor worldEventPosition = Reflection.getField(packetPlayOutWorldEvent, TechHider.blockPosition, 0); - public static final Reflection.FieldAccessor blockPositionY = Reflection.getField("{nms.core}.BaseBlockPosition", int.class, 1); + private static final Class packetPlayOutWorldEvent = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundLevelEventPacket"); + private static final Reflection.Field worldEventPosition = Reflection.getField(packetPlayOutWorldEvent, TechHider.blockPosition, 0); + public static final Reflection.Field blockPositionY = Reflection.getField("net.minecraft.core.Vec3i", int.class, 1); private Object worldEventHider(Player player, Object packet) { Object baseBlock = worldEventPosition.get(packet); return packetHider(player, packet, new Location(Config.world, TechHider.blockPositionX.get(baseBlock), blockPositionY.get(baseBlock), TechHider.blockPositionZ.get(baseBlock))); } - private static final Class packetPlayOutExplosion = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutExplosion"); - private static final Reflection.FieldAccessor explosionBlocks = Reflection.getField(packetPlayOutExplosion, List.class, 0); + private static final Class packetPlayOutExplosion = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundExplodePacket"); + private static final Reflection.Field explosionBlocks = Reflection.getField(packetPlayOutExplosion, List.class, 0); private static final Function explosionLocation = posPacketToLocation(packetPlayOutExplosion, double.class, 1.0); private Object explosionHider(Player player, Object packet) { if(explosionBlocks.get(packet).isEmpty()) @@ -223,9 +223,9 @@ public class HullHider implements Listener { } private static Function posPacketToLocation(Class type, Class posType, double factor) { - Reflection.FieldAccessor x = Reflection.getField(type, posType, 0); - Reflection.FieldAccessor y = Reflection.getField(type, posType, 1); - Reflection.FieldAccessor z = Reflection.getField(type, posType, 2); + Reflection.Field x = Reflection.getField(type, posType, 0); + Reflection.Field y = Reflection.getField(type, posType, 1); + Reflection.Field z = Reflection.getField(type, posType, 2); return packet -> new Location(Config.world, x.get(packet).doubleValue()/factor, y.get(packet).doubleValue()/factor, z.get(packet).doubleValue()/factor); } diff --git a/KotlinCore/build.gradle.kts b/KotlinCore/build.gradle.kts index 0c610074..c3bb85b5 100644 --- a/KotlinCore/build.gradle.kts +++ b/KotlinCore/build.gradle.kts @@ -1,7 +1,7 @@ /* * This file is a part of the SteamWar software. * - * Copyright (C) 2024 SteamWar.de-Serverteam + * Copyright (C) 2024 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 diff --git a/KotlinCore/src/de/steamwar/kotlin/KotlinInventory.kt b/KotlinCore/src/de/steamwar/kotlin/KotlinInventory.kt new file mode 100644 index 00000000..54798c49 --- /dev/null +++ b/KotlinCore/src/de/steamwar/kotlin/KotlinInventory.kt @@ -0,0 +1,42 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2025 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.kotlin + +import de.steamwar.inventory.SWInventory +import org.bukkit.entity.Player +import org.bukkit.event.inventory.InventoryClickEvent +import org.bukkit.inventory.ItemStack + +abstract class KotlinInventory(val player: Player) { + + private val inv: SWInventory by lazy { createInventory() } + + abstract fun createInventory(): SWInventory + + fun open() = inv.open() + + operator fun set(slot: Int, item: Pair Unit>) { + inv.setItemEvent(slot, item.first, item.second) + } + + operator fun set(slot: Int, item: ItemStack) { + inv.setItemEvent(slot, item) { } + } +} \ No newline at end of file diff --git a/KotlinCore/src/de/steamwar/kotlin/inventory/SWInventoryHolder.kt b/KotlinCore/src/de/steamwar/kotlin/inventory/SWInventoryHolder.kt deleted file mode 100644 index 3afb3183..00000000 --- a/KotlinCore/src/de/steamwar/kotlin/inventory/SWInventoryHolder.kt +++ /dev/null @@ -1,60 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2024 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.kotlin.inventory - -import org.bukkit.event.inventory.InventoryClickEvent -import org.bukkit.event.inventory.InventoryCloseEvent -import org.bukkit.inventory.Inventory -import org.bukkit.inventory.InventoryHolder -import org.bukkit.inventory.ItemStack - -abstract class SWInventoryHolder: InventoryHolder { - - val _inventory: Inventory by lazy { createInventory() } - - private val callbacks = mutableMapOf Unit>() - - override fun getInventory(): Inventory = _inventory - - abstract fun createInventory(): Inventory - - open fun handleInventoryClick(event: InventoryClickEvent) { - callbacks[event.slot]?.invoke(event) - } - - fun addItem(item: ItemStack, slot: Int, callback: (event: InventoryClickEvent) -> Unit) { - _inventory.setItem(slot, item) - addCallback(slot, callback) - } - - fun addCallback(slot: Int, callback: (event: InventoryClickEvent) -> Unit) { - callbacks[slot] = callback - } - - open fun handleClose(event: InventoryCloseEvent) { } - - operator fun set(slot: Int, item: Pair Unit>) { - addItem(item.first, slot, item.second) - } - - operator fun set(slot: Int, item: ItemStack) { - addItem(item, slot) { } - } -} \ No newline at end of file diff --git a/LobbySystem/src/de/steamwar/lobby/LobbySystem.properties b/LobbySystem/src/de/steamwar/lobby/LobbySystem.properties index 2d3aa782..3375de0a 100644 --- a/LobbySystem/src/de/steamwar/lobby/LobbySystem.properties +++ b/LobbySystem/src/de/steamwar/lobby/LobbySystem.properties @@ -10,6 +10,13 @@ NPC_CHAT_2 = §eSteam§8War§f was established in 2019. NPC_CHAT_3 = §fBecome a part of our team by applying via our Discord server (https://steamwar.de/discord). NPC_CHAT_4 = §fYou can develop your own buildserver features with our Lua script system. NPC_CHAT_5 = §fThere are many secrets to discover in this lobby. +## TheBreadBeard +NPC_CHAT_3266_0 = §fI collect alts like Infinity Stones. +NPC_CHAT_3266_1 = §fYou want my Bread? You can have it! Just look for it! I've hidden the best bakery in the world somewhere! +NPC_CHAT_3266_2 = §fHey, I am TheBreadBeard, ex- EuropSuchties player, formerly (un)known as WarGear_Titan. +NPC_CHAT_3266_3 = §fInventor of Lactose Intolerance, the Placeholder and Infinity-Ring. All technical principles no one knows or needs. +NPC_CHAT_3266_4 = §fKnown for the lobby-banners, logos, spontaneous arenas, as well as an organizer and moderator of many events. +NPC_CHAT_3266_5 = §fFrom supporter to moderator to builder ... Maybe the journey takes me to being a developer next. # Portal Command PORTAL_COMMAND_LIST_HELP = §8/§7portal §elist §8- §7Lists all portals diff --git a/LobbySystem/src/de/steamwar/lobby/LobbySystem_de.properties b/LobbySystem/src/de/steamwar/lobby/LobbySystem_de.properties index 73808174..9823f57c 100644 --- a/LobbySystem/src/de/steamwar/lobby/LobbySystem_de.properties +++ b/LobbySystem/src/de/steamwar/lobby/LobbySystem_de.properties @@ -10,6 +10,13 @@ NPC_CHAT_2 = §eSteam§8War§f gibt es seit 2019. NPC_CHAT_3 = §fBewerbe dich gerne für unser Team über unseren Discord-Server (https://steamwar.de/discord). NPC_CHAT_4 = §fDu kannst mit unserm Lua Script-System deine eigenen Bau Features programmieren. NPC_CHAT_5 = §fAuf dieser Lobby sind so einige secrets versteckt. +## TheBreadBeard +NPC_CHAT_3266_0 = §fIch sammel Alts wie Infinity Stones. +NPC_CHAT_3266_1 = §fIhr wollt meine Teigwaren? Die könnt ihr haben! Sucht sie doch! Irgendwo hab ich die beste Bäckerei der Welt versteckt! +NPC_CHAT_3266_2 = §fMoin, Ich bin TheBreadBeard, ehemaliger EuropSuchties Spieler, damals (un)bekannt als WarGear_Titan. +NPC_CHAT_3266_3 = §fErfinder der Laktoseintoleranz, des Platzhalters und des Infinity-Rings. Alles Prinzipien, die keiner kennt und keiner braucht. +NPC_CHAT_3266_4 = §fBekannt für die Lobbybanner, Logos, spontane Arenen, sowie als Leiter von so manchem Event. +NPC_CHAT_3266_5 = §fVon Supporter zu Moderator zu Builder ... Vielleicht führt mich die Reise als Nächstes zum Developer. # Portal Command PORTAL_COMMAND_LIST_HELP = §8/§7portal §elist §8- §7Listet alle Portale auf diff --git a/LobbySystem/src/de/steamwar/lobby/team/TeamPlayer.java b/LobbySystem/src/de/steamwar/lobby/team/TeamPlayer.java index 2829ec2f..989fca7a 100644 --- a/LobbySystem/src/de/steamwar/lobby/team/TeamPlayer.java +++ b/LobbySystem/src/de/steamwar/lobby/team/TeamPlayer.java @@ -23,7 +23,6 @@ import de.steamwar.lobby.LobbySystem; import de.steamwar.lobby.display.NPC; import de.steamwar.lobby.listener.BasicListener; import de.steamwar.sql.SteamwarUser; -import de.steamwar.sql.UserPerm; import lombok.AllArgsConstructor; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -135,6 +134,10 @@ public class TeamPlayer extends BasicListener { return false; } + private String parseRandomMessage(Player player, SteamwarUser target, String message) throws MissingResourceException { + return LobbySystem.getMessage().parsePrefixed(message + random.nextInt(6), player, target.getUserName(), target.prefix().getColorCode() + target.prefix().getChatPrefix()); + } + @EventHandler public void onPlayerInteractEntity(PlayerInteractEntityEvent event) { if (!(event.getRightClicked() instanceof Villager)) { @@ -145,10 +148,14 @@ public class TeamPlayer extends BasicListener { return; } - String message = "NPC_CHAT_" + random.nextInt(6); - SteamwarUser user = SteamwarUser.get(event.getRightClicked().getName()); - UserPerm.Prefix prefix = user.prefix(); - LobbySystem.getMessage().send(message, event.getPlayer(), event.getRightClicked().getName(), prefix.getColorCode() + prefix.getChatPrefix()); + SteamwarUser target = SteamwarUser.get(event.getRightClicked().getName()); + String message; + try { + message = parseRandomMessage(event.getPlayer(), target, "NPC_CHAT_" + target.getId() + "_"); + } catch (MissingResourceException e) { + message = parseRandomMessage(event.getPlayer(), target, "NPC_CHAT_"); + } + event.getPlayer().sendMessage(message); } @EventHandler diff --git a/MissileWars/src/de/steamwar/misslewars/slowmo/SlowMoUtils.java b/MissileWars/src/de/steamwar/misslewars/slowmo/SlowMoUtils.java index dbde1f0f..01e55c37 100644 --- a/MissileWars/src/de/steamwar/misslewars/slowmo/SlowMoUtils.java +++ b/MissileWars/src/de/steamwar/misslewars/slowmo/SlowMoUtils.java @@ -21,7 +21,7 @@ package de.steamwar.misslewars.slowmo; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import org.bukkit.Bukkit; import org.bukkit.World; @@ -32,7 +32,7 @@ public class SlowMoUtils { private static final Field field; public static final boolean freezeEnabled; - private static final Reflection.MethodInvoker getWorldHandle = Reflection.getTypedMethod(Reflection.getClass("{obc}.CraftWorld"), "getHandle", null); + private static final Reflection.Method getWorldHandle = Reflection.getTypedMethod(Reflection.getClass("org.bukkit.craftbukkit.CraftWorld"), "getHandle", null); private static boolean frozen = false; private static final World world; @@ -40,7 +40,7 @@ public class SlowMoUtils { static { Field temp; try { - temp = Reflection.getClass("{nms.server.level}.WorldServer").getField("freezed"); + temp = Reflection.getClass("net.minecraft.server.level.ServerLevel").getField("freezed"); } catch (NoSuchFieldException e) { temp = null; } diff --git a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommandUtils.java b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommandUtils.java index 2b953b74..f92c7224 100644 --- a/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommandUtils.java +++ b/SchematicSystem/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/schematiccommand/SchematicCommandUtils.java @@ -245,7 +245,7 @@ public class SchematicCommandUtils { SchematicSystem.MESSAGE.sendPrefixless("UTIL_INFO_ELO", player, node.getElo(Season.getSeason())); } - SchematicSystem.MESSAGE.sendPrefixless("UTIL_INFO_FORMAT", player, node.getSchemFormat() ? ".schem" : ".schematic"); + SchematicSystem.MESSAGE.sendPrefixless("UTIL_INFO_FORMAT", player, node.getFileEnding()); CheckedSchematic.getLastDeclinedOfNode(node.getId()).stream().findFirst().ifPresent(checkedSchematic -> SchematicSystem.MESSAGE.sendPrefixless("UTIL_INFO_STATUS", player, checkedSchematic.getEndTime(), checkedSchematic.getDeclineReason())); } else { SchematicSystem.MESSAGE.sendPrefixless("UTIL_INFO_TYPE", player, SchematicSystem.MESSAGE.parse("UTIL_INFO_TYPE_DIR", player)); @@ -470,6 +470,9 @@ public class SchematicCommandUtils { } else if (extend == SchematicCommand.Extend.AUSFAHREN) { NetworkSender.send(new PrepareSchemPacket(SteamwarUser.get(player.getUniqueId()).getId(), node.getId(), type.toDB())); SchematicSystem.MESSAGE.send("UTIL_TYPE_EXTEND", player); + } else { + node.setSchemtype(type.checkType()); + SchematicSystem.MESSAGE.send("UTIL_SUBMIT_DIRECT_DONE", player); } } } diff --git a/SchematicSystem/build.gradle.kts b/SchematicSystem/build.gradle.kts index 2c9ef365..f9871adc 100644 --- a/SchematicSystem/build.gradle.kts +++ b/SchematicSystem/build.gradle.kts @@ -1,7 +1,7 @@ /* * This file is a part of the SteamWar software. * - * Copyright (C) 2024 SteamWar.de-Serverteam + * Copyright (C) 2024 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 diff --git a/SpigotCore/SpigotCore_14/src/de/steamwar/core/FlatteningWrapper14.java b/SpigotCore/SpigotCore_14/src/de/steamwar/core/FlatteningWrapper14.java index b7a9bf7f..2033fc09 100644 --- a/SpigotCore/SpigotCore_14/src/de/steamwar/core/FlatteningWrapper14.java +++ b/SpigotCore/SpigotCore_14/src/de/steamwar/core/FlatteningWrapper14.java @@ -19,7 +19,7 @@ package de.steamwar.core; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.NamespacedKey; @@ -226,14 +226,14 @@ public class FlatteningWrapper14 implements FlatteningWrapper.IFlatteningWrapper renamedLegacy.put("RECORD_12", Material.MUSIC_DISC_WAIT); } - private static final Reflection.FieldAccessor scoreboardName = Reflection.getField(FlatteningWrapper.scoreboardObjective, Reflection.getClass("{nms.network.chat}.IChatBaseComponent"), 0); + private static final Reflection.Field scoreboardName = Reflection.getField(FlatteningWrapper.scoreboardObjective, Reflection.getClass("net.minecraft.network.chat.Component"), 0); @Override public void setScoreboardTitle(Object packet, String title) { scoreboardName.set(packet, ChatWrapper.impl.stringToChatComponent(title)); } - private static final Class scoreActionEnum = Core.getVersion() < 21 ? Reflection.getClass("{nms.server}.ScoreboardServer$Action") : null; - private static final Reflection.FieldAccessor scoreAction = Core.getVersion() < 21 ? Reflection.getField(FlatteningWrapper.scoreboardScore, scoreActionEnum, 0) : null; + private static final Class scoreActionEnum = Core.getVersion() < 21 ? Reflection.getClass("net.minecraft.server.ServerScoreboard$Method") : null; + private static final Reflection.Field scoreAction = Core.getVersion() < 21 ? Reflection.getField(FlatteningWrapper.scoreboardScore, scoreActionEnum, 0) : null; private static final Object scoreActionChange = Core.getVersion() < 21 ? scoreActionEnum.getEnumConstants()[0] : null; @Override @@ -300,7 +300,7 @@ public class FlatteningWrapper14 implements FlatteningWrapper.IFlatteningWrapper return head; } - private static final Class entityPose = Reflection.getClass("{nms.world.entity}.EntityPose"); + private static final Class entityPose = Reflection.getClass("net.minecraft.world.entity.Pose"); private static final Object standing = entityPose.getEnumConstants()[0]; private static final Object swimming = entityPose.getEnumConstants()[3]; private static final Object sneaking = entityPose.getEnumConstants()[5]; @@ -327,13 +327,13 @@ public class FlatteningWrapper14 implements FlatteningWrapper.IFlatteningWrapper return displayName != null ? Optional.of(ChatWrapper.impl.stringToChatComponent(displayName)) : Optional.empty(); } - 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(Core.getVersion() > 18 ? "net.minecraft.core.registries.BuiltInRegistries" : "{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() > 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 Class registryBlocks = Reflection.getClass("net.minecraft.core.DefaultedRegistry"); + private static final Class entityTypes = Reflection.getClass("net.minecraft.world.entity.EntityType"); + private static final Object entityTypesRegistry = Reflection.getField(Reflection.getClass(Core.getVersion() > 18 ? "net.minecraft.core.registries.BuiltInRegistries" : "net.minecraft.core.IRegistry"), registryBlocks, 0, entityTypes).get(null); + private static final Reflection.Method get = Reflection.getMethod(registryBlocks, null, Reflection.getClass("net.minecraft.resources.ResourceLocation")); + private static final Reflection.Field spawnType = Reflection.getField(ProtocolWrapper.spawnPacket, entityTypes, 0); + private static final Reflection.Field spawnLivingType = Core.getVersion() > 18 ? spawnType : Reflection.getField(ProtocolWrapper.spawnLivingPacket, int.class, 1); + private static final Reflection.Method toMinecraft = Reflection.getMethod("org.bukkit.craftbukkit.util.CraftNamespacedKey", "toMinecraft", NamespacedKey.class); private static final Map types = new HashMap<>(); static { types.put(EntityType.ARMOR_STAND, 1); @@ -352,8 +352,8 @@ public class FlatteningWrapper14 implements FlatteningWrapper.IFlatteningWrapper return player.getClientViewDistance(); } - private static final Reflection.MethodInvoker getHandle = Reflection.getMethod("{obc}.CraftWorld", "getHandle"); - private static final Reflection.MethodInvoker save = Reflection.getMethod("{nms.server.level}.WorldServer", null, Reflection.getClass("{nms.util}.IProgressUpdate"), boolean.class, boolean.class); + private static final Reflection.Method getHandle = Reflection.getMethod("org.bukkit.craftbukkit.CraftWorld", "getHandle"); + private static final Reflection.Method save = Reflection.getMethod("net.minecraft.server.level.ServerLevel", null, Reflection.getClass("net.minecraft.util.ProgressListener"), boolean.class, boolean.class); @Override public void syncSave(World world) { save.invoke(getHandle.invoke(world), null, true, false); diff --git a/SpigotCore/SpigotCore_14/src/de/steamwar/core/WorldEditWrapper14.java b/SpigotCore/SpigotCore_14/src/de/steamwar/core/WorldEditWrapper14.java index cd116bac..3251e5bc 100644 --- a/SpigotCore/SpigotCore_14/src/de/steamwar/core/WorldEditWrapper14.java +++ b/SpigotCore/SpigotCore_14/src/de/steamwar/core/WorldEditWrapper14.java @@ -22,7 +22,6 @@ package de.steamwar.core; import com.google.common.collect.ImmutableList; import com.google.common.collect.Maps; import com.sk89q.jnbt.*; -import com.sk89q.worldedit.EmptyClipboardException; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.extension.input.InputParseException; @@ -45,36 +44,30 @@ import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.registry.LegacyMapper; import de.steamwar.sql.NoClipboardException; +import de.steamwar.sql.NodeData; import org.bukkit.entity.Player; import org.bukkit.util.Vector; import java.io.*; import java.util.*; -import java.util.logging.Level; import java.util.stream.Collectors; import static com.google.common.base.Preconditions.checkNotNull; +@SuppressWarnings("removal") public class WorldEditWrapper14 implements WorldEditWrapper { - private static final ClipboardFormat SCHEMATIC = BuiltInClipboardFormat.MCEDIT_SCHEMATIC; - private static final ClipboardFormat SCHEM = BuiltInClipboardFormat.SPONGE_SCHEMATIC; - @Override - public InputStream getPlayerClipboard(Player player, boolean schemFormat) { - return WorldEditWrapper.getPlayerClipboard(player, schemFormat, (outputStream, clipboard, clipboardHolder) -> { - if(schemFormat){ - ClipboardWriter writer = SCHEM.getWriter(outputStream); - writer.write(clipboard); - writer.close(); - }else{ - SCHEMATIC.getWriter(outputStream).write(clipboard); - } + public InputStream getPlayerClipboard(Player player) { + return WorldEditWrapper.getPlayerClipboard(player, (outputStream, clipboard, clipboardHolder) -> { + ClipboardWriter writer = BuiltInClipboardFormat.SPONGE_SCHEMATIC.getWriter(outputStream); + writer.write(clipboard); + writer.close(); }); } @Override - public void setPlayerClipboard(Player player, InputStream is, boolean schemFormat) { + public void setPlayerClipboard(Player player, InputStream is, NodeData.SchematicFormat schemFormat) { Clipboard clipboard = null; try { clipboard = getClipboard(is, schemFormat); @@ -90,12 +83,17 @@ public class WorldEditWrapper14 implements WorldEditWrapper { } @Override - public Clipboard getClipboard(InputStream is, boolean schemFormat) throws IOException { + public Clipboard getClipboard(InputStream is, NodeData.SchematicFormat schemFormat) throws IOException { try { - if(schemFormat){ - return new SpongeSchematicReader(new NBTInputStream(is)).read(); - }else{ - return new MCEditSchematicReader(new NBTInputStream(is)).read(); + + switch (schemFormat) { + case SPONGE_V2: + case SPONGE_V3: + return new SpongeSchematicReader(new NBTInputStream(is), this).read(); + case MCEDIT: + return new MCEditSchematicReader(new NBTInputStream(is)).read(); + default: + throw new IOException("This schematic format is currently not supported"); } } catch (NullPointerException e) { throw new NoClipboardException(); @@ -124,6 +122,15 @@ public class WorldEditWrapper14 implements WorldEditWrapper { return new org.bukkit.util.Vector(v.getX(), v.getY(), v.getZ()); } + @Override + public NodeData.SchematicFormat getNativeFormat() { + return NodeData.SchematicFormat.SPONGE_V2; + } + + public Map applyDataFixer(DataFixer fixer, int dataVersion, Map values) { + return fixer.fixUp(DataFixer.FixTypes.BLOCK_ENTITY, new CompoundTag(values), dataVersion).getValue(); + } + private static class MCEditSchematicReader extends NBTSchematicReader { private final NBTInputStream inputStream; @@ -387,22 +394,24 @@ public class WorldEditWrapper14 implements WorldEditWrapper { inputStream.close(); } } - private static class SpongeSchematicReader extends NBTSchematicReader { + public static class SpongeSchematicReader extends NBTSchematicReader { private final NBTInputStream inputStream; private DataFixer fixer = null; private int schematicVersion = -1; private int dataVersion = -1; private boolean faweSchem = false; + private final WorldEditWrapper14 wrapper; /** * Create a new instance. * * @param inputStream the input stream to read from */ - public SpongeSchematicReader(NBTInputStream inputStream) { + public SpongeSchematicReader(NBTInputStream inputStream, WorldEditWrapper14 wrapper) { checkNotNull(inputStream); this.inputStream = inputStream; + this.wrapper = wrapper; } @Override @@ -418,7 +427,7 @@ public class WorldEditWrapper14 implements WorldEditWrapper { dataVersion = 1631; // this is a relatively safe assumption unless someone imports a schematic from 1.12, e.g. sponge 7.1- fixer = platform.getDataFixer(); return readVersion1(schematicTag); - } else if (schematicVersion == 2) { + } else if (schematicVersion == 2 || schematicVersion == 3) { dataVersion = requireTag(schematic, "DataVersion", IntTag.class).getValue(); if (dataVersion < liveDataVersion) { fixer = platform.getDataFixer(); @@ -447,14 +456,18 @@ public class WorldEditWrapper14 implements WorldEditWrapper { private CompoundTag getBaseTag() throws IOException { NamedTag rootTag = inputStream.readNamedTag(); - if (!rootTag.getName().equals("Schematic")) { - throw new IOException("Tag 'Schematic' does not exist or is not first"); - } CompoundTag schematicTag = (CompoundTag) rootTag.getTag(); // Check Map schematic = schematicTag.getValue(); + if (schematic.size() == 1) { + schematicTag = requireTag(schematic, "Schematic", CompoundTag.class); + schematic = schematicTag.getValue(); + } else if (!rootTag.getName().equals("Schematic")) { + throw new IOException("Tag 'Schematic' does not exist or is not first"); + } + schematicVersion = requireTag(schematic, "Version", IntTag.class).getValue(); return schematicTag; } @@ -499,12 +512,16 @@ public class WorldEditWrapper14 implements WorldEditWrapper { region = new CuboidRegion(origin, origin.add(width, height, length).subtract(BlockVector3.ONE)); } - IntTag paletteMaxTag = getTag(schematic, "PaletteMax", IntTag.class); - Map paletteObject = requireTag(schematic, "Palette", CompoundTag.class).getValue(); - if (paletteMaxTag != null && paletteObject.size() != paletteMaxTag.getValue()) { - throw new IOException("Block palette size does not match expected size."); + Map blockContainer = null; + boolean v3Mode = false; + + if (schematicVersion == 3) { + blockContainer = requireTag(schematic, "Blocks", CompoundTag.class).getValue(); + v3Mode = true; } + Map paletteObject = requireTag(v3Mode ? blockContainer: schematic, "Palette", CompoundTag.class).getValue(); + Map palette = new HashMap<>(); ParserContext parserContext = new ParserContext(); @@ -526,12 +543,12 @@ public class WorldEditWrapper14 implements WorldEditWrapper { palette.put(id, state); } - byte[] blocks = requireTag(schematic, "BlockData", ByteArrayTag.class).getValue(); + byte[] blocks = requireTag(v3Mode ? blockContainer: schematic, v3Mode ? "Data" : "BlockData", ByteArrayTag.class).getValue(); Map> tileEntitiesMap = new HashMap<>(); - ListTag tileEntities = getTag(schematic, "BlockEntities", ListTag.class); + ListTag tileEntities = getTag(v3Mode ? blockContainer: schematic, "BlockEntities", ListTag.class); if (tileEntities == null) { - tileEntities = getTag(schematic, "TileEntities", ListTag.class); + tileEntities = getTag(v3Mode ? blockContainer: schematic, "TileEntities", ListTag.class); } if (tileEntities != null) { List> tileEntityTags = tileEntities.getValue().stream() @@ -562,7 +579,7 @@ public class WorldEditWrapper14 implements WorldEditWrapper { values.remove("Id"); values.remove("Pos"); if (fixer != null) { - tileEntity = fixer.fixUp(DataFixer.FixTypes.BLOCK_ENTITY, new CompoundTag(values), dataVersion).getValue(); + tileEntity = wrapper.applyDataFixer(fixer, dataVersion, values); } else { tileEntity = values; } diff --git a/SpigotCore/SpigotCore_14/src/de/steamwar/techhider/BlockIds14.java b/SpigotCore/SpigotCore_14/src/de/steamwar/techhider/BlockIds14.java index 322ce206..ebf5e952 100644 --- a/SpigotCore/SpigotCore_14/src/de/steamwar/techhider/BlockIds14.java +++ b/SpigotCore/SpigotCore_14/src/de/steamwar/techhider/BlockIds14.java @@ -19,7 +19,7 @@ package de.steamwar.techhider; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import com.google.common.collect.ImmutableList; import org.bukkit.Material; @@ -28,21 +28,21 @@ import java.util.Set; public class BlockIds14 implements BlockIds { - private static final Class blockStateList = Reflection.getClass("{nms.world.level.block.state}.BlockStateList"); - private static final Class fluidTypeFlowing = Reflection.getClass("{nms.world.level.material}.FluidTypeFlowing"); - private static final Class fluid = Reflection.getClass("{nms.world.level.material}.Fluid"); + private static final Class blockStateList = Reflection.getClass("net.minecraft.world.level.block.state.StateDefinition"); + private static final Class fluidTypeFlowing = Reflection.getClass("net.minecraft.world.level.material.FlowingFluid"); + private static final Class fluid = Reflection.getClass("net.minecraft.world.level.material.FluidState"); - private static final Reflection.MethodInvoker getBlockData = Reflection.getTypedMethod(TechHider.block, null, TechHider.iBlockData); + private static final Reflection.Method getBlockData = Reflection.getTypedMethod(TechHider.block, null, TechHider.iBlockData); @Override public int materialToId(Material material) { return getCombinedId(getBlockData.invoke(getBlock(material))); } - private static final Reflection.MethodInvoker getStates = Reflection.getTypedMethod(TechHider.block, null, blockStateList); - private static final Reflection.MethodInvoker getStateList = Reflection.getTypedMethod(blockStateList, null, ImmutableList.class); - private static final Object water = Reflection.getTypedMethod(fluidTypeFlowing, null, fluid, boolean.class).invoke(Reflection.getField(Reflection.getClass("{nms.world.level.material}.FluidTypes"), fluidTypeFlowing, 1).get(null), false); - private static final Iterable registryBlockId = (Iterable) Reflection.getField(TechHider.block, Reflection.getClass("{nms.core}.RegistryBlockID"), 0).get(null); - private static final Reflection.MethodInvoker getFluid = Reflection.getTypedMethod(TechHider.iBlockData, null, fluid); + private static final Reflection.Method getStates = Reflection.getTypedMethod(TechHider.block, null, blockStateList); + private static final Reflection.Method getStateList = Reflection.getTypedMethod(blockStateList, null, ImmutableList.class); + private static final Object water = Reflection.getTypedMethod(fluidTypeFlowing, null, fluid, boolean.class).invoke(Reflection.getField(Reflection.getClass("net.minecraft.world.level.material.Fluids"), fluidTypeFlowing, 1).get(null), false); + private static final Iterable registryBlockId = (Iterable) Reflection.getField(TechHider.block, Reflection.getClass("net.minecraft.core.IdMapper"), 0).get(null); + private static final Reflection.Method getFluid = Reflection.getTypedMethod(TechHider.iBlockData, null, fluid); @Override public Set materialToAllIds(Material material) { Set ids = new HashSet<>(); @@ -61,12 +61,12 @@ public class BlockIds14 implements BlockIds { return ids; } - private static final Reflection.MethodInvoker getBlock = Reflection.getTypedMethod(TechHider.craftMagicNumbers, "getBlock", TechHider.block, Material.class); + private static final Reflection.Method getBlock = Reflection.getTypedMethod(TechHider.craftMagicNumbers, "getBlock", TechHider.block, Material.class); private Object getBlock(Material material) { return getBlock.invoke(null, material); } - private static final Reflection.MethodInvoker getCombinedId = Reflection.getTypedMethod(TechHider.block, null, int.class, TechHider.iBlockData); + private static final Reflection.Method getCombinedId = Reflection.getTypedMethod(TechHider.block, null, int.class, TechHider.iBlockData); private int getCombinedId(Object blockData) { return (int) getCombinedId.invoke(null, blockData); } diff --git a/SpigotCore/SpigotCore_14/src/de/steamwar/techhider/ProtocolWrapper14.java b/SpigotCore/SpigotCore_14/src/de/steamwar/techhider/ProtocolWrapper14.java index ea98d273..7c658dbd 100644 --- a/SpigotCore/SpigotCore_14/src/de/steamwar/techhider/ProtocolWrapper14.java +++ b/SpigotCore/SpigotCore_14/src/de/steamwar/techhider/ProtocolWrapper14.java @@ -19,7 +19,7 @@ package de.steamwar.techhider; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import org.bukkit.entity.Player; import java.util.function.BiFunction; @@ -30,8 +30,8 @@ public class ProtocolWrapper14 extends ProtocolWrapper8 { @Override public BiFunction blockBreakHiderGenerator(Class blockBreakPacket, TechHider techHider) { UnaryOperator blockBreakCloner = ProtocolUtils.shallowCloneGenerator(blockBreakPacket); - Reflection.FieldAccessor blockBreakPosition = Reflection.getField(blockBreakPacket, TechHider.blockPosition, 0); - Reflection.FieldAccessor blockBreakBlockData = Reflection.getField(blockBreakPacket, TechHider.iBlockData, 0); + Reflection.Field blockBreakPosition = Reflection.getField(blockBreakPacket, TechHider.blockPosition, 0); + Reflection.Field blockBreakBlockData = Reflection.getField(blockBreakPacket, TechHider.iBlockData, 0); return (p, packet) -> { switch (techHider.getLocationEvaluator().checkBlockPos(p, blockBreakPosition.get(packet))) { diff --git a/SpigotCore/SpigotCore_18/src/de/steamwar/core/CraftbukkitWrapper18.java b/SpigotCore/SpigotCore_18/src/de/steamwar/core/CraftbukkitWrapper18.java index 1627791c..6cfaade4 100644 --- a/SpigotCore/SpigotCore_18/src/de/steamwar/core/CraftbukkitWrapper18.java +++ b/SpigotCore/SpigotCore_18/src/de/steamwar/core/CraftbukkitWrapper18.java @@ -19,7 +19,7 @@ package de.steamwar.core; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket; import net.minecraft.world.level.World; @@ -29,8 +29,8 @@ import org.bukkit.entity.Player; public class CraftbukkitWrapper18 implements CraftbukkitWrapper.ICraftbukkitWrapper { - private static final Reflection.MethodInvoker getHandle = Reflection.getMethod("{obc}.CraftChunk", "getHandle"); - private static final Reflection.MethodInvoker getLightEngine = Reflection.getTypedMethod(World.class, null, LightEngine.class); + private static final Reflection.Method getHandle = Reflection.getMethod("org.bukkit.craftbukkit.CraftChunk", "getHandle"); + private static final Reflection.Method getLightEngine = Reflection.getTypedMethod(World.class, null, LightEngine.class); @Override public void sendChunk(Player p, int chunkX, int chunkZ) { diff --git a/SpigotCore/SpigotCore_18/src/de/steamwar/core/ProtocolWrapper18.java b/SpigotCore/SpigotCore_18/src/de/steamwar/core/ProtocolWrapper18.java index 54cc3030..e5cdf160 100644 --- a/SpigotCore/SpigotCore_18/src/de/steamwar/core/ProtocolWrapper18.java +++ b/SpigotCore/SpigotCore_18/src/de/steamwar/core/ProtocolWrapper18.java @@ -19,7 +19,7 @@ package de.steamwar.core; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import com.mojang.authlib.GameProfile; import com.mojang.datafixers.util.Pair; import org.bukkit.GameMode; @@ -30,16 +30,16 @@ import java.util.List; public class ProtocolWrapper18 implements ProtocolWrapper { - private static final Reflection.FieldAccessor equipmentStack = Reflection.getField(equipmentPacket, List.class, 0); + private static final Reflection.Field equipmentStack = Reflection.getField(equipmentPacket, List.class, 0); @Override public void setEquipmentPacketStack(Object packet, Object slot, Object stack) { equipmentStack.set(packet, Collections.singletonList(new Pair<>(slot, stack))); } - private static final Class playerInfoPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutPlayerInfo"); - private static final Class playerInfoActionClass = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutPlayerInfo$EnumPlayerInfoAction"); - private static final Reflection.FieldAccessor playerInfoAction = Reflection.getField(playerInfoPacket, playerInfoActionClass, 0); - private static final Reflection.FieldAccessor playerInfoData = Reflection.getField(playerInfoPacket, List.class, 0); + private static final Class playerInfoPacket = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutPlayerInfo"); + private static final Class playerInfoActionClass = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutPlayerInfo$EnumPlayerInfoAction"); + private static final Reflection.Field playerInfoAction = Reflection.getField(playerInfoPacket, playerInfoActionClass, 0); + private static final Reflection.Field playerInfoData = Reflection.getField(playerInfoPacket, List.class, 0); private static final EnumMap actions = new EnumMap<>(PlayerInfoAction.class); static { Object[] nativeActions = playerInfoActionClass.getEnumConstants(); @@ -47,8 +47,8 @@ public class ProtocolWrapper18 implements ProtocolWrapper { actions.put(PlayerInfoAction.GAMEMODE, nativeActions[1]); actions.put(PlayerInfoAction.REMOVE, nativeActions[4]); } - private static final Class iChatBaseComponent = Reflection.getClass("{nms.network.chat}.IChatBaseComponent"); - private static final Reflection.ConstructorInvoker playerInfoDataConstructor = Reflection.getConstructor("{nms.network.protocol.game}.PacketPlayOutPlayerInfo$PlayerInfoData", GameProfile.class, int.class, enumGamemode, iChatBaseComponent); + private static final Class iChatBaseComponent = Reflection.getClass("net.minecraft.network.chat.Component"); + private static final Reflection.Constructor playerInfoDataConstructor = Reflection.getConstructor("net.minecraft.network.protocol.game.PacketPlayOutPlayerInfo$PlayerInfoData", GameProfile.class, int.class, enumGamemode, iChatBaseComponent); @Override @SuppressWarnings("deprecation") diff --git a/SpigotCore/SpigotCore_18/src/de/steamwar/core/WorldEditWrapper18.java b/SpigotCore/SpigotCore_18/src/de/steamwar/core/WorldEditWrapper18.java index 903113c4..1c216a1a 100644 --- a/SpigotCore/SpigotCore_18/src/de/steamwar/core/WorldEditWrapper18.java +++ b/SpigotCore/SpigotCore_18/src/de/steamwar/core/WorldEditWrapper18.java @@ -19,25 +19,18 @@ package de.steamwar.core; -import com.sk89q.jnbt.NBTInputStream; -import com.sk89q.worldedit.extent.clipboard.Clipboard; -import com.sk89q.worldedit.extent.clipboard.io.*; -import de.steamwar.sql.NoClipboardException; +import com.sk89q.jnbt.AdventureNBTConverter; +import com.sk89q.jnbt.CompoundTag; +import com.sk89q.jnbt.Tag; +import com.sk89q.worldedit.world.DataFixer; -import java.io.IOException; -import java.io.InputStream; +import java.util.Map; public class WorldEditWrapper18 extends WorldEditWrapper14 { @Override @SuppressWarnings("removal") - public Clipboard getClipboard(InputStream is, boolean schemFormat) throws IOException { - NBTInputStream nbtStream = new NBTInputStream(is); - //Use FAWE reader due to FAWE capability of reading corrupt FAWE schems - try { - return (schemFormat ? new SpongeSchematicReader(nbtStream) : new MCEditSchematicReader(nbtStream)).read(); - } catch (NullPointerException e) { - throw new NoClipboardException(); - } + public Map applyDataFixer(DataFixer fixer, int dataVersion, Map values) { + return ((CompoundTag) AdventureNBTConverter.fromAdventure(fixer.fixUp(DataFixer.FixTypes.BLOCK_ENTITY, new CompoundTag(values).asBinaryTag(), dataVersion))).getValue(); } } diff --git a/SpigotCore/SpigotCore_18/src/de/steamwar/techhider/ChunkHider18.java b/SpigotCore/SpigotCore_18/src/de/steamwar/techhider/ChunkHider18.java index 16cecb9b..ace24a54 100644 --- a/SpigotCore/SpigotCore_18/src/de/steamwar/techhider/ChunkHider18.java +++ b/SpigotCore/SpigotCore_18/src/de/steamwar/techhider/ChunkHider18.java @@ -19,7 +19,7 @@ package de.steamwar.techhider; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import de.steamwar.core.Core; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; @@ -46,12 +46,12 @@ public class ChunkHider18 implements ChunkHider { private static final UnaryOperator chunkPacketCloner = ProtocolUtils.shallowCloneGenerator(ClientboundLevelChunkWithLightPacket.class); private static final UnaryOperator chunkDataCloner = ProtocolUtils.shallowCloneGenerator(ClientboundLevelChunkPacketData.class); - private static final Reflection.FieldAccessor chunkXField = Reflection.getField(ClientboundLevelChunkWithLightPacket.class, int.class, 0); - private static final Reflection.FieldAccessor chunkZField = Reflection.getField(ClientboundLevelChunkWithLightPacket.class, int.class, 1); - private static final Reflection.FieldAccessor chunkData = Reflection.getField(ClientboundLevelChunkWithLightPacket.class, ClientboundLevelChunkPacketData.class, 0); + private static final Reflection.Field chunkXField = Reflection.getField(ClientboundLevelChunkWithLightPacket.class, int.class, 0); + private static final Reflection.Field chunkZField = Reflection.getField(ClientboundLevelChunkWithLightPacket.class, int.class, 1); + private static final Reflection.Field chunkData = Reflection.getField(ClientboundLevelChunkWithLightPacket.class, ClientboundLevelChunkPacketData.class, 0); - private static final Reflection.FieldAccessor dataField = Reflection.getField(ClientboundLevelChunkPacketData.class, byte[].class, 0); - private static final Reflection.FieldAccessor tileEntities = Reflection.getField(ClientboundLevelChunkPacketData.class, List.class, 0); + private static final Reflection.Field dataField = Reflection.getField(ClientboundLevelChunkPacketData.class, byte[].class, 0); + private static final Reflection.Field tileEntities = Reflection.getField(ClientboundLevelChunkPacketData.class, List.class, 0); @Override public BiFunction chunkHiderGenerator(TechHider techHider) { @@ -87,11 +87,11 @@ public class ChunkHider18 implements ChunkHider { }; } - public static final Class tileEntity = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundLevelChunkPacketData$a"); - protected static final Reflection.FieldAccessor entityType = Reflection.getField(tileEntity, TileEntityTypes.class, 0); + public static final Class tileEntity = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundLevelChunkPacketData$BlockEntityInfo"); + protected static final Reflection.Field entityType = Reflection.getField(tileEntity, TileEntityTypes.class, 0); private static final IRegistry tileEntityTypes = Reflection.getField(Core.getVersion() > 18 ? Reflection.getClass("net.minecraft.core.registries.BuiltInRegistries") : IRegistry.class, IRegistry.class, 0, TileEntityTypes.class).get(null); - private static final Reflection.MethodInvoker getKey = Reflection.getTypedMethod(IRegistry.class, null, MinecraftKey.class, Object.class); - private static final Reflection.MethodInvoker getName = Reflection.getTypedMethod(MinecraftKey.class, null, String.class); + private static final Reflection.Method getKey = Reflection.getTypedMethod(IRegistry.class, null, MinecraftKey.class, Object.class); + private static final Reflection.Method getName = Reflection.getTypedMethod(MinecraftKey.class, null, String.class); protected boolean tileEntityVisible(Set hiddenBlockEntities, Object tile) { return !hiddenBlockEntities.contains((String) getName.invoke(getKey.invoke(tileEntityTypes, entityType.get(tile)))); } diff --git a/SpigotCore/SpigotCore_18/src/de/steamwar/techhider/ProtocolWrapper18.java b/SpigotCore/SpigotCore_18/src/de/steamwar/techhider/ProtocolWrapper18.java index 9fef09fd..1553806a 100644 --- a/SpigotCore/SpigotCore_18/src/de/steamwar/techhider/ProtocolWrapper18.java +++ b/SpigotCore/SpigotCore_18/src/de/steamwar/techhider/ProtocolWrapper18.java @@ -19,7 +19,7 @@ package de.steamwar.techhider; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import net.minecraft.core.SectionPosition; import net.minecraft.network.protocol.game.PacketPlayOutBlockBreak; import net.minecraft.world.level.block.entity.TileEntitySign; @@ -32,9 +32,9 @@ import java.util.function.BiFunction; public class ProtocolWrapper18 implements ProtocolWrapper { - private static final Reflection.FieldAccessor multiBlockChangeChunk = Reflection.getField(TechHider.multiBlockChangePacket, SectionPosition.class, 0); - private static final Reflection.FieldAccessor multiBlockChangePos = Reflection.getField(TechHider.multiBlockChangePacket, short[].class, 0); - private static final Reflection.FieldAccessor multiBlockChangeBlocks = Reflection.getField(TechHider.multiBlockChangePacket, IBlockData[].class, 0); + private static final Reflection.Field multiBlockChangeChunk = Reflection.getField(TechHider.multiBlockChangePacket, SectionPosition.class, 0); + private static final Reflection.Field multiBlockChangePos = Reflection.getField(TechHider.multiBlockChangePacket, short[].class, 0); + private static final Reflection.Field multiBlockChangeBlocks = Reflection.getField(TechHider.multiBlockChangePacket, IBlockData[].class, 0); @Override public BiFunction multiBlockChangeGenerator(TechHider techHider) { return (p, packet) -> { @@ -81,7 +81,7 @@ public class ProtocolWrapper18 implements ProtocolWrapper { }; } - private static final Reflection.FieldAccessor tileEntityType = Reflection.getField(TechHider.tileEntityDataPacket, TileEntityTypes.class, 0); + private static final Reflection.Field tileEntityType = Reflection.getField(TechHider.tileEntityDataPacket, TileEntityTypes.class, 0); private static final TileEntityTypes signType = Reflection.getField(TileEntityTypes.class, TileEntityTypes.class, 0, TileEntitySign.class).get(null); @Override public boolean unfilteredTileEntityDataAction(Object packet) { diff --git a/SpigotCore/SpigotCore_19/src/de/steamwar/core/ProtocolWrapper19.java b/SpigotCore/SpigotCore_19/src/de/steamwar/core/ProtocolWrapper19.java index f4f399f3..f796dcdd 100644 --- a/SpigotCore/SpigotCore_19/src/de/steamwar/core/ProtocolWrapper19.java +++ b/SpigotCore/SpigotCore_19/src/de/steamwar/core/ProtocolWrapper19.java @@ -19,7 +19,7 @@ package de.steamwar.core; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import com.mojang.authlib.GameProfile; import com.mojang.datafixers.util.Pair; import net.minecraft.SystemUtils; @@ -35,15 +35,15 @@ import java.util.function.LongSupplier; public class ProtocolWrapper19 implements ProtocolWrapper { - private static final Reflection.FieldAccessor equipmentStack = Reflection.getField(equipmentPacket, List.class, 0); + private static final Reflection.Field equipmentStack = Reflection.getField(equipmentPacket, List.class, 0); @Override public void setEquipmentPacketStack(Object packet, Object slot, Object stack) { equipmentStack.set(packet, Collections.singletonList(new Pair<>(slot, stack))); } - private static final Reflection.ConstructorInvoker removePacketConstructor = Reflection.getConstructor(ClientboundPlayerInfoRemovePacket.class, List.class); - private static final Reflection.FieldAccessor updateActions = Reflection.getField(ClientboundPlayerInfoUpdatePacket.class, EnumSet.class, 0); - private static final Reflection.FieldAccessor updatePlayers = Reflection.getField(ClientboundPlayerInfoUpdatePacket.class, List.class, 0); + private static final Reflection.Constructor removePacketConstructor = Reflection.getConstructor(ClientboundPlayerInfoRemovePacket.class, List.class); + private static final Reflection.Field updateActions = Reflection.getField(ClientboundPlayerInfoUpdatePacket.class, EnumSet.class, 0); + private static final Reflection.Field updatePlayers = Reflection.getField(ClientboundPlayerInfoUpdatePacket.class, List.class, 0); @Override @SuppressWarnings("deprecation") diff --git a/SpigotCore/SpigotCore_20/src/de/steamwar/core/CraftbukkitWrapper20.java b/SpigotCore/SpigotCore_20/src/de/steamwar/core/CraftbukkitWrapper20.java index 68963457..31faa3f0 100644 --- a/SpigotCore/SpigotCore_20/src/de/steamwar/core/CraftbukkitWrapper20.java +++ b/SpigotCore/SpigotCore_20/src/de/steamwar/core/CraftbukkitWrapper20.java @@ -19,7 +19,7 @@ package de.steamwar.core; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket; import net.minecraft.world.level.World; @@ -30,8 +30,8 @@ import org.bukkit.entity.Player; public class CraftbukkitWrapper20 implements CraftbukkitWrapper.ICraftbukkitWrapper { - private static final Reflection.MethodInvoker getHandle = Reflection.getMethod("{obc}.CraftChunk", "getHandle", ChunkStatus.class); - private static final Reflection.MethodInvoker getLightEngine = Reflection.getTypedMethod(World.class, null, LevelLightEngine.class); + private static final Reflection.Method getHandle = Reflection.getMethod("org.bukkit.craftbukkit.CraftChunk", "getHandle", ChunkStatus.class); + private static final Reflection.Method getLightEngine = Reflection.getTypedMethod(World.class, null, LevelLightEngine.class); @Override public void sendChunk(Player p, int chunkX, int chunkZ) { diff --git a/SpigotCore/SpigotCore_21/build.gradle.kts b/SpigotCore/SpigotCore_21/build.gradle.kts index b9a7805e..8f2acba4 100644 --- a/SpigotCore/SpigotCore_21/build.gradle.kts +++ b/SpigotCore/SpigotCore_21/build.gradle.kts @@ -21,7 +21,13 @@ plugins { steamwar.java } +java { + sourceCompatibility = JavaVersion.VERSION_21 + targetCompatibility = JavaVersion.VERSION_21 +} + dependencies { + compileOnly(project(":CommonCore", "default")) compileOnly(project(":SpigotCore:SpigotCore_Main", "default")) compileOnly(project(":SpigotCore:SpigotCore_18", "default")) compileOnly(project(":SpigotCore:SpigotCore_14", "default")) @@ -29,16 +35,6 @@ dependencies { compileOnly(libs.fawe21) - compileOnly(libs.paperapi21) { - attributes { - // Very Hacky, but it works - attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, 21) - } - } - compileOnly(libs.nms21) { - attributes { - // Very Hacky, but it works - attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, 21) - } - } + compileOnly(libs.paperapi21) + compileOnly(libs.nms21) } diff --git a/SpigotCore/SpigotCore_21/src/de/steamwar/core/BountifulWrapper21.java b/SpigotCore/SpigotCore_21/src/de/steamwar/core/BountifulWrapper21.java index d144c9b6..e01a06fc 100644 --- a/SpigotCore/SpigotCore_21/src/de/steamwar/core/BountifulWrapper21.java +++ b/SpigotCore/SpigotCore_21/src/de/steamwar/core/BountifulWrapper21.java @@ -19,7 +19,7 @@ package de.steamwar.core; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import net.minecraft.world.entity.PositionMoveRotation; import net.minecraft.world.phys.Vec3D; @@ -28,12 +28,12 @@ public class BountifulWrapper21 extends BountifulWrapper9 { @Override public BountifulWrapper.PositionSetter getPositionSetter(Class packetClass, int fieldOffset) { try { - Reflection.FieldAccessor field = Reflection.getField(packetClass, PositionMoveRotation.class, 0); + Reflection.Field field = Reflection.getField(packetClass, PositionMoveRotation.class, 0); return (packet, x, y, z, pitch, yaw) -> { PositionMoveRotation pos = field.get(packet); - field.set(packet, new PositionMoveRotation(new Vec3D(x, y, z), pos.b(), pitch, yaw)); + field.set(packet, new PositionMoveRotation(new Vec3D(x, y, z), pos.b(), yaw, pitch)); }; } catch (IllegalArgumentException e) { return super.getPositionSetter(packetClass, fieldOffset); diff --git a/SpigotCore/SpigotCore_21/src/de/steamwar/core/CraftbukkitWrapper21.java b/SpigotCore/SpigotCore_21/src/de/steamwar/core/CraftbukkitWrapper21.java index 2309a2a6..337ee1db 100644 --- a/SpigotCore/SpigotCore_21/src/de/steamwar/core/CraftbukkitWrapper21.java +++ b/SpigotCore/SpigotCore_21/src/de/steamwar/core/CraftbukkitWrapper21.java @@ -19,7 +19,7 @@ package de.steamwar.core; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket; import net.minecraft.world.level.World; @@ -30,8 +30,8 @@ import org.bukkit.entity.Player; public class CraftbukkitWrapper21 implements CraftbukkitWrapper.ICraftbukkitWrapper { - private static final Reflection.MethodInvoker getHandle = Reflection.getMethod("{obc}.CraftChunk", "getHandle", ChunkStatus.class); - private static final Reflection.MethodInvoker getLightEngine = Reflection.getTypedMethod(World.class, null, LevelLightEngine.class); + private static final Reflection.Method getHandle = Reflection.getMethod("org.bukkit.craftbukkit.CraftChunk", "getHandle", ChunkStatus.class); + private static final Reflection.Method getLightEngine = Reflection.getTypedMethod(World.class, null, LevelLightEngine.class); @Override public void sendChunk(Player p, int chunkX, int chunkZ) { diff --git a/SpigotCore/SpigotCore_21/src/de/steamwar/core/WorldEditWrapper21.java b/SpigotCore/SpigotCore_21/src/de/steamwar/core/WorldEditWrapper21.java index 4ae22cac..52947f3a 100644 --- a/SpigotCore/SpigotCore_21/src/de/steamwar/core/WorldEditWrapper21.java +++ b/SpigotCore/SpigotCore_21/src/de/steamwar/core/WorldEditWrapper21.java @@ -20,33 +20,30 @@ package de.steamwar.core; import com.fastasyncworldedit.core.extent.clipboard.io.FastSchematicReaderV2; -import com.fastasyncworldedit.core.extent.clipboard.io.FastSchematicReaderV3; import com.sk89q.jnbt.NBTInputStream; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.extent.clipboard.io.BuiltInClipboardFormat; import com.sk89q.worldedit.extent.clipboard.io.ClipboardWriter; import com.sk89q.worldedit.extent.clipboard.io.MCEditSchematicReader; -import com.sk89q.worldedit.extent.clipboard.io.sponge.SpongeSchematicV1Reader; +import com.sk89q.worldedit.extent.clipboard.io.sponge.SpongeSchematicV2Reader; +import com.sk89q.worldedit.extent.clipboard.io.sponge.SpongeSchematicV3Reader; import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.math.transform.Transform; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.session.ClipboardHolder; +import de.steamwar.sql.NodeData; import org.bukkit.entity.Player; import org.bukkit.util.Vector; import org.enginehub.linbus.stream.LinBinaryIO; -import org.enginehub.linbus.stream.LinStream; -import org.enginehub.linbus.tree.LinCompoundTag; -import org.enginehub.linbus.tree.LinRootEntry; -import org.enginehub.linbus.tree.LinTagType; import java.io.*; public class WorldEditWrapper21 implements WorldEditWrapper { @Override - public InputStream getPlayerClipboard(Player player, boolean schemFormat) { - return WorldEditWrapper.getPlayerClipboard(player, schemFormat, (outputStream, clipboard, clipboardHolder) -> { + public InputStream getPlayerClipboard(Player player) { + return WorldEditWrapper.getPlayerClipboard(player, (outputStream, clipboard, clipboardHolder) -> { ClipboardWriter writer = BuiltInClipboardFormat.FAST_V3.getWriter(outputStream); writer.write(clipboard); writer.close(); @@ -54,7 +51,7 @@ public class WorldEditWrapper21 implements WorldEditWrapper { } @Override - public void setPlayerClipboard(Player player, InputStream is, boolean schemFormat) { + public void setPlayerClipboard(Player player, InputStream is, NodeData.SchematicFormat schemFormat) { Clipboard clipboard = null; try { clipboard = getClipboard(is, schemFormat); @@ -70,35 +67,13 @@ public class WorldEditWrapper21 implements WorldEditWrapper { } @Override - public Clipboard getClipboard(InputStream is, boolean schemFormat) throws IOException { - if (!schemFormat) { - return new MCEditSchematicReader(new NBTInputStream(is)).read(); - } else { - BufferedInputStream bis = new BufferedInputStream(is); - - bis.mark(Integer.MAX_VALUE); - - LinStream linStream = LinBinaryIO.read(new DataInputStream(bis)); - - LinCompoundTag entry = LinRootEntry.readFrom(linStream).value(); - - if (entry.value().size() == 1) { - entry = entry.getTag("Schematic", LinTagType.compoundTag()); - } - - bis.reset(); - - switch (entry.getTag("Version", LinTagType.intTag()).valueAsInt()) { - case 1: - return new SpongeSchematicV1Reader(entry.linStream()).read(); - case 2: - return new FastSchematicReaderV2(new NBTInputStream(bis)).read(); - case 3: - return new FastSchematicReaderV3(bis).read(); - default: - throw new IOException("Unknown schematic version"); - } - } + @SuppressWarnings("removal") + public Clipboard getClipboard(InputStream is, NodeData.SchematicFormat schemFormat) throws IOException { + return switch (schemFormat) { + case MCEDIT -> new MCEditSchematicReader(new NBTInputStream(is)).read(); + case SPONGE_V2 -> new SpongeSchematicV2Reader(LinBinaryIO.read(new DataInputStream(is))).read(); + case SPONGE_V3 -> new SpongeSchematicV3Reader(LinBinaryIO.read(new DataInputStream(is))).read(); + }; } @Override @@ -122,4 +97,9 @@ public class WorldEditWrapper21 implements WorldEditWrapper { v = transform.apply(v); return new org.bukkit.util.Vector(v.x(), v.y(), v.z()); } + + @Override + public NodeData.SchematicFormat getNativeFormat() { + return NodeData.SchematicFormat.SPONGE_V3; + } } diff --git a/SpigotCore/SpigotCore_8/src/de/steamwar/core/BountifulWrapper8.java b/SpigotCore/SpigotCore_8/src/de/steamwar/core/BountifulWrapper8.java index 54ea45b3..9f0d8e1a 100644 --- a/SpigotCore/SpigotCore_8/src/de/steamwar/core/BountifulWrapper8.java +++ b/SpigotCore/SpigotCore_8/src/de/steamwar/core/BountifulWrapper8.java @@ -19,13 +19,12 @@ package de.steamwar.core; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.BaseComponent; import net.minecraft.server.v1_8_R3.ChatComponentText; import net.minecraft.server.v1_8_R3.MathHelper; import net.minecraft.server.v1_8_R3.PacketPlayOutChat; -import net.minecraft.server.v1_8_R3.PacketPlayOutEntityTeleport; import org.bukkit.Sound; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; import org.bukkit.entity.Player; @@ -50,8 +49,8 @@ public class BountifulWrapper8 implements BountifulWrapper.IBountifulWrapper { return index; } - private static final Class watchableObject = Reflection.getClass("{nms}.DataWatcher$WatchableObject"); - private static final Reflection.ConstructorInvoker watchableObjectConstructor = Reflection.getConstructor(watchableObject, int.class, int.class, Object.class); + private static final Class watchableObject = Reflection.getClass("net.minecraft.DataWatcher$WatchableObject"); + private static final Reflection.Constructor watchableObjectConstructor = Reflection.getConstructor(watchableObject, int.class, int.class, Object.class); private static final Map, Integer> watchableDatatypes = new HashMap<>(); static { watchableDatatypes.put(byte.class, 0); @@ -68,28 +67,28 @@ public class BountifulWrapper8 implements BountifulWrapper.IBountifulWrapper { @Override public BountifulWrapper.PositionSetter getPositionSetter(Class packetClass, int fieldOffset) { - Reflection.FieldAccessor posX = Reflection.getField(packetClass, int.class, fieldOffset); - Reflection.FieldAccessor posY = Reflection.getField(packetClass, int.class, fieldOffset +1); - Reflection.FieldAccessor posZ = Reflection.getField(packetClass, int.class, fieldOffset +2); - Reflection.FieldAccessor lookPitch = Reflection.getField(packetClass, byte.class, 0); - Reflection.FieldAccessor lookYaw = Reflection.getField(packetClass, byte.class, 1); + Reflection.Field posX = Reflection.getField(packetClass, int.class, fieldOffset); + Reflection.Field posY = Reflection.getField(packetClass, int.class, fieldOffset +1); + Reflection.Field posZ = Reflection.getField(packetClass, int.class, fieldOffset +2); + Reflection.Field lookYaw = Reflection.getField(packetClass, byte.class, 0); + Reflection.Field lookPitch = Reflection.getField(packetClass, byte.class, 1); return (packet, x, y, z, pitch, yaw) -> { posX.set(packet, MathHelper.floor(x * 32)); posY.set(packet, MathHelper.floor(y * 32)); posZ.set(packet, MathHelper.floor(z * 32)); - lookPitch.set(packet, (byte)(pitch * 256 / 360)); lookYaw.set(packet, (byte)(yaw * 256 / 360)); + lookPitch.set(packet, (byte)(pitch * 256 / 360)); }; } @Override public BountifulWrapper.PositionSetter getRelMoveSetter(Class packetClass) { - Reflection.FieldAccessor moveX = Reflection.getField(packetClass, "b", byte.class); - Reflection.FieldAccessor moveY = Reflection.getField(packetClass, "c", byte.class); - Reflection.FieldAccessor moveZ = Reflection.getField(packetClass, "d", byte.class); - Reflection.FieldAccessor lookYaw = Reflection.getField(packetClass, "e", byte.class); - Reflection.FieldAccessor lookPitch = Reflection.getField(packetClass, "f", byte.class); + Reflection.Field moveX = Reflection.getField(packetClass, "b", byte.class); + Reflection.Field moveY = Reflection.getField(packetClass, "c", byte.class); + Reflection.Field moveZ = Reflection.getField(packetClass, "d", byte.class); + Reflection.Field lookYaw = Reflection.getField(packetClass, "e", byte.class); + Reflection.Field lookPitch = Reflection.getField(packetClass, "f", byte.class); return (packet, x, y, z, pitch, yaw) -> { moveX.set(packet, (byte)(x*32)); diff --git a/SpigotCore/SpigotCore_8/src/de/steamwar/core/ChatWrapper8.java b/SpigotCore/SpigotCore_8/src/de/steamwar/core/ChatWrapper8.java index 951cdc8a..c41c1710 100644 --- a/SpigotCore/SpigotCore_8/src/de/steamwar/core/ChatWrapper8.java +++ b/SpigotCore/SpigotCore_8/src/de/steamwar/core/ChatWrapper8.java @@ -19,22 +19,22 @@ package de.steamwar.core; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import java.util.ArrayList; import java.util.List; public class ChatWrapper8 implements ChatWrapper { - private static final Reflection.ConstructorInvoker chatComponentConstructor = Reflection.getConstructor(Reflection.getClass("{nms.network.chat}.ChatComponentText"), String.class); + private static final Reflection.Constructor chatComponentConstructor = Reflection.getConstructor(Reflection.getClass("net.minecraft.network.chat.ChatComponentText"), String.class); @Override public Object stringToChatComponent(String text) { return chatComponentConstructor.invoke(text); } - private static final Class metadataPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityMetadata"); - private static final Reflection.FieldAccessor metadataEntity = Reflection.getField(metadataPacket, int.class, 0); - private static final Reflection.FieldAccessor metadataMetadata = Reflection.getField(metadataPacket, List.class, 0); + private static final Class metadataPacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket"); + private static final Reflection.Field metadataEntity = Reflection.getField(metadataPacket, int.class, 0); + private static final Reflection.Field metadataMetadata = Reflection.getField(metadataPacket, List.class, 0); @Override public Object getDataWatcherPacket(int entityId, Object... dataWatcherKeyValues) { Object packet = Reflection.newInstance(metadataPacket); diff --git a/SpigotCore/SpigotCore_8/src/de/steamwar/core/FlatteningWrapper8.java b/SpigotCore/SpigotCore_8/src/de/steamwar/core/FlatteningWrapper8.java index 7d485286..b191a069 100644 --- a/SpigotCore/SpigotCore_8/src/de/steamwar/core/FlatteningWrapper8.java +++ b/SpigotCore/SpigotCore_8/src/de/steamwar/core/FlatteningWrapper8.java @@ -19,7 +19,7 @@ package de.steamwar.core; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.entity.EntityType; @@ -32,9 +32,9 @@ import java.util.Map; public class FlatteningWrapper8 implements FlatteningWrapper.IFlatteningWrapper { - private static final Reflection.FieldAccessor scoreboardName = Reflection.getField(FlatteningWrapper.scoreboardObjective, String.class, 1); - private static final Class scoreActionEnum = Reflection.getClass("{nms}.PacketPlayOutScoreboardScore$EnumScoreboardAction"); - private static final Reflection.FieldAccessor scoreAction = Reflection.getField(FlatteningWrapper.scoreboardScore, scoreActionEnum, 0); + private static final Reflection.Field scoreboardName = Reflection.getField(FlatteningWrapper.scoreboardObjective, String.class, 1); + private static final Class scoreActionEnum = Reflection.getClass("net.minecraft.PacketPlayOutScoreboardScore$EnumScoreboardAction"); + private static final Reflection.Field scoreAction = Reflection.getField(FlatteningWrapper.scoreboardScore, scoreActionEnum, 0); private static final Object scoreActionChange = scoreActionEnum.getEnumConstants()[0]; @Override @@ -76,11 +76,11 @@ public class FlatteningWrapper8 implements FlatteningWrapper.IFlatteningWrapper return Byte.valueOf((byte)(pose == FlatteningWrapper.EntityPose.SNEAKING ? 2 : 0)); } - private static final Class dataWatcher = Reflection.getClass("{nms}.DataWatcher"); - private static final Class namedSpawnPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutNamedEntitySpawn"); - private static final Reflection.FieldAccessor namedSpawnDataWatcher = Reflection.getField(namedSpawnPacket, dataWatcher, 0); - private static final Class entity = Reflection.getClass("{nms}.Entity"); - private static final Reflection.ConstructorInvoker dataWatcherConstructor = Reflection.getConstructor(dataWatcher, entity); + private static final Class dataWatcher = Reflection.getClass("net.minecraft.DataWatcher"); + private static final Class namedSpawnPacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundAddPlayerPacket"); + private static final Reflection.Field namedSpawnDataWatcher = Reflection.getField(namedSpawnPacket, dataWatcher, 0); + private static final Class entity = Reflection.getClass("net.minecraft.Entity"); + private static final Reflection.Constructor dataWatcherConstructor = Reflection.getConstructor(dataWatcher, entity); @Override public void setNamedSpawnPacketDataWatcher(Object packet) { namedSpawnDataWatcher.set(packet, dataWatcherConstructor.invoke((Object) null)); @@ -92,8 +92,8 @@ public class FlatteningWrapper8 implements FlatteningWrapper.IFlatteningWrapper } - private static final Reflection.FieldAccessor spawnType = Reflection.getField(ProtocolWrapper.spawnPacket, int.class, Core.getVersion() > 8 ? 6 : 9); - private static final Reflection.FieldAccessor spawnLivingType = Reflection.getField(ProtocolWrapper.spawnLivingPacket, int.class, 1); + private static final Reflection.Field spawnType = Reflection.getField(ProtocolWrapper.spawnPacket, int.class, Core.getVersion() > 8 ? 6 : 9); + private static final Reflection.Field spawnLivingType = Reflection.getField(ProtocolWrapper.spawnLivingPacket, int.class, 1); private static final Map types = new HashMap<>(); static { types.put(TrickyTrialsWrapper.impl.getTntEntityType(), 50); @@ -113,7 +113,7 @@ public class FlatteningWrapper8 implements FlatteningWrapper.IFlatteningWrapper return 10; } - private static final Reflection.MethodInvoker save = Reflection.getMethod("{obc}.CraftWorld", "save", boolean.class); + private static final Reflection.Method save = Reflection.getMethod("org.bukkit.craftbukkit.CraftWorld", "save", boolean.class); @Override public void syncSave(World world) { save.invoke(world, true); diff --git a/SpigotCore/SpigotCore_8/src/de/steamwar/core/ProtocolWrapper8.java b/SpigotCore/SpigotCore_8/src/de/steamwar/core/ProtocolWrapper8.java index 9f0b234b..e30caa17 100644 --- a/SpigotCore/SpigotCore_8/src/de/steamwar/core/ProtocolWrapper8.java +++ b/SpigotCore/SpigotCore_8/src/de/steamwar/core/ProtocolWrapper8.java @@ -19,7 +19,7 @@ package de.steamwar.core; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import com.mojang.authlib.GameProfile; import org.bukkit.GameMode; @@ -29,27 +29,27 @@ import java.util.List; public class ProtocolWrapper8 implements ProtocolWrapper { - private static final Reflection.FieldAccessor equipmentSlot; + private static final Reflection.Field equipmentSlot; static { if(Core.getVersion() == 8) { equipmentSlot = Reflection.getField(equipmentPacket, int.class, 1); } else { - Class enumItemSlot = Reflection.getClass("{nms.world.entity}.EnumItemSlot"); + Class enumItemSlot = Reflection.getClass("net.minecraft.world.entity.EnumItemSlot"); equipmentSlot = Reflection.getField(equipmentPacket, enumItemSlot, 0); } } - private static final Reflection.FieldAccessor equipmentStack = Reflection.getField(equipmentPacket, itemStack, 0); + private static final Reflection.Field equipmentStack = Reflection.getField(equipmentPacket, itemStack, 0); @Override public void setEquipmentPacketStack(Object packet, Object slot, Object stack) { equipmentSlot.set(packet, slot); equipmentStack.set(packet, stack); } - private static final Class playerInfoPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutPlayerInfo"); - private static final Class playerInfoActionClass = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutPlayerInfo$EnumPlayerInfoAction"); - private static final Reflection.FieldAccessor playerInfoAction = Reflection.getField(playerInfoPacket, playerInfoActionClass, 0); - private static final Reflection.FieldAccessor playerInfoData = Reflection.getField(playerInfoPacket, List.class, 0); + private static final Class playerInfoPacket = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutPlayerInfo"); + private static final Class playerInfoActionClass = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutPlayerInfo$EnumPlayerInfoAction"); + private static final Reflection.Field playerInfoAction = Reflection.getField(playerInfoPacket, playerInfoActionClass, 0); + private static final Reflection.Field playerInfoData = Reflection.getField(playerInfoPacket, List.class, 0); private static final EnumMap actions = new EnumMap<>(PlayerInfoAction.class); static { Object[] nativeActions = playerInfoActionClass.getEnumConstants(); @@ -57,8 +57,8 @@ public class ProtocolWrapper8 implements ProtocolWrapper { actions.put(PlayerInfoAction.GAMEMODE, nativeActions[1]); actions.put(PlayerInfoAction.REMOVE, nativeActions[4]); } - private static final Class iChatBaseComponent = Reflection.getClass("{nms.network.chat}.IChatBaseComponent"); - private static final Reflection.ConstructorInvoker playerInfoDataConstructor = Reflection.getConstructor("{nms.network.protocol.game}.PacketPlayOutPlayerInfo$PlayerInfoData", playerInfoPacket, GameProfile.class, int.class, enumGamemode, iChatBaseComponent); + private static final Class iChatBaseComponent = Reflection.getClass("net.minecraft.network.chat.Component"); + private static final Reflection.Constructor playerInfoDataConstructor = Reflection.getConstructor("net.minecraft.network.protocol.game.PacketPlayOutPlayerInfo$PlayerInfoData", playerInfoPacket, GameProfile.class, int.class, enumGamemode, iChatBaseComponent); @Override @SuppressWarnings("deprecation") diff --git a/SpigotCore/SpigotCore_8/src/de/steamwar/core/WorldEditWrapper8.java b/SpigotCore/SpigotCore_8/src/de/steamwar/core/WorldEditWrapper8.java index f3fc2800..75957933 100644 --- a/SpigotCore/SpigotCore_8/src/de/steamwar/core/WorldEditWrapper8.java +++ b/SpigotCore/SpigotCore_8/src/de/steamwar/core/WorldEditWrapper8.java @@ -37,6 +37,7 @@ import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.session.ClipboardHolder; import com.sk89q.worldedit.world.registry.WorldData; +import de.steamwar.sql.NodeData; import org.bukkit.entity.Player; import java.io.IOException; @@ -50,13 +51,13 @@ import java.util.stream.Collectors; public class WorldEditWrapper8 implements WorldEditWrapper { @Override - public InputStream getPlayerClipboard(Player player, boolean schemFormat) { - return WorldEditWrapper.getPlayerClipboard(player, schemFormat, (outputStream, clipboard, clipboardHolder) -> + public InputStream getPlayerClipboard(Player player) { + return WorldEditWrapper.getPlayerClipboard(player, (outputStream, clipboard, clipboardHolder) -> ClipboardFormat.SCHEMATIC.getWriter(outputStream).write(clipboard, clipboardHolder.getWorldData())); } @Override - public void setPlayerClipboard(Player player, InputStream is, boolean schemFormat) { + public void setPlayerClipboard(Player player, InputStream is, NodeData.SchematicFormat schemFormat) { WorldData world = new BukkitWorld(player.getWorld()).getWorldData(); Clipboard clipboard; try { @@ -70,11 +71,16 @@ public class WorldEditWrapper8 implements WorldEditWrapper { } @Override - public Clipboard getClipboard(InputStream is, boolean schemFormat) throws IOException { - if(schemFormat) - return new SpongeSchematicReader(new NBTInputStream(is)).read(WorldEdit.getInstance().getServer().getWorlds().get(0).getWorldData()); - else - return new SchematicReader(new NBTInputStream(is)).read(WorldEdit.getInstance().getServer().getWorlds().get(0).getWorldData()); + public Clipboard getClipboard(InputStream is, NodeData.SchematicFormat schemFormat) throws IOException { + switch (schemFormat) { + case MCEDIT: + return new SchematicReader(new NBTInputStream(is)).read(WorldEdit.getInstance().getServer().getWorlds().get(0).getWorldData()); + case SPONGE_V2: + case SPONGE_V3: + return new SpongeSchematicReader(new NBTInputStream(is)).read(WorldEdit.getInstance().getServer().getWorlds().get(0).getWorldData()); + default: + throw new IllegalArgumentException("Unsupported schematic format"); + } } @Override @@ -99,6 +105,11 @@ public class WorldEditWrapper8 implements WorldEditWrapper { return new org.bukkit.util.Vector(v.getX(), v.getY(), v.getZ()); } + @Override + public NodeData.SchematicFormat getNativeFormat() { + return NodeData.SchematicFormat.MCEDIT; + } + private static class SpongeSchematicReader implements ClipboardReader { private final NBTInputStream inputStream; @@ -137,6 +148,13 @@ public class WorldEditWrapper8 implements WorldEditWrapper { IDConverter8 ids = new IDConverter8(); Map schematic = schematicTag.getValue(); + boolean v3Mode = false; + + if (schematic.size() == 1) { + schematic = (requireTag(schematic, "Schematic", CompoundTag.class)).getValue(); + v3Mode = true; + } + int width = (requireTag(schematic, "Width", ShortTag.class)).getValue(); int height = (requireTag(schematic, "Height", ShortTag.class)).getValue(); int length = (requireTag(schematic, "Length", ShortTag.class)).getValue(); @@ -167,10 +185,13 @@ public class WorldEditWrapper8 implements WorldEditWrapper { region = new CuboidRegion(min, min.add(width, height, length).subtract(BlockVector.ONE)); } - IntTag paletteMaxTag = getTag(schematic, "PaletteMax", IntTag.class); - Map paletteObject = requireTag(schematic, "Palette", CompoundTag.class).getValue(); - if (paletteMaxTag != null && paletteObject.size() != paletteMaxTag.getValue()) - throw new IOException("Block palette size does not match expected size."); + Map blockContainer = null; + + if (v3Mode) { + blockContainer = getTag(schematic, "Blocks", CompoundTag.class).getValue(); + } + + Map paletteObject = requireTag(v3Mode ? blockContainer : schematic, "Palette", CompoundTag.class).getValue(); Map palette = new HashMap<>(); ParserContext parserContext = new ParserContext(); @@ -182,11 +203,11 @@ public class WorldEditWrapper8 implements WorldEditWrapper { palette.put(requireTag(paletteObject, palettePart, IntTag.class).getValue(), new BaseBlock(blockID.getBlockId(), blockID.getDataId())); } - byte[] blocks = requireTag(schematic, "BlockData", ByteArrayTag.class).getValue(); + byte[] blocks = requireTag(v3Mode ? blockContainer : schematic, v3Mode ? "Data" : "BlockData", ByteArrayTag.class).getValue(); Map> tileEntitiesMap = new HashMap<>(); - ListTag tileEntities = getTag(schematic, "BlockEntities", ListTag.class); + ListTag tileEntities = getTag(v3Mode ? blockContainer : schematic, "BlockEntities", ListTag.class); if (tileEntities == null) { - tileEntities = getTag(schematic, "TileEntities", ListTag.class); + tileEntities = getTag(v3Mode ? blockContainer : schematic, "TileEntities", ListTag.class); } if (tileEntities != null) { diff --git a/SpigotCore/SpigotCore_8/src/de/steamwar/scoreboard/SWScoreboard8.java b/SpigotCore/SpigotCore_8/src/de/steamwar/scoreboard/SWScoreboard8.java index d65cf989..a1648419 100644 --- a/SpigotCore/SpigotCore_8/src/de/steamwar/scoreboard/SWScoreboard8.java +++ b/SpigotCore/SpigotCore_8/src/de/steamwar/scoreboard/SWScoreboard8.java @@ -19,7 +19,7 @@ package de.steamwar.scoreboard; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; import de.steamwar.core.Core; import de.steamwar.core.FlatteningWrapper; @@ -30,15 +30,15 @@ import java.util.HashMap; import java.util.Map; public class SWScoreboard8 implements SWScoreboard { - private static final Reflection.FieldAccessor scoreboardName = Reflection.getField(FlatteningWrapper.scoreboardObjective, String.class, 0); - private static final Reflection.FieldAccessor scoreboardAction = Reflection.getField(FlatteningWrapper.scoreboardObjective, int.class, Core.getVersion() > 15 ? 3 : 0); - private static final Class scoreboardDisplayEnum = Reflection.getClass("{nms.world.scores.criteria}.IScoreboardCriteria$EnumScoreboardHealthDisplay"); - private static final Reflection.FieldAccessor scoreboardDisplayType = Reflection.getField(FlatteningWrapper.scoreboardObjective, scoreboardDisplayEnum, 0); + private static final Reflection.Field scoreboardName = Reflection.getField(FlatteningWrapper.scoreboardObjective, String.class, 0); + private static final Reflection.Field scoreboardAction = Reflection.getField(FlatteningWrapper.scoreboardObjective, int.class, Core.getVersion() > 15 ? 3 : 0); + private static final Class scoreboardDisplayEnum = Reflection.getClass("net.minecraft.world.scores.criteria.IScoreboardCriteria$EnumScoreboardHealthDisplay"); + private static final Reflection.Field scoreboardDisplayType = Reflection.getField(FlatteningWrapper.scoreboardObjective, scoreboardDisplayEnum, 0); private static final Object displayTypeIntegers = scoreboardDisplayEnum.getEnumConstants()[0]; - private static final Reflection.FieldAccessor scoreName = Reflection.getField(FlatteningWrapper.scoreboardScore, String.class, 0); - private static final Reflection.FieldAccessor scoreScoreboardName = Reflection.getField(FlatteningWrapper.scoreboardScore, String.class, 1); - private static final Reflection.FieldAccessor scoreValue = Reflection.getField(FlatteningWrapper.scoreboardScore, int.class, 0); + private static final Reflection.Field scoreName = Reflection.getField(FlatteningWrapper.scoreboardScore, String.class, 0); + private static final Reflection.Field scoreScoreboardName = Reflection.getField(FlatteningWrapper.scoreboardScore, String.class, 1); + private static final Reflection.Field scoreValue = Reflection.getField(FlatteningWrapper.scoreboardScore, int.class, 0); private static final HashMap playerBoards = new HashMap<>(); //Object -> Scoreboard | Alle Versionen in der Map! private static int toggle = 0; // Scoreboard 0 updates while scoreboard 1 is presenting. toggle marks the current active scoreboard @@ -48,9 +48,9 @@ public class SWScoreboard8 implements SWScoreboard { private static final Object[] DISPLAY_SIDEBAR = new Object[2]; static { - Class scoreboardDisplayObjective = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutScoreboardDisplayObjective"); - Reflection.FieldAccessor scoreboardDisplayName = Reflection.getField(scoreboardDisplayObjective, String.class, 0); - Reflection.FieldAccessor scoreboardDisplaySlot = Reflection.getField(scoreboardDisplayObjective, int.class, 0); + Class scoreboardDisplayObjective = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutScoreboardDisplayObjective"); + Reflection.Field scoreboardDisplayName = Reflection.getField(scoreboardDisplayObjective, String.class, 0); + Reflection.Field scoreboardDisplaySlot = Reflection.getField(scoreboardDisplayObjective, int.class, 0); for(int id = 0; id < 2; id++) { DELETE_SCOREBOARD[id] = Reflection.newInstance(FlatteningWrapper.scoreboardObjective); scoreboardName.set(DELETE_SCOREBOARD[id], SIDEBAR + id); diff --git a/SpigotCore/SpigotCore_8/src/de/steamwar/techhider/ChunkHider8.java b/SpigotCore/SpigotCore_8/src/de/steamwar/techhider/ChunkHider8.java index 50adcaa3..0aebc6e1 100644 --- a/SpigotCore/SpigotCore_8/src/de/steamwar/techhider/ChunkHider8.java +++ b/SpigotCore/SpigotCore_8/src/de/steamwar/techhider/ChunkHider8.java @@ -19,14 +19,14 @@ package de.steamwar.techhider; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import org.bukkit.entity.Player; import java.util.function.BiFunction; public class ChunkHider8 implements ChunkHider { - protected static final Class mapChunkPacket = Reflection.getClass("{nms}.PacketPlayOutMapChunk"); + protected static final Class mapChunkPacket = Reflection.getClass("net.minecraft.PacketPlayOutMapChunk"); @Override public Class mapChunkPacket() { return mapChunkPacket; diff --git a/SpigotCore/SpigotCore_8/src/de/steamwar/techhider/ProtocolWrapper8.java b/SpigotCore/SpigotCore_8/src/de/steamwar/techhider/ProtocolWrapper8.java index b0de38c8..78633bc1 100644 --- a/SpigotCore/SpigotCore_8/src/de/steamwar/techhider/ProtocolWrapper8.java +++ b/SpigotCore/SpigotCore_8/src/de/steamwar/techhider/ProtocolWrapper8.java @@ -19,7 +19,7 @@ package de.steamwar.techhider; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import org.bukkit.entity.Player; import java.lang.reflect.Array; @@ -27,16 +27,16 @@ import java.util.ArrayList; import java.util.function.BiFunction; public class ProtocolWrapper8 implements ProtocolWrapper { - private static final Class chunkCoordinateIntPair = Reflection.getClass("{nms}.ChunkCoordIntPair"); - private static final Reflection.FieldAccessor multiBlockChangeChunk = Reflection.getField(TechHider.multiBlockChangePacket, chunkCoordinateIntPair, 0); - private static final Reflection.FieldAccessor chunkCoordinateX = Reflection.getField(chunkCoordinateIntPair, int.class, 0); - private static final Reflection.FieldAccessor chunkCoordinateZ = Reflection.getField(chunkCoordinateIntPair, int.class, 1); - private static final Class multiBlockChangeInfo = Reflection.getClass("{nms}.PacketPlayOutMultiBlockChange$MultiBlockChangeInfo"); - private static final Reflection.ConstructorInvoker multiBlockChangeInfoConstructor = Reflection.getConstructor(multiBlockChangeInfo, TechHider.multiBlockChangePacket, short.class, TechHider.iBlockData); - private static final Reflection.FieldAccessor multiBlockChangeInfoBlock = Reflection.getField(multiBlockChangeInfo, TechHider.iBlockData, 0); - private static final Reflection.FieldAccessor multiBlockChangeInfoPos = Reflection.getField(multiBlockChangeInfo, short.class, 0); - private static final Class multiBlockChangeInfoArray = Reflection.getClass("[L{nms}.PacketPlayOutMultiBlockChange$MultiBlockChangeInfo;"); - private static final Reflection.FieldAccessor multiBlockChangeInfos = Reflection.getField(TechHider.multiBlockChangePacket, multiBlockChangeInfoArray, 0); + private static final Class chunkCoordinateIntPair = Reflection.getClass("net.minecraft.ChunkCoordIntPair"); + private static final Reflection.Field multiBlockChangeChunk = Reflection.getField(TechHider.multiBlockChangePacket, chunkCoordinateIntPair, 0); + private static final Reflection.Field chunkCoordinateX = Reflection.getField(chunkCoordinateIntPair, int.class, 0); + private static final Reflection.Field chunkCoordinateZ = Reflection.getField(chunkCoordinateIntPair, int.class, 1); + private static final Class multiBlockChangeInfo = Reflection.getClass("net.minecraft.PacketPlayOutMultiBlockChange$MultiBlockChangeInfo"); + private static final Reflection.Constructor multiBlockChangeInfoConstructor = Reflection.getConstructor(multiBlockChangeInfo, TechHider.multiBlockChangePacket, short.class, TechHider.iBlockData); + private static final Reflection.Field multiBlockChangeInfoBlock = Reflection.getField(multiBlockChangeInfo, TechHider.iBlockData, 0); + private static final Reflection.Field multiBlockChangeInfoPos = Reflection.getField(multiBlockChangeInfo, short.class, 0); + private static final Class multiBlockChangeInfoArray = Reflection.getClass("[L" + Reflection.LEGACY_NET_MINECRAFT_SERVER + ".PacketPlayOutMultiBlockChange$MultiBlockChangeInfo;"); + private static final Reflection.Field multiBlockChangeInfos = Reflection.getField(TechHider.multiBlockChangePacket, multiBlockChangeInfoArray, 0); @Override public BiFunction multiBlockChangeGenerator(TechHider techHider) { return (p, packet) -> { @@ -72,7 +72,7 @@ public class ProtocolWrapper8 implements ProtocolWrapper { }; } - private static final Reflection.FieldAccessor tileEntityDataAction = Reflection.getField(TechHider.tileEntityDataPacket, int.class, 0); + private static final Reflection.Field tileEntityDataAction = Reflection.getField(TechHider.tileEntityDataPacket, int.class, 0); @Override public boolean unfilteredTileEntityDataAction(Object packet) { return tileEntityDataAction.get(packet) != 9; diff --git a/SpigotCore/SpigotCore_9/build.gradle.kts b/SpigotCore/SpigotCore_9/build.gradle.kts index 3463498a..a888faf1 100644 --- a/SpigotCore/SpigotCore_9/build.gradle.kts +++ b/SpigotCore/SpigotCore_9/build.gradle.kts @@ -26,6 +26,4 @@ dependencies { compileOnly(project(":SpigotCore:SpigotCore_8", "default")) compileOnly(libs.nms9) - - compileOnly(libs.viaapi) } diff --git a/SpigotCore/SpigotCore_9/src/de/steamwar/core/BountifulWrapper9.java b/SpigotCore/SpigotCore_9/src/de/steamwar/core/BountifulWrapper9.java index fa126698..ce7f6170 100644 --- a/SpigotCore/SpigotCore_9/src/de/steamwar/core/BountifulWrapper9.java +++ b/SpigotCore/SpigotCore_9/src/de/steamwar/core/BountifulWrapper9.java @@ -19,11 +19,9 @@ package de.steamwar.core; -import com.comphenix.tinyprotocol.Reflection; -import com.viaversion.viaversion.api.Via; +import de.steamwar.Reflection; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.BaseComponent; -import net.minecraft.server.v1_9_R2.PacketPlayOutEntity; import org.bukkit.Sound; import org.bukkit.entity.Player; @@ -38,23 +36,23 @@ 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) + if(type == ChatMessageType.CHAT) type = ChatMessageType.SYSTEM; player.spigot().sendMessage(type, msg); } - private static final Class dataWatcherObject = Reflection.getClass("{nms.network.syncher}.DataWatcherObject"); - private static final Class dataWatcherRegistry = Reflection.getClass("{nms.network.syncher}.DataWatcherRegistry"); - private static final Class dataWatcherSerializer = Reflection.getClass("{nms.network.syncher}.DataWatcherSerializer"); - private static final Reflection.ConstructorInvoker dataWatcherObjectConstructor = Reflection.getConstructor(dataWatcherObject, int.class, dataWatcherSerializer); + private static final Class dataWatcherObject = Reflection.getClass("net.minecraft.network.syncher.EntityDataAccessor"); + private static final Class dataWatcherRegistry = Reflection.getClass("net.minecraft.network.syncher.EntityDataSerializers"); + private static final Class dataWatcherSerializer = Reflection.getClass("net.minecraft.network.syncher.EntityDataSerializer"); + private static final Reflection.Constructor dataWatcherObjectConstructor = Reflection.getConstructor(dataWatcherObject, int.class, dataWatcherSerializer); @Override public Object getDataWatcherObject(int index, Class type) { return dataWatcherObjectConstructor.invoke(index, Reflection.getField(dataWatcherRegistry, dataWatcherSerializer, 0, type).get(null)); } - private static final Class item = Reflection.getClass("{nms.network.syncher}.DataWatcher$Item"); - private static final Reflection.ConstructorInvoker itemConstructor = Reflection.getConstructor(item, dataWatcherObject, Object.class); + private static final Class item = Reflection.getClass("net.minecraft.network.syncher.SynchedEntityData$DataItem"); + private static final Reflection.Constructor itemConstructor = Reflection.getConstructor(item, dataWatcherObject, Object.class); @Override public Object getDataWatcherItem(Object dwo, Object value) { return itemConstructor.invoke(dwo, value); @@ -62,24 +60,24 @@ public class BountifulWrapper9 implements BountifulWrapper.IBountifulWrapper { @Override public BountifulWrapper.PositionSetter getPositionSetter(Class packetClass, int fieldOffset) { - Reflection.FieldAccessor posX = Reflection.getField(packetClass, double.class, fieldOffset); - Reflection.FieldAccessor posY = Reflection.getField(packetClass, double.class, fieldOffset+1); - Reflection.FieldAccessor posZ = Reflection.getField(packetClass, double.class, fieldOffset+2); + Reflection.Field posX = Reflection.getField(packetClass, double.class, fieldOffset); + Reflection.Field posY = Reflection.getField(packetClass, double.class, fieldOffset+1); + Reflection.Field posZ = Reflection.getField(packetClass, double.class, fieldOffset+2); boolean isByteClass = packetClass.getSimpleName().contains("PacketPlayOutEntityTeleport") || packetClass.getSimpleName().contains("PacketPlayOutNamedEntitySpawn"); Class pitchYawType = isByteClass ? byte.class : int.class; - Reflection.FieldAccessor lookPitch = Reflection.getField(packetClass, pitchYawType, isByteClass ? 0 : 1); - Reflection.FieldAccessor lookYaw = Reflection.getField(packetClass, pitchYawType, isByteClass ? 1 : 2); + Reflection.Field lookYaw = Reflection.getField(packetClass, pitchYawType, isByteClass ? 0 : 1); + Reflection.Field lookPitch = Reflection.getField(packetClass, pitchYawType, isByteClass ? 1 : 2); return (packet, x, y, z, pitch, yaw) -> { posX.set(packet, x); posY.set(packet, y); posZ.set(packet, z); if (isByteClass) { - lookPitch.set(packet, (byte) (pitch*256/360)); lookYaw.set(packet, (byte) (yaw*256/360)); + lookPitch.set(packet, (byte) (pitch*256/360)); } else { - lookPitch.set(packet, (int) (pitch*256/360)); lookYaw.set(packet, (int) (yaw*256/360)); + lookPitch.set(packet, (int) (pitch*256/360)); } }; } @@ -87,24 +85,24 @@ public class BountifulWrapper9 implements BountifulWrapper.IBountifulWrapper { @Override public BountifulWrapper.PositionSetter getRelMoveSetter(Class packetClass) { Class type = Core.getVersion() > 12 ? short.class : int.class; - Reflection.FieldAccessor moveX = Reflection.getField(packetClass, "b", type); - Reflection.FieldAccessor moveY = Reflection.getField(packetClass, "c", type); - Reflection.FieldAccessor moveZ = Reflection.getField(packetClass, "d", type); - Reflection.FieldAccessor movePitch = Reflection.getField(packetClass, "e", byte.class); - Reflection.FieldAccessor moveYaw = Reflection.getField(packetClass, "f", byte.class); + Reflection.Field moveX = Reflection.getField(packetClass, "b", type); + Reflection.Field moveY = Reflection.getField(packetClass, "c", type); + Reflection.Field moveZ = Reflection.getField(packetClass, "d", type); + Reflection.Field moveYaw = Reflection.getField(packetClass, "e", byte.class); + Reflection.Field movePitch = Reflection.getField(packetClass, "f", byte.class); return (packet, x, y, z, pitch, yaw) -> { moveX.set(packet, (short)(x*4096)); moveY.set(packet, (short)(y*4096)); moveZ.set(packet, (short)(z*4096)); - movePitch.set(packet, (byte)(pitch*256/360)); moveYaw.set(packet, (byte)(yaw*256/360)); + movePitch.set(packet, (byte)(pitch*256/360)); }; } @Override public BountifulWrapper.UUIDSetter getUUIDSetter(Class packetClass) { - Reflection.FieldAccessor uuidField = Reflection.getField(packetClass, UUID.class, 0); + Reflection.Field uuidField = Reflection.getField(packetClass, UUID.class, 0); return uuidField::set; } diff --git a/SpigotCore/SpigotCore_9/src/de/steamwar/core/CraftbukkitWrapper9.java b/SpigotCore/SpigotCore_9/src/de/steamwar/core/CraftbukkitWrapper9.java index 8d111e31..608209dc 100644 --- a/SpigotCore/SpigotCore_9/src/de/steamwar/core/CraftbukkitWrapper9.java +++ b/SpigotCore/SpigotCore_9/src/de/steamwar/core/CraftbukkitWrapper9.java @@ -19,16 +19,16 @@ package de.steamwar.core; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; import org.bukkit.entity.Player; public class CraftbukkitWrapper9 implements CraftbukkitWrapper.ICraftbukkitWrapper { - private static final Class chunk = Reflection.getClass("{nms.world.level.chunk}.Chunk"); - private static final Class packetPlayOutMapChunk = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutMapChunk"); - private static final Reflection.ConstructorInvoker newPacketPlayOutMapChunk = Reflection.getConstructor(packetPlayOutMapChunk, chunk, int.class); - private static final Reflection.MethodInvoker getHandle = Reflection.getMethod("{obc}.CraftChunk", "getHandle"); + private static final Class chunk = Reflection.getClass("net.minecraft.world.level.chunk.LevelChunk"); + private static final Class packetPlayOutMapChunk = Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutMapChunk"); + private static final Reflection.Constructor newPacketPlayOutMapChunk = Reflection.getConstructor(packetPlayOutMapChunk, chunk, int.class); + private static final Reflection.Method getHandle = Reflection.getMethod("org.bukkit.craftbukkit.CraftChunk", "getHandle"); @Override public void sendChunk(Player p, int chunkX, int chunkZ) { diff --git a/SpigotCore/SpigotCore_9/src/de/steamwar/techhider/ChunkHider9.java b/SpigotCore/SpigotCore_9/src/de/steamwar/techhider/ChunkHider9.java index 89f6570f..96060822 100644 --- a/SpigotCore/SpigotCore_9/src/de/steamwar/techhider/ChunkHider9.java +++ b/SpigotCore/SpigotCore_9/src/de/steamwar/techhider/ChunkHider9.java @@ -19,7 +19,7 @@ package de.steamwar.techhider; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import org.bukkit.entity.Player; @@ -34,14 +34,14 @@ public class ChunkHider9 extends ChunkHider8 { private static final UnaryOperator mapChunkCloner = ProtocolUtils.shallowCloneGenerator(mapChunkPacket); - private static final Reflection.FieldAccessor mapChunkX = Reflection.getField(mapChunkPacket, int.class, 0); - private static final Reflection.FieldAccessor mapChunkZ = Reflection.getField(mapChunkPacket, int.class, 1); - private static final Reflection.FieldAccessor mapChunkBitMask = Reflection.getField(mapChunkPacket, int.class, 2); - private static final Reflection.FieldAccessor mapChunkBlockEntities = Reflection.getField(mapChunkPacket, List.class, 0); - private static final Reflection.FieldAccessor mapChunkData = Reflection.getField(mapChunkPacket, byte[].class, 0); + private static final Reflection.Field mapChunkX = Reflection.getField(mapChunkPacket, int.class, 0); + private static final Reflection.Field mapChunkZ = Reflection.getField(mapChunkPacket, int.class, 1); + private static final Reflection.Field mapChunkBitMask = Reflection.getField(mapChunkPacket, int.class, 2); + private static final Reflection.Field mapChunkBlockEntities = Reflection.getField(mapChunkPacket, List.class, 0); + private static final Reflection.Field mapChunkData = Reflection.getField(mapChunkPacket, byte[].class, 0); - private static final Class nbtTagCompound = Reflection.getClass("{nms.nbt}.NBTTagCompound"); - private static final Reflection.MethodInvoker nbtTagGetString = Reflection.getTypedMethod(nbtTagCompound, null, String.class, String.class); + private static final Class nbtTagCompound = Reflection.getClass("net.minecraft.nbt.CompoundTag"); + private static final Reflection.Method nbtTagGetString = Reflection.getTypedMethod(nbtTagCompound, null, String.class, String.class); @Override public BiFunction chunkHiderGenerator(TechHider techHider) { diff --git a/SpigotCore/SpigotCore_Main/build.gradle.kts b/SpigotCore/SpigotCore_Main/build.gradle.kts index 88825bc9..cc941d8c 100644 --- a/SpigotCore/SpigotCore_Main/build.gradle.kts +++ b/SpigotCore/SpigotCore_Main/build.gradle.kts @@ -35,7 +35,6 @@ dependencies { compileOnly(libs.spigotapi) compileOnly(libs.netty) compileOnly(libs.authlib) - compileOnly(libs.viaapi) compileOnly(libs.fastutil) implementation(libs.anvilgui) diff --git a/SpigotCore/SpigotCore_Main/src/com/comphenix/tinyprotocol/Reflection.java b/SpigotCore/SpigotCore_Main/src/com/comphenix/tinyprotocol/Reflection.java deleted file mode 100644 index 4bc66b5c..00000000 --- a/SpigotCore/SpigotCore_Main/src/com/comphenix/tinyprotocol/Reflection.java +++ /dev/null @@ -1,416 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2024 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 com.comphenix.tinyprotocol; - -import de.steamwar.core.Core; -import jdk.internal.misc.Unsafe; -import org.bukkit.Bukkit; - -import java.lang.reflect.*; -import java.util.Arrays; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * An utility class that simplifies reflection in Bukkit plugins. - * - * @author Kristian - */ -public final class Reflection { - /** - * An interface for invoking a specific constructor. - */ - public interface ConstructorInvoker { - /** - * Invoke a constructor for a specific class. - * - * @param arguments - the arguments to pass to the constructor. - * @return The constructed object. - */ - Object invoke(Object... arguments); - } - - /** - * An interface for invoking a specific method. - */ - public interface MethodInvoker { - /** - * Invoke a method on a specific target object. - * - * @param target - the target object, or NULL for a static method. - * @param arguments - the arguments to pass to the method. - * @return The return value, or NULL if is void. - */ - Object invoke(Object target, Object... arguments); - } - - /** - * An interface for retrieving the field content. - * - * @param - field type. - */ - public interface FieldAccessor { - /** - * Retrieve the content of a field. - * - * @param target - the target object, or NULL for a static field. - * @return The value of the field. - */ - T get(Object target); - - /** - * Set the content of a field. - * - * @param target - the target object, or NULL for a static field. - * @param value - the new value of the field. - */ - void set(Object target, Object value); - - /** - * Determine if the given object has this field. - * - * @param target - the object to test. - * @return TRUE if it does, FALSE otherwise. - */ - boolean hasField(Object target); - } - - // Deduce the net.minecraft.server.v* package - private static final String OBC_PREFIX = Bukkit.getServer().getClass().getPackage().getName(); - private static final String NMS_PREFIX = OBC_PREFIX.replace("org.bukkit.craftbukkit", "net.minecraft.server"); - private static final String VERSION = OBC_PREFIX.replace("org.bukkit.craftbukkit", "").replace(".", ""); - - // Variable replacement - private static final Pattern MATCH_VARIABLE = Pattern.compile("\\{([^\\}]+)\\}"); - - private Reflection() { - // Seal class - } - - /** - * Retrieve a field accessor for a specific field type and name. - * - * @param target - the target type. - * @param name - the name of the field, or NULL to ignore. - * @param fieldType - a compatible field type. - * @return The field accessor. - */ - public static FieldAccessor getField(Class target, String name, Class fieldType) { - return getField(target, name, fieldType, 0); - } - - /** - * Retrieve a field accessor for a specific field type and name. - * - * @param className - lookup name of the class, see {@link #getClass(String)}. - * @param name - the name of the field, or NULL to ignore. - * @param fieldType - a compatible field type. - * @return The field accessor. - */ - public static FieldAccessor getField(String className, String name, Class fieldType) { - return getField(getClass(className), name, fieldType, 0); - } - - /** - * Retrieve a field accessor for a specific field type and name. - * - * @param target - the target type. - * @param fieldType - a compatible field type. - * @param index - the number of compatible fields to skip. - * @return The field accessor. - */ - public static FieldAccessor getField(Class target, Class fieldType, int index) { - return getField(target, null, fieldType, index); - } - - /** - * Retrieve a field accessor for a specific field type and name. - * - * @param className - lookup name of the class, see {@link #getClass(String)}. - * @param fieldType - a compatible field type. - * @param index - the number of compatible fields to skip. - * @return The field accessor. - */ - public static FieldAccessor getField(String className, Class fieldType, int index) { - return getField(getClass(className), fieldType, index); - } - - public static FieldAccessor getField(Class target, Class fieldType, int index, Class... parameters) { - return getField(target, null, fieldType, index, parameters); - } - - private static FieldAccessor getField(Class target, String name, Class fieldType, int index, Class... parameters) { - for (final Field field : target.getDeclaredFields()) { - if(matching(field, name, fieldType, parameters) && index-- <= 0) { - field.setAccessible(true); - - return new FieldAccessor() { - @Override - @SuppressWarnings("unchecked") - public T get(Object target) { - try { - return (T) field.get(target); - } catch (IllegalAccessException e) { - throw new IllegalArgumentException("Cannot access reflection.", e); - } - } - - @Override - public void set(Object target, Object value) { - try { - field.set(target, value); - } catch (IllegalAccessException e) { - throw new IllegalArgumentException("Cannot access reflection.", e); - } - } - - @Override - public boolean hasField(Object target) { - // target instanceof DeclaringClass - return field.getDeclaringClass().isAssignableFrom(target.getClass()); - } - }; - } - } - - // Search in parent classes - if (target.getSuperclass() != null) - return getField(target.getSuperclass(), name, fieldType, index); - - throw new IllegalArgumentException("Cannot find field with type " + fieldType); - } - - private static boolean matching(Field field, String name, Class fieldType, Class... parameters) { - if(name != null && !field.getName().equals(name)) - return false; - - if(!fieldType.isAssignableFrom(field.getType())) - return false; - - if(parameters.length > 0) { - Type[] arguments = ((ParameterizedType)field.getGenericType()).getActualTypeArguments(); - - for(int i = 0; i < parameters.length; i++) { - if(arguments[i] instanceof ParameterizedType ? ((ParameterizedType) arguments[i]).getRawType() != parameters[i] : arguments[i] != parameters[i]) - return false; - } - } - return true; - } - - /** - * Search for the first publicly and privately defined method of the given name and parameter count. - * - * @param className - lookup name of the class, see {@link #getClass(String)}. - * @param methodName - the method name, or NULL to skip. - * @param params - the expected parameters. - * @return An object that invokes this specific method. - * @throws IllegalStateException If we cannot find this method. - */ - public static MethodInvoker getMethod(String className, String methodName, Class... params) { - return getTypedMethod(getClass(className), methodName, null, params); - } - - /** - * Search for the first publicly and privately defined method of the given name and parameter count. - * - * @param clazz - a class to start with. - * @param methodName - the method name, or NULL to skip. - * @param params - the expected parameters. - * @return An object that invokes this specific method. - * @throws IllegalStateException If we cannot find this method. - */ - public static MethodInvoker getMethod(Class clazz, String methodName, Class... params) { - return getTypedMethod(clazz, methodName, null, params); - } - - /** - * Search for the first publicly and privately defined method of the given name and parameter count. - * - * @param clazz - a class to start with. - * @param methodName - the method name, or NULL to skip. - * @param returnType - the expected return type, or NULL to ignore. - * @param params - the expected parameters. - * @return An object that invokes this specific method. - * @throws IllegalStateException If we cannot find this method. - */ - public static MethodInvoker getTypedMethod(Class clazz, String methodName, Class returnType, Class... params) { - for (final Method method : clazz.getDeclaredMethods()) { - if ((methodName == null || method.getName().equals(methodName)) - && (returnType == null || method.getReturnType().equals(returnType)) - && Arrays.equals(method.getParameterTypes(), params)) { - method.setAccessible(true); - - return (target, arguments) -> { - try { - return method.invoke(target, arguments); - } catch (Exception e) { - throw new IllegalArgumentException("Cannot invoke method " + method, e); - } - }; - } - } - - // Search in every superclass - if (clazz.getSuperclass() != null) - return getTypedMethod(clazz.getSuperclass(), methodName, returnType, params); - - throw new IllegalStateException(String.format("Unable to find method %s (%s).", methodName, Arrays.asList(params))); - } - - /** - * Search for the first publically and privately defined constructor of the given name and parameter count. - * - * @param className - lookup name of the class, see {@link #getClass(String)}. - * @param params - the expected parameters. - * @return An object that invokes this constructor. - * @throws IllegalStateException If we cannot find this method. - */ - public static ConstructorInvoker getConstructor(String className, Class... params) { - return getConstructor(getClass(className), params); - } - - /** - * Search for the first publically and privately defined constructor of the given name and parameter count. - * - * @param clazz - a class to start with. - * @param params - the expected parameters. - * @return An object that invokes this constructor. - * @throws IllegalStateException If we cannot find this method. - */ - public static ConstructorInvoker getConstructor(Class clazz, Class... params) { - for (final Constructor constructor : clazz.getDeclaredConstructors()) { - if (Arrays.equals(constructor.getParameterTypes(), params)) { - constructor.setAccessible(true); - - return arguments -> { - try { - return constructor.newInstance(arguments); - } catch (Exception e) { - throw new IllegalArgumentException("Cannot invoke constructor " + constructor, e); - } - }; - } - } - - throw new IllegalStateException(String.format("Unable to find constructor for %s (%s).", clazz, Arrays.asList(params))); - } - - /** - * Retrieve a class from its full name, without knowing its type on compile time. - *

- * This is useful when looking up fields by a NMS or OBC type. - *

- * - * @param lookupName - the class name with variables. - * @return The class. - */ - public static Class getUntypedClass(String lookupName) { - @SuppressWarnings({ "rawtypes", "unchecked" }) - Class clazz = (Class) getClass(lookupName); - return clazz; - } - - /** - * Retrieve a class from its full name. - *

- * Strings enclosed with curly brackets - such as {TEXT} - will be replaced according to the following table: - *

- * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - * - *
VariableContent
{nms}Actual package name of net.minecraft.server.VERSION
{obc}Actual pacakge name of org.bukkit.craftbukkit.VERSION
{version}The current Minecraft package VERSION, if any.
- * - * @param lookupName - the class name with variables. - * @return The looked up class. - * @throws IllegalArgumentException If a variable or class could not be found. - */ - public static Class getClass(String lookupName) { - try { - return Class.forName(expandVariables(lookupName)); - } catch (ClassNotFoundException e) { - throw new IllegalArgumentException("Cannot find " + expandVariables(lookupName), e); - } - } - - /** - * Expand variables such as "{nms}" and "{obc}" to their corresponding packages. - * - * @param name - the full name of the class. - * @return The expanded string. - */ - private static String expandVariables(String name) { - StringBuffer output = new StringBuffer(); - Matcher matcher = MATCH_VARIABLE.matcher(name); - - while (matcher.find()) { - String variable = matcher.group(1); - String replacement; - - // Expand all detected variables - if (variable.startsWith("nms")) { - if(Core.getVersion() >= 17) - replacement = "net.minecraft" + variable.substring(3); - else - replacement = NMS_PREFIX; - } else if ("obc".equals(variable)) - replacement = OBC_PREFIX; - else if ("version".equals(variable)) - replacement = VERSION; - else - throw new IllegalArgumentException("Unknown variable: " + variable); - - // Assume the expanded variables are all packages, and append a dot - if (replacement.length() > 0 && matcher.end() < name.length() && name.charAt(matcher.end()) != '.') - replacement += "."; - matcher.appendReplacement(output, Matcher.quoteReplacement(replacement)); - } - - matcher.appendTail(output); - return output.toString(); - } - - @SuppressWarnings("deprecation") - public static Object newInstance(Class clazz) { - try { - if (Core.getVersion() > 15) { - return Unsafe.getUnsafe().allocateInstance(clazz); - } else { - return clazz.newInstance(); - } - } catch (InstantiationException | IllegalAccessException e) { - throw new SecurityException("Could not create object", e); - } - } -} diff --git a/SpigotCore/SpigotCore_Main/src/com/comphenix/tinyprotocol/TinyProtocol.java b/SpigotCore/SpigotCore_Main/src/com/comphenix/tinyprotocol/TinyProtocol.java index 7019c26d..3a0124e0 100644 --- a/SpigotCore/SpigotCore_Main/src/com/comphenix/tinyprotocol/TinyProtocol.java +++ b/SpigotCore/SpigotCore_Main/src/com/comphenix/tinyprotocol/TinyProtocol.java @@ -19,7 +19,8 @@ package com.comphenix.tinyprotocol; -import com.comphenix.tinyprotocol.Reflection.FieldAccessor; +import de.steamwar.Reflection; +import de.steamwar.Reflection.Field; import de.steamwar.core.Core; import io.netty.channel.Channel; import io.netty.channel.ChannelDuplexHandler; @@ -42,19 +43,19 @@ import java.util.logging.Level; public class TinyProtocol implements Listener { - private static final Class craftServer = Reflection.getClass("{obc}.CraftServer"); - private static final Class dedicatedPlayerList = Reflection.getClass("{nms.server.dedicated}.DedicatedPlayerList"); - private static final FieldAccessor getPlayerList = Reflection.getField(craftServer, dedicatedPlayerList, 0); - private static final Class playerList = Reflection.getClass("{nms.server.players}.PlayerList"); - private static final Class minecraftServer = Reflection.getClass("{nms.server}.MinecraftServer"); - private static final FieldAccessor getMinecraftServer = Reflection.getField(playerList, minecraftServer, 0); - public static final Class serverConnection = Reflection.getClass("{nms.server.network}.ServerConnection"); - private static final FieldAccessor getServerConnection = Reflection.getField(minecraftServer, serverConnection, 0); + private static final Class craftServer = Reflection.getClass("org.bukkit.craftbukkit.CraftServer"); + private static final Class dedicatedPlayerList = Reflection.getClass("net.minecraft.server.dedicated.DedicatedPlayerList"); + private static final Field getPlayerList = Reflection.getField(craftServer, dedicatedPlayerList, 0); + private static final Class playerList = Reflection.getClass("net.minecraft.server.players.PlayerList"); + private static final Class minecraftServer = Reflection.getClass("net.minecraft.server.MinecraftServer"); + private static final Field getMinecraftServer = Reflection.getField(playerList, minecraftServer, 0); + public static final Class serverConnection = Reflection.getClass("net.minecraft.server.network.ServerConnectionListener"); + private static final Field getServerConnection = Reflection.getField(minecraftServer, serverConnection, 0); public static Object getServerConnection(Plugin plugin) { return getServerConnection.get(getMinecraftServer.get(getPlayerList.get(plugin.getServer()))); } - private static final Class networkManager = Reflection.getClass("{nms.network}.NetworkManager"); - public static final FieldAccessor networkManagers = Reflection.getField(serverConnection, List.class, 0, networkManager); + private static final Class networkManager = Reflection.getClass("net.minecraft.network.NetworkManager"); + public static final Field networkManagers = Reflection.getField(serverConnection, List.class, 0, networkManager); public static final TinyProtocol instance = new TinyProtocol(Core.getInstance()); private static int id = 0; @@ -136,8 +137,8 @@ public class TinyProtocol implements Listener { } } - private static final FieldAccessor getChannel = Reflection.getField(networkManager, Channel.class, 0); - private static final FieldAccessor getUUID = Reflection.getField(networkManager, UUID.class, 0); + private static final Field getChannel = Reflection.getField(networkManager, Channel.class, 0); + private static final Field getUUID = Reflection.getField(networkManager, UUID.class, 0); private final class PacketInterceptor extends ChannelDuplexHandler { private final Player player; diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/Reflection.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/Reflection.java new file mode 100644 index 00000000..92e3d3fd --- /dev/null +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/Reflection.java @@ -0,0 +1,318 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2024 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; + +import de.steamwar.core.Core; +import jdk.internal.misc.Unsafe; +import lombok.AllArgsConstructor; +import lombok.experimental.UtilityClass; +import org.bukkit.Bukkit; + +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; + + +@UtilityClass +public final class Reflection { + + public static final int MAJOR_VERSION; + public static final int MINOR_VERSION; + static { + String[] version = Bukkit.getServer().getBukkitVersion().split("-")[0].split("\\."); + MAJOR_VERSION = Integer.parseInt(version[1]); + MINOR_VERSION = version.length > 2 ? Integer.parseInt(version[2]) : 0; + } + + private static final String ORG_BUKKIT_CRAFTBUKKIT = Bukkit.getServer().getClass().getPackage().getName(); + public static final String LEGACY_NET_MINECRAFT_SERVER = ORG_BUKKIT_CRAFTBUKKIT.replace("org.bukkit.craftbukkit", "net.minecraft.server"); + + private static final Map spigotClassnames = new HashMap<>(); + static { + // See https://mappings.dev for complete mappings + spigotClassnames.put("net.minecraft.Util", "net.minecraft.SystemUtils"); + + spigotClassnames.put("net.minecraft.core.BlockPos", "net.minecraft.core.BlockPosition"); + spigotClassnames.put("net.minecraft.core.DefaultedRegistry", "net.minecraft.core.RegistryBlocks"); + spigotClassnames.put("net.minecraft.core.IdMapper", "net.minecraft.core.RegistryBlockID"); + spigotClassnames.put("net.minecraft.core.Vec3i", "net.minecraft.core.BaseBlockPosition"); + + spigotClassnames.put("net.minecraft.nbt.CompoundTag", "net.minecraft.nbt.NBTTagCompound"); + + spigotClassnames.put("net.minecraft.network.Connection", "net.minecraft.network.NetworkManager"); + + spigotClassnames.put("net.minecraft.network.chat.Component", "net.minecraft.network.chat.IChatBaseComponent"); + + spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundAddEntityPacket", "net.minecraft.network.protocol.game.PacketPlayOutSpawnEntity"); + spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundAddPlayerPacket", "net.minecraft.network.protocol.game.PacketPlayOutNamedEntitySpawn"); + spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundAnimatePacket", "net.minecraft.network.protocol.game.PacketPlayOutAnimation"); + spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundBlockDestructionPacket", "net.minecraft.network.protocol.game.PacketPlayOutBlockBreak"); + spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket", "net.minecraft.network.protocol.game.PacketPlayOutTileEntityData"); + spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundBlockEventPacket", "net.minecraft.network.protocol.game.PacketPlayOutBlockAction"); + spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundBlockUpdatePacket", "net.minecraft.network.protocol.game.PacketPlayOutBlockChange"); + spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundContainerClosePacket", "net.minecraft.network.protocol.game.PacketPlayOutCloseWindow"); + spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundEntityEventPacket", "net.minecraft.network.protocol.game.PacketPlayOutEntityStatus"); + spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundExplodePacket", "net.minecraft.network.protocol.game.PacketPlayOutExplosion"); + spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundGameEventPacket", "net.minecraft.network.protocol.game.PacketPlayOutGameStateChange"); + spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundLevelChunkPacketData$BlockEntityInfo", "net.minecraft.network.protocol.game.ClientboundLevelChunkPacketData$a"); + spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundLevelEventPacket", "net.minecraft.network.protocol.game.PacketPlayOutWorldEvent"); + spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundLevelParticlesPacket", "net.minecraft.network.protocol.game.PacketPlayOutWorldParticles"); + spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundMoveEntityPacket", "net.minecraft.network.protocol.game.PacketPlayOutEntity"); + spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundMoveEntityPacket$Pos", "net.minecraft.network.protocol.game.PacketPlayOutEntity$PacketPlayOutRelEntityMove"); + spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundMoveEntityPacket$PosRot", "net.minecraft.network.protocol.game.PacketPlayOutEntity$PacketPlayOutRelEntityMoveLook"); + spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundMoveEntityPacket$Rot", "net.minecraft.network.protocol.game.PacketPlayOutEntity$PacketPlayOutEntityLook"); + spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundOpenSignEditorPacket", "net.minecraft.network.protocol.game.PacketPlayOutOpenSignEditor"); + spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket", "net.minecraft.network.protocol.game.PacketPlayOutEntityDestroy"); + spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundRotateHeadPacket", "net.minecraft.network.protocol.game.PacketPlayOutEntityHeadRotation"); + spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundSectionBlocksUpdatePacket", "net.minecraft.network.protocol.game.PacketPlayOutMultiBlockChange"); + spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket", "net.minecraft.network.protocol.game.PacketPlayOutEntityMetadata"); + spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundSetEntityMotionPacket", "net.minecraft.network.protocol.game.PacketPlayOutEntityVelocity"); + spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket", "net.minecraft.network.protocol.game.PacketPlayOutEntityEquipment"); + spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundSetObjectivePacket", "net.minecraft.network.protocol.game.PacketPlayOutScoreboardObjective"); + spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundSetScorePacket", "net.minecraft.network.protocol.game.PacketPlayOutScoreboardScore"); + spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundSoundPacket", "net.minecraft.network.protocol.game.PacketPlayOutNamedSoundEffect"); + spigotClassnames.put("net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket", "net.minecraft.network.protocol.game.PacketPlayOutEntityTeleport"); + spigotClassnames.put("net.minecraft.network.protocol.game.ServerboundContainerClickPacket", "net.minecraft.network.protocol.game.PacketPlayInWindowClick"); + spigotClassnames.put("net.minecraft.network.protocol.game.ServerboundInteractPacket", "net.minecraft.network.protocol.game.PacketPlayInUseEntity"); + spigotClassnames.put("net.minecraft.network.protocol.game.ServerboundInteractPacket$Action", "net.minecraft.network.protocol.game.PacketPlayInUseEntity$EnumEntityUseAction"); + spigotClassnames.put("net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$Pos", "net.minecraft.network.protocol.game.PacketPlayInFlying$PacketPlayInPosition"); + spigotClassnames.put("net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$PosRot", "net.minecraft.network.protocol.game.PacketPlayInFlying$PacketPlayInPositionLook"); + spigotClassnames.put("net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$Rot", "net.minecraft.network.protocol.game.PacketPlayInFlying$PacketPlayInLook"); + spigotClassnames.put("net.minecraft.network.protocol.game.ServerboundPlayerActionPacket", "net.minecraft.network.protocol.game.PacketPlayInBlockDig"); + spigotClassnames.put("net.minecraft.network.protocol.game.ServerboundSetCreativeModeSlotPacket", "net.minecraft.network.protocol.game.PacketPlayInSetCreativeSlot"); + spigotClassnames.put("net.minecraft.network.protocol.game.ServerboundSignUpdatePacket", "net.minecraft.network.protocol.game.PacketPlayInUpdateSign"); + spigotClassnames.put("net.minecraft.network.protocol.game.ServerboundUseItemPacket", "net.minecraft.network.protocol.game.PacketPlayInBlockPlace"); + spigotClassnames.put("net.minecraft.network.protocol.game.ServerboundUseItemOnPacket", "net.minecraft.network.protocol.game.PacketPlayInUseItem"); + + spigotClassnames.put("net.minecraft.network.syncher.EntityDataAccessor", "net.minecraft.network.syncher.DataWatcherObject"); + spigotClassnames.put("net.minecraft.network.syncher.EntityDataSerializer", "net.minecraft.network.syncher.DataWatcherSerializer"); + spigotClassnames.put("net.minecraft.network.syncher.EntityDataSerializers", "net.minecraft.network.syncher.DataWatcherRegistry"); + spigotClassnames.put("net.minecraft.network.syncher.SynchedEntityData$DataItem", "net.minecraft.network.syncher.DataWatcher$Item"); + + spigotClassnames.put("net.minecraft.server.ServerScoreboard$Method", "net.minecraft.server.ScoreboardServer$Action"); + + spigotClassnames.put("net.minecraft.server.level.ChunkMap", "net.minecraft.server.level.PlayerChunkMap"); + spigotClassnames.put("net.minecraft.server.level.ChunkMap$TrackedEntity", "net.minecraft.server.level.PlayerChunkMap$EntityTracker"); + spigotClassnames.put("net.minecraft.server.level.ServerChunkCache", "net.minecraft.server.level.ChunkProviderServer"); + spigotClassnames.put("net.minecraft.server.level.ServerLevel", "net.minecraft.server.level.WorldServer"); + spigotClassnames.put("net.minecraft.server.level.ServerPlayer", "net.minecraft.server.level.EntityPlayer"); + + spigotClassnames.put("net.minecraft.server.network.ServerConnectionListener", "net.minecraft.server.network.ServerConnection"); + + spigotClassnames.put("net.minecraft.world.InteractionHand", "net.minecraft.world.EnumHand"); + + spigotClassnames.put("net.minecraft.world.entity.EntityType", "net.minecraft.world.entity.EntityTypes"); + spigotClassnames.put("net.minecraft.world.entity.Pose", "net.minecraft.world.entity.EntityPose"); + + spigotClassnames.put("net.minecraft.world.entity.item.PrimedTnt", "net.minecraft.world.entity.item.EntityTNTPrimed"); + + spigotClassnames.put("net.minecraft.world.entity.projectile.AbstractArrow", "net.minecraft.world.entity.projectile.EntityArrow"); + + spigotClassnames.put("net.minecraft.world.level.GameType", "net.minecraft.world.level.EnumGamemode"); + spigotClassnames.put("net.minecraft.world.level.LevelAccessor", "net.minecraft.world.level.GeneratorAccess"); + + spigotClassnames.put("net.minecraft.world.level.block.state.BlockState", "net.minecraft.world.level.block.state.IBlockData"); + spigotClassnames.put("net.minecraft.world.level.block.state.StateDefinition", "net.minecraft.world.level.block.state.BlockStateList"); + + spigotClassnames.put("net.minecraft.world.level.chunk.LevelChunk", "net.minecraft.world.level.chunk.Chunk"); + + spigotClassnames.put("net.minecraft.world.level.material.FlowingFluid", "net.minecraft.world.level.material.FluidTypeFlowing"); + spigotClassnames.put("net.minecraft.world.level.material.Fluids", "net.minecraft.world.level.material.FluidTypes"); + spigotClassnames.put("net.minecraft.world.level.material.FluidState", "net.minecraft.world.level.material.Fluid"); + + spigotClassnames.put("net.minecraft.world.phys.BlockHitResult", "net.minecraft.world.phys.MovingObjectPositionBlock"); + spigotClassnames.put("net.minecraft.world.phys.Vec3", "net.minecraft.world.phys.Vec3D"); + + spigotClassnames.put("net.minecraft.resources.ResourceLocation", "net.minecraft.resources.MinecraftKey"); + + spigotClassnames.put("net.minecraft.util.ProgressListener", "net.minecraft.util.IProgressUpdate"); + } + + public static Class getClass(String name) { + try { + if(name.startsWith("org.bukkit.craftbukkit")) { + return Class.forName(ORG_BUKKIT_CRAFTBUKKIT + name.substring(22)); + } else if(MAJOR_VERSION < 17 && name.startsWith("net.minecraft")) { + return Class.forName(LEGACY_NET_MINECRAFT_SERVER + "." + spigotClassnames.getOrDefault(name, name).split("[.](?=[^.]*$)")[1]); + } else if(MAJOR_VERSION < 21 || MINOR_VERSION < 4) { + return Class.forName(spigotClassnames.getOrDefault(name, name)); + } else { + return Class.forName(name); + } + } catch (ClassNotFoundException e) { + throw new IllegalArgumentException("Cannot find " + name, e); + } + } + + @AllArgsConstructor + public static class Field { + private final java.lang.reflect.Field f; + + @SuppressWarnings("unchecked") + public T get(Object target) { + try { + return (T) f.get(target); + } catch (IllegalAccessException e) { + throw new IllegalArgumentException("Cannot read field", e); + } + } + + public void set(Object target, Object value) { + try { + f.set(target, value); + } catch (IllegalAccessException e) { + throw new IllegalArgumentException("Cannot write field", e); + } + } + } + + public static Field getField(Class target, String name, Class fieldType) { + return getField(target, name, fieldType, 0); + } + + public static Field getField(String className, String name, Class fieldType) { + return getField(getClass(className), name, fieldType, 0); + } + + public static Field getField(Class target, Class fieldType, int index) { + return getField(target, null, fieldType, index); + } + + public static Field getField(String className, Class fieldType, int index) { + return getField(getClass(className), fieldType, index); + } + + public static Field getField(Class target, Class fieldType, int index, Class... parameters) { + return getField(target, null, fieldType, index, parameters); + } + + private static Field getField(Class target, String name, Class fieldType, int index, Class... parameters) { + for (final java.lang.reflect.Field field : target.getDeclaredFields()) { + if(matching(field, name, fieldType, parameters) && index-- <= 0) { + field.setAccessible(true); + return new Field<>(field); + } + } + + // Search in parent classes + if (target.getSuperclass() != null) + return getField(target.getSuperclass(), name, fieldType, index); + + throw new IllegalArgumentException("Cannot find field with type " + fieldType); + } + + private static boolean matching(java.lang.reflect.Field field, String name, Class fieldType, Class... parameters) { + if(name != null && !field.getName().equals(name)) + return false; + + if(!fieldType.isAssignableFrom(field.getType())) + return false; + + if(parameters.length > 0) { + Type[] arguments = ((ParameterizedType)field.getGenericType()).getActualTypeArguments(); + + for(int i = 0; i < parameters.length; i++) { + if(arguments[i] instanceof ParameterizedType ? ((ParameterizedType) arguments[i]).getRawType() != parameters[i] : arguments[i] != parameters[i]) + return false; + } + } + return true; + } + + @AllArgsConstructor + public static class Method { + private final java.lang.reflect.Method m; + + public Object invoke(Object target, Object... arguments) { + try { + return m.invoke(target, arguments); + } catch (Exception e) { + throw new IllegalArgumentException("Cannot invoke method " + m, e); + } + } + } + + public static Method getMethod(String className, String methodName, Class... params) { + return getTypedMethod(getClass(className), methodName, null, params); + } + + public static Method getMethod(Class clazz, String methodName, Class... params) { + return getTypedMethod(clazz, methodName, null, params); + } + + public static Method getTypedMethod(Class clazz, String methodName, Class returnType, Class... params) { + for (final java.lang.reflect.Method method : clazz.getDeclaredMethods()) { + if ((methodName == null || method.getName().equals(methodName)) + && (returnType == null || method.getReturnType().equals(returnType)) + && Arrays.equals(method.getParameterTypes(), params)) { + method.setAccessible(true); + return new Method(method); + } + } + + // Search in every superclass + if (clazz.getSuperclass() != null) + return getTypedMethod(clazz.getSuperclass(), methodName, returnType, params); + + throw new IllegalArgumentException(String.format("Cannot find method %s (%s).", methodName, Arrays.asList(params))); + } + + @AllArgsConstructor + public static class Constructor { + private final java.lang.reflect.Constructor c; + + public Object invoke(Object... arguments) { + try { + return c.newInstance(arguments); + } catch (Exception e) { + throw new IllegalArgumentException("Cannot invoke constructor " + c, e); + } + } + } + + public static Constructor getConstructor(String className, Class... params) { + return getConstructor(getClass(className), params); + } + + public static Constructor getConstructor(Class clazz, Class... params) { + for (final java.lang.reflect.Constructor constructor : clazz.getDeclaredConstructors()) { + if (Arrays.equals(constructor.getParameterTypes(), params)) { + constructor.setAccessible(true); + return new Constructor(constructor); + } + } + + throw new IllegalStateException(String.format("Unable to find constructor for %s (%s).", clazz, Arrays.asList(params))); + } + + public static Object newInstance(Class clazz) { + try { + if (Core.getVersion() > 15) { + return Unsafe.getUnsafe().allocateInstance(clazz); + } else { + return clazz.newInstance(); + } + } catch (InstantiationException | IllegalAccessException e) { + throw new SecurityException("Could not create object", e); + } + } +} diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CheckpointUtilsJ9.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CheckpointUtilsJ9.java index cde82084..e5edcfae 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CheckpointUtilsJ9.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CheckpointUtilsJ9.java @@ -19,9 +19,8 @@ package de.steamwar.core; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; -import com.viaversion.viaversion.api.Via; import de.steamwar.sql.internal.Statement; import io.netty.channel.ChannelFuture; import org.bukkit.Bukkit; @@ -91,15 +90,14 @@ class CheckpointUtilsJ9 { } - private static final Reflection.FieldAccessor channelFutures = Reflection.getField(TinyProtocol.serverConnection, List.class, 0, ChannelFuture.class); - private static final Reflection.MethodInvoker bind = Reflection.getMethod(TinyProtocol.serverConnection, null, InetAddress.class, int.class); + private static final Reflection.Field channelFutures = Reflection.getField(TinyProtocol.serverConnection, List.class, 0, ChannelFuture.class); + private static final Reflection.Method bind = Reflection.getMethod(TinyProtocol.serverConnection, null, InetAddress.class, int.class); private static void freezeInternal(Path path) throws Exception { Bukkit.getPluginManager().callEvent(new CRIUSleepEvent()); Bukkit.getWorlds().forEach(FlatteningWrapper.impl::syncSave); Statement.closeAll(); // Close socket - Via.getManager().getInjector().uninject(); Object serverConnection = TinyProtocol.getServerConnection(Core.getInstance()); List channels = channelFutures.get(serverConnection); for(Object future : channels) { @@ -140,7 +138,6 @@ class CheckpointUtilsJ9 { ((ChannelFuture) future).channel().config().setAutoRead(true); } } - Via.getManager().getInjector().inject(); Bukkit.getPluginManager().callEvent(new CRIUWakeupEvent()); Core.getInstance().getLogger().log(Level.INFO, "Checkpoint restored"); diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CommandRemover.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CommandRemover.java index bbce1378..52787db6 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CommandRemover.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/CommandRemover.java @@ -19,7 +19,7 @@ package de.steamwar.core; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import lombok.experimental.UtilityClass; import org.bukkit.Bukkit; import org.bukkit.command.Command; @@ -29,8 +29,8 @@ import java.util.Map; @UtilityClass public class CommandRemover { - private static final Reflection.FieldAccessor commandMap = Reflection.getField("{obc}.CraftServer", "commandMap", SimpleCommandMap.class); - private static final Reflection.FieldAccessor knownCommands = Reflection.getField(SimpleCommandMap.class, "knownCommands", Map.class); + private static final Reflection.Field commandMap = Reflection.getField("org.bukkit.craftbukkit.CraftServer", "commandMap", SimpleCommandMap.class); + private static final Reflection.Field knownCommands = Reflection.getField(SimpleCommandMap.class, "knownCommands", Map.class); public static void removeAll(String... cmds) { Map knownCmds = knownCommands.get(commandMap.get(Bukkit.getServer())); for (String cmd : cmds) { diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/Core.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/Core.java index 9c1e51ef..4e7b7576 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/Core.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/Core.java @@ -20,6 +20,7 @@ package de.steamwar.core; import com.comphenix.tinyprotocol.TinyProtocol; +import de.steamwar.Reflection; import de.steamwar.command.*; import de.steamwar.core.authlib.AuthlibInjector; import de.steamwar.core.events.*; @@ -44,10 +45,8 @@ public class Core extends JavaPlugin{ public static final Message MESSAGE = new Message("SpigotCore", Core.class.getClassLoader()); - private static final int VERSION = Integer.parseInt(Bukkit.getServer().getClass().getPackage().getName().split("_", 3)[1]); - public static int getVersion(){ - return VERSION; + return Reflection.MAJOR_VERSION; } private static JavaPlugin instance; @@ -100,9 +99,6 @@ public class Core extends JavaPlugin{ CheckpointUtils.signalHandler(); new AntiNocom(); - if(Core.getVersion() < 17 && Bukkit.getPluginManager().getPlugin("ViaVersion") != null) - new PartialChunkFixer(); - if(Core.getVersion() >= 19) new ServerDataHandler(); diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/ErrorHandler.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/ErrorHandler.java index c9585847..5a801f11 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/ErrorHandler.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/ErrorHandler.java @@ -19,7 +19,7 @@ package de.steamwar.core; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import de.steamwar.sql.SWException; import java.io.ByteArrayOutputStream; @@ -40,7 +40,7 @@ public class ErrorHandler extends Handler { Logger.getLogger("").addHandler(this); Class watchdogThread = Reflection.getClass("org.spigotmc.WatchdogThread"); - Reflection.FieldAccessor getInstance = Reflection.getField(watchdogThread, watchdogThread, 0); + Reflection.Field getInstance = Reflection.getField(watchdogThread, watchdogThread, 0); Thread watchdog = (Thread) getInstance.get(null); watchdogThreadId = watchdog.getId(); } diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/FlatteningWrapper.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/FlatteningWrapper.java index 479760cf..b4d954f8 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/FlatteningWrapper.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/FlatteningWrapper.java @@ -19,7 +19,7 @@ package de.steamwar.core; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.entity.EntityType; @@ -29,8 +29,8 @@ import org.bukkit.inventory.ItemStack; public class FlatteningWrapper { private FlatteningWrapper() {} - public static final Class scoreboardObjective = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutScoreboardObjective"); - public static final Class scoreboardScore = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutScoreboardScore"); + public static final Class scoreboardObjective = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundSetObjectivePacket"); + public static final Class scoreboardScore = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundSetScorePacket"); public static final IFlatteningWrapper impl = VersionDependent.getVersionImpl(Core.getInstance()); diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/ProtocolWrapper.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/ProtocolWrapper.java index e6787497..9c226741 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/ProtocolWrapper.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/ProtocolWrapper.java @@ -19,7 +19,7 @@ package de.steamwar.core; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import com.mojang.authlib.GameProfile; import org.bukkit.GameMode; @@ -27,16 +27,16 @@ import java.util.function.LongSupplier; public interface ProtocolWrapper { - Class itemStack = Reflection.getClass("{nms.world.item}.ItemStack"); - Class spawnPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutSpawnEntity"); - Class spawnLivingPacket = Core.getVersion() > 18 ? ProtocolWrapper.spawnPacket : Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutSpawnEntityLiving"); - Class equipmentPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityEquipment"); + Class itemStack = Reflection.getClass("net.minecraft.world.item.ItemStack"); + Class spawnPacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundAddEntityPacket"); + Class spawnLivingPacket = Core.getVersion() > 18 ? ProtocolWrapper.spawnPacket : Reflection.getClass("net.minecraft.network.protocol.game.PacketPlayOutSpawnEntityLiving"); + Class equipmentPacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket"); - Class enumGamemode = Reflection.getClass(Core.getVersion() > 9 ? "{nms.world.level}.EnumGamemode" : "{nms}.WorldSettings$EnumGamemode"); - Reflection.MethodInvoker getGameModeById = Reflection.getTypedMethod(enumGamemode, null, enumGamemode, int.class); + Class enumGamemode = Reflection.getClass(Core.getVersion() > 9 ? "net.minecraft.world.level.GameType" : "net.minecraft.WorldSettings$EnumGamemode"); + Reflection.Method getGameModeById = Reflection.getTypedMethod(enumGamemode, null, enumGamemode, int.class); // 0: hand, 1: offhand, 2: feet, 3: legs, 4: chest, 5: head - Object[] itemSlots = Core.getVersion() > 8 ? Reflection.getClass("{nms.world.entity}.EnumItemSlot").getEnumConstants() : new Integer[]{0, 0, 1, 2, 3, 4}; + Object[] itemSlots = Core.getVersion() > 8 ? Reflection.getClass("net.minecraft.world.entity.EnumItemSlot").getEnumConstants() : new Integer[]{0, 0, 1, 2, 3, 4}; ProtocolWrapper impl = VersionDependent.getVersionImpl(Core.getInstance()); @@ -45,7 +45,7 @@ public interface ProtocolWrapper { Object playerInfoPacketConstructor(PlayerInfoAction action, GameProfile profile, GameMode mode); default void initTPSWarp(LongSupplier longSupplier) { - Class systemUtils = Reflection.getClass("{nms}.SystemUtils"); + Class systemUtils = Reflection.getClass("net.minecraft.Util"); Reflection.getField(systemUtils, LongSupplier.class, 0).set(systemUtils, (LongSupplier) () -> System.nanoTime() + longSupplier.getAsLong()); } diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java index 54a5f7e2..f6714e0e 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/TPSWatcher.java @@ -19,7 +19,7 @@ package de.steamwar.core; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import org.bukkit.Bukkit; public class TPSWatcher { @@ -79,9 +79,9 @@ public class TPSWatcher { } } - private static final Class minecraftServer = Reflection.getClass("{nms.server}.MinecraftServer"); - private static final Reflection.MethodInvoker getServer = Reflection.getTypedMethod(minecraftServer, "getServer", minecraftServer); - private static final Reflection.FieldAccessor recentTps = Reflection.getField(minecraftServer, "recentTps", double[].class); + private static final Class minecraftServer = Reflection.getClass("net.minecraft.server.MinecraftServer"); + private static final Reflection.Method getServer = Reflection.getTypedMethod(minecraftServer, "getServer", minecraftServer); + private static final Reflection.Field recentTps = Reflection.getField(minecraftServer, "recentTps", double[].class); private static double[] getSpigotTPS() { return recentTps.get(getServer.invoke(null)); } diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditWrapper.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditWrapper.java index 87906944..9928b947 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditWrapper.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/WorldEditWrapper.java @@ -26,6 +26,7 @@ import com.sk89q.worldedit.session.ClipboardHolder; import de.steamwar.sql.NoClipboardException; import com.sk89q.worldedit.math.transform.Transform; import com.sk89q.worldedit.regions.Region; +import de.steamwar.sql.NodeData; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.util.Vector; @@ -36,20 +37,22 @@ import java.util.logging.Level; public interface WorldEditWrapper { WorldEditWrapper impl = VersionDependent.getVersionImpl(Core.getInstance()); - InputStream getPlayerClipboard(Player player, boolean schemFormat); - void setPlayerClipboard(Player player, InputStream is, boolean schemFormat); - Clipboard getClipboard(InputStream is, boolean schemFormat) throws IOException; + InputStream getPlayerClipboard(Player player); + void setPlayerClipboard(Player player, InputStream is, NodeData.SchematicFormat schemFormat); + Clipboard getClipboard(InputStream is, NodeData.SchematicFormat schemFormat) throws IOException; Vector getOrigin(Clipboard clipboard); Vector getMinimum(Region region); Vector getMaximum(Region region); Vector applyTransform(Vector vector, Transform transform); + NodeData.SchematicFormat getNativeFormat(); + static WorldEditPlugin getWorldEditPlugin() { return (WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit"); } - public static InputStream getPlayerClipboard(Player player, boolean schemFormat, SchematicWriter consumer) { + static InputStream getPlayerClipboard(Player player, SchematicWriter consumer) { ClipboardHolder clipboardHolder; try { clipboardHolder = WorldEditWrapper.getWorldEditPlugin().getSession(player).getClipboard(); @@ -85,7 +88,7 @@ public interface WorldEditWrapper { return inputStream; } - public static interface SchematicWriter { + interface SchematicWriter { void write(OutputStream outputStream, Clipboard clipboard, ClipboardHolder holder) throws IOException; } } diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/authlib/AuthlibInjector.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/authlib/AuthlibInjector.java index 0c9c188b..b9c4011a 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/authlib/AuthlibInjector.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/authlib/AuthlibInjector.java @@ -19,7 +19,7 @@ package de.steamwar.core.authlib; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import com.mojang.authlib.GameProfileRepository; import com.mojang.authlib.yggdrasil.YggdrasilGameProfileRepository; @@ -27,8 +27,8 @@ public class AuthlibInjector { private AuthlibInjector() {} public static void inject() { - Class minecraftServerClass = Reflection.getClass("{nms.server}.MinecraftServer"); - Reflection.FieldAccessor gameProfile = Reflection.getField(minecraftServerClass, GameProfileRepository.class, 0); + Class minecraftServerClass = Reflection.getClass("net.minecraft.server.MinecraftServer"); + Reflection.Field gameProfile = Reflection.getField(minecraftServerClass, GameProfileRepository.class, 0); Object minecraftServer = Reflection.getTypedMethod(minecraftServerClass, "getServer", minecraftServerClass).invoke(null); gameProfile.set(minecraftServer, new SteamwarGameProfileRepository((YggdrasilGameProfileRepository) gameProfile.get(minecraftServer))); } diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/events/AntiNocom.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/events/AntiNocom.java index ea7759da..14f8badc 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/events/AntiNocom.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/events/AntiNocom.java @@ -19,7 +19,7 @@ package de.steamwar.core.events; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; import de.steamwar.core.Core; import de.steamwar.sql.SWException; @@ -54,13 +54,13 @@ public class AntiNocom implements Listener { } private void registerUseItem() { - Class useItem = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInUseItem"); + Class useItem = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundUseItemOnPacket"); 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); + Class movingObjectPositionBlock = Reflection.getClass("net.minecraft.world.phys.BlockHitResult"); + Reflection.Field useItemPosition = Reflection.getField(useItem, movingObjectPositionBlock, 0); + Reflection.Field movingBlockPosition = Reflection.getField(movingObjectPositionBlock, TechHider.blockPosition, 0); getPosition = (packet) -> movingBlockPosition.get(useItemPosition.get(packet)); } else { @@ -73,8 +73,8 @@ public class AntiNocom implements Listener { }); } - 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 static final Class blockDig = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundPlayerActionPacket"); + private static final Reflection.Field digPosition = Reflection.getField(blockDig, TechHider.blockPosition, 0); private Object onDig(Player player, Object packet) { Object pos = digPosition.get(packet); return isValid(player, "Dig", TechHider.blockPositionX.get(pos), TechHider.blockPositionZ.get(pos)) ? packet : null; diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/events/PartialChunkFixer.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/events/PartialChunkFixer.java deleted file mode 100644 index 6efab3c5..00000000 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/events/PartialChunkFixer.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2022 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 com.viaversion.viaversion.api.Via; -import com.viaversion.viaversion.api.ViaAPI; -import de.steamwar.core.Core; -import de.steamwar.core.CraftbukkitWrapper; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; - -import java.util.ArrayList; -import java.util.List; - -/** - * TinyProtocol can't translate BlockEntities during 1.16 to 1.17 conversions du to removed partial chunk update support. This class cancels PartialChunkUpdates for this players and sends them a complete chunk instead. - * This class can only be loaded on 1.9 to 1.15 with active ViaVersion. - **/ -public class PartialChunkFixer { - - private static final int PROTOCOL1_17 = 755; - private static final Class mapChunk = Reflection.getClass("{nms}.PacketPlayOutMapChunk"); - private static final Reflection.FieldAccessor fullChunkFlag = Reflection.getField(mapChunk, boolean.class, 0); - private static final Reflection.FieldAccessor chunkX = Reflection.getField(mapChunk, int.class, 0); - private static final Reflection.FieldAccessor chunkZ = Reflection.getField(mapChunk, int.class, 1); - - private final ViaAPI via = Via.getAPI(); - - private final List chunksToResend = new ArrayList<>(); - - public PartialChunkFixer() { - TinyProtocol.instance.addFilter(mapChunk, this::chunkFilter); - Bukkit.getScheduler().runTaskTimer(Core.getInstance(), () -> { - synchronized (chunksToResend) { - for(ResendChunk chunk : chunksToResend) { - CraftbukkitWrapper.impl.sendChunk(chunk.player, chunk.x, chunk.z); - } - chunksToResend.clear(); - } - }, 1, 1); - } - - private Object chunkFilter(Player player, Object packet) { - if(via.getPlayerVersion(player) >= PROTOCOL1_17 && !fullChunkFlag.get(packet)) { - // partial chunk update - synchronized (chunksToResend) { - chunksToResend.add(new ResendChunk(player, chunkX.get(packet), chunkZ.get(packet))); - } - return null; - } - return packet; - } - - private static class ResendChunk { - private final Player player; - private final int x; - private final int z; - - private ResendChunk(Player player, int x, int z) { - this.player = player; - this.x = x; - this.z = z; - } - } -} diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/events/PlayerJoinedEvent.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/events/PlayerJoinedEvent.java index 8936de9a..29b0ffd8 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/core/events/PlayerJoinedEvent.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/core/events/PlayerJoinedEvent.java @@ -35,7 +35,7 @@ public class PlayerJoinedEvent implements Listener{ @EventHandler(priority = EventPriority.LOWEST) private void onJoin(PlayerJoinEvent event) { Player player = event.getPlayer(); - SteamwarUser user = Statement.productionDatabase() ? SteamwarUser.get(player.getUniqueId()) : SteamwarUser.getOrCreate(player.getUniqueId(), player.getName(), uuid -> {}, (oldName, newName) -> {}); + SteamwarUser user = Statement.productionDatabase() ? SteamwarUser.get(player.getUniqueId()) : SteamwarUser.getOrCreate(player.getUniqueId(), player.getName(), uuid -> {}); UserPerm.Prefix prefix = user.prefix(); if(prefix != UserPerm.emptyPrefix) { diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntity.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntity.java index 6948dc68..e7ecb1a8 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntity.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntity.java @@ -19,7 +19,7 @@ package de.steamwar.entity; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import de.steamwar.core.*; import it.unimi.dsi.fastutil.ints.IntArrayList; import it.unimi.dsi.fastutil.ints.IntList; @@ -160,9 +160,9 @@ public class REntity { server.postEntityMove(this, fromX, fromZ); } - private static final Class animationPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutAnimation"); - private static final Reflection.FieldAccessor animationEntity = Reflection.getField(animationPacket, int.class, Core.getVersion() > 15 ? (Core.getVersion() > 19 ? 5 : 6) : 0); - private static final Reflection.FieldAccessor animationAnimation = Reflection.getField(animationPacket, int.class, Core.getVersion() > 15 ? (Core.getVersion() > 19 ? 6 : 7) : 1); + private static final Class animationPacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundAnimatePacket"); + private static final Reflection.Field animationEntity = Reflection.getField(animationPacket, int.class, Core.getVersion() > 15 ? (Core.getVersion() > 19 ? 5 : 6) : 0); + private static final Reflection.Field animationAnimation = Reflection.getField(animationPacket, int.class, Core.getVersion() > 15 ? (Core.getVersion() > 19 ? 6 : 7) : 1); public void showAnimation(byte animation) { Object packet = Reflection.newInstance(animationPacket); animationEntity.set(packet, entityId); @@ -170,11 +170,11 @@ public class REntity { server.updateEntity(this, packet); } - private static final Class velocityPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityVelocity"); - private static final Reflection.FieldAccessor velocityEntity = Reflection.getField(velocityPacket, int.class, 0); - private static final Reflection.FieldAccessor velocityX = Reflection.getField(velocityPacket, int.class, 1); - private static final Reflection.FieldAccessor velocityY = Reflection.getField(velocityPacket, int.class, 2); - private static final Reflection.FieldAccessor velocityZ = Reflection.getField(velocityPacket, int.class, 3); + private static final Class velocityPacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundSetEntityMotionPacket"); + private static final Reflection.Field velocityEntity = Reflection.getField(velocityPacket, int.class, 0); + private static final Reflection.Field velocityX = Reflection.getField(velocityPacket, int.class, 1); + private static final Reflection.Field velocityY = Reflection.getField(velocityPacket, int.class, 2); + private static final Reflection.Field velocityZ = Reflection.getField(velocityPacket, int.class, 3); public void setVelocity(double dX, double dY, double dZ) { Object packet = Reflection.newInstance(velocityPacket); velocityEntity.set(packet, entityId); @@ -184,9 +184,9 @@ public class REntity { server.updateEntity(this, packet); } - private static final Class statusPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityStatus"); - private static final Reflection.FieldAccessor statusEntity = Reflection.getField(statusPacket, int.class, 0); - private static final Reflection.FieldAccessor statusStatus = Reflection.getField(statusPacket, byte.class, 0); + private static final Class statusPacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundEntityEventPacket"); + private static final Reflection.Field statusEntity = Reflection.getField(statusPacket, int.class, 0); + private static final Reflection.Field statusStatus = Reflection.getField(statusPacket, byte.class, 0); public void showDamage() { Object packet = Reflection.newInstance(statusPacket); statusEntity.set(packet, entityId); @@ -293,7 +293,7 @@ public class REntity { return 4; } } - private static final Reflection.FieldAccessor additionalData = Reflection.getField(ProtocolWrapper.spawnPacket, int.class, objectDataOffset()); + private static final Reflection.Field additionalData = Reflection.getField(ProtocolWrapper.spawnPacket, int.class, objectDataOffset()); private Object spawnPacketGenerator() { Object packet = spawnPacketGenerator.apply(this); additionalData.set(packet, objectData); @@ -346,8 +346,8 @@ public class REntity { } } - private static final Class destroyPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityDestroy"); - private static final Reflection.FieldAccessor destroyEntities; + private static final Class destroyPacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket"); + private static final Reflection.Field destroyEntities; static { if(Core.getVersion() > 15) destroyEntities = Reflection.getField(destroyPacket, IntList.class, 0); @@ -393,8 +393,8 @@ public class REntity { return ChatWrapper.impl.getDataWatcherPacket(entityId, dataWatcherKeyValues); } - public static final Class teleportPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityTeleport"); - public static final Reflection.FieldAccessor teleportEntity = Reflection.getField(teleportPacket, int.class, 0); + public static final Class teleportPacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket"); + public static final Reflection.Field teleportEntity = Reflection.getField(teleportPacket, int.class, 0); public static final BountifulWrapper.PositionSetter teleportPosition = BountifulWrapper.impl.getPositionSetter(teleportPacket, Core.getVersion() == 8 ? 1 : 0); private Object getTeleportPacket(){ Object packet = Reflection.newInstance(teleportPacket); @@ -403,12 +403,12 @@ public class REntity { return packet; } - private static final Class entityPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntity"); - private static final Reflection.FieldAccessor moveEntityId = Reflection.getField(entityPacket, int.class, 0); + private static final Class entityPacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundMoveEntityPacket"); + private static final Reflection.Field moveEntityId = Reflection.getField(entityPacket, int.class, 0); private static final BountifulWrapper.PositionSetter movePosition = BountifulWrapper.impl.getRelMoveSetter(entityPacket); - private static final Class lookPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntity$PacketPlayOutEntityLook"); - private static final Class movePacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntity$PacketPlayOutRelEntityMove"); - private static final Class moveLookPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntity$PacketPlayOutRelEntityMoveLook"); + private static final Class lookPacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundMoveEntityPacket$Rot"); + private static final Class movePacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundMoveEntityPacket$Pos"); + private static final Class moveLookPacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundMoveEntityPacket$PosRot"); private Object getMoveLookPacket(double diffX, double diffY, double diffZ, boolean rotEq) { Class clazz; if(diffX == 0 && diffY == 0 && diffZ == 0) { @@ -428,9 +428,9 @@ public class REntity { return packet; } - private static final Class headRotationPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutEntityHeadRotation"); - private static final Reflection.FieldAccessor headRotationEntity = Reflection.getField(headRotationPacket, int.class, 0); - private static final Reflection.FieldAccessor headRotationYaw = Reflection.getField(headRotationPacket, byte.class, 0); + private static final Class headRotationPacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundRotateHeadPacket"); + private static final Reflection.Field headRotationEntity = Reflection.getField(headRotationPacket, int.class, 0); + private static final Reflection.Field headRotationYaw = Reflection.getField(headRotationPacket, byte.class, 0); private Object getHeadRotationPacket(){ Object packet = Reflection.newInstance(headRotationPacket); headRotationEntity.set(packet, entityId); @@ -438,10 +438,10 @@ public class REntity { return packet; } - private static final Reflection.FieldAccessor equipmentEntity = Reflection.getField(ProtocolWrapper.equipmentPacket, int.class, 0); + private static final Reflection.Field equipmentEntity = Reflection.getField(ProtocolWrapper.equipmentPacket, int.class, 0); - private static final Class craftItemStack = Reflection.getClass("{obc}.inventory.CraftItemStack"); - private static final Reflection.MethodInvoker asNMSCopy = Reflection.getTypedMethod(REntity.craftItemStack, "asNMSCopy", ProtocolWrapper.itemStack, ItemStack.class); + private static final Class craftItemStack = Reflection.getClass("org.bukkit.craftbukkit.inventory.CraftItemStack"); + private static final Reflection.Method asNMSCopy = Reflection.getTypedMethod(REntity.craftItemStack, "asNMSCopy", ProtocolWrapper.itemStack, ItemStack.class); protected Object getEquipmentPacket(Object slot, ItemStack stack){ Object packet = Reflection.newInstance(ProtocolWrapper.equipmentPacket); equipmentEntity.set(packet, entityId); @@ -462,7 +462,7 @@ public class REntity { } protected static Function spawnPacketGenerator(Class spawnPacket, int posOffset) { - Reflection.FieldAccessor entityId = Reflection.getField(spawnPacket, int.class, 0); + Reflection.Field entityId = Reflection.getField(spawnPacket, int.class, 0); BountifulWrapper.PositionSetter position = BountifulWrapper.impl.getPositionSetter(spawnPacket, posOffset); return entity -> { diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java index 442d05dd..d5ced550 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java @@ -19,7 +19,7 @@ package de.steamwar.entity; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; import de.steamwar.core.Core; import de.steamwar.core.FlatteningWrapper; @@ -47,14 +47,14 @@ 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 Class useEntityEnumAction = Reflection.getClass("{nms.network.protocol.game}.PacketPlayInUseEntity$EnumEntityUseAction"); - private static final Reflection.FieldAccessor useEntityAction = Reflection.getField(useEntity, useEntityEnumAction, 0); + private static final Class useEntity = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundInteractPacket"); + private static final Reflection.Field useEntityTarget = Reflection.getField(useEntity, int.class, 0); + private static final Class useEntityEnumAction = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundInteractPacket$Action"); + private static final Reflection.Field useEntityAction = Reflection.getField(useEntity, useEntityEnumAction, 0); private static final Function getEntityAction; static { if(Core.getVersion() > 15) { - Reflection.MethodInvoker useEntityGetAction = Reflection.getMethod(useEntityEnumAction, "a"); + Reflection.Method useEntityGetAction = Reflection.getMethod(useEntityEnumAction, "a"); getEntityAction = value -> ((Enum) useEntityGetAction.invoke(value)).ordinal(); } else { getEntityAction = value -> ((Enum) value).ordinal(); diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RPlayer.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RPlayer.java index 1aa10d85..b4aaa3ee 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RPlayer.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/entity/RPlayer.java @@ -19,7 +19,7 @@ package de.steamwar.entity; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import com.mojang.authlib.GameProfile; import de.steamwar.core.BountifulWrapper; import de.steamwar.core.Core; @@ -91,9 +91,9 @@ public class RPlayer extends REntity { packetSink.accept(ProtocolWrapper.impl.playerInfoPacketConstructor(ProtocolWrapper.PlayerInfoAction.REMOVE, new GameProfile(uuid, name), GameMode.CREATIVE)); } - private static final Class namedSpawnPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutNamedEntitySpawn"); + private static final Class namedSpawnPacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundAddPlayerPacket"); private static final Function namedSpawnPacketGenerator = spawnPacketGenerator(namedSpawnPacket, Core.getVersion() == 8 ? 1 : 0); - private static final Reflection.FieldAccessor namedSpawnUUID = Reflection.getField(namedSpawnPacket, UUID.class, 0); + private static final Reflection.Field namedSpawnUUID = Reflection.getField(namedSpawnPacket, UUID.class, 0); private Object getNamedSpawnPacket() { Object packet = namedSpawnPacketGenerator.apply(this); namedSpawnUUID.set(packet, uuid); diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/network/handlers/ServerDataHandler.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/network/handlers/ServerDataHandler.java index bfcbbb5c..8941432b 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/network/handlers/ServerDataHandler.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/network/handlers/ServerDataHandler.java @@ -19,13 +19,13 @@ package de.steamwar.network.handlers; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; public class ServerDataHandler { public ServerDataHandler() { - TinyProtocol.instance.addFilter(Reflection.getClass("{nms.network.protocol.game}.ClientboundServerDataPacket"), (p, o) -> null); - TinyProtocol.instance.addFilter(Reflection.getClass("{nms.network.protocol.game}.ServerboundChatSessionUpdatePacket"), (player, packet) -> null); + TinyProtocol.instance.addFilter(Reflection.getClass("net.minecraft.network.protocol.game.ClientboundServerDataPacket"), (p, o) -> null); + TinyProtocol.instance.addFilter(Reflection.getClass("net.minecraft.network.protocol.game.ServerboundChatSessionUpdatePacket"), (player, packet) -> null); } } diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/providers/BauServerInfo.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/providers/BauServerInfo.java index b7de60b1..ddc7839e 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/providers/BauServerInfo.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/providers/BauServerInfo.java @@ -19,22 +19,15 @@ package de.steamwar.providers; -import de.steamwar.sql.SteamwarUser; import org.bukkit.Bukkit; -import java.util.UUID; - public class BauServerInfo { private static Integer bauOwner = null; static { try { bauOwner = Integer.parseInt(Bukkit.getWorlds().get(0).getName()); - } catch (NumberFormatException e) { - try { - bauOwner = SteamwarUser.get(UUID.fromString(Bukkit.getWorlds().get(0).getName())).getId(); - } catch (IllegalArgumentException ignored) {} - } + } catch (NumberFormatException ignored) {} } public static Integer getOwnerId() { diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/sql/SchematicData.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/sql/SchematicData.java index ecbf86aa..62f00369 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/sql/SchematicData.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/sql/SchematicData.java @@ -36,7 +36,7 @@ import java.util.zip.GZIPInputStream; public class SchematicData { - public static Clipboard clipboardFromStream(InputStream is, boolean schemFormat) { + public static Clipboard clipboardFromStream(InputStream is, NodeData.SchematicFormat schemFormat) { try { return WorldEditWrapper.impl.getClipboard(is, schemFormat); } catch (IOException e) { @@ -61,15 +61,11 @@ public class SchematicData { } public void saveFromPlayer(Player player) throws IOException, NoClipboardException { - saveFromPlayer(player, Core.getVersion() > 12); - } - - public void saveFromPlayer(Player player, boolean newFormat) throws IOException, NoClipboardException { - data.saveFromStream(WorldEditWrapper.impl.getPlayerClipboard(player, newFormat), newFormat); + data.saveFromStream(WorldEditWrapper.impl.getPlayerClipboard(player), WorldEditWrapper.impl.getNativeFormat()); } @Deprecated - public void saveFromBytes(byte[] bytes, boolean newFormat) { + public void saveFromBytes(byte[] bytes, NodeData.SchematicFormat newFormat) { data.saveFromStream(new ByteArrayInputStream(bytes), newFormat); } } diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/ProtocolUtils.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/ProtocolUtils.java index fe7bc707..57f27921 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/ProtocolUtils.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/ProtocolUtils.java @@ -19,7 +19,7 @@ package de.steamwar.techhider; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import com.google.common.primitives.Bytes; import io.netty.buffer.ByteBuf; diff --git a/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/TechHider.java b/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/TechHider.java index 9f3ccf90..bae5b7be 100644 --- a/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/TechHider.java +++ b/SpigotCore/SpigotCore_Main/src/de/steamwar/techhider/TechHider.java @@ -19,7 +19,7 @@ package de.steamwar.techhider; -import com.comphenix.tinyprotocol.Reflection; +import de.steamwar.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; import de.steamwar.core.Core; import lombok.Getter; @@ -35,21 +35,21 @@ import java.util.stream.Collectors; public class TechHider { - public static final Class blockPosition = Reflection.getClass("{nms.core}.BlockPosition"); - private static final Class baseBlockPosition = Reflection.getClass("{nms.core}.BaseBlockPosition"); - public static final Reflection.FieldAccessor blockPositionX = Reflection.getField(baseBlockPosition, int.class, 0); - public static final Reflection.FieldAccessor blockPositionY = Reflection.getField(baseBlockPosition, int.class, 1); - public static final Reflection.FieldAccessor blockPositionZ = Reflection.getField(baseBlockPosition, int.class, 2); + public static final Class blockPosition = Reflection.getClass("net.minecraft.core.BlockPos"); + private static final Class baseBlockPosition = Reflection.getClass("net.minecraft.core.Vec3i"); + public static final Reflection.Field blockPositionX = Reflection.getField(baseBlockPosition, int.class, 0); + public static final Reflection.Field blockPositionY = Reflection.getField(baseBlockPosition, int.class, 1); + public static final Reflection.Field blockPositionZ = Reflection.getField(baseBlockPosition, int.class, 2); - public static final Class iBlockData = Reflection.getClass("{nms.world.level.block.state}.IBlockData"); - public static final Class block = Reflection.getClass("{nms.world.level.block}.Block"); - private static final Reflection.MethodInvoker getBlockDataByBlock = Reflection.getTypedMethod(block, null, iBlockData); + public static final Class iBlockData = Reflection.getClass("net.minecraft.world.level.block.state.BlockState"); + public static final Class block = Reflection.getClass("net.minecraft.world.level.block.Block"); + private static final Reflection.Method getBlockDataByBlock = Reflection.getTypedMethod(block, null, iBlockData); - public static final Class craftMagicNumbers = Reflection.getClass("{obc}.util.CraftMagicNumbers"); - private static final Reflection.MethodInvoker getBlockByMaterial = Reflection.getTypedMethod(craftMagicNumbers, "getBlock", block, Material.class); + public static final Class craftMagicNumbers = Reflection.getClass("org.bukkit.craftbukkit.util.CraftMagicNumbers"); + private static final Reflection.Method getBlockByMaterial = Reflection.getTypedMethod(craftMagicNumbers, "getBlock", block, Material.class); - private static final Reflection.MethodInvoker getBlockByBlockData = Reflection.getTypedMethod(iBlockData, null, block); - private static final Reflection.MethodInvoker getMaterialByBlock = Reflection.getTypedMethod(craftMagicNumbers, "getMaterial", Material.class, block); + private static final Reflection.Method getBlockByBlockData = Reflection.getTypedMethod(iBlockData, null, block); + private static final Reflection.Method getMaterialByBlock = Reflection.getTypedMethod(craftMagicNumbers, "getMaterial", Material.class, block); public boolean iBlockDataHidden(Object iBlockData) { return obfuscate.contains((Material) getMaterialByBlock.invoke(null, getBlockByBlockData.invoke(iBlockData))); } @@ -86,14 +86,14 @@ public class TechHider { techhiders.put(ChunkHider.impl.mapChunkPacket(), ChunkHider.impl.chunkHiderGenerator(this)); if(Core.getVersion() > 12 && Core.getVersion() < 19) { - Class blockBreakClass = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutBlockBreak"); + Class blockBreakClass = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundBlockDestructionPacket"); techhiders.put(blockBreakClass, ProtocolWrapper.impl.blockBreakHiderGenerator(blockBreakClass, this)); } if(Core.getVersion() > 8){ - techhiders.put(Reflection.getClass("{nms.network.protocol.game}.PacketPlayInUseItem"), (p, packet) -> p.getGameMode() == GameMode.SPECTATOR ? null : packet); + techhiders.put(Reflection.getClass("net.minecraft.network.protocol.game.ServerboundUseItemOnPacket"), (p, packet) -> p.getGameMode() == GameMode.SPECTATOR ? null : packet); } - techhiders.put(Reflection.getClass("{nms.network.protocol.game}.PacketPlayInUseEntity"), (p, packet) -> p.getGameMode() == GameMode.SPECTATOR ? null : packet); + techhiders.put(Reflection.getClass("net.minecraft.network.protocol.game.ServerboundInteractPacket"), (p, packet) -> p.getGameMode() == GameMode.SPECTATOR ? null : packet); } @@ -105,13 +105,13 @@ public class TechHider { techhiders.forEach(TinyProtocol.instance::removeFilter); } - public static final Class multiBlockChangePacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutMultiBlockChange"); + public static final Class multiBlockChangePacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundSectionBlocksUpdatePacket"); public static final UnaryOperator multiBlockChangeCloner = ProtocolUtils.shallowCloneGenerator(TechHider.multiBlockChangePacket); - private static final Class blockChangePacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutBlockChange"); + private static final Class blockChangePacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundBlockUpdatePacket"); private static final Function blockChangeCloner = ProtocolUtils.shallowCloneGenerator(blockChangePacket); - private static final Reflection.FieldAccessor blockChangePosition = Reflection.getField(blockChangePacket, blockPosition, 0); - private static final Reflection.FieldAccessor blockChangeBlockData = Reflection.getField(blockChangePacket, iBlockData, 0); + private static final Reflection.Field blockChangePosition = Reflection.getField(blockChangePacket, blockPosition, 0); + private static final Reflection.Field blockChangeBlockData = Reflection.getField(blockChangePacket, iBlockData, 0); private Object blockChangeHider(Player p, Object packet) { switch (locationEvaluator.checkBlockPos(p, blockChangePosition.get(packet))) { case SKIP: @@ -131,16 +131,16 @@ public class TechHider { } } - private static final Class blockActionPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutBlockAction"); - private static final Reflection.FieldAccessor blockActionPosition = Reflection.getField(blockActionPacket, blockPosition, 0); + private static final Class blockActionPacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundBlockEventPacket"); + private static final Reflection.Field blockActionPosition = Reflection.getField(blockActionPacket, blockPosition, 0); private Object blockActionHider(Player p, Object packet) { if (locationEvaluator.checkBlockPos(p, blockActionPosition.get(packet)) == State.SKIP) return packet; return null; } - public static final Class tileEntityDataPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutTileEntityData"); - private static final Reflection.FieldAccessor tileEntityDataPosition = Reflection.getField(tileEntityDataPacket, blockPosition, 0); + public static final Class tileEntityDataPacket = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket"); + private static final Reflection.Field tileEntityDataPosition = Reflection.getField(tileEntityDataPacket, blockPosition, 0); private Object tileEntityDataHider(Player p, Object packet) { switch (locationEvaluator.checkBlockPos(p, tileEntityDataPosition.get(packet))) { case SKIP: diff --git a/SpigotCore/SpigotCore_Main/src/plugin.yml b/SpigotCore/SpigotCore_Main/src/plugin.yml index 75652668..a29249d2 100644 --- a/SpigotCore/SpigotCore_Main/src/plugin.yml +++ b/SpigotCore/SpigotCore_Main/src/plugin.yml @@ -4,7 +4,6 @@ author: Lixfel api-version: "1.13" load: STARTUP softdepend: - - ViaVersion - WorldEdit main: de.steamwar.core.Core diff --git a/SpigotCore/build.gradle.kts b/SpigotCore/build.gradle.kts index b7ff647e..d615cfc7 100644 --- a/SpigotCore/build.gradle.kts +++ b/SpigotCore/build.gradle.kts @@ -40,5 +40,10 @@ dependencies { implementation(project(":SpigotCore:SpigotCore_18")) implementation(project(":SpigotCore:SpigotCore_19")) implementation(project(":SpigotCore:SpigotCore_20")) - implementation(project(":SpigotCore:SpigotCore_21")) + implementation(project(":SpigotCore:SpigotCore_21")) { + attributes { + // Very Hacky, but it works + attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, 21) + } + } } diff --git a/TNTLeague/src/de/steamwar/tntleague/events/GlobalListener.kt b/TNTLeague/src/de/steamwar/tntleague/events/GlobalListener.kt index b01dffd9..77aa9dfb 100644 --- a/TNTLeague/src/de/steamwar/tntleague/events/GlobalListener.kt +++ b/TNTLeague/src/de/steamwar/tntleague/events/GlobalListener.kt @@ -19,9 +19,7 @@ package de.steamwar.tntleague.events -import de.steamwar.kotlin.inventory.SWInventoryHolder import de.steamwar.message.SubMessage -import de.steamwar.tntleague.colorByTeam import de.steamwar.tntleague.config.TNTLeagueWorldConfig import de.steamwar.tntleague.game.TNTLeagueGame import de.steamwar.tntleague.game.TNTLeagueTeam @@ -34,9 +32,7 @@ import org.bukkit.event.EventPriority import org.bukkit.event.Listener import org.bukkit.event.entity.PlayerDeathEvent import org.bukkit.event.inventory.CraftItemEvent -import org.bukkit.event.inventory.InventoryClickEvent import org.bukkit.event.player.* -import java.util.logging.Level object GlobalListener: Listener { @@ -66,15 +62,6 @@ object GlobalListener: Listener { e.isCancelled = true } - @EventHandler(priority = EventPriority.LOWEST) - fun onPlayerClick(e: InventoryClickEvent) { - val holder = e.inventory.getHolder(false) - if (holder is SWInventoryHolder && e.clickedInventory == holder._inventory) { - e.isCancelled = true - holder.handleInventoryClick(e) - } - } - @EventHandler(priority = EventPriority.LOWEST) fun onPlayerMove(e: PlayerMoveEvent) { if (e.to.blockY < TNTLeagueWorldConfig.minHeight) { diff --git a/TNTLeague/src/de/steamwar/tntleague/events/IngameListener.kt b/TNTLeague/src/de/steamwar/tntleague/events/IngameListener.kt index 976e49a3..f3722c22 100644 --- a/TNTLeague/src/de/steamwar/tntleague/events/IngameListener.kt +++ b/TNTLeague/src/de/steamwar/tntleague/events/IngameListener.kt @@ -27,13 +27,11 @@ import de.steamwar.tntleague.inventory.DealerInventory import de.steamwar.tntleague.util.TNTLeagueScoreboard import org.bukkit.GameMode import org.bukkit.Location -import org.bukkit.Material import org.bukkit.entity.EntityType import org.bukkit.event.EventHandler import org.bukkit.event.Listener import org.bukkit.event.entity.EntityExplodeEvent import org.bukkit.event.player.PlayerAttemptPickupItemEvent -import org.bukkit.event.player.PlayerDropItemEvent import org.bukkit.event.player.PlayerInteractEntityEvent import org.bukkit.event.player.PlayerJoinEvent import org.bukkit.event.player.PlayerMoveEvent @@ -46,7 +44,7 @@ object IngameListener : Listener { if (e.rightClicked.type == EntityType.WANDERING_TRADER) { e.isCancelled = true - e.player.openInventory(DealerInventory(e.player).getInventory()) + DealerInventory(e.player).open() } } @@ -75,13 +73,6 @@ object IngameListener : Listener { } } - @EventHandler - fun onDropPickaxe(e: PlayerDropItemEvent) { - if (e.itemDrop.itemStack.type == Material.DIAMOND_PICKAXE) { - e.isCancelled = true - } - } - @EventHandler fun onPickupCoins(e: PlayerAttemptPickupItemEvent) { if (e.item.itemStack.isSimilar(DealerInventory.coins)) { diff --git a/TNTLeague/src/de/steamwar/tntleague/events/LobbyListener.kt b/TNTLeague/src/de/steamwar/tntleague/events/LobbyListener.kt index 586b0e79..bb570498 100644 --- a/TNTLeague/src/de/steamwar/tntleague/events/LobbyListener.kt +++ b/TNTLeague/src/de/steamwar/tntleague/events/LobbyListener.kt @@ -39,11 +39,6 @@ object LobbyListener: Listener { } } - @EventHandler(priority = EventPriority.LOWEST) - fun onPlayerQuit(e: PlayerQuitEvent) { - TNTLeagueGame.playerLeave(e.player) - } - @EventHandler fun onPlayerDamage(e: EntityDamageEvent) { e.isCancelled = true diff --git a/TNTLeague/src/de/steamwar/tntleague/game/TNTLeagueTeam.kt b/TNTLeague/src/de/steamwar/tntleague/game/TNTLeagueTeam.kt index 3828d9e8..200f457e 100644 --- a/TNTLeague/src/de/steamwar/tntleague/game/TNTLeagueTeam.kt +++ b/TNTLeague/src/de/steamwar/tntleague/game/TNTLeagueTeam.kt @@ -128,7 +128,7 @@ data class TNTLeagueTeam(val config: TNTLeagueWorldConfig.TeamConfig, private va fun leave(player: Player) { members.remove(player) - if (TNTLeagueGame.state != TNTLeagueGame.GameState.RUNNING) { + if (TNTLeagueGame.state == TNTLeagueGame.GameState.LOBBY) { if (members.isEmpty()) { plugin.server.onlinePlayers.firstOrNull { it != player && TNTLeagueGame.getTeam(it) == null }?.run { members.add(this) diff --git a/TNTLeague/src/de/steamwar/tntleague/inventory/CategoryInventory.kt b/TNTLeague/src/de/steamwar/tntleague/inventory/CategoryInventory.kt index 3a23812f..76200073 100644 --- a/TNTLeague/src/de/steamwar/tntleague/inventory/CategoryInventory.kt +++ b/TNTLeague/src/de/steamwar/tntleague/inventory/CategoryInventory.kt @@ -19,7 +19,8 @@ package de.steamwar.tntleague.inventory -import de.steamwar.kotlin.inventory.SWInventoryHolder +import de.steamwar.inventory.SWInventory +import de.steamwar.kotlin.KotlinInventory import de.steamwar.tntleague.config.TNTLeagueConfig import de.steamwar.tntleague.inventory.DealerInventory.Companion.buyItem import de.steamwar.tntleague.inventory.DealerInventory.Companion.itemsByCategory @@ -29,8 +30,8 @@ import org.bukkit.Bukkit import org.bukkit.entity.Player import org.bukkit.inventory.Inventory -class CategoryInventory(val player: Player, category: TNTLeagueConfig.ItemCategory): SWInventoryHolder() { - override fun createInventory(): Inventory = Bukkit.createInventory(this, 9 * 6, Component.text(message.parse("DEALER", player))) +class CategoryInventory(player: Player, category: TNTLeagueConfig.ItemCategory): KotlinInventory(player) { + override fun createInventory() = SWInventory(player, 9 * 6, message.parse("DEALER", player)) init { itemsByCategory[category]!!.forEachIndexed { index, item -> diff --git a/TNTLeague/src/de/steamwar/tntleague/inventory/DealerInventory.kt b/TNTLeague/src/de/steamwar/tntleague/inventory/DealerInventory.kt index d0af0ca4..418c15fb 100644 --- a/TNTLeague/src/de/steamwar/tntleague/inventory/DealerInventory.kt +++ b/TNTLeague/src/de/steamwar/tntleague/inventory/DealerInventory.kt @@ -19,8 +19,9 @@ package de.steamwar.tntleague.inventory +import de.steamwar.inventory.SWInventory import de.steamwar.inventory.SWItem -import de.steamwar.kotlin.inventory.SWInventoryHolder +import de.steamwar.kotlin.KotlinInventory import de.steamwar.tntleague.config.TNTLeagueConfig import de.steamwar.tntleague.game.TNTLeagueGame import de.steamwar.tntleague.message @@ -38,7 +39,7 @@ import org.bukkit.inventory.ItemStack import org.bukkit.persistence.PersistentDataType import java.util.* -class DealerInventory(val player: Player): SWInventoryHolder() { +class DealerInventory(player: Player): KotlinInventory(player) { init { this[10] = SWItem(Material.REDSTONE_BLOCK, message.parse("DEALER_REDSTONE", player)).itemStack to openCategory(TNTLeagueConfig.ItemCategory.REDSTONE) @@ -51,9 +52,9 @@ class DealerInventory(val player: Player): SWInventoryHolder() { } } - private fun openCategory(cat: TNTLeagueConfig.ItemCategory): (e: InventoryClickEvent) -> Unit = { player.openInventory(CategoryInventory(player, cat).inventory) } + private fun openCategory(cat: TNTLeagueConfig.ItemCategory): (e: InventoryClickEvent) -> Unit = { CategoryInventory(player, cat).open() } - override fun createInventory(): Inventory = plugin.server.createInventory(this, 6 * 9, Component.text(message.parse("DEALER", player))) + override fun createInventory() = SWInventory(player, 9 * 6, message.parse("DEALER", player)) companion object { private val priceKey = NamespacedKey(plugin, "price") diff --git a/VelocityCore/Persistent/src/de/steamwar/persistent/Subserver.java b/VelocityCore/Persistent/src/de/steamwar/persistent/Subserver.java index 072f1467..9050255e 100644 --- a/VelocityCore/Persistent/src/de/steamwar/persistent/Subserver.java +++ b/VelocityCore/Persistent/src/de/steamwar/persistent/Subserver.java @@ -220,25 +220,22 @@ public class Subserver { try { if (checkpoint) { start(process.getErrorStream(), line -> line.contains("Restore finished successfully.")); + Thread.sleep(300); //Wait for port to be reopened } else { start(process.getInputStream(), line -> { if (line.contains("Loading libraries, please wait")) sendProgress(2); else if (line.contains("Starting Minecraft server on")) - sendProgress(4); + sendProgress(5); else if (line.contains("Preparing start region")) - sendProgress(6); - return line.contains("Finished mapping loading"); + sendProgress(8); + return line.contains("Done ("); }); } if (!started) return; - sendProgress(8); - - Thread.sleep(300); - sendProgress(10); for (Player cachedPlayer : cachedPlayers) { sendPlayer(cachedPlayer); diff --git a/VelocityCore/build.gradle.kts b/VelocityCore/build.gradle.kts index 78603f8c..844e9f21 100644 --- a/VelocityCore/build.gradle.kts +++ b/VelocityCore/build.gradle.kts @@ -47,6 +47,8 @@ java { dependencies { annotationProcessor(libs.velocityapi) compileOnly(libs.velocity) + compileOnly(libs.viaapi) + compileOnly(libs.viavelocity) compileOnly(project(":VelocityCore:Persistent", "default")) @@ -61,6 +63,7 @@ dependencies { } implementation(libs.msgpack) - implementation(libs.apolloprotos) + + implementation(libs.nbt) } \ No newline at end of file diff --git a/VelocityCore/deployarena.py b/VelocityCore/deployarena.py index d058b8e4..2195e264 100755 --- a/VelocityCore/deployarena.py +++ b/VelocityCore/deployarena.py @@ -37,11 +37,11 @@ if __name__ == "__main__": with open(configfile, 'r') as file: gamemode = yaml.load(file) - builderworld = path.expanduser(f'~/builder{version}/{worldname}') + builderworld = path.expanduser(f'/worlds/builder{version}/{worldname}') arenaworld = f'/servers/{gamemode["Server"]["Folder"]}/arenas/{worldname}' if path.exists(arenaworld): - backupworld = path.expanduser(f'~/backup/arenas/{datetime.datetime.now()}-{worldname}-{version}.tar.xz') + backupworld = path.expanduser(f'/mnt/storage/backup/arenas/{datetime.datetime.now()}-{worldname}-{version}.tar.xz') with tarfile.open(backupworld, 'w:xz') as tar: tar.add(arenaworld, arcname=worldname) diff --git a/VelocityCore/src/de/steamwar/messages/BungeeCore.properties b/VelocityCore/src/de/steamwar/messages/BungeeCore.properties index e8ca12bb..c9527253 100644 --- a/VelocityCore/src/de/steamwar/messages/BungeeCore.properties +++ b/VelocityCore/src/de/steamwar/messages/BungeeCore.properties @@ -369,23 +369,18 @@ R_USAGE=§8/§7r §8[§eanswer§8] #RegelnCommand REGELN_RULES=§7§lRules REGELN_AS=§eAirShip §7Rules -REGELN_AS_HOVER=§7https://steamwar.de/spielmodi/airship-regelwerk/ -REGELN_AS_URL=https://steamwar.de/spielmodi/airship-regelwerk/ +REGELN_AS_URL=https://steamwar.de/en/rules/airship REGELN_MWG=§eMiniWarGear §7Rules -REGELN_MWG_HOVER=§7https://steamwar.de/spielmodi/miniwargear-regelwerk/ -REGELN_MWG_URL=https://steamwar.de/spielmodi/miniwargear-regelwerk/ +REGELN_MWG_URL=https://steamwar.de/en/rules/miniwargear REGELN_WG=§eWarGear §7Rules -REGELN_WG_HOVER=§7https://steamwar.de/spielmodi/wargear-regelwerk/ -REGELN_WG_URL=https://steamwar.de/spielmodi/wargear-regelwerk/ +REGELN_WG_URL=https://steamwar.de/en/rules/wargear REGELN_WS=§eWarShip §7Rules -REGELN_WS_HOVER=§7https://steamwar.de/spielmodi/warship-regelwerk/ -REGELN_WS_URL=https://steamwar.de/spielmodi/warship-regelwerk/ +REGELN_WS_URL=https://steamwar.de/en/rules/warship REGELN_QG=§eQuickGear §7Rules -REGELN_QG_HOVER=§7https://steamwar.de/spielmodi/quickgear-regelwerk/ -REGELN_QG_URL=https://steamwar.de/spielmodi/quickgear-regelwerk/ +REGELN_QG_URL=https://steamwar.de/en/rules/quickgear REGELN_CONDUCT=§eCode of conduct -REGELN_CONDUCT_HOVER=§7https://steamwar.de/verhaltensrichtlinien/ -REGELN_CONDUCT_URL=https://steamwar.de/verhaltensrichtlinien/ +REGELN_CONDUCT_URL=https://steamwar.de/en/code-of-conduct +URL_FORMAT=§7{0} #ReplayCommand REPLAY_TITLE=Most recent fights @@ -541,7 +536,7 @@ TP_USAGE_EVENT=§8/§7tp §8[§ePlayer §7or §eteam§8] UNIGNORE_USAGE=§8/§7unignore §8[§eplayer§8] UNIGNORE_NOT_PLAYER=§cThis player does not exist! UNIGNORE_NOT_IGNORED=§cYou are not ignoring this player. -UNIGNORE_UNIGNORED=§7You ignored §e{0}§8. +UNIGNORE_UNIGNORED=§7You unignored §e{0}§8. #WebregisterCommand WEB_USAGE=§8/§7webpassword §8[§epassword§8] @@ -729,6 +724,9 @@ MOD_ITEM_BACK=§7Back INV_PAGE_BACK=§{0}Seite zurück INV_PAGE_NEXT=§{0}Seite vor +#VersionAnnouncer +SERVER_VERSION=§7This server runs on Minecraft version §e{0} + #Discord DC_UNLINKED=For this action your Discord account has to be linked to your Minecraft account. To link your accounts go onto the SteamWar Discord to the `regeln-infos` Channel and click on `Minecraft Verknüpfen`. DC_TITLE_SCHEMINFO=Schematic Info diff --git a/VelocityCore/src/de/steamwar/messages/BungeeCore_de.properties b/VelocityCore/src/de/steamwar/messages/BungeeCore_de.properties index db367a1f..c50cf682 100644 --- a/VelocityCore/src/de/steamwar/messages/BungeeCore_de.properties +++ b/VelocityCore/src/de/steamwar/messages/BungeeCore_de.properties @@ -350,23 +350,17 @@ R_USAGE=§8/§7r §8[§eAntwort§8] #RegelnCommand REGELN_RULES=§7§lRegelwerke REGELN_AS=§eAirShip§8-§7Regelwerk -REGELN_AS_HOVER=§7https://steamwar.de/spielmodi/airship-regelwerk/ -REGELN_AS_URL=https://steamwar.de/spielmodi/airship-regelwerk/ +REGELN_AS_URL=https://steamwar.de/regeln/airship REGELN_MWG=§eMiniWarGear§8-§7Regelwerk -REGELN_MWG_HOVER=§7https://steamwar.de/spielmodi/miniwargear-regelwerk/ -REGELN_MWG_URL=https://steamwar.de/spielmodi/miniwargear-regelwerk/ +REGELN_MWG_URL=https://steamwar.de/regeln/miniwargear REGELN_WG=§eWarGear§8-§7Regelwerk -REGELN_WG_HOVER=§7https://steamwar.de/spielmodi/wargear-regelwerk/ -REGELN_WG_URL=https://steamwar.de/spielmodi/wargear-regelwerk/ +REGELN_WG_URL=https://steamwar.de/regeln/wargear REGELN_WS=§eWarShip§8-§7Regelwerk -REGELN_WS_HOVER=§7https://steamwar.de/spielmodi/warship-regelwerk/ -REGELN_WS_URL=https://steamwar.de/spielmodi/warship-regelwerk/ +REGELN_WS_URL=https://steamwar.de/regeln/warship REGELN_QG=§eQuickGear§8-§7Regelwerk -REGELN_QG_HOVER=§7https://steamwar.de/spielmodi/quickgear-regelwerk/ -REGELN_QG_URL=https://steamwar.de/spielmodi/quickgear-regelwerk/ +REGELN_QG_URL=https://steamwar.de/regeln/quickgear REGELN_CONDUCT=§eVerhaltensrichtlinien -REGELN_CONDUCT_HOVER=§7https://steamwar.de/verhaltensrichtlinien/ -REGELN_CONDUCT_URL=https://steamwar.de/verhaltensrichtlinien/ +REGELN_CONDUCT_URL=https://steamwar.de/verhaltensrichtlinien #ReplayCommand REPLAY_TITLE=Letzte Kämpfe @@ -682,6 +676,9 @@ ADVENT_CALENDAR_OPEN=§7Du hast §e{0}§7 aus dem Adventskalender erhalten! INV_PAGE_BACK=§{0}Page back INV_PAGE_NEXT=§{0}Next page +#VersionAnnouncer +SERVER_VERSION=§7Dieser Server läuft auf Minecraft-Version §e{0} + #Discord DC_UNLINKED=Für diese Aktion muss dein Minecraftaccount mit deinem Discordaccount verknüpft sein, gehe dazu auf dem SteamWar-Discord in den `regeln-infos` Channel und Klicke auf `Minecraft Verknüpfen`. DC_TITLE_SCHEMINFO=Schematicinfo diff --git a/VelocityCore/src/de/steamwar/velocitycore/GameModeConfig.java b/VelocityCore/src/de/steamwar/velocitycore/GameModeConfig.java index 8dab4d8d..208f6df3 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/GameModeConfig.java +++ b/VelocityCore/src/de/steamwar/velocitycore/GameModeConfig.java @@ -27,10 +27,14 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.function.BiConsumer; +import java.util.regex.Matcher; +import java.util.regex.Pattern; @Getter public class GameModeConfig { + private static final Pattern terminatingNumber = Pattern.compile("(\\d+)$"); + public static void loadAll(Class config, BiConsumer consumer) { File folder = new File(VelocityCore.get().getDataDirectory().getParent().toFile(), "FightSystem"); if(!folder.exists()) @@ -51,9 +55,9 @@ public class GameModeConfig { @Getter public static class Server { private String Folder; - private String ServerJar; private List ChatNames = Collections.emptyList(); private List Maps; + private boolean Spigot = false; private boolean Ranked = false; private boolean Historic = false; } @@ -66,8 +70,10 @@ public class GameModeConfig { private boolean ManualCheck = true; } - public String getServerJar() { - return getServer().getServerJar(); + public ServerVersion getVersion() { + Matcher matcher = terminatingNumber.matcher(getServer().getFolder()); + matcher.find(); + return ServerVersion.valueOf((getServer().isSpigot() ? "SPIGOT_" : "PAPER_") + matcher.group(1)); } public String getFolder() { diff --git a/VelocityCore/src/de/steamwar/velocitycore/Node.java b/VelocityCore/src/de/steamwar/velocitycore/Node.java index b97ef0ba..9c717886 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/Node.java +++ b/VelocityCore/src/de/steamwar/velocitycore/Node.java @@ -63,7 +63,7 @@ public abstract class Node { nodes.forEach(consumer); } - public abstract ProcessBuilder startServer(String serverJar, File directory, String worldDir, String levelName, int port, String xmx, String... dParams); + public abstract ProcessBuilder startServer(String serverJar, File directory, String worldDir, String levelName, int port, String... dParams); protected abstract ProcessBuilder prepareExecution(String... command); protected abstract void calcLoadLimit(); @@ -95,17 +95,17 @@ public abstract class Node { return hostname; } - protected void constructServerstart(File directory, List cmd, String serverJar, String worldDir, String levelName, int port, String xmx, String... dParams) { + protected void constructServerstart(File directory, List cmd, String serverJar, String worldDir, String levelName, int port, String... dParams) { if (JAVA_8.contains(serverJar)) - cmd.add("/usr/lib/jvm/java-8-openj9-amd64/bin/java"); + cmd.add("/usr/lib/jvm/openj9-8/bin/java"); else - cmd.add("/usr/lib/jvm/java-21-openj9-amd64/bin/java"); + cmd.add("/usr/lib/jvm/openj9-21/bin/java"); for(String param : dParams){ cmd.add("-D" + param); } cmd.add("-Xshareclasses:nonfatal,name=" + directory.getName()); - cmd.add("-Xmx" + xmx); + cmd.add("-Xmx768M"); cmd.addAll(OPENJ9_ARGS); if (!JAVA_8.contains(serverJar)) { cmd.add("--add-opens"); @@ -113,7 +113,7 @@ public abstract class Node { cmd.add("-XX:-CRIUSecProvider"); } cmd.add("-jar"); - cmd.add("/binarys/" + serverJar); + cmd.add("/jars/" + serverJar); cmd.add("--log-strip-color"); cmd.add("--world-dir"); cmd.add(worldDir); @@ -142,9 +142,9 @@ public abstract class Node { } @Override - public ProcessBuilder startServer(String serverJar, File directory, String worldDir, String levelName, int port, String xmx, String... dParams) { + public ProcessBuilder startServer(String serverJar, File directory, String worldDir, String levelName, int port, String... dParams) { List cmd = new ArrayList<>(); - constructServerstart(directory, cmd, serverJar, worldDir, levelName, port, xmx, dParams); + constructServerstart(directory, cmd, serverJar, worldDir, levelName, port, dParams); ProcessBuilder builder = new ProcessBuilder(cmd); builder.directory(directory); return builder; @@ -174,7 +174,7 @@ public abstract class Node { } @Override - public ProcessBuilder startServer(String serverJar, File directory, String worldDir, String levelName, int port, String xmx, String... dParams) { + public ProcessBuilder startServer(String serverJar, File directory, String worldDir, String levelName, int port, String... dParams) { List cmd = new ArrayList<>(); cmd.add("ssh"); cmd.add("-L"); @@ -183,7 +183,7 @@ public abstract class Node { cmd.add("cd"); cmd.add(directory.getPath()); cmd.add(";"); - constructServerstart(directory, cmd, serverJar, worldDir, levelName, port, xmx, dParams); + constructServerstart(directory, cmd, serverJar, worldDir, levelName, port, dParams); return new ProcessBuilder(cmd); } diff --git a/VelocityCore/src/de/steamwar/velocitycore/ServerStarter.java b/VelocityCore/src/de/steamwar/velocitycore/ServerStarter.java index 1b834390..a6707c45 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/ServerStarter.java +++ b/VelocityCore/src/de/steamwar/velocitycore/ServerStarter.java @@ -20,6 +20,8 @@ package de.steamwar.velocitycore; import com.velocitypowered.api.proxy.Player; +import com.viaversion.viaversion.api.Via; +import com.viaversion.viaversion.velocity.platform.VelocityViaConfig; import de.steamwar.messages.Chatter; import de.steamwar.persistent.Arenaserver; import de.steamwar.persistent.Bauserver; @@ -44,20 +46,23 @@ public class ServerStarter { private static final Portrange ARENA_PORTS = VelocityCore.MAIN_SERVER ? new Portrange(3000, 3100) : (VelocityCore.get().getConfig().isEventmode() ? new Portrange(4000, 5000) : BAU_PORTS); public static final String SERVER_PATH = "/servers/"; - private static final String USER_HOME = System.getProperty("user.home") + "/"; - private static final String EVENT_PATH = USER_HOME + "event/"; - public static final String TEMP_WORLD_PATH = USER_HOME + "arenaserver/"; - public static final String TUTORIAL_PATH = USER_HOME + "tutorials/"; - public static final String WORLDS_BASE_PATH = USER_HOME + "userworlds"; - public static final String BUILDER_BASE_PATH = USER_HOME + "builder"; + private static final String TMP_DATA = System.getProperty("user.home") + "/"; + private static final String EVENT_PATH = TMP_DATA + "event/"; + public static final String TEMP_WORLD_PATH = TMP_DATA + "arenaserver/"; + + private static final String WORLDS_FOLDER = "/worlds"; + public static final String TUTORIAL_PATH = WORLDS_FOLDER + "/tutorials/"; + public static final String WORLDS_BASE_PATH = WORLDS_FOLDER + "/userworlds"; + public static final String BUILDER_BASE_PATH = WORLDS_FOLDER + "/builder"; + + private static final String WORLDS_STORAGE_BASE_PATH = "/mnt/storage/worlds/userworlds"; private File directory = null; private String worldDir = null; private Node node = null; - private String serverJar = "spigot-1.15.2.jar"; - private String xmx = "768M"; + private ServerVersion version = ServerVersion.PAPER_20; private Portrange portrange = BAU_PORTS; private Function serverNameProvider = port -> node.getName() + port; private BooleanSupplier startCondition = () -> true; @@ -78,7 +83,7 @@ public class ServerStarter { public ServerStarter arena(ArenaMode mode, String map) { portrange = ARENA_PORTS; serverNameProvider = port -> mode.getGameName() + (port - portrange.start); - serverJar = mode.getServerJar(); + version = mode.getVersion(); allowMerge = true; fightMap = map; gameMode = mode.getInternalName(); @@ -145,18 +150,24 @@ public class ServerStarter { } public ServerStarter build(ServerVersion version, UUID owner) { + this.version = version; directory = version.getServerDirectory("Bau"); - serverJar = version.getServerJar(); worldDir = version.getWorldFolder(WORLDS_BASE_PATH); - worldName = version != ServerVersion.SPIGOT_12 ? String.valueOf(SteamwarUser.get(owner).getId()) : owner.toString(); + worldName = String.valueOf(SteamwarUser.get(owner).getId()); checkpoint = true; build(owner); worldSetup = () -> { File world = new File(worldDir, worldName); - if (!world.exists()) - copyWorld(node, new File(directory, "Bauwelt").getPath(), world.getPath()); + if (!world.exists()) { + File storage = new File(version.getWorldFolder(WORLDS_STORAGE_BASE_PATH), worldName); + + if(storage.exists()) + node.execute("mv", storage.getPath(), world.getPath()); + else + copyWorld(node, new File(directory, "Bauwelt").getPath(), world.getPath()); + } }; // Send players to existing server @@ -184,6 +195,7 @@ public class ServerStarter { } public ServerStarter tutorial(Player owner, Tutorial tutorial) { + version = ServerVersion.SPIGOT_15; directory = new File(SERVER_PATH, "Tutorial"); buildWithTemp(owner); tempWorld(TUTORIAL_PATH + tutorial.getTutorialId()); @@ -219,7 +231,7 @@ public class ServerStarter { } public ServerStarter builder(ServerVersion version, String map, File generator) { - serverJar = version.getServerJar(); + this.version = version; directory = version.getServerDirectory("Builder"); worldDir = version.getWorldFolder(BUILDER_BASE_PATH); worldName = map; @@ -294,6 +306,7 @@ public class ServerStarter { if(checkpoint) arguments.put("checkpoint", checkpointDir.getPath()); + ((VelocityViaConfig) Via.getConfig()).getVelocityServerProtocols().put(serverName, version.getProtocolVersion().getProtocol()); if(checkpoint && checkpointDir.exists()) { try(DataOutputStream out = new DataOutputStream(Files.newOutputStream(new File(checkpointDir, "port").toPath()))) { out.writeInt(port); @@ -313,7 +326,7 @@ public class ServerStarter { private void regularStart(String serverName, int port) { postStart(constructor.construct(serverName, port, node.startServer( - serverJar, directory, worldDir, worldName, port, xmx, arguments.entrySet().stream().map(entry -> entry.getKey() + "=" + entry.getValue()).toArray(String[]::new) + version.getServerJar(), directory, worldDir, worldName, port, arguments.entrySet().stream().map(entry -> entry.getKey() + "=" + entry.getValue()).toArray(String[]::new) ), worldCleanup, null)); } diff --git a/VelocityCore/src/de/steamwar/velocitycore/ServerVersion.java b/VelocityCore/src/de/steamwar/velocitycore/ServerVersion.java index 31b8e39e..a5e08b55 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/ServerVersion.java +++ b/VelocityCore/src/de/steamwar/velocitycore/ServerVersion.java @@ -19,6 +19,8 @@ package de.steamwar.velocitycore; +import com.velocitypowered.api.network.ProtocolVersion; +import lombok.AllArgsConstructor; import lombok.Getter; import java.io.File; @@ -27,12 +29,22 @@ import java.util.Map; import java.util.Set; @Getter +@AllArgsConstructor public enum ServerVersion { - SPIGOT_12("spigot-1.12.2.jar", 12), - SPIGOT_15("spigot-1.15.2.jar", 15), - PAPER_19("paper-1.19.3.jar", 19), - PAPER_20("paper-1.20.1.jar", 20), - PAPER_21("paper-1.21.jar", 21); + SPIGOT_8("spigot-1.8.8.jar", 8, ProtocolVersion.MINECRAFT_1_8), + SPIGOT_9("spigot-1.9.4.jar", 9, ProtocolVersion.MINECRAFT_1_9), + SPIGOT_10("spigot-1.10.2.jar", 10, ProtocolVersion.MINECRAFT_1_10), + SPIGOT_12("spigot-1.12.2.jar", 12, ProtocolVersion.MINECRAFT_1_12_2), + SPIGOT_14("spigot-1.14.4.jar", 14, ProtocolVersion.MINECRAFT_1_14_4), + SPIGOT_15("spigot-1.15.2.jar", 15, ProtocolVersion.MINECRAFT_1_15_2), + + PAPER_8("paper-1.8.8.jar", 8, ProtocolVersion.MINECRAFT_1_8), + PAPER_10("paper-1.10.2.jar", 10, ProtocolVersion.MINECRAFT_1_10), + PAPER_12("paper-1.12.2.jar", 12, ProtocolVersion.MINECRAFT_1_12_2), + PAPER_18("paper-1.18.2.jar", 15, ProtocolVersion.MINECRAFT_1_18_2), + PAPER_19("paper-1.19.3.jar", 19, ProtocolVersion.MINECRAFT_1_19_3), + PAPER_20("paper-1.20.1.jar", 20, ProtocolVersion.MINECRAFT_1_20), + PAPER_21("paper-1.21.3.jar", 21, ProtocolVersion.MINECRAFT_1_21_2); private static final Map chatMap = new HashMap<>(); @@ -74,13 +86,20 @@ public enum ServerVersion { return chatMap.keySet(); } + private static final Map versionMap = new HashMap<>(); + + static { + for(ServerVersion version : values()) + versionMap.put(version.getVersionSuffix(), version); + } + + public static ServerVersion get(int version) { + return versionMap.get(version); + } + private final String serverJar; private final int versionSuffix; - - ServerVersion(String serverJar, int versionSuffix) { - this.serverJar = serverJar; - this.versionSuffix = versionSuffix; - } + private final ProtocolVersion protocolVersion; public String getWorldFolder(String base) { return base + versionSuffix + "/"; diff --git a/VelocityCore/src/de/steamwar/velocitycore/VelocityCore.java b/VelocityCore/src/de/steamwar/velocitycore/VelocityCore.java index 6a5b3ade..3cec098b 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/VelocityCore.java +++ b/VelocityCore/src/de/steamwar/velocitycore/VelocityCore.java @@ -152,6 +152,7 @@ public class VelocityCore implements ReloadablePlugin { new BanListener(); new CheckListener(); new IPSanitizer(); + new VersionAnnouncer(); local = new Node.LocalNode(); if(MAIN_SERVER) { @@ -251,7 +252,17 @@ public class VelocityCore implements ReloadablePlugin { @Override public void onProxyShutdown(ProxyShutdownEvent event) { try { - DiscordBot.withBot(bot -> bot.getJda().shutdownNow()); + DiscordBot.withBot(bot -> { + bot.getJda().shutdownNow(); + bot.getJda().getHttpClient().connectionPool().evictAll(); + bot.getJda().getHttpClient().dispatcher().executorService().shutdown(); + try { + if(!bot.getJda().awaitShutdown(1, TimeUnit.SECONDS)) + logger.log(Level.SEVERE, "Could not await discord bot shutdown"); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } + }); } catch (Throwable e) { logger.log(Level.SEVERE, "Could not shutdown discord bot", e); } diff --git a/VelocityCore/src/de/steamwar/velocitycore/commands/BauCommand.java b/VelocityCore/src/de/steamwar/velocitycore/commands/BauCommand.java index 150df3fd..710bb1be 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/commands/BauCommand.java +++ b/VelocityCore/src/de/steamwar/velocitycore/commands/BauCommand.java @@ -214,7 +214,7 @@ public class BauCommand extends SWCommand { public void delete(PlayerChatter sender, @OptionalValue(value = "", onlyUINIG = true) ServerVersion version) { SWInventory inventory = new SWInventory(sender, 9, new Message("BAU_DELETE_GUI_NAME")); inventory.addItem(0, new SWItem(new Message("BAU_DELETE_GUI_DELETE"), 10), click -> { - String world = version.getWorldFolder(ServerStarter.WORLDS_BASE_PATH) + (version != ServerVersion.SPIGOT_12 ? sender.user().getId() : sender.user().getUUID().toString()); + String world = version.getWorldFolder(ServerStarter.WORLDS_BASE_PATH) + sender.user().getId(); VelocityCore.schedule(() -> { Bauserver subserver = Bauserver.get(sender.user().getUUID()); diff --git a/VelocityCore/src/de/steamwar/velocitycore/commands/BuilderCloudCommand.java b/VelocityCore/src/de/steamwar/velocitycore/commands/BuilderCloudCommand.java index 4c5c115d..51c0f1bf 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/commands/BuilderCloudCommand.java +++ b/VelocityCore/src/de/steamwar/velocitycore/commands/BuilderCloudCommand.java @@ -90,7 +90,7 @@ public class BuilderCloudCommand extends SWCommand { } VelocityCore.schedule(() -> { - VelocityCore.local.execute("/binarys/deployarena.py", arenaMode.getConfig(), Integer.toString(version.getVersionSuffix()), map); + VelocityCore.local.execute("deployarena.py", arenaMode.getConfig(), Integer.toString(version.getVersionSuffix()), map); ArenaMode.init(); sender.system("BUILDERCLOUD_DEPLOY_FINISHED"); }).schedule(); diff --git a/VelocityCore/src/de/steamwar/velocitycore/commands/DevCommand.java b/VelocityCore/src/de/steamwar/velocitycore/commands/DevCommand.java index e24432cc..71b4427c 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/commands/DevCommand.java +++ b/VelocityCore/src/de/steamwar/velocitycore/commands/DevCommand.java @@ -21,18 +21,21 @@ package de.steamwar.velocitycore.commands; import com.velocitypowered.api.proxy.server.RegisteredServer; import com.velocitypowered.api.proxy.server.ServerInfo; -import de.steamwar.messages.Chatter; -import de.steamwar.messages.Message; -import de.steamwar.sql.UserPerm; -import de.steamwar.velocitycore.ArenaMode; -import de.steamwar.velocitycore.VelocityCore; +import com.viaversion.viaversion.api.Via; +import com.viaversion.viaversion.velocity.platform.VelocityViaConfig; import de.steamwar.command.SWCommand; import de.steamwar.command.SWCommandUtils; import de.steamwar.command.TypeMapper; import de.steamwar.command.TypeValidator; +import de.steamwar.messages.Chatter; +import de.steamwar.messages.Message; import de.steamwar.messages.PlayerChatter; import de.steamwar.sql.Punishment; import de.steamwar.sql.SteamwarUser; +import de.steamwar.sql.UserPerm; +import de.steamwar.velocitycore.ArenaMode; +import de.steamwar.velocitycore.ServerVersion; +import de.steamwar.velocitycore.VelocityCore; import lombok.Getter; import java.io.File; @@ -113,28 +116,32 @@ public class DevCommand extends SWCommand { private void updateDevServers() { String[] serverFiles = devServerDir.list(); - Map devServerFiles = new HashMap<>(); + Map devServerPorts = new HashMap<>(); + Map devServerVersions = new HashMap<>(); if (serverFiles != null) { for (String serverFile : serverFiles) { String[] server = serverFile.split("\\."); - devServerFiles.put(server[0], Integer.parseInt(server[1])); + devServerPorts.put(server[0], Integer.parseInt(server[1])); + devServerVersions.put(server[0], Integer.parseInt(server[2])); } } devServers.entrySet().removeIf(entry -> { - if (!devServerFiles.containsKey(entry.getKey())) { + if (!devServerPorts.containsKey(entry.getKey())) { VelocityCore.getProxy().unregisterServer(entry.getValue().getServerInfo()); return true; } return false; }); - devServerFiles.forEach((key, value) -> { - if (devServers.containsKey(key)) + devServerPorts.forEach((username, value) -> { + if (devServers.containsKey(username)) return; - SteamwarUser user = SteamwarUser.get(key); - devServers.put(user.getUserName().toLowerCase(), VelocityCore.getProxy().registerServer(new ServerInfo("Dev " + user.getUserName(), new InetSocketAddress("127.0.0.1", value)))); + SteamwarUser user = SteamwarUser.get(username); + String name = "Dev " + user.getUserName(); + ((VelocityViaConfig) Via.getConfig()).getVelocityServerProtocols().put(name, ServerVersion.get(devServerVersions.get(username)).getProtocolVersion().getProtocol()); + devServers.put(user.getUserName().toLowerCase(), VelocityCore.getProxy().registerServer(new ServerInfo(name, new InetSocketAddress("127.0.0.1", value)))); }); } } diff --git a/VelocityCore/src/de/steamwar/velocitycore/commands/PunishmentCommand.java b/VelocityCore/src/de/steamwar/velocitycore/commands/PunishmentCommand.java index da847019..1dc8ebde 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/commands/PunishmentCommand.java +++ b/VelocityCore/src/de/steamwar/velocitycore/commands/PunishmentCommand.java @@ -61,7 +61,7 @@ public class PunishmentCommand { return null; } - return SteamwarUser.getOrCreate(uuid, name, u -> {}, (o, n) -> {}); + return SteamwarUser.getOrCreate(uuid, name, u -> {}); } private static UUID getUUIDofOfflinePlayer(String playerName) { diff --git a/VelocityCore/src/de/steamwar/velocitycore/commands/RulesCommand.java b/VelocityCore/src/de/steamwar/velocitycore/commands/RulesCommand.java index cf403c4d..e379d6b1 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/commands/RulesCommand.java +++ b/VelocityCore/src/de/steamwar/velocitycore/commands/RulesCommand.java @@ -36,6 +36,6 @@ public class RulesCommand extends SWCommand { sender.system("REGELN_RULES"); for(String ruleset : Arrays.asList("REGELN_AS", "REGELN_MWG", "REGELN_WG", "REGELN_WS", "REGELN_QG", "REGELN_CONDUCT")) - sender.prefixless(ruleset, new Message(ruleset + "_HOVER"), ClickEvent.openUrl(sender.parseToPlain(ruleset + "_URL"))); + sender.prefixless(ruleset, new Message("URL_FORMAT", sender.parseToPlain(ruleset + "_URL")), ClickEvent.openUrl(sender.parseToPlain(ruleset + "_URL"))); } } diff --git a/VelocityCore/src/de/steamwar/velocitycore/commands/SetLocaleCommand.java b/VelocityCore/src/de/steamwar/velocitycore/commands/SetLocaleCommand.java index 689485cf..a2e66b6b 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/commands/SetLocaleCommand.java +++ b/VelocityCore/src/de/steamwar/velocitycore/commands/SetLocaleCommand.java @@ -19,12 +19,10 @@ package de.steamwar.velocitycore.commands; -import de.steamwar.velocitycore.network.NetworkSender; import de.steamwar.command.SWCommand; -import de.steamwar.messages.Chatter; +import de.steamwar.messages.PlayerChatter; import de.steamwar.network.packets.server.LocaleInvalidationPacket; - -import java.util.Objects; +import de.steamwar.velocitycore.network.NetworkSender; public class SetLocaleCommand extends SWCommand { @@ -33,8 +31,8 @@ public class SetLocaleCommand extends SWCommand { } @Register - public void genericCommand(Chatter sender) { - sender.user().setLocale(Objects.requireNonNull(sender.getLocale()), true); + public void genericCommand(PlayerChatter sender) { + sender.user().setLocale(sender.getPlayer().getPlayerSettings().getLocale(), true); sender.withPlayer(player -> NetworkSender.send(player, new LocaleInvalidationPacket(sender.user().getId()))); sender.system("LOCK_LOCALE_CHANGED"); } diff --git a/VelocityCore/src/de/steamwar/velocitycore/commands/WebpasswordCommand.java b/VelocityCore/src/de/steamwar/velocitycore/commands/WebpasswordCommand.java index ff3370c8..d19dedd0 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/commands/WebpasswordCommand.java +++ b/VelocityCore/src/de/steamwar/velocitycore/commands/WebpasswordCommand.java @@ -21,10 +21,7 @@ package de.steamwar.velocitycore.commands; import de.steamwar.command.SWCommand; import de.steamwar.messages.Chatter; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; +import de.steamwar.sql.SteamwarUser; public class WebpasswordCommand extends SWCommand { @@ -40,33 +37,11 @@ public class WebpasswordCommand extends SWCommand { return; } - ProcessBuilder pb = new ProcessBuilder("php", "/var/www/register.php", sender.user().getUserName(), password); - pb.redirectErrorStream(true); - try { - Process regProcess = pb.start(); - BufferedReader reader = new BufferedReader(new InputStreamReader(regProcess.getInputStream())); - String errorLine; - if((errorLine = reader.readLine()) != null) { - if ("updated".equals(errorLine)) { - sender.system("WEB_UPDATED"); - return; - } else { - throw new SecurityException("Could not create webaccount " + errorLine); - } - } + SteamwarUser user = sender.user(); + boolean resetPW = user.hasPassword(); - sender.system("WEB_CREATED"); - } catch (IOException e) { - throw new SecurityException("Could not create webaccount", e); - } - } + user.setPassword(password); - public static void changeUsername(String oldUsername, String newUsername){ - ProcessBuilder pb = new ProcessBuilder("php", "/var/www/changename.php", oldUsername, newUsername); - try { - pb.start(); - } catch (IOException e) { - throw new SecurityException("Could not change username", e); - } + sender.system(resetPW ? "WEB_UPDATED" : "WEB_CREATED"); } } diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java b/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java index 10cb773f..ecdc5a53 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java @@ -100,7 +100,7 @@ public class DiscordBot { .createDefault(config.getToken()) .setStatus(OnlineStatus.ONLINE) .setMemberCachePolicy(MemberCachePolicy.ONLINE) - .enableIntents(GatewayIntent.MESSAGE_CONTENT) + .enableIntents(GatewayIntent.GUILD_MEMBERS, GatewayIntent.MESSAGE_CONTENT) .build(); instance = this; @@ -165,6 +165,7 @@ public class DiscordBot { .setComponents(actionRows), DiscordTicketHandler::openTicket); eventChannel = new StaticMessageChannel(config.channel("events"), EventChannel::get); checklistChannel = new ChecklistChannel(config.channel("checklist")); + config.getCouncilThread().forEach((roleId, threadId) -> new CouncilChannel(DiscordBot.getGuild().getRoleById(roleId), DiscordBot.getGuild().getThreadChannelById(threadId))); announcementChannel = new DiscordChannel(config.channel("announcement")) { @Override @@ -185,6 +186,8 @@ public class DiscordBot { } }).repeat(30, TimeUnit.SECONDS).schedule(); + VelocityCore.schedule(CouncilChannel::updateAll).repeat(1, TimeUnit.HOURS).schedule(); + jda.addEventListener( new DiscordTicketHandler(), new DiscordTeamEvent(), diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordConfig.java b/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordConfig.java index af930d77..7f201abb 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordConfig.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordConfig.java @@ -56,6 +56,8 @@ public class DiscordConfig { private String ticketcategory; + private Map councilThread; + @NoArgsConstructor public static class DiscordRole { diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/channels/CouncilChannel.java b/VelocityCore/src/de/steamwar/velocitycore/discord/channels/CouncilChannel.java new file mode 100644 index 00000000..e5129f24 --- /dev/null +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/channels/CouncilChannel.java @@ -0,0 +1,69 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2025 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.velocitycore.discord.channels; + +import de.steamwar.sql.SteamwarUser; +import de.steamwar.velocitycore.discord.DiscordBot; +import it.unimi.dsi.fastutil.Pair; +import net.dv8tion.jda.api.EmbedBuilder; +import net.dv8tion.jda.api.entities.Role; +import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel; +import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder; + +import java.util.Comparator; +import java.util.HashSet; +import java.util.Set; +import java.util.UUID; + +public class CouncilChannel extends StaticMessageChannel { + + private static final Set channels = new HashSet<>(); + + public static void updateAll() { + channels.forEach(StaticMessageChannel::update); + } + + public CouncilChannel(Role role, ThreadChannel threadChannel) { + super(threadChannel, () -> { + MessageCreateBuilder messageCreateBuilder = new MessageCreateBuilder(); + messageCreateBuilder.setContent("# Ratsmitglieder"); + + DiscordBot.getGuild().findMembersWithRoles(role).get() + .stream() + .map(member -> { + SteamwarUser steamwarUser = SteamwarUser.get(member.getIdLong()); + String name = steamwarUser == null ? member.getEffectiveName() : steamwarUser.getUserName(); + UUID uuid = steamwarUser == null ? null : steamwarUser.getUUID(); + return Pair.of(name, uuid); + }) + .sorted(Comparator.comparing(Pair::key)) + .forEach(pair -> { + messageCreateBuilder.addEmbeds(new EmbedBuilder() + .setTitle(pair.key()) + .setImage(pair.value() == null ? null : "https://api.steamwar.de/data/skin/" + pair.value().toString()) + .build()); + }); + + return messageCreateBuilder; + }, event -> {}); + + channels.add(this); + } +} diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/channels/DiscordChannel.java b/VelocityCore/src/de/steamwar/velocitycore/discord/channels/DiscordChannel.java index 35e78714..b420f601 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/channels/DiscordChannel.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/channels/DiscordChannel.java @@ -19,11 +19,11 @@ package de.steamwar.velocitycore.discord.channels; -import de.steamwar.velocitycore.discord.DiscordBot; -import de.steamwar.velocitycore.discord.listeners.ChannelListener; import de.steamwar.messages.Chatter; import de.steamwar.messages.Message; import de.steamwar.sql.SteamwarUser; +import de.steamwar.velocitycore.discord.DiscordBot; +import de.steamwar.velocitycore.discord.listeners.ChannelListener; import lombok.AllArgsConstructor; import lombok.Getter; import net.dv8tion.jda.api.entities.User; @@ -31,7 +31,6 @@ import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; import net.dv8tion.jda.api.events.interaction.component.GenericComponentInteractionCreateEvent; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder; -import net.dv8tion.jda.api.utils.messages.MessageCreateData; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; @@ -53,7 +52,11 @@ public class DiscordChannel extends Chatter.PlayerlessChatter { } public DiscordChannel(String channel) { - this(SteamwarUser.get(-1), DiscordBot.getGuild().getTextChannelById(channel)); + this(DiscordBot.getGuild().getTextChannelById(channel)); + } + + public DiscordChannel(MessageChannel channel) { + this(SteamwarUser.get(-1), channel); ChannelListener.getChannels().put(this.channel, this); } diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/channels/StaticMessageChannel.java b/VelocityCore/src/de/steamwar/velocitycore/discord/channels/StaticMessageChannel.java index 3a165915..69549d38 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/channels/StaticMessageChannel.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/channels/StaticMessageChannel.java @@ -21,6 +21,7 @@ package de.steamwar.velocitycore.discord.channels; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.Message; +import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; import net.dv8tion.jda.api.events.interaction.component.GenericComponentInteractionCreateEvent; import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder; import net.dv8tion.jda.api.utils.messages.MessageEditData; @@ -48,7 +49,17 @@ public class StaticMessageChannel extends DiscordChannel { super(channel); this.supplier = supplier; this.interaction = interaction; + init(); + } + public StaticMessageChannel(MessageChannel channel, Supplier supplier, Consumer interaction) { + super(channel); + this.supplier = supplier; + this.interaction = interaction; + init(); + } + + private void init() { if(getChannel().getLatestMessageIdLong() != 0) message = getChannel().getIterableHistory().complete().stream().filter(m -> m.getAuthor().isBot()).findFirst().orElse(null); diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/DiscordSchemUpload.java b/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/DiscordSchemUpload.java index 037eadcd..4a202368 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/DiscordSchemUpload.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/DiscordSchemUpload.java @@ -25,19 +25,23 @@ import de.steamwar.sql.NodeData; import de.steamwar.sql.Punishment; import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SteamwarUser; +import dev.dewy.nbt.Nbt; +import dev.dewy.nbt.tags.collection.CompoundTag; import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.hooks.ListenerAdapter; -import java.io.IOException; -import java.io.InputStream; +import java.io.*; import java.util.Arrays; import java.util.List; import java.util.concurrent.ExecutionException; import java.util.logging.Level; +import java.util.zip.GZIPInputStream; public class DiscordSchemUpload extends ListenerAdapter { + private static final Nbt NBT = new Nbt(); + private static final List SCHEM_FILE_ENDINGS = Arrays.asList(".schem", ".schematic"); @Override @@ -79,7 +83,18 @@ public class DiscordSchemUpload extends ListenerAdapter { node = SchematicNode.createSchematic(user.getId(), name, null); try (InputStream in = attachment.getProxy().download().get()) { - NodeData.get(node).saveFromStream(in, fileName.substring(dot).equalsIgnoreCase(".schem")); + byte[] bytes = in.readAllBytes(); + CompoundTag tags = NBT.fromStream(new DataInputStream(new GZIPInputStream(new ByteArrayInputStream(bytes)))); + + NodeData.SchematicFormat version = NodeData.SchematicFormat.SPONGE_V2; + + if (tags.size() == 1) { + version = NodeData.SchematicFormat.SPONGE_V3; + } else if (tags.contains("Materials")) { + version = NodeData.SchematicFormat.MCEDIT; + } + + NodeData.get(node).saveFromStream(new ByteArrayInputStream(bytes), version); sender.system("DC_SCHEMUPLOAD_SUCCESS", name); } catch (InterruptedException e) { Thread.currentThread().interrupt(); diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/DiscordTicketHandler.java b/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/DiscordTicketHandler.java index a9592c6c..f32b4767 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/DiscordTicketHandler.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/DiscordTicketHandler.java @@ -41,12 +41,12 @@ import net.dv8tion.jda.api.interactions.components.ActionRow; import net.dv8tion.jda.api.interactions.components.buttons.Button; import net.dv8tion.jda.api.utils.SplitUtil; import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder; +import net.dv8tion.jda.api.utils.messages.MessageCreateData; import net.kyori.adventure.text.event.ClickEvent; import org.jetbrains.annotations.NotNull; import java.awt.*; import java.time.Instant; -import java.util.Collections; import java.util.LinkedList; import java.util.stream.Collectors; @@ -112,9 +112,12 @@ public class DiscordTicketHandler extends ListenerAdapter { .setTimestamp(Instant.now()) .setTitle(event.getChannel().getName()); + User user; if(channel.getTopic() != null && !channel.getTopic().isEmpty()) { - User user = event.getJDA().retrieveUserById(channel.getTopic()).complete(); + user = event.getJDA().retrieveUserById(channel.getTopic()).complete(); embedBuilder.setAuthor(user.getName(), null, user.getAvatarUrl()); + } else { + user = null; } TextChannel logChannel = event.getGuild().getTextChannelById(TICKET_LOG); @@ -124,7 +127,14 @@ public class DiscordTicketHandler extends ListenerAdapter { 2000, SplitUtil.Strategy.NEWLINE, SplitUtil.Strategy.ANYWHERE - ).stream().map(message -> new MessageCreateBuilder().setEmbeds(embedBuilder.setDescription(message).build())).forEach(builder -> logChannel.sendMessage(builder.build()).queue()); + ).stream().map(message -> new MessageCreateBuilder().setEmbeds(embedBuilder.setDescription(message).build())) + .forEach(builder -> { + MessageCreateData createData = builder.build(); + logChannel.sendMessage(createData).queue(); + if (user != null) { + user.openPrivateChannel().queue(privateChannel -> privateChannel.sendMessage(createData).queue()); + } + }); Chatter.serverteam().prefixless("DISCORD_TICKET_CLOSED", channel.getName()); channel.delete().reason("Closed").queue(); diff --git a/VelocityCore/src/de/steamwar/velocitycore/listeners/ConnectionListener.java b/VelocityCore/src/de/steamwar/velocitycore/listeners/ConnectionListener.java index c1a4b51d..95edeabb 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/listeners/ConnectionListener.java +++ b/VelocityCore/src/de/steamwar/velocitycore/listeners/ConnectionListener.java @@ -39,6 +39,7 @@ import net.kyori.adventure.text.event.ClickEvent; import java.util.HashSet; import java.util.Set; import java.util.UUID; +import java.util.function.BiConsumer; public class ConnectionListener extends BasicListener { @@ -56,7 +57,7 @@ public class ConnectionListener extends BasicListener { if(!(subject instanceof Player player)) return perm -> Tristate.TRUE; - Set perms = SteamwarUser.getOrCreate(player.getUniqueId(), player.getUsername(), ConnectionListener::newPlayer, WebpasswordCommand::changeUsername).perms(); + Set perms = SteamwarUser.getOrCreate(player.getUniqueId(), player.getUsername(), ConnectionListener::newPlayer).perms(); if(perms.contains(UserPerm.ADMINISTRATION)) return perm -> Tristate.TRUE; else if(perms.contains(UserPerm.TEAM)) diff --git a/VelocityCore/src/de/steamwar/velocitycore/listeners/IPSanitizer.java b/VelocityCore/src/de/steamwar/velocitycore/listeners/IPSanitizer.java index 7b0876a5..bc8c42ba 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/listeners/IPSanitizer.java +++ b/VelocityCore/src/de/steamwar/velocitycore/listeners/IPSanitizer.java @@ -20,6 +20,7 @@ package de.steamwar.velocitycore.listeners; import com.velocitypowered.api.event.Subscribe; +import com.velocitypowered.api.event.connection.DisconnectEvent; import com.velocitypowered.api.event.connection.PreLoginEvent; import com.velocitypowered.api.proxy.Player; import com.velocitypowered.proxy.connection.MinecraftConnection; @@ -32,21 +33,32 @@ import de.steamwar.velocitycore.mods.Hostname; import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.SocketAddress; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; import java.util.logging.Level; public class IPSanitizer extends BasicListener { - private static final Reflection.Field remoteAddress = new Reflection.Field<>(MinecraftConnection.class, "remoteAddress"); + private static final Map trueAddress = new HashMap<>(); // Will likely slightly leak over time public static InetAddress getTrueAddress(Player player) { - return ((InetSocketAddress) ((ConnectedPlayer)player).getConnection().getChannel().remoteAddress()).getAddress(); + return trueAddress.getOrDefault(player.getUniqueId(), ((InetSocketAddress) ((ConnectedPlayer)player).getConnection().getChannel().remoteAddress()).getAddress()); } - private final InetSocketAddress sanitized = new InetSocketAddress("127.127.127.127", 25565); + private static final Reflection.Field remoteAddress = new Reflection.Field<>(MinecraftConnection.class, "remoteAddress"); + private static final InetSocketAddress sanitized = new InetSocketAddress("127.127.127.127", 25565); @Subscribe public void loginEvent(PreLoginEvent e) { - VelocityCore.getLogger().log(Level.INFO, "%s has logged in with user name %s".formatted(e.getConnection().getRemoteAddress(), e.getUsername())); + InetSocketAddress address = e.getConnection().getRemoteAddress(); + VelocityCore.getLogger().log(Level.INFO, "%s has logged in with user name %s".formatted(address, e.getUsername())); + trueAddress.put(e.getUniqueId(), address.getAddress()); remoteAddress.set(Hostname.getInitialInboundConnection((LoginInboundConnection) e.getConnection()).getConnection(), sanitized); } + + @Subscribe + public void disconnectEvent(DisconnectEvent e) { + trueAddress.remove(e.getPlayer().getUniqueId()); + } } diff --git a/VelocityCore/src/de/steamwar/velocitycore/listeners/PluginMessage.java b/VelocityCore/src/de/steamwar/velocitycore/listeners/PluginMessage.java index 05e91edb..af208aed 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/listeners/PluginMessage.java +++ b/VelocityCore/src/de/steamwar/velocitycore/listeners/PluginMessage.java @@ -137,7 +137,6 @@ public class PluginMessage extends BasicListener { "itemswapper:enableshulker", "itemswapper:enablerefill", //https://github.com/tr7zw/ItemSwapper/tree/main (Easier inventory item swapping) "jade:show_overlay", "jade:receive_data", "jade:server_ping", "jade:server_ping_v1", //https://github.com/Snownee/Jade (Information over block/entity under crosshair) "bclib:hello_client", "bclib:request_files", "bclib:send_files", "bclib:chunker", //https://github.com/quiqueck/BCLib (Library for additional dimensions) - "roughlyenoughitems:ci_msg", "roughlyenoughitems:request_tags_s2c", "roughlyenoughitems:og_not_enough", //https://github.com/shedaniel/RoughlyEnoughItems (Crafting recipe helper) "essentialclient:chunkdebug", "essentialclient:clientscript", "essentialclient:gamerule", //https://github.com/senseiwells/EssentialClient (Carpet mod extension) "couplings:server_config", //https://github.com/ChloeDawn/Couplings (Opens/closes double doors/gates simultaneously) "yigd:grave_overview_s2c", "yigd:grave_selection_s2c", "yigd:player_selection_s2c", //https://github.com/B1n-ry/Youre-in-grave-danger (Adds new block - graves) @@ -190,6 +189,10 @@ public class PluginMessage extends BasicListener { "better-suggestions:entity_scores_response", "better-suggestions:entity_tags_response", //https://github.com/shurik204/better-suggestions (Better command tab completion) "farmingforblockheads:chicken_nest_effect", "farmingforblockheads:market_categories", //https://github.com/TwelveIterationMods/FarmingForBlockheads (Improved farming with new blocks) + //https://github.com/shedaniel/RoughlyEnoughItems (Crafting recipe helper) + "roughlyenoughitems:ci_msg", "roughlyenoughitems:request_tags_s2c", "roughlyenoughitems:og_not_enough", + "roughlyenoughitems:sync_displays", + //https://modrinth.com/mod/servux "servux:structures", "servux:entity_data", "servux:hud_metadata", "servux:debug_service", "servux:tweaks", diff --git a/VelocityCore/src/de/steamwar/velocitycore/listeners/VersionAnnouncer.java b/VelocityCore/src/de/steamwar/velocitycore/listeners/VersionAnnouncer.java new file mode 100644 index 00000000..c28a8fee --- /dev/null +++ b/VelocityCore/src/de/steamwar/velocitycore/listeners/VersionAnnouncer.java @@ -0,0 +1,47 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2024 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.velocitycore.listeners; + +import com.velocitypowered.api.event.Subscribe; +import com.velocitypowered.api.event.player.ServerConnectedEvent; +import com.velocitypowered.api.network.ProtocolVersion; +import com.velocitypowered.api.proxy.Player; +import com.velocitypowered.api.proxy.server.ServerInfo; +import com.viaversion.viaversion.api.Via; +import com.viaversion.viaversion.velocity.platform.VelocityViaConfig; +import de.steamwar.messages.Chatter; +import de.steamwar.persistent.Subserver; + +public class VersionAnnouncer extends BasicListener { + + @Subscribe + public void postConnect(ServerConnectedEvent e) { + ServerInfo server = e.getServer().getServerInfo(); + if(!Subserver.isBuild(Subserver.getSubserver(server))) + return; + + Player player = e.getPlayer(); + int serverVersion = ((VelocityViaConfig) Via.getConfig()).getVelocityServerProtocols().get(server.getName()); + if(Via.getAPI().getPlayerVersion(player) == serverVersion) + return; + + player.sendActionBar(Chatter.of(player).parse("SERVER_VERSION", ProtocolVersion.getProtocolVersion(serverVersion).getMostRecentSupportedVersion())); + } +} diff --git a/VelocityCore/src/de/steamwar/velocitycore/tablist/Tablist.java b/VelocityCore/src/de/steamwar/velocitycore/tablist/Tablist.java index 1c5b74c5..f15bc79c 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/tablist/Tablist.java +++ b/VelocityCore/src/de/steamwar/velocitycore/tablist/Tablist.java @@ -143,8 +143,10 @@ public class Tablist extends ChannelInboundHandlerAdapter { public void onServerPostSwitch() { if(player.getProtocolVersion().noLessThan(ProtocolVersion.MINECRAFT_1_20)) { - if(player.getProtocolVersion().greaterThan(ProtocolVersion.MINECRAFT_1_20)) + if(player.getProtocolVersion().greaterThan(ProtocolVersion.MINECRAFT_1_20)) { + sendTabPacket(current, null); current.clear(); + } sendPacket(player, createTeamPacket); } diff --git a/WebsiteBackend/build.gradle.kts b/WebsiteBackend/build.gradle.kts index 2cf527a7..d58a5142 100644 --- a/WebsiteBackend/build.gradle.kts +++ b/WebsiteBackend/build.gradle.kts @@ -53,4 +53,5 @@ dependencies { implementation(libs.yamlconfig) implementation(libs.kotlinxSerializationCbor) implementation(libs.ktorRateLimit) + implementation(libs.nbt) } \ No newline at end of file diff --git a/WebsiteBackend/src/de/steamwar/plugins/Auth.kt b/WebsiteBackend/src/de/steamwar/plugins/Auth.kt index cc5c0822..eeca85ee 100644 --- a/WebsiteBackend/src/de/steamwar/plugins/Auth.kt +++ b/WebsiteBackend/src/de/steamwar/plugins/Auth.kt @@ -104,6 +104,7 @@ Message: ${cause.message} call.response.headers.append("X-Caught", "1") } + /* onCallRespond { call -> if ((call.response.status() ?: HttpStatusCode.OK).isSuccess()) { return@onCallRespond @@ -125,5 +126,5 @@ Message: ${cause.message} """.trimIndent() SWException.log(msg, stack) - } + }*/ } \ No newline at end of file diff --git a/WebsiteBackend/src/de/steamwar/routes/Schematic.kt b/WebsiteBackend/src/de/steamwar/routes/Schematic.kt index b873b97d..02f12243 100644 --- a/WebsiteBackend/src/de/steamwar/routes/Schematic.kt +++ b/WebsiteBackend/src/de/steamwar/routes/Schematic.kt @@ -19,13 +19,13 @@ package de.steamwar.routes +import de.steamwar.ResponseError import de.steamwar.plugins.SWAuthPrincipal import de.steamwar.plugins.SWPermissionCheck -import de.steamwar.sql.NodeData -import de.steamwar.sql.NodeDownload -import de.steamwar.sql.NodeMember -import de.steamwar.sql.SWException -import de.steamwar.sql.SchematicNode +import de.steamwar.sql.* +import de.steamwar.sql.NodeData.SchematicFormat +import dev.dewy.nbt.Nbt +import dev.dewy.nbt.tags.collection.CompoundTag import io.ktor.http.* import io.ktor.server.application.* import io.ktor.server.auth.* @@ -33,11 +33,15 @@ import io.ktor.server.request.* import io.ktor.server.response.* import io.ktor.server.routing.* import kotlinx.serialization.Serializable +import java.io.BufferedInputStream +import java.io.ByteArrayInputStream +import java.io.DataInputStream import java.security.MessageDigest import java.time.Duration import java.time.Instant import java.time.temporal.ChronoUnit import java.util.* +import java.util.zip.GZIPInputStream @Serializable data class ResponseSchematic(val name: String, val id: Int, val type: String?, val owner: Int, val item: String, val lastUpdate: Long, val rank: Int, val replaceColor: Boolean, val allowReplay: Boolean) { @@ -71,6 +75,8 @@ data class SchematicCode(val id: Int, val code: String, val expires: Long) @Serializable data class UploadSchematic(val name: String, val content: String) +val nbt = Nbt() + fun Route.configureSchematic() { route("/download/{code}") { get { @@ -88,7 +94,7 @@ fun Route.configureSchematic() { return@get } - call.response.header("Content-Disposition", "attachment; filename=\"${node.name}.${if (data.nodeFormat) "schem" else "schematic"}\"") + call.response.header("Content-Disposition", "attachment; filename=\"${node.name}${data.nodeFormat.fileEnding}\"") call.respondBytes(data.schemData().readAllBytes(), contentType = ContentType.Application.OctetStream, status = HttpStatusCode.OK) } get("/info") { @@ -103,25 +109,55 @@ fun Route.configureSchematic() { post { val file = call.receive() val schemName = file.name.substringBeforeLast(".") + + if (SchematicNode.invalidSchemName(arrayOf(schemName))) { + call.respond(HttpStatusCode.BadRequest, ResponseError( + error = "INVALID_NAME" + )) + return@post + } + val schemType = file.name.substringAfterLast(".") if (schemType != "schem" && schemType != "schematic") { - call.respond(HttpStatusCode.BadRequest) + call.respond(HttpStatusCode.BadRequest, ResponseError( + error = "INVALID_SUFFIX" + )) return@post } val user = call.principal()!!.user - val content = Base64.getDecoder().decode(file.content) - var node = SchematicNode.getSchematicNode(user.id, schemName, 0) + var node = SchematicNode.getSchematicNode(user.id, schemName, null as Int?) if (node == null) { - node = SchematicNode.createSchematic(user.id, schemName, 0) + node = SchematicNode.createSchematic(user.id, schemName, null) } - val data = NodeData(node.id, false) - data.saveFromStream(content.inputStream(), schemType == "schem") + try { + val content = Base64.getDecoder().decode(file.content) - call.respond(ResponseSchematic(node)) + var schem = nbt.fromStream(DataInputStream(BufferedInputStream(GZIPInputStream(content.inputStream())))) + + if (schem.size() == 1) schem = schem.first() as CompoundTag + + val version = schem.let { + if (it.contains("Materials")) + return@let SchematicFormat.MCEDIT + else if (it.contains("Blocks")) + return@let SchematicFormat.SPONGE_V3 + else + return@let SchematicFormat.SPONGE_V2 + } + + val data = NodeData(node.id, version) + data.saveFromStream(content.inputStream(), version) + + call.respond(ResponseSchematic(node)) + } catch (e: Exception) { + call.respond(HttpStatusCode.BadRequest, ResponseError( + error = e.message ?: "GENERIC", code = "UPLOAD_ERROR" + )) + } } } } diff --git a/build.gradle.kts b/build.gradle.kts index 21b9838c..011b3e37 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,7 +1,7 @@ /* * This file is a part of the SteamWar software. * - * Copyright (C) 2024 SteamWar.de-Serverteam + * Copyright (C) 2025 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 diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle index ff9b2587..5aa2e416 100644 --- a/buildSrc/build.gradle +++ b/buildSrc/build.gradle @@ -1,7 +1,7 @@ /* * This file is a part of the SteamWar software. * - * Copyright (C) 2024 SteamWar.de-Serverteam + * Copyright (C) 2025 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 diff --git a/buildSrc/src/steamwar.java.gradle b/buildSrc/src/steamwar.java.gradle index e68f9fda..a0da4a5f 100644 --- a/buildSrc/src/steamwar.java.gradle +++ b/buildSrc/src/steamwar.java.gradle @@ -1,7 +1,7 @@ /* * This file is a part of the SteamWar software. * - * Copyright (C) 2024 SteamWar.de-Serverteam + * Copyright (C) 2025 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 diff --git a/buildSrc/src/steamwar.kotlin.gradle b/buildSrc/src/steamwar.kotlin.gradle index 03b0a99d..72e6d640 100644 --- a/buildSrc/src/steamwar.kotlin.gradle +++ b/buildSrc/src/steamwar.kotlin.gradle @@ -1,7 +1,7 @@ /* * This file is a part of the SteamWar software. * - * Copyright (C) 2024 SteamWar.de-Serverteam + * Copyright (C) 2025 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 diff --git a/gradle.properties b/gradle.properties index 9d0945b1..91f3a83a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,7 @@ # # This file is a part of the SteamWar software. # -# Copyright (C) 2024 SteamWar.de-Serverteam +# Copyright (C) 2025 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 diff --git a/settings.gradle.kts b/settings.gradle.kts index a29c0412..cea601bf 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,7 +1,7 @@ /* * This file is a part of the SteamWar software. * - * Copyright (C) 2024 SteamWar.de-Serverteam + * Copyright (C) 2025 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 @@ -44,7 +44,7 @@ dependencyResolutionManagement { maven { if (isInCi) { - url = URI("file:///var/www/html/maven/") + url = URI("file:///var/www/maven/") } else { url = URI("https://steamwar.de/maven/") credentials { @@ -116,7 +116,6 @@ dependencyResolutionManagement { library("authlib", "com.mojang:authlib:1.5.25") library("datafixer", "com.mojang:datafixerupper:4.0.26") library("brigadier", "com.mojang:brigadier:1.0.18") - library("viaapi", "com.viaversion:viaversion-api:4.3.1") library("anvilgui", "net.wesjd:anvilgui:1.10.3-SNAPSHOT") library("nms8", "de.steamwar:spigot:1.8") @@ -138,6 +137,8 @@ dependencyResolutionManagement { library("velocity", "de.steamwar:velocity:RELEASE") library("velocityapi", "com.velocitypowered:velocity-api:3.3.0-SNAPSHOT") + library("viaapi", "com.viaversion:viaversion-api:4.3.1") + library("viavelocity", "com.viaversion:viaversion-velocity:4.3.1") library("jda", "net.dv8tion:JDA:5.2.0") library("msgpack", "org.msgpack:msgpack-core:0.9.8") library("apolloprotos", "com.lunarclient:apollo-protos:1.0-SNAPSHOT") @@ -164,6 +165,8 @@ dependencyResolutionManagement { library("yamlconfig", "org.bspfsystems:yamlconfiguration:1.3.0") library("kotlinxSerializationCbor", "org.jetbrains.kotlinx:kotlinx-serialization-cbor:1.4.1") library("ktorRateLimit", "io.ktor:ktor-server-rate-limit:$ktorVersion") + + library("nbt", "dev.dewy:nbt:1.5.1") } } } diff --git a/steamwarci.yml b/steamwarci.yml index 9e5f7f8e..0fa07cde 100644 --- a/steamwarci.yml +++ b/steamwarci.yml @@ -1,36 +1,37 @@ build: - "./gradlew build --no-daemon" + artifacts: - "/binarys/bausystem2.0.jar": "BauSystem/build/libs/BauSystem-all.jar" + "/jars/BauSystem.jar": "BauSystem/build/libs/BauSystem-all.jar" - "/binarys/fightsystem.jar": "FightSystem/build/libs/FightSystem-all.jar" - "/binarys/FightSystem_Standalone.jar": "FightSystem/FightSystem_Standalone/build/libs/FightSystem_Standalone-all.jar" + "/jars/FightSystem.jar": "FightSystem/build/libs/FightSystem-all.jar" + #"/binarys/FightSystem_Standalone.jar": "FightSystem/FightSystem_Standalone/build/libs/FightSystem_Standalone-all.jar" - "/binarys/kotlincore.jar": "KotlinCore/build/libs/KotlinCore-all.jar" - "/binarys/tntleague.jar": "TNTLeague/build/libs/TNTLeague.jar" + "/jars/KotlinCore.jar": "KotlinCore/build/libs/KotlinCore-all.jar" + "/jars/TNTLeague.jar": "TNTLeague/build/libs/TNTLeague.jar" - "/binarys/lobbysystem2.0.jar": "LobbySystem/build/libs/LobbySystem.jar" + "/jars/LobbySystem.jar": "LobbySystem/build/libs/LobbySystem.jar" - "/binarys/missilewars.jar": "MissileWars/build/libs/MissileWars.jar" + "/jars/MissileWars.jar": "MissileWars/build/libs/MissileWars.jar" - "/binarys/realtime.jar": "Realtime/build/libs/Realtime.jar" + "/jars/RealTime.jar": "Realtime/build/libs/Realtime.jar" - "/binarys/schematicsystem.jar": "SchematicSystem/build/libs/SchematicSystem-all.jar" + "/jars/SchematicSystem.jar": "SchematicSystem/build/libs/SchematicSystem-all.jar" - "/binarys/spigotcore.jar": "SpigotCore/build/libs/SpigotCore-all.jar" + "/jars/SpigotCore.jar": "SpigotCore/build/libs/SpigotCore-all.jar" - "/binarys/Builder.jar": "Teamserver/build/libs/Teamserver.jar" + "/jars/Builder.jar": "Teamserver/build/libs/Teamserver.jar" - "/binarys/towerrun.jar": "TowerRun/build/libs/TowerRun.jar" + "/jars/TowerRun.jar": "TowerRun/build/libs/TowerRun.jar" - "/binarys/tutorialsystem.jar": "TutorialSystem/build/libs/TutorialSystem.jar" + "/jars/TutorialSystem.jar": "TutorialSystem/build/libs/TutorialSystem.jar" - "/binarys/PersistentVelocityCore.jar": "VelocityCore/Persistent/build/libs/Persistent.jar" - "/binarys/VelocityCore.jar": "VelocityCore/build/libs/VelocityCore-all.jar" - "/binarys/deployarena.py": "VelocityCore/deployarena.py" + "/jars/PersistentVelocityCore.jar": "VelocityCore/Persistent/build/libs/Persistent.jar" + "/jars/VelocityCore.jar": "VelocityCore/build/libs/VelocityCore-all.jar" + "/usr/local/bin/deployarena.py": "VelocityCore/deployarena.py" - "/binarys/website-api.jar": "WebsiteBackend/build/libs/WebsiteBackend-all.jar" + "/jars/website-api.jar": "WebsiteBackend/build/libs/WebsiteBackend-all.jar" release: - "sudo systemctl restart api.service"