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:
2025-07-31 11:34:56 +02:00
parent cf52b50333
commit e7803dcf82
18 changed files with 135 additions and 35 deletions
@@ -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));
}
}