forked from SteamWar/SteamWar
Remove more reflection
This commit is contained in:
@@ -19,7 +19,6 @@
|
||||
|
||||
package de.steamwar.fightsystem.ai;
|
||||
|
||||
import de.steamwar.Reflection;
|
||||
import de.steamwar.fightsystem.ArenaMode;
|
||||
import de.steamwar.fightsystem.Config;
|
||||
import de.steamwar.fightsystem.fight.FightTeam;
|
||||
@@ -30,28 +29,30 @@ import org.bukkit.Material;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.function.BooleanSupplier;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@AllArgsConstructor
|
||||
public class AIManager {
|
||||
private static final List<AIManager> AIs = Arrays.asList(
|
||||
new AIManager(DummyAI.class, Material.STONE, () -> ArenaMode.Test.contains(Config.mode))
|
||||
new AIManager("DummyAI", DummyAI::new, Material.STONE, () -> ArenaMode.Test.contains(Config.mode))
|
||||
);
|
||||
|
||||
public static List<AIManager> availableAIs() {
|
||||
return AIs.stream().filter(manager -> manager.available.getAsBoolean()).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private final Class<? extends AI> aiClass;
|
||||
private final String name;
|
||||
private final Function<FightTeam, AI> constructor;
|
||||
@Getter
|
||||
private final Material icon;
|
||||
private final BooleanSupplier available;
|
||||
|
||||
public String name() {
|
||||
return aiClass.getSimpleName();
|
||||
return name;
|
||||
}
|
||||
|
||||
public void join(FightTeam team) {
|
||||
Reflection.getConstructor(aiClass, FightTeam.class).invoke(team);
|
||||
constructor.apply(team);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,9 +83,8 @@ public class Recording implements Listener {
|
||||
}
|
||||
|
||||
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);
|
||||
CraftbukkitWrapper.impl.entityIterator().filter(filter).map(net.minecraft.world.entity.Entity::getBukkitEntity).forEach(consumer);
|
||||
}
|
||||
|
||||
public Recording() {
|
||||
|
||||
@@ -21,12 +21,10 @@ package de.steamwar.fightsystem.utils;
|
||||
|
||||
import com.comphenix.tinyprotocol.TinyProtocol;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import de.steamwar.Reflection;
|
||||
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;
|
||||
@@ -34,19 +32,11 @@ 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 = ServerLevel.class;
|
||||
public static final Reflection.Method getWorldHandle = Reflection.getTypedMethod(CraftWorld.class, "getHandle", worldServer);
|
||||
|
||||
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();
|
||||
|
||||
public Material idToMaterial(int blockState) {
|
||||
|
||||
+3
-17
@@ -19,14 +19,10 @@
|
||||
|
||||
package de.steamwar.fightsystem.utils;
|
||||
|
||||
import de.steamwar.Reflection;
|
||||
import de.steamwar.fightsystem.Config;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.level.chunk.LevelChunk;
|
||||
import net.minecraft.world.level.chunk.LevelChunkSection;
|
||||
import net.minecraft.world.level.entity.LevelEntityGetter;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.GameRule;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.CraftWorld;
|
||||
@@ -41,26 +37,16 @@ import java.util.stream.StreamSupport;
|
||||
public class CraftbukkitWrapper {
|
||||
public static final CraftbukkitWrapper impl = new CraftbukkitWrapper();
|
||||
|
||||
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(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);
|
||||
return ((CraftEntity) e).getHandle();
|
||||
}
|
||||
|
||||
public float headRotation(Entity e) {
|
||||
return getEntity(e).getYHeadRot();
|
||||
}
|
||||
|
||||
private static final Reflection.Method getWorldEntities = Reflection.getTypedMethod(ServerLevel.class, null, LevelEntityGetter.class);
|
||||
private static final Reflection.Method getIterable = Reflection.getTypedMethod(LevelEntityGetter.class, null, Iterable.class);
|
||||
public Stream<?> entityIterator() {
|
||||
return StreamSupport.stream(((Iterable<?>) getIterable.invoke(getWorldEntities.invoke(getWorld.invoke(Config.world)))).spliterator(), false);
|
||||
public Stream<net.minecraft.world.entity.Entity> entityIterator() {
|
||||
return StreamSupport.stream(((CraftWorld) Config.world).getHandle().getEntities().getAll().spliterator(), false);
|
||||
}
|
||||
|
||||
public void setupGamerule() {
|
||||
|
||||
+1
-3
@@ -19,7 +19,6 @@
|
||||
|
||||
package de.steamwar.fightsystem.utils;
|
||||
|
||||
import de.steamwar.Reflection;
|
||||
import de.steamwar.fightsystem.Config;
|
||||
import it.unimi.dsi.fastutil.shorts.Short2ObjectArrayMap;
|
||||
import net.minecraft.core.BlockPos;
|
||||
@@ -34,12 +33,11 @@ import java.util.List;
|
||||
public class HullHiderWrapper {
|
||||
public static final HullHiderWrapper impl = new HullHiderWrapper();
|
||||
|
||||
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++) {
|
||||
Hull.IntVector change = changes.get(i);
|
||||
blockdata[i] = getState.invoke(Config.world.getBlockData(change.getX(), change.getY(), change.getZ()));
|
||||
blockdata[i] = ((CraftBlockData) Config.world.getBlockData(change.getX(), change.getY(), change.getZ())).getState();
|
||||
}
|
||||
|
||||
return generateBlockChangePacket(changes, blockdata);
|
||||
|
||||
Reference in New Issue
Block a user