forked from SteamWar/SteamWar
Introduce support for Minecraft 1.21: Add ReflectionWrapper21, ChunkHider21, and enhance version compatibility across systems.
This commit is contained in:
@@ -26,6 +26,7 @@ import de.steamwar.fightsystem.commands.Commands;
|
||||
import de.steamwar.fightsystem.commands.GUI;
|
||||
import de.steamwar.fightsystem.listener.PersonalKitCreator;
|
||||
import de.steamwar.fightsystem.utils.FlatteningWrapper;
|
||||
import de.steamwar.fightsystem.utils.ReflectionWrapper;
|
||||
import de.steamwar.inventory.SWInventory;
|
||||
import de.steamwar.inventory.SWItem;
|
||||
import de.steamwar.sql.PersonalKit;
|
||||
@@ -214,17 +215,8 @@ public class Kit {
|
||||
assert normal != null;
|
||||
return !normal.isEnchantmentInKit(stack) && !stack.getEnchantments().isEmpty();
|
||||
}
|
||||
|
||||
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<String> keys = new HashSet<>((Set<String>) getKeys.invoke(getTag.invoke(asNMSCopy.invoke(null, stack))));
|
||||
keys.remove("Enchantments");
|
||||
keys.remove("Damage");
|
||||
return !keys.isEmpty();
|
||||
return ReflectionWrapper.impl.hasItems(stack);
|
||||
}
|
||||
|
||||
private boolean isEnchantmentInKit(ItemStack stack){
|
||||
|
||||
@@ -62,6 +62,7 @@ public class HullHider implements Listener {
|
||||
private final Hull[] hulls;
|
||||
private final Map<Class<?>, BiFunction<Player, Object, Object>> packetHiders = new HashMap<>();
|
||||
|
||||
private static final Class<?> packetPlayOutExplosion = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundExplodePacket");
|
||||
public HullHider() {
|
||||
if(!TechHiderWrapper.ENABLED) {
|
||||
hulls = new Hull[0];
|
||||
@@ -208,14 +209,8 @@ public class HullHider implements Listener {
|
||||
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("net.minecraft.network.protocol.game.ClientboundExplodePacket");
|
||||
private static final Reflection.Field<List> explosionBlocks = Reflection.getField(packetPlayOutExplosion, List.class, 0);
|
||||
private static final Function<Object, Location> explosionLocation = posPacketToLocation(packetPlayOutExplosion, double.class, 1.0);
|
||||
private Object explosionHider(Player player, Object packet) {
|
||||
if(explosionBlocks.get(packet).isEmpty())
|
||||
return packetHider(player, packet, explosionLocation.apply(packet));
|
||||
|
||||
return packet;
|
||||
return ReflectionWrapper.impl.explosionHider(player, packet, this::packetHider);
|
||||
}
|
||||
|
||||
private void posHiderGenerator(String typeName, Class<? extends Number> posType, double factor) {
|
||||
@@ -224,7 +219,7 @@ public class HullHider implements Listener {
|
||||
packetHiders.put(type, (player, packet) -> packetHider(player, packet, location.apply(packet)));
|
||||
}
|
||||
|
||||
private static Function<Object, Location> posPacketToLocation(Class<?> type, Class<? extends Number> posType, double factor) {
|
||||
public static Function<Object, Location> posPacketToLocation(Class<?> type, Class<? extends Number> posType, double factor) {
|
||||
Reflection.Field<? extends Number> x = Reflection.getField(type, posType, 0);
|
||||
Reflection.Field<? extends Number> y = Reflection.getField(type, posType, 1);
|
||||
Reflection.Field<? extends Number> z = Reflection.getField(type, posType, 2);
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.fightsystem.utils;
|
||||
|
||||
import de.steamwar.core.VersionDependent;
|
||||
import de.steamwar.fightsystem.FightSystem;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public interface ReflectionWrapper {
|
||||
ReflectionWrapper impl = VersionDependent.getVersionImpl(FightSystem.getPlugin());
|
||||
|
||||
Object explosionHider(Player player, Object packet, PacketHiderFunction packetHiderFunction);
|
||||
boolean hasItems(ItemStack stack);
|
||||
|
||||
public interface PacketHiderFunction {
|
||||
Object hide(Player player, Object packet, Location location);
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -59,7 +59,7 @@ public class TechHiderWrapper extends StateDependent implements TechHider.Locati
|
||||
private final SecretKey key;
|
||||
|
||||
public TechHiderWrapper() {
|
||||
super(ENABLED, FightState.Schem);
|
||||
super(ENABLED, FightState.All);
|
||||
techHider = new TechHider(this, Config.ObfuscateWith, Config.HiddenBlocks, Config.HiddenBlockEntities);
|
||||
|
||||
try {
|
||||
@@ -68,7 +68,7 @@ public class TechHiderWrapper extends StateDependent implements TechHider.Locati
|
||||
throw new SecurityException(e);
|
||||
}
|
||||
|
||||
new StateDependentListener(ENABLED, FightState.Schem, this);
|
||||
new StateDependentListener(ENABLED, FightState.All, this);
|
||||
register();
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ softdepend:
|
||||
- SpigotCore
|
||||
depend:
|
||||
- WorldEdit
|
||||
api-version: "1.13"
|
||||
api-version: "1.21.6"
|
||||
|
||||
commands:
|
||||
ak:
|
||||
|
||||
Reference in New Issue
Block a user