forked from SteamWar/SteamWar
Remove most calls to Reflection.getClass
This commit is contained in:
@@ -19,7 +19,6 @@
|
||||
|
||||
package de.steamwar.fightsystem.commands;
|
||||
|
||||
import de.steamwar.Reflection;
|
||||
import de.steamwar.fightsystem.Config;
|
||||
import de.steamwar.fightsystem.FightSystem;
|
||||
import de.steamwar.fightsystem.fight.Fight;
|
||||
@@ -33,15 +32,14 @@ import lombok.experimental.UtilityClass;
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.SimpleCommandMap;
|
||||
import org.bukkit.craftbukkit.CraftServer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@UtilityClass
|
||||
public class Commands {
|
||||
|
||||
private static final Reflection.Field<SimpleCommandMap> commandMap = Reflection.getField("org.bukkit.craftbukkit.CraftServer", "commandMap", SimpleCommandMap.class);
|
||||
public static void injectCommand(Command cmd) {
|
||||
commandMap.get(Bukkit.getServer()).register("FightSystem", cmd);
|
||||
((CraftServer) Bukkit.getServer()).getCommandMap().register("FightSystem", cmd);
|
||||
}
|
||||
|
||||
private static void errNoTeam(Player p){
|
||||
|
||||
@@ -25,6 +25,7 @@ import de.steamwar.fightsystem.states.FightState;
|
||||
import de.steamwar.fightsystem.states.StateDependentTask;
|
||||
import de.steamwar.fightsystem.utils.WorldOfColorWrapper;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import net.minecraft.world.entity.projectile.AbstractArrow;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
@@ -43,9 +44,8 @@ public class ArrowStopper {
|
||||
new StateDependentTask(Config.GameModeConfig.Techhider.Active, FightState.Running, this::run, 1, 1);
|
||||
}
|
||||
|
||||
private static final Class<?> entityArrow = Reflection.getClass("net.minecraft.world.entity.projectile.AbstractArrow");
|
||||
private void run() {
|
||||
Recording.iterateOverEntities(entityArrow::isInstance, entity -> {
|
||||
Recording.iterateOverEntities(AbstractArrow.class::isInstance, entity -> {
|
||||
Projectile arrow = (Projectile) entity;
|
||||
if (invalidEntity(arrow))
|
||||
return;
|
||||
|
||||
+2
-2
@@ -20,11 +20,11 @@
|
||||
package de.steamwar.fightsystem.listener;
|
||||
|
||||
import com.comphenix.tinyprotocol.TinyProtocol;
|
||||
import de.steamwar.Reflection;
|
||||
import de.steamwar.core.Core;
|
||||
import de.steamwar.fightsystem.Config;
|
||||
import de.steamwar.fightsystem.utils.CraftbukkitWrapper;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import net.minecraft.network.protocol.game.ServerboundUseItemOnPacket;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.*;
|
||||
@@ -45,7 +45,7 @@ public class ClickAnalyzer {
|
||||
public ClickAnalyzer() {
|
||||
TinyProtocol.instance.addFilter(Recording.blockPlacePacket, this::onBlockPlace);
|
||||
if(Core.getVersion() > 8)
|
||||
TinyProtocol.instance.addFilter(Reflection.getClass("net.minecraft.network.protocol.game.ServerboundUseItemOnPacket"), this::onBlockPlace);
|
||||
TinyProtocol.instance.addFilter(ServerboundUseItemOnPacket.class, this::onBlockPlace);
|
||||
}
|
||||
|
||||
public Object onBlockPlace(Player player, Object packet) {
|
||||
|
||||
@@ -40,6 +40,9 @@ import de.steamwar.fightsystem.utils.CraftbukkitWrapper;
|
||||
import de.steamwar.fightsystem.utils.FlatteningWrapper;
|
||||
import de.steamwar.fightsystem.utils.SWSound;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import net.minecraft.network.protocol.game.ServerboundPlayerActionPacket;
|
||||
import net.minecraft.network.protocol.game.ServerboundUseItemPacket;
|
||||
import net.minecraft.world.entity.item.PrimedTnt;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@@ -79,8 +82,8 @@ public class Recording implements Listener {
|
||||
return fp == null || !fp.isLiving() || FightState.getFightState() == FightState.SPECTATE;
|
||||
}
|
||||
|
||||
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 final Class<?> primedTnt = PrimedTnt.class;
|
||||
private static final Reflection.Method getBukkitEntity = Reflection.getTypedMethod(net.minecraft.world.entity.Entity.class, "getBukkitEntity", null);
|
||||
public static void iterateOverEntities(Predicate<Object> filter, Consumer<Entity> consumer) {
|
||||
CraftbukkitWrapper.impl.entityIterator().filter(filter).map(entity -> (Entity) getBukkitEntity.invoke(entity)).forEach(consumer);
|
||||
}
|
||||
@@ -131,7 +134,7 @@ public class Recording implements Listener {
|
||||
GlobalRecorder.getInstance().entitySpeed(entity);
|
||||
}
|
||||
|
||||
private static final Class<?> blockDigPacket = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundPlayerActionPacket");
|
||||
private static final Class<?> blockDigPacket = ServerboundPlayerActionPacket.class;
|
||||
private static final Class<?> playerDigType = blockDigPacket.getDeclaredClasses()[0];
|
||||
private static final Reflection.Field<?> blockDigType = Reflection.getField(blockDigPacket, playerDigType, 0);
|
||||
private static final Object releaseUseItem = playerDigType.getEnumConstants()[5];
|
||||
@@ -141,7 +144,7 @@ public class Recording implements Listener {
|
||||
return packet;
|
||||
}
|
||||
|
||||
public static final Class<?> blockPlacePacket = Reflection.getClass("net.minecraft.network.protocol.game.ServerboundUseItemPacket");
|
||||
public static final Class<?> blockPlacePacket = ServerboundUseItemPacket.class;
|
||||
private Object blockPlace(Player p, Object packet) {
|
||||
boolean mainHand = BountifulWrapper.impl.mainHand(packet);
|
||||
if(!isNotSent(p) && BountifulWrapper.impl.bowInHand(mainHand, p))
|
||||
|
||||
@@ -26,6 +26,7 @@ import de.steamwar.core.ProtocolWrapper;
|
||||
import de.steamwar.fightsystem.FightSystem;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
@@ -33,16 +34,17 @@ import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.craftbukkit.CraftWorld;
|
||||
import org.bukkit.craftbukkit.block.CraftBlockState;
|
||||
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class BlockIdWrapper {
|
||||
public static final Class<?> worldServer = Reflection.getClass("net.minecraft.server.level.ServerLevel");
|
||||
public static final Reflection.Method getWorldHandle = Reflection.getTypedMethod(Reflection.getClass("org.bukkit.craftbukkit.CraftWorld"), "getHandle", worldServer);
|
||||
public static final Class<?> worldServer = ServerLevel.class;
|
||||
public static final Reflection.Method getWorldHandle = Reflection.getTypedMethod(CraftWorld.class, "getHandle", worldServer);
|
||||
|
||||
public static final Class<?> craftPlayer = Reflection.getClass("org.bukkit.craftbukkit.entity.CraftPlayer");
|
||||
public static final Class<?> entityPlayer = Reflection.getClass("net.minecraft.server.level.ServerPlayer");
|
||||
public static final Class<?> craftPlayer = CraftPlayer.class;
|
||||
public static final Class<?> entityPlayer = ServerPlayer.class;
|
||||
public static final Reflection.Method getPlayer = Reflection.getTypedMethod(craftPlayer, "getHandle", entityPlayer);
|
||||
|
||||
public static final BlockIdWrapper impl = new BlockIdWrapper();
|
||||
|
||||
+2
-1
@@ -24,6 +24,7 @@ import de.steamwar.fightsystem.fight.Fight;
|
||||
import de.steamwar.fightsystem.fight.FightTeam;
|
||||
import de.steamwar.fightsystem.listener.Recording;
|
||||
import de.steamwar.fightsystem.record.GlobalRecorder;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.attribute.AttributeInstance;
|
||||
@@ -44,7 +45,7 @@ import java.util.Map;
|
||||
public class BountifulWrapper {
|
||||
public static final BountifulWrapper impl = new BountifulWrapper();
|
||||
|
||||
private static final Class<?> enumHand = Reflection.getClass("net.minecraft.world.InteractionHand");
|
||||
private static final Class<?> enumHand = InteractionHand.class;
|
||||
private static final Object mainHand = enumHand.getEnumConstants()[0];
|
||||
private static final Reflection.Field<?> blockPlaceHand = Reflection.getField(Recording.blockPlacePacket, enumHand, 0);
|
||||
|
||||
|
||||
+3
-2
@@ -30,6 +30,7 @@ import org.bukkit.Chunk;
|
||||
import org.bukkit.GameRule;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.CraftWorld;
|
||||
import org.bukkit.craftbukkit.entity.CraftEntity;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
import java.util.HashSet;
|
||||
@@ -40,14 +41,14 @@ import java.util.stream.StreamSupport;
|
||||
public class CraftbukkitWrapper {
|
||||
public static final CraftbukkitWrapper impl = new CraftbukkitWrapper();
|
||||
|
||||
private static final Reflection.Method getWorld = Reflection.getMethod(Reflection.getClass("org.bukkit.craftbukkit.CraftWorld"), "getHandle");
|
||||
private static final Reflection.Method getWorld = Reflection.getMethod(CraftWorld.class, "getHandle");
|
||||
private static final Reflection.Method getChunk = Reflection.getTypedMethod(ServerLevel.class, null, LevelChunk.class, int.class, int.class);
|
||||
private static final Reflection.Method getChunkSections = Reflection.getTypedMethod(LevelChunk.class, null, LevelChunkSection[].class);
|
||||
private LevelChunkSection[] getChunkSections(World world, int x, int z) {
|
||||
return (LevelChunkSection[]) getChunkSections.invoke(getChunk.invoke(getWorld.invoke(world), x, z));
|
||||
}
|
||||
|
||||
private static final Reflection.Method getEntity = Reflection.getTypedMethod(Reflection.getClass("org.bukkit.craftbukkit.entity.CraftEntity"), "getHandle", net.minecraft.world.entity.Entity.class);
|
||||
private static final Reflection.Method getEntity = Reflection.getTypedMethod(CraftEntity.class, "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);
|
||||
}
|
||||
|
||||
@@ -34,6 +34,9 @@ import de.steamwar.fightsystem.states.StateDependentListener;
|
||||
import de.steamwar.fightsystem.states.StateDependentTask;
|
||||
import de.steamwar.techhider.TechHider;
|
||||
import lombok.Getter;
|
||||
import net.minecraft.core.Vec3i;
|
||||
import net.minecraft.network.protocol.game.ClientboundExplodePacket;
|
||||
import net.minecraft.network.protocol.game.ClientboundLevelEventPacket;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@@ -61,7 +64,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");
|
||||
private static final Class<?> packetPlayOutExplosion = ClientboundExplodePacket.class;
|
||||
public HullHider() {
|
||||
if(!TechHiderWrapper.ENABLED) {
|
||||
hulls = new Hull[0];
|
||||
@@ -200,9 +203,9 @@ public class HullHider implements Listener {
|
||||
}
|
||||
|
||||
|
||||
private static final Class<?> packetPlayOutWorldEvent = Reflection.getClass("net.minecraft.network.protocol.game.ClientboundLevelEventPacket");
|
||||
private static final Class<?> packetPlayOutWorldEvent = ClientboundLevelEventPacket.class;
|
||||
private static final Reflection.Field<?> worldEventPosition = Reflection.getField(packetPlayOutWorldEvent, TechHider.blockPosition, 0);
|
||||
public static final Reflection.Field<Integer> blockPositionY = Reflection.getField("net.minecraft.core.Vec3i", int.class, 1);
|
||||
public static final Reflection.Field<Integer> blockPositionY = Reflection.getField(Vec3i.class, 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)));
|
||||
|
||||
+2
-1
@@ -27,13 +27,14 @@ import net.minecraft.core.SectionPos;
|
||||
import net.minecraft.network.protocol.game.ClientboundBlockUpdatePacket;
|
||||
import net.minecraft.network.protocol.game.ClientboundSectionBlocksUpdatePacket;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import org.bukkit.craftbukkit.block.data.CraftBlockData;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class HullHiderWrapper {
|
||||
public static final HullHiderWrapper impl = new HullHiderWrapper();
|
||||
|
||||
private static final Reflection.Method getState = Reflection.getTypedMethod(Reflection.getClass("org.bukkit.craftbukkit.block.data.CraftBlockData"), "getState", BlockState.class);
|
||||
private static final Reflection.Method getState = Reflection.getTypedMethod(CraftBlockData.class, "getState", BlockState.class);
|
||||
public Object generateBlockChangePacket(List<Hull.IntVector> changes) {
|
||||
Object[] blockdata = new Object[changes.size()];
|
||||
for(int i = 0; i < blockdata.length; i++) {
|
||||
|
||||
Reference in New Issue
Block a user