forked from SteamWar/SteamWar
Enhance compatibility and feature support for Minecraft 1.21: Add ProtocolWrapper21, update gamerule management, streamline entity tracking, and refine chunk hider logic.
This commit is contained in:
@@ -55,4 +55,7 @@ public class CraftbukkitWrapper10 implements CraftbukkitWrapper {
|
||||
public Stream<?> entityIterator() {
|
||||
return ((CraftWorld) Config.world).getHandle().entityList.stream();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setupGamerule() { }
|
||||
}
|
||||
|
||||
@@ -55,4 +55,7 @@ public class CraftbukkitWrapper12 implements CraftbukkitWrapper {
|
||||
public Stream<?> entityIterator() {
|
||||
return ((CraftWorld) Config.world).getHandle().entityList.stream();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setupGamerule() { }
|
||||
}
|
||||
|
||||
@@ -56,4 +56,7 @@ public class CraftbukkitWrapper14 implements CraftbukkitWrapper {
|
||||
public Stream<?> entityIterator() {
|
||||
return ((CraftWorld) Config.world).getHandle().entitiesById.values().stream();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setupGamerule() { }
|
||||
}
|
||||
|
||||
@@ -56,4 +56,7 @@ public class CraftbukkitWrapper15 implements CraftbukkitWrapper {
|
||||
public Stream<?> entityIterator() {
|
||||
return ((CraftWorld) Config.world).getHandle().entitiesById.values().stream();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setupGamerule() { }
|
||||
}
|
||||
|
||||
@@ -62,4 +62,7 @@ public class CraftbukkitWrapper18 implements CraftbukkitWrapper {
|
||||
public Stream<?> entityIterator() {
|
||||
return StreamSupport.stream(((Iterable<?>) getIterable.invoke(getWorldEntities.invoke(getWorld.invoke(Config.world)))).spliterator(), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setupGamerule() { }
|
||||
}
|
||||
|
||||
@@ -41,4 +41,5 @@ dependencies {
|
||||
}
|
||||
|
||||
compileOnly(libs.fastutil)
|
||||
compileOnly(libs.authlib)
|
||||
}
|
||||
|
||||
+13
-23
@@ -19,34 +19,24 @@
|
||||
|
||||
package de.steamwar.fightsystem.utils;
|
||||
|
||||
import de.steamwar.Reflection;
|
||||
import de.steamwar.fightsystem.Config;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import com.comphenix.tinyprotocol.TinyProtocol;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import de.steamwar.core.ProtocolWrapper;
|
||||
import de.steamwar.fightsystem.FightSystem;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.server.level.ChunkMap;
|
||||
import net.minecraft.server.level.ServerChunkCache;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
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 BlockIdWrapper21 implements BlockIdWrapper {
|
||||
static Int2ObjectMap<ChunkMap.TrackedEntity> tracker;
|
||||
|
||||
static Reflection.Field<Object> chunkMap = Reflection.getField(ServerChunkCache.class, "chunkMap", Object.class);
|
||||
static {
|
||||
ServerChunkCache chunkCache = ((CraftWorld) Config.world).getHandle().getChunkSource();
|
||||
Object map = chunkMap.get(chunkCache);
|
||||
Reflection.Field<Int2ObjectMap> eMapField = Reflection.getField(map.getClass(), "entityMap", Int2ObjectMap.class);
|
||||
tracker = eMapField.get(map);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Material idToMaterial(int blockState) {
|
||||
@@ -71,17 +61,17 @@ public class BlockIdWrapper21 implements BlockIdWrapper {
|
||||
|
||||
@Override
|
||||
public void trackEntity(Player player, Entity entity) {
|
||||
ChunkMap.TrackedEntity trackedEntity = tracker.get(entity.getEntityId());
|
||||
if (trackedEntity != null) {
|
||||
trackedEntity.updatePlayer(((CraftPlayer) player).getHandle());
|
||||
}
|
||||
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) {
|
||||
ChunkMap.TrackedEntity trackedEntity = tracker.get(entity.getEntityId());
|
||||
if (trackedEntity != null) {
|
||||
trackedEntity.removePlayer(((CraftPlayer) player).getHandle());
|
||||
}
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
|
||||
package de.steamwar.fightsystem.utils;
|
||||
|
||||
import de.steamwar.fightsystem.Config;
|
||||
import org.bukkit.GameRule;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
public class CraftbukkitWrapper21 extends CraftbukkitWrapper18 {
|
||||
@@ -27,4 +29,9 @@ public class CraftbukkitWrapper21 extends CraftbukkitWrapper18 {
|
||||
public float headRotation(Entity e) {
|
||||
return getEntity(e).getYHeadRot();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setupGamerule() {
|
||||
Config.world.setGameRule(GameRule.LOCATOR_BAR, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,4 +52,7 @@ public class CraftbukkitWrapper8 implements CraftbukkitWrapper {
|
||||
public Stream<?> entityIterator() {
|
||||
return ((CraftWorld) Config.world).getHandle().entityList.stream();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setupGamerule() { }
|
||||
}
|
||||
|
||||
@@ -55,4 +55,7 @@ public class CraftbukkitWrapper9 implements CraftbukkitWrapper {
|
||||
public Stream<?> entityIterator() {
|
||||
return ((CraftWorld) Config.world).getHandle().entityList.stream();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setupGamerule() { }
|
||||
}
|
||||
|
||||
@@ -188,6 +188,8 @@ public class FightSystem extends JavaPlugin {
|
||||
}else if(Config.mode == ArenaMode.PREPARE) {
|
||||
Fight.getUnrotated().setSchem(SchematicNode.getSchematicNode(Config.PrepareSchemID));
|
||||
}
|
||||
|
||||
CraftbukkitWrapper.impl.setupGamerule();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -33,4 +33,6 @@ public interface CraftbukkitWrapper {
|
||||
float headRotation(Entity e);
|
||||
|
||||
Stream<?> entityIterator();
|
||||
|
||||
void setupGamerule();
|
||||
}
|
||||
|
||||
+2
-2
@@ -59,7 +59,7 @@ public class TechHiderWrapper extends StateDependent implements TechHider.Locati
|
||||
private final SecretKey key;
|
||||
|
||||
public TechHiderWrapper() {
|
||||
super(ENABLED, FightState.All);
|
||||
super(ENABLED, FightState.Schem);
|
||||
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.All, this);
|
||||
new StateDependentListener(ENABLED, FightState.Schem, this);
|
||||
register();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user