diff --git a/v1_17/src/main/java/com/denizenscript/denizen/nms/v1_17/impl/ProfileEditorImpl.java b/v1_17/src/main/java/com/denizenscript/denizen/nms/v1_17/impl/ProfileEditorImpl.java index 83695129aa..ea9fb55f0d 100644 --- a/v1_17/src/main/java/com/denizenscript/denizen/nms/v1_17/impl/ProfileEditorImpl.java +++ b/v1_17/src/main/java/com/denizenscript/denizen/nms/v1_17/impl/ProfileEditorImpl.java @@ -14,6 +14,10 @@ import com.denizenscript.denizencore.utilities.CoreUtilities; import com.denizenscript.denizencore.utilities.debugging.Debug; import net.md_5.bungee.api.ChatColor; +import net.minecraft.network.chat.Component; +import net.minecraft.network.protocol.game.ClientboundAddPlayerPacket; +import net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket; +import net.minecraft.network.protocol.game.ClientboundRemoveEntityPacket; import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerLevel; import org.bukkit.Bukkit; @@ -34,7 +38,7 @@ public class ProfileEditorImpl extends ProfileEditor { protected void updatePlayer(Player player, final boolean isSkinChanging) { final ServerPlayer entityPlayer = ((CraftPlayer) player).getHandle(); final UUID uuid = player.getUniqueId(); - PacketPlayOutEntityDestroy destroyPacket = new PacketPlayOutEntityDestroy(entityPlayer.getId()); + ClientboundRemoveEntityPacket destroyPacket = new ClientboundRemoveEntityPacket(entityPlayer.getId()); for (Player p : Bukkit.getServer().getOnlinePlayers()) { if (!p.getUniqueId().equals(uuid)) { PacketHelperImpl.send(p, destroyPacket); @@ -43,8 +47,8 @@ protected void updatePlayer(Player player, final boolean isSkinChanging) { new BukkitRunnable() { @Override public void run() { - PacketPlayOutPlayerInfo playerInfo = new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, entityPlayer); - PacketPlayOutNamedEntitySpawn spawnPacket = new PacketPlayOutNamedEntitySpawn(entityPlayer); + ClientboundPlayerInfoPacket playerInfo = new ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.ADD_PLAYER, entityPlayer); + ClientboundAddPlayerPacket spawnPacket = new ClientboundAddPlayerPacket(entityPlayer); for (Player player : Bukkit.getServer().getOnlinePlayers()) { PacketHelperImpl.send(player, playerInfo); if (!player.getUniqueId().equals(uuid)) { @@ -61,15 +65,15 @@ public void run() { }.runTaskLater(NMSHandler.getJavaPlugin(), 5); } - public static boolean handleAlteredProfiles(PacketPlayOutPlayerInfo packet, DenizenNetworkManagerImpl manager) { + public static boolean handleAlteredProfiles(ClientboundPlayerInfoPacket packet, DenizenNetworkManagerImpl manager) { if (ProfileEditor.mirrorUUIDs.isEmpty() && !RenameCommand.hasAnyDynamicRenames()) { return true; } - PacketPlayOutPlayerInfo.EnumPlayerInfoAction action = ReflectionHelper.getFieldValue(PacketPlayOutPlayerInfo.class, "a", packet); - if (action != PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER && action != PacketPlayOutPlayerInfo.EnumPlayerInfoAction.UPDATE_DISPLAY_NAME) { + ClientboundPlayerInfoPacket.Action action = ReflectionHelper.getFieldValue(ClientboundPlayerInfoPacket.class, "a", packet); + if (action != ClientboundPlayerInfoPacket.Action.ADD_PLAYER && action != ClientboundPlayerInfoPacket.Action.UPDATE_DISPLAY_NAME) { return true; } - List dataList = ReflectionHelper.getFieldValue(PacketPlayOutPlayerInfo.class, "b", packet); + List dataList = ReflectionHelper.getFieldValue(ClientboundPlayerInfoPacket.class, "b", packet); if (dataList == null) { return true; } @@ -84,19 +88,19 @@ public static boolean handleAlteredProfiles(PacketPlayOutPlayerInfo packet, Deni if (!any) { return true; } - GameProfile ownProfile = manager.player.getProfile(); + GameProfile ownProfile = manager.player.getGameProfile(); for (Object data : dataList) { GameProfile gameProfile = (GameProfile) playerInfoData_gameProfile.get(data); if (!ProfileEditor.mirrorUUIDs.contains(gameProfile.getId()) && !RenameCommand.customNames.containsKey(gameProfile.getId())) { - PacketPlayOutPlayerInfo newPacket = new PacketPlayOutPlayerInfo(action); - List newPacketDataList = ReflectionHelper.getFieldValue(PacketPlayOutPlayerInfo.class, "b", newPacket); + ClientboundPlayerInfoPacket newPacket = new ClientboundPlayerInfoPacket(action); + List newPacketDataList = ReflectionHelper.getFieldValue(ClientboundPlayerInfoPacket.class, "b", newPacket); newPacketDataList.add(data); manager.oldManager.send(newPacket); } else { String rename = RenameCommand.getCustomNameFor(gameProfile.getId(), manager.player.getBukkitEntity(), false); - PacketPlayOutPlayerInfo newPacket = new PacketPlayOutPlayerInfo(action); - List newPacketDataList = ReflectionHelper.getFieldValue(PacketPlayOutPlayerInfo.class, "b", newPacket); + ClientboundPlayerInfoPacket newPacket = new ClientboundPlayerInfoPacket(action); + List newPacketDataList = ReflectionHelper.getFieldValue(ClientboundPlayerInfoPacket.class, "b", newPacket); GameProfile patchedProfile = new GameProfile(gameProfile.getId(), rename != null ? (rename.length() > 16 ? rename.substring(0, 16) : rename) : gameProfile.getName()); if (ProfileEditor.mirrorUUIDs.contains(gameProfile.getId())) { patchedProfile.getProperties().putAll(ownProfile.getProperties()); @@ -105,7 +109,7 @@ public static boolean handleAlteredProfiles(PacketPlayOutPlayerInfo packet, Deni patchedProfile.getProperties().putAll(gameProfile.getProperties()); } String listRename = RenameCommand.getCustomNameFor(gameProfile.getId(), manager.player.getBukkitEntity(), true); - IChatBaseComponent displayName = listRename != null ? Handler.componentToNMS(FormattedTextHelper.parse(listRename, ChatColor.WHITE)) : (IChatBaseComponent) playerInfoData_displayName.get(data); + Component displayName = listRename != null ? Handler.componentToNMS(FormattedTextHelper.parse(listRename, ChatColor.WHITE)) : (Component) playerInfoData_displayName.get(data); Object newData = playerInfoData_construct.newInstance(newPacket, patchedProfile, playerInfoData_latency.getInt(data), playerInfoData_gamemode.get(data), displayName); newPacketDataList.add(newData); manager.oldManager.send(newPacket); @@ -119,12 +123,12 @@ public static boolean handleAlteredProfiles(PacketPlayOutPlayerInfo packet, Deni } } - public static void updatePlayerProfiles(PacketPlayOutPlayerInfo packet) { - PacketPlayOutPlayerInfo.EnumPlayerInfoAction action = ReflectionHelper.getFieldValue(PacketPlayOutPlayerInfo.class, "a", packet); - if (action != PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER) { + public static void updatePlayerProfiles(ClientboundPlayerInfoPacket packet) { + ClientboundPlayerInfoPacket.Action action = ReflectionHelper.getFieldValue(ClientboundPlayerInfoPacket.class, "a", packet); + if (action != ClientboundPlayerInfoPacket.Action.ADD_PLAYER) { return; } - List dataList = ReflectionHelper.getFieldValue(PacketPlayOutPlayerInfo.class, "b", packet); + List dataList = ReflectionHelper.getFieldValue(ClientboundPlayerInfoPacket.class, "b", packet); if (dataList != null) { try { for (Object data : dataList) { @@ -162,7 +166,7 @@ private static GameProfile getGameProfile(PlayerProfile playerProfile) { Field pidLatency = null, pidGamemode = null, pidGameProfile = null, pidDisplayName = null; Constructor pidConstruct = null; try { - for (Class clzz : PacketPlayOutPlayerInfo.class.getDeclaredClasses()) { + for (Class clzz : ClientboundPlayerInfoPacket.class.getDeclaredClasses()) { if (CoreUtilities.toLowerCase(clzz.getName()).contains("infodata")) { // PlayerInfoData. pid = clzz; pidLatency = clzz.getDeclaredField("b"); diff --git a/v1_17/src/main/java/com/denizenscript/denizen/nms/v1_17/impl/SidebarImpl.java b/v1_17/src/main/java/com/denizenscript/denizen/nms/v1_17/impl/SidebarImpl.java index b5eaf3de14..488f0594f9 100644 --- a/v1_17/src/main/java/com/denizenscript/denizen/nms/v1_17/impl/SidebarImpl.java +++ b/v1_17/src/main/java/com/denizenscript/denizen/nms/v1_17/impl/SidebarImpl.java @@ -5,82 +5,95 @@ import com.denizenscript.denizen.nms.abstracts.Sidebar; import com.denizenscript.denizen.utilities.FormattedTextHelper; import com.denizenscript.denizen.utilities.Utilities; +import com.denizenscript.denizen.utilities.debugging.Debug; import net.md_5.bungee.api.ChatColor; -import net.minecraft.network.chat.IChatBaseComponent; -import net.minecraft.network.protocol.game.PacketPlayOutScoreboardDisplayObjective; -import net.minecraft.network.protocol.game.PacketPlayOutScoreboardObjective; -import net.minecraft.network.protocol.game.PacketPlayOutScoreboardScore; -import net.minecraft.network.protocol.game.PacketPlayOutScoreboardTeam; -import net.minecraft.server.ScoreboardServer; +import net.minecraft.network.chat.MutableComponent; +import net.minecraft.network.protocol.game.ClientboundSetDisplayObjectivePacket; +import net.minecraft.network.protocol.game.ClientboundSetObjectivePacket; +import net.minecraft.network.protocol.game.ClientboundSetPlayerTeamPacket; +import net.minecraft.network.protocol.game.ClientboundSetScorePacket; +import net.minecraft.server.ServerScoreboard; +import net.minecraft.world.scores.Objective; +import net.minecraft.world.scores.PlayerTeam; import net.minecraft.world.scores.Scoreboard; -import net.minecraft.world.scores.ScoreboardObjective; -import net.minecraft.world.scores.ScoreboardTeam; -import net.minecraft.world.scores.criteria.IScoreboardCriteria; +import net.minecraft.world.scores.criteria.ObjectiveCriteria; import org.bukkit.entity.Player; +import java.lang.reflect.Constructor; import java.util.ArrayList; import java.util.List; public class SidebarImpl extends Sidebar { - public static final Scoreboard dummyScoreboard = new Scoreboard(); - public static final IScoreboardCriteria dummyCriteria = new IScoreboardCriteria("dummy"); // what + public static Scoreboard dummyScoreboard = new Scoreboard(); + public static ObjectiveCriteria dummyCriteria; - private ScoreboardObjective obj1; - private ScoreboardObjective obj2; + static { + try { + Constructor constructor = ObjectiveCriteria.class.getConstructor(String.class); + constructor.setAccessible(true); + dummyCriteria = constructor.newInstance("dummy"); + } + catch (Throwable ex) { + Debug.echoError(ex); + } + } + + public Objective obj1; + public Objective obj2; public SidebarImpl(Player player) { super(player); - IChatBaseComponent chatComponentTitle = Handler.componentToNMS(FormattedTextHelper.parse(title, ChatColor.WHITE)); - this.obj1 = new ScoreboardObjective(dummyScoreboard, "dummy_1", dummyCriteria, chatComponentTitle, IScoreboardCriteria.EnumScoreboardHealthDisplay.INTEGER); - this.obj2 = new ScoreboardObjective(dummyScoreboard, "dummy_2", dummyCriteria, chatComponentTitle, IScoreboardCriteria.EnumScoreboardHealthDisplay.INTEGER); + MutableComponent chatComponentTitle = Handler.componentToNMS(FormattedTextHelper.parse(title, ChatColor.WHITE)); + this.obj1 = new Objective(dummyScoreboard, "dummy_1", dummyCriteria, chatComponentTitle, ObjectiveCriteria.RenderType.INTEGER); + this.obj2 = new Objective(dummyScoreboard, "dummy_2", dummyCriteria, chatComponentTitle, ObjectiveCriteria.RenderType.INTEGER); } @Override protected void setDisplayName(String title) { if (this.obj1 != null) { - IChatBaseComponent chatComponentTitle = Handler.componentToNMS(FormattedTextHelper.parse(title, ChatColor.WHITE)); + MutableComponent chatComponentTitle = Handler.componentToNMS(FormattedTextHelper.parse(title, ChatColor.WHITE)); this.obj1.setDisplayName(chatComponentTitle); this.obj2.setDisplayName(chatComponentTitle); } } - public List generatedTeams = new ArrayList<>(); + public List generatedTeams = new ArrayList<>(); @Override public void sendUpdate() { - List oldTeams = generatedTeams; + List oldTeams = generatedTeams; generatedTeams = new ArrayList<>(); - PacketHelperImpl.send(player, new PacketPlayOutScoreboardObjective(this.obj1, 0)); + PacketHelperImpl.send(player, new ClientboundSetObjectivePacket(this.obj1, 0)); for (int i = 0; i < this.lines.length; i++) { String line = this.lines[i]; if (line == null) { break; } String lineId = Utilities.generateRandomColors(8); - ScoreboardTeam team = new ScoreboardTeam(dummyScoreboard, lineId); - team.getPlayerNameSet().add(lineId); - team.setPrefix(Handler.componentToNMS(FormattedTextHelper.parse(line, ChatColor.WHITE))); + PlayerTeam team = new PlayerTeam(dummyScoreboard, lineId); + team.getPlayers().add(lineId); + team.setPlayerPrefix(Handler.componentToNMS(FormattedTextHelper.parse(line, ChatColor.WHITE))); generatedTeams.add(team); - PacketHelperImpl.send(player, new PacketPlayOutScoreboardTeam(team, 0)); - PacketHelperImpl.send(player, new PacketPlayOutScoreboardScore(ScoreboardServer.Action.CHANGE, obj1.getName(), lineId, this.scores[i])); + PacketHelperImpl.send(player, ClientboundSetPlayerTeamPacket.createAddOrModifyPacket(team, false)); + PacketHelperImpl.send(player, new ClientboundSetScorePacket(ServerScoreboard.Method.CHANGE, obj1.getName(), lineId, this.scores[i])); } - PacketHelperImpl.send(player, new PacketPlayOutScoreboardDisplayObjective(1, this.obj1)); - PacketHelperImpl.send(player, new PacketPlayOutScoreboardObjective(this.obj2, 1)); - ScoreboardObjective temp = this.obj2; + PacketHelperImpl.send(player, new ClientboundSetDisplayObjectivePacket(1, this.obj1)); + PacketHelperImpl.send(player, new ClientboundSetObjectivePacket(this.obj2, 1)); + Objective temp = this.obj2; this.obj2 = this.obj1; this.obj1 = temp; - for (ScoreboardTeam team : oldTeams) { - PacketHelperImpl.send(player, new PacketPlayOutScoreboardTeam(team, 1)); + for (PlayerTeam team : oldTeams) { + PacketHelperImpl.send(player, ClientboundSetPlayerTeamPacket.createRemovePacket(team)); } } @Override public void remove() { - for (ScoreboardTeam team : generatedTeams) { - PacketHelperImpl.send(player, new PacketPlayOutScoreboardTeam(team, 1)); + for (PlayerTeam team : generatedTeams) { + PacketHelperImpl.send(player, ClientboundSetPlayerTeamPacket.createRemovePacket(team)); } generatedTeams.clear(); - PacketHelperImpl.send(player, new PacketPlayOutScoreboardObjective(this.obj2, 1)); + PacketHelperImpl.send(player, new ClientboundSetObjectivePacket(this.obj2, 1)); } } diff --git a/v1_17/src/main/java/com/denizenscript/denizen/nms/v1_17/impl/blocks/BlockLightImpl.java b/v1_17/src/main/java/com/denizenscript/denizen/nms/v1_17/impl/blocks/BlockLightImpl.java index 76ce22c38e..54b7859b0e 100644 --- a/v1_17/src/main/java/com/denizenscript/denizen/nms/v1_17/impl/blocks/BlockLightImpl.java +++ b/v1_17/src/main/java/com/denizenscript/denizen/nms/v1_17/impl/blocks/BlockLightImpl.java @@ -6,19 +6,19 @@ import com.denizenscript.denizencore.utilities.ReflectionHelper; import com.denizenscript.denizencore.utilities.debugging.Debug; import net.minecraft.core.BlockPos; -import net.minecraft.network.protocol.game.PacketPlayOutBlockChange; -import net.minecraft.network.protocol.game.PacketPlayOutLightUpdate; -import net.minecraft.server.level.LightEngineThreaded; +import net.minecraft.network.protocol.game.ClientboundBlockUpdatePacket; +import net.minecraft.network.protocol.game.ClientboundLightUpdatePacket; +import net.minecraft.server.level.ServerChunkCache; +import net.minecraft.server.level.ThreadedLevelLightEngine; import net.minecraft.world.level.ChunkPos; -import net.minecraft.world.level.EnumSkyBlock; -import net.minecraft.world.level.World; -import net.minecraft.world.level.chunk.Chunk; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.LightLayer; +import net.minecraft.world.level.chunk.ChunkAccess; import net.minecraft.world.level.chunk.ChunkStatus; -import net.minecraft.world.level.chunk.IChunkAccess; +import net.minecraft.world.level.chunk.DataLayer; import net.minecraft.world.level.chunk.LevelChunk; -import net.minecraft.world.level.chunk.NibbleArray; -import net.minecraft.world.level.lighting.LightEngine; -import net.minecraft.world.level.lighting.LightEngineBlock; +import net.minecraft.world.level.lighting.BlockLightEngine; +import net.minecraft.world.level.lighting.LevelLightEngine; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.craftbukkit.v1_17_R1.CraftChunk; @@ -32,13 +32,13 @@ public class BlockLightImpl extends BlockLight { - public static final Field PACKETPLAYOUTLIGHTUPDATE_CHUNKX = ReflectionHelper.getFields(PacketPlayOutLightUpdate.class).get("a"); - public static final Field PACKETPLAYOUTLIGHTUPDATE_CHUNKZ = ReflectionHelper.getFields(PacketPlayOutLightUpdate.class).get("b"); - public static final Field PACKETPLAYOUTLIGHTUPDATE_BLOCKLIGHT_BITMASK = ReflectionHelper.getFields(PacketPlayOutLightUpdate.class).get("d"); - public static final Field PACKETPLAYOUTLIGHTUPDATE_BLOCKLIGHT_DATA = ReflectionHelper.getFields(PacketPlayOutLightUpdate.class).get("h"); - public static final Field PACKETPLAYOUTBLOCKCHANGE_POSITION = ReflectionHelper.getFields(PacketPlayOutBlockChange.class).get("a"); + public static final Field PACKETPLAYOUTLIGHTUPDATE_CHUNKX = ReflectionHelper.getFields(ClientboundLightUpdatePacket.class).get("a"); + public static final Field PACKETPLAYOUTLIGHTUPDATE_CHUNKZ = ReflectionHelper.getFields(ClientboundLightUpdatePacket.class).get("b"); + public static final Field PACKETPLAYOUTLIGHTUPDATE_BLOCKLIGHT_BITMASK = ReflectionHelper.getFields(ClientboundLightUpdatePacket.class).get("d"); + public static final Field PACKETPLAYOUTLIGHTUPDATE_BLOCKLIGHT_DATA = ReflectionHelper.getFields(ClientboundLightUpdatePacket.class).get("h"); + public static final Field PACKETPLAYOUTBLOCKCHANGE_POSITION = ReflectionHelper.getFields(ClientboundBlockUpdatePacket.class).get("a"); - public static final Class LIGHTENGINETHREADED_UPDATE = LightEngineThreaded.class.getDeclaredClasses()[0]; + public static final Class LIGHTENGINETHREADED_UPDATE = ThreadedLevelLightEngine.class.getDeclaredClasses()[0]; public static final Object LIGHTENGINETHREADED_UPDATE_PRE; static { @@ -52,12 +52,12 @@ public class BlockLightImpl extends BlockLight { LIGHTENGINETHREADED_UPDATE_PRE = preObj; } - public static final MethodHandle LIGHTENGINETHREADED_QUEUERUNNABLE = ReflectionHelper.getMethodHandle(LightEngineThreaded.class, "a", + public static final MethodHandle LIGHTENGINETHREADED_QUEUERUNNABLE = ReflectionHelper.getMethodHandle(ThreadedLevelLightEngine.class, "a", int.class, int.class, LIGHTENGINETHREADED_UPDATE, Runnable.class); - public static void enqueueRunnable(Chunk chunk, Runnable runnable) { - LightEngine lightEngine = chunk.e(); - if (lightEngine instanceof LightEngineThreaded) { + public static void enqueueRunnable(LevelChunk chunk, Runnable runnable) { + LevelLightEngine lightEngine = chunk.getLevel().getChunkSource().getLightEngine(); + if (lightEngine instanceof ThreadedLevelLightEngine) { ChunkPos coord = chunk.getPos(); try { LIGHTENGINETHREADED_QUEUERUNNABLE.invoke(lightEngine, coord.x, coord.z, LIGHTENGINETHREADED_UPDATE_PRE, runnable); @@ -103,18 +103,18 @@ public static BlockLight createLight(Location location, int lightLevel, long tic return blockLight; } - public static void checkIfLightsBrokenByPacket(PacketPlayOutBlockChange packet, World world) { + public static void checkIfLightsBrokenByPacket(ClientboundBlockUpdatePacket packet, Level world) { try { BlockPos pos = (BlockPos) PACKETPLAYOUTBLOCKCHANGE_POSITION.get(packet); int chunkX = pos.getX() >> 4; int chunkZ = pos.getZ() >> 4; Bukkit.getScheduler().scheduleSyncDelayedTask(NMSHandler.getJavaPlugin(), () -> { - Chunk chunk = world.getChunkAt(chunkX, chunkZ); + LevelChunk chunk = world.getChunkAt(chunkX, chunkZ); boolean any = false; for (Vector vec : RELATIVE_CHUNKS) { - IChunkAccess other = world.getChunkAt(chunkX + vec.getBlockX(), chunkZ + vec.getBlockZ(), ChunkStatus.FULL, false); - if (other instanceof Chunk) { - List lights = lightsByChunk.get(new ChunkCoordinate(((Chunk) other).bukkitChunk)); + ChunkAccess other = world.getChunk(chunkX + vec.getBlockX(), chunkZ + vec.getBlockZ(), ChunkStatus.FULL, false); + if (other instanceof LevelChunk) { + List lights = lightsByChunk.get(new ChunkCoordinate(((LevelChunk) other).bukkitChunk)); if (lights != null) { any = true; for (BlockLight light : lights) { @@ -133,7 +133,7 @@ public static void checkIfLightsBrokenByPacket(PacketPlayOutBlockChange packet, } } - public static void checkIfLightsBrokenByPacket(PacketPlayOutLightUpdate packet, World world) { + public static void checkIfLightsBrokenByPacket(ClientboundLightUpdatePacket packet, Level world) { if (doNotCheck) { return; } @@ -143,11 +143,11 @@ public static void checkIfLightsBrokenByPacket(PacketPlayOutLightUpdate packet, int bitMask = PACKETPLAYOUTLIGHTUPDATE_BLOCKLIGHT_BITMASK.getInt(packet); List blockData = (List) PACKETPLAYOUTLIGHTUPDATE_BLOCKLIGHT_DATA.get(packet); Bukkit.getScheduler().scheduleSyncDelayedTask(NMSHandler.getJavaPlugin(), () -> { - IChunkAccess chk = world.getChunkAt(cX, cZ, ChunkStatus.FULL, false); - if (!(chk instanceof Chunk)) { + ChunkAccess chk = world.getChunk(cX, cZ, ChunkStatus.FULL, false); + if (!(chk instanceof LevelChunk)) { return; } - List lights = lightsByChunk.get(new ChunkCoordinate(((Chunk) chk).bukkitChunk)); + List lights = lightsByChunk.get(new ChunkCoordinate(((LevelChunk) chk).bukkitChunk)); if (lights == null) { return; } @@ -159,7 +159,7 @@ public static void checkIfLightsBrokenByPacket(PacketPlayOutLightUpdate packet, } } if (any) { - Bukkit.getScheduler().scheduleSyncDelayedTask(NMSHandler.getJavaPlugin(), () -> sendNearbyChunkUpdates((Chunk) chk), 3); + Bukkit.getScheduler().scheduleSyncDelayedTask(NMSHandler.getJavaPlugin(), () -> sendNearbyChunkUpdates((LevelChunk) chk), 3); } }, 1); } @@ -181,11 +181,11 @@ public boolean checkIfChangedBy(int bitmask, List data) { if ((bitmask & (1 << i)) != 0) { if (i == layer) { byte[] blocks = data.get(found); - NibbleArray arr = new NibbleArray(blocks); + DataLayer arr = new DataLayer(blocks); int x = blockLoc.getBlockX() - (chunkCoord.x << 4); int y = blockLoc.getBlockY() % 16; int z = blockLoc.getBlockZ() - (chunkCoord.z << 4); - int level = arr.a(x, y, z); + int level = arr.get(x, y, z); return intendedLevel != level; } found++; @@ -194,20 +194,20 @@ public boolean checkIfChangedBy(int bitmask, List data) { return false; } - public static void runResetFor(final Chunk chunk, final BlockPos pos) { + public static void runResetFor(final LevelChunk chunk, final BlockPos pos) { Runnable runnable = () -> { - LightEngine lightEngine = chunk.e(); - LightEngineBlock engineBlock = (LightEngineBlock) lightEngine.a(EnumSkyBlock.BLOCK); - engineBlock.a(pos); + LevelLightEngine lightEngine = chunk.getLevel().getChunkSource().getLightEngine(); + BlockLightEngine engineBlock = (BlockLightEngine) lightEngine.getLayerListener(LightLayer.BLOCK); + engineBlock.checkBlock(pos); }; enqueueRunnable(chunk, runnable); } - public static void runSetFor(final Chunk chunk, final BlockPos pos, final int level) { + public static void runSetFor(final LevelChunk chunk, final BlockPos pos, final int level) { Runnable runnable = () -> { - LightEngine lightEngine = chunk.e(); - LightEngineBlock engineBlock = (LightEngineBlock) lightEngine.a(EnumSkyBlock.BLOCK); - engineBlock.a(pos, level); + LevelLightEngine lightEngine = chunk.getLevel().getChunkSource().getLightEngine(); + BlockLightEngine engineBlock = (BlockLightEngine) lightEngine.getLayerListener(LightLayer.BLOCK); + engineBlock.onBlockEmissionIncrease(pos, level); }; enqueueRunnable(chunk, runnable); } @@ -247,19 +247,19 @@ public void sendNearbyChunkUpdates() { public static void sendNearbyChunkUpdates(LevelChunk chunk) { ChunkPos pos = chunk.getPos(); for (Vector vec : RELATIVE_CHUNKS) { - IChunkAccess other = chunk.getLevel().getChunkAt(pos.x + vec.getBlockX(), pos.z + vec.getBlockZ(), ChunkStatus.FULL, false); - if (other instanceof Chunk) { - sendSingleChunkUpdate((Chunk) other); + ChunkAccess other = chunk.getLevel().getChunk(pos.x + vec.getBlockX(), pos.z + vec.getBlockZ(), ChunkStatus.FULL, false); + if (other instanceof LevelChunk) { + sendSingleChunkUpdate((LevelChunk) other); } } } - public static void sendSingleChunkUpdate(Chunk chunk) { + public static void sendSingleChunkUpdate(LevelChunk chunk) { doNotCheck = true; - LightEngine lightEngine = chunk.e(); + LevelLightEngine lightEngine = chunk.getLevel().getChunkSource().getLightEngine(); ChunkPos pos = chunk.getPos(); - PacketPlayOutLightUpdate packet = new PacketPlayOutLightUpdate(pos, lightEngine, true); // TODO: 1.16: should 'trust edges' be true here? - chunk.world.getChunkProvider().chunkMap.a(pos, false).forEach((player) -> { + ClientboundLightUpdatePacket packet = new ClientboundLightUpdatePacket(pos, lightEngine, null, null, true); // TODO: 1.16: should 'trust edges' be true here? + ((ServerChunkCache) chunk.getLevel().getChunkSource()).chunkMap.getPlayers(pos, false).forEach((player) -> { player.connection.send(packet); }); doNotCheck = false; diff --git a/v1_17/src/main/java/com/denizenscript/denizen/nms/v1_17/impl/network/fakes/FakeNetworkManagerImpl.java b/v1_17/src/main/java/com/denizenscript/denizen/nms/v1_17/impl/network/fakes/FakeNetworkManagerImpl.java index 4362a1b4dc..4f291c1dbc 100644 --- a/v1_17/src/main/java/com/denizenscript/denizen/nms/v1_17/impl/network/fakes/FakeNetworkManagerImpl.java +++ b/v1_17/src/main/java/com/denizenscript/denizen/nms/v1_17/impl/network/fakes/FakeNetworkManagerImpl.java @@ -10,7 +10,7 @@ public class FakeNetworkManagerImpl extends Connection { public FakeNetworkManagerImpl(PacketFlow enumprotocoldirection) { super(enumprotocoldirection); channel = new FakeChannelImpl(null); - socketAddress = new SocketAddress() { + address = new SocketAddress() { }; } } diff --git a/v1_17/src/main/java/com/denizenscript/denizen/nms/v1_17/impl/network/fakes/FakePlayerConnectionImpl.java b/v1_17/src/main/java/com/denizenscript/denizen/nms/v1_17/impl/network/fakes/FakePlayerConnectionImpl.java index 5e3823dedf..c76cff7a88 100644 --- a/v1_17/src/main/java/com/denizenscript/denizen/nms/v1_17/impl/network/fakes/FakePlayerConnectionImpl.java +++ b/v1_17/src/main/java/com/denizenscript/denizen/nms/v1_17/impl/network/fakes/FakePlayerConnectionImpl.java @@ -6,9 +6,9 @@ import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.network.ServerGamePacketListenerImpl; -public class FakePlayerConnectionImplImpl extends ServerGamePacketListenerImpl { +public class FakePlayerConnectionImpl extends ServerGamePacketListenerImpl { - public FakePlayerConnectionImplImpl(MinecraftServer minecraftserver, Connection networkmanager, ServerPlayer entityplayer) { + public FakePlayerConnectionImpl(MinecraftServer minecraftserver, Connection networkmanager, ServerPlayer entityplayer) { super(minecraftserver, networkmanager, entityplayer); } diff --git a/v1_17/src/main/java/com/denizenscript/denizen/nms/v1_17/impl/network/handlers/AbstractListenerPlayInImpl.java b/v1_17/src/main/java/com/denizenscript/denizen/nms/v1_17/impl/network/handlers/AbstractListenerPlayInImpl.java index 848d0c627c..392a7d7d25 100644 --- a/v1_17/src/main/java/com/denizenscript/denizen/nms/v1_17/impl/network/handlers/AbstractListenerPlayInImpl.java +++ b/v1_17/src/main/java/com/denizenscript/denizen/nms/v1_17/impl/network/handlers/AbstractListenerPlayInImpl.java @@ -2,10 +2,8 @@ import com.denizenscript.denizen.nms.NMSHandler; import com.denizenscript.denizencore.utilities.debugging.Debug; -import io.netty.util.concurrent.Future; -import io.netty.util.concurrent.GenericFutureListener; -import net.minecraft.network.NetworkManager; -import net.minecraft.network.chat.IChatBaseComponent; +import net.minecraft.network.Connection; +import net.minecraft.network.chat.Component; import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.game.*; import net.minecraft.server.MinecraftServer; @@ -15,7 +13,6 @@ import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer; import org.bukkit.event.player.PlayerTeleportEvent; -import javax.annotation.Nullable; import java.util.Set; public class AbstractListenerPlayInImpl extends ServerGamePacketListenerImpl { @@ -35,12 +32,12 @@ public CraftPlayer getPlayer() { } @Override - public NetworkManager a() { - return this.networkManager; + public Connection getConnection() { + return this.connection; } @Override - public void disconnect(IChatBaseComponent ichatbasecomponent) { + public void disconnect(Component ichatbasecomponent) { oldListener.disconnect(ichatbasecomponent); } @@ -50,8 +47,8 @@ public void disconnect(String s) { } @Override - public void a(double d0, double d1, double d2, float f, float f1) { - oldListener.a(d0, d1, d2, f, f1); + public void dismount(double d0, double d1, double d2, float f, float f1) { + oldListener.dismount(d0, d1, d2, f, f1); } @Override @@ -60,23 +57,33 @@ public void a(double d0, double d1, double d2, float f, float f1, PlayerTeleport } @Override - public void a(double d0, double d1, double d2, float f, float f1, Set set) { - oldListener.a(d0, d1, d2, f, f1, set); + public void teleport(double d0, double d1, double d2, float f, float f1) { + oldListener.teleport(d0, d1, d2, f, f1); } @Override - public void a(double d0, double d1, double d2, float f, float f1, Set set, PlayerTeleportEvent.TeleportCause cause) { + public void b(double d0, double d1, double d2, float f, float f1, PlayerTeleportEvent.TeleportCause cause) { + oldListener.b(d0, d1, d2, f, f1, cause); + } + + @Override + public void teleport(double d0, double d1, double d2, float f, float f1, Set set) { + oldListener.teleport(d0, d1, d2, f, f1, set); + } + + @Override + public void a(double d0, double d1, double d2, float f, float f1, Set set, PlayerTeleportEvent.TeleportCause cause) { oldListener.a(d0, d1, d2, f, f1, set, cause); } @Override - public void teleport(Location dest) { - oldListener.teleport(dest); + public boolean a(double d0, double d1, double d2, float f, float f1, Set set, boolean flag, PlayerTeleportEvent.TeleportCause cause) { + return oldListener.a(d0, d1, d2, f, f1, set, flag, cause); } @Override - public void send(final Packet packet) { - oldListener.send(packet); + public void teleport(Location dest) { + oldListener.teleport(dest); } @Override @@ -90,11 +97,21 @@ public void tick() { } @Override - public void syncPosition() { - oldListener.syncPosition(); + public void resetPosition() { + oldListener.resetPosition(); } - public void handlePacketIn(Packet packet) { + @Override + public void onDisconnect(Component ichatbasecomponent) { + oldListener.onDisconnect(ichatbasecomponent); + } + + @Override + public void send(Packet packet) { + oldListener.send(packet); + } + + public void handlePacketIn(Packet packet) { denizenNetworkManager.packetsReceived++; if (NMSHandler.debugPackets) { Debug.log("Packet: " + packet.getClass().getCanonicalName() + " sent from " + player.getName()); @@ -102,280 +119,272 @@ public void handlePacketIn(Packet packet) { } @Override - public void a(PacketPlayInChat packet) { + public void handlePlayerInput(ServerboundPlayerInputPacket packet) { handlePacketIn(packet); - oldListener.a(packet); + oldListener.handlePlayerInput(packet); } @Override - public void a(PacketPlayInKeepAlive packet) { + public void handleMoveVehicle(ServerboundMoveVehiclePacket packet) { handlePacketIn(packet); - oldListener.a(packet); + oldListener.handleMoveVehicle(packet); } @Override - public void a(PacketPlayInArmAnimation packet) { + public void handleAcceptTeleportPacket(ServerboundAcceptTeleportationPacket packet) { handlePacketIn(packet); - oldListener.a(packet); + oldListener.handleAcceptTeleportPacket(packet); } @Override - public void a(PacketPlayInTabComplete packet) { + public void handleRecipeBookSeenRecipePacket(ServerboundRecipeBookSeenRecipePacket packet) { handlePacketIn(packet); - oldListener.a(packet); + oldListener.handleRecipeBookSeenRecipePacket(packet); } @Override - public void a(PacketPlayInClientCommand packet) { + public void handleRecipeBookChangeSettingsPacket(ServerboundRecipeBookChangeSettingsPacket packet) { handlePacketIn(packet); - oldListener.a(packet); + oldListener.handleRecipeBookChangeSettingsPacket(packet); } @Override - public void a(PacketPlayInSettings packet) { + public void handleSeenAdvancements(ServerboundSeenAdvancementsPacket packet) { handlePacketIn(packet); - oldListener.a(packet); + oldListener.handleSeenAdvancements(packet); } @Override - public void a(PacketPlayInTransaction packet) { + public void handleCustomCommandSuggestions(ServerboundCommandSuggestionPacket packet) { handlePacketIn(packet); - oldListener.a(packet); + oldListener.handleCustomCommandSuggestions(packet); } @Override - public void a(PacketPlayInEnchantItem packet) { + public void handleSetCommandBlock(ServerboundSetCommandBlockPacket packet) { handlePacketIn(packet); - oldListener.a(packet); + oldListener.handleSetCommandBlock(packet); } @Override - public void a(PacketPlayInWindowClick packet) { + public void handleSetCommandMinecart(ServerboundSetCommandMinecartPacket packet) { handlePacketIn(packet); - oldListener.a(packet); + oldListener.handleSetCommandMinecart(packet); } @Override - public void a(PacketPlayInCloseWindow packet) { + public void handlePickItem(ServerboundPickItemPacket packet) { handlePacketIn(packet); - oldListener.a(packet); + oldListener.handlePickItem(packet); } @Override - public void a(PacketPlayInCustomPayload packet) { + public void handleRenameItem(ServerboundRenameItemPacket packet) { handlePacketIn(packet); - oldListener.a(packet); + oldListener.handleRenameItem(packet); } @Override - public void a(PacketPlayInUseEntity packet) { + public void handleSetBeaconPacket(ServerboundSetBeaconPacket packet) { handlePacketIn(packet); - oldListener.a(packet); + oldListener.handleSetBeaconPacket(packet); } @Override - public void a(PacketPlayInFlying packet) { + public void handleSetStructureBlock(ServerboundSetStructureBlockPacket packet) { handlePacketIn(packet); - // TODO: The underlying issue that necessitated this fix in 1.16 is probably fixed in 1.17 - if (!(packet instanceof PacketPlayInFlying.PacketPlayInLook) && player.getVehicle() != null) { - player.connection.send(new PacketPlayOutMount(player.getVehicle())); - } - oldListener.a(packet); + oldListener.handleSetStructureBlock(packet); } @Override - public void a(PacketPlayInAbilities packet) { + public void handleSetJigsawBlock(ServerboundSetJigsawBlockPacket packet) { handlePacketIn(packet); - oldListener.a(packet); + oldListener.handleSetJigsawBlock(packet); } @Override - public void a(PacketPlayInBlockDig packet) { + public void handleJigsawGenerate(ServerboundJigsawGeneratePacket packet) { handlePacketIn(packet); - oldListener.a(packet); + oldListener.handleJigsawGenerate(packet); } @Override - public void a(PacketPlayInEntityAction packet) { + public void handleSelectTrade(ServerboundSelectTradePacket packet) { handlePacketIn(packet); - oldListener.a(packet); + oldListener.handleSelectTrade(packet); } @Override - public void a(PacketPlayInSteerVehicle packet) { + public void handleEditBook(ServerboundEditBookPacket packet) { handlePacketIn(packet); - oldListener.a(packet); + oldListener.handleEditBook(packet); } @Override - public void a(PacketPlayInHeldItemSlot packet) { + public void handleEntityTagQuery(ServerboundEntityTagQuery packet) { handlePacketIn(packet); - oldListener.a(packet); + oldListener.handleEntityTagQuery(packet); } @Override - public void a(PacketPlayInSetCreativeSlot packet) { + public void handleBlockEntityTagQuery(ServerboundBlockEntityTagQuery packet) { handlePacketIn(packet); - oldListener.a(packet); + oldListener.handleBlockEntityTagQuery(packet); } @Override - public void a(PacketPlayInUpdateSign packet) { + public void handleMovePlayer(ServerboundMovePlayerPacket packet) { handlePacketIn(packet); - oldListener.a(packet); + oldListener.handleMovePlayer(packet); } @Override - public void a(PacketPlayInBlockPlace packet) { + public void handlePlayerAction(ServerboundPlayerActionPacket packet) { handlePacketIn(packet); - oldListener.a(packet); + oldListener.handlePlayerAction(packet); } @Override - public void a(PacketPlayInSpectate packet) { + public void handleUseItemOn(ServerboundUseItemOnPacket packet) { handlePacketIn(packet); - oldListener.a(packet); + oldListener.handleUseItemOn(packet); } @Override - public void a(PacketPlayInResourcePackStatus packet) { + public void handleUseItem(ServerboundUseItemPacket packet) { handlePacketIn(packet); - oldListener.a(packet); + oldListener.handleUseItem(packet); } @Override - public void a(PacketPlayInBoatMove packet) { + public void handleTeleportToEntityPacket(ServerboundTeleportToEntityPacket packet) { handlePacketIn(packet); - oldListener.a(packet); + oldListener.handleTeleportToEntityPacket(packet); } @Override - public void a(PacketPlayInTeleportAccept packet) { + public void handleResourcePackResponse(ServerboundResourcePackPacket packet) { handlePacketIn(packet); - oldListener.a(packet); + oldListener.handleResourcePackResponse(packet); } @Override - public void a(PacketPlayInUseItem packet) { + public void handlePaddleBoat(ServerboundPaddleBoatPacket packet) { handlePacketIn(packet); - oldListener.a(packet); + oldListener.handlePaddleBoat(packet); } @Override - public void a(PacketPlayInVehicleMove packet) { + public void handlePong(ServerboundPongPacket packet) { handlePacketIn(packet); - oldListener.a(packet); + oldListener.handlePong(packet); } @Override - public void a(PacketPlayInAdvancements packet) { + public void handleSetCarriedItem(ServerboundSetCarriedItemPacket packet) { handlePacketIn(packet); - oldListener.a(packet); + oldListener.handleSetCarriedItem(packet); } @Override - public void a(PacketPlayInAutoRecipe packet) { + public void handleChat(ServerboundChatPacket packet) { handlePacketIn(packet); - oldListener.a(packet); + oldListener.handleChat(packet); } @Override - public void a(PacketPlayInRecipeDisplayed packet) { + public void handleAnimate(ServerboundSwingPacket packet) { handlePacketIn(packet); - oldListener.a(packet); + oldListener.handleAnimate(packet); } @Override - public void a(PacketPlayInBEdit packet) { + public void handlePlayerCommand(ServerboundPlayerCommandPacket packet) { handlePacketIn(packet); - oldListener.a(packet); + oldListener.handlePlayerCommand(packet); } @Override - public void a(PacketPlayInTrSel packet) { + public void handleInteract(ServerboundInteractPacket packet) { handlePacketIn(packet); - oldListener.a(packet); + oldListener.handleInteract(packet); } @Override - public void a(PacketPlayInBeacon packet) { + public void handleClientCommand(ServerboundClientCommandPacket packet) { handlePacketIn(packet); - oldListener.a(packet); + oldListener.handleClientCommand(packet); } @Override - public void a(PacketPlayInStruct packet) { + public void handleContainerClose(ServerboundContainerClosePacket packet) { handlePacketIn(packet); - oldListener.a(packet); + oldListener.handleContainerClose(packet); } @Override - public void a(PacketPlayInItemName packet) { + public void handleContainerClick(ServerboundContainerClickPacket packet) { handlePacketIn(packet); - oldListener.a(packet); + oldListener.handleContainerClick(packet); } @Override - public void a(PacketPlayInPickItem packet) { + public void handlePlaceRecipe(ServerboundPlaceRecipePacket packet) { handlePacketIn(packet); - oldListener.a(packet); + oldListener.handlePlaceRecipe(packet); } @Override - public void a(PacketPlayInTileNBTQuery packet) { + public void handleContainerButtonClick(ServerboundContainerButtonClickPacket packet) { handlePacketIn(packet); - oldListener.a(packet); + oldListener.handleContainerButtonClick(packet); } @Override - public void a(PacketPlayInEntityNBTQuery packet) { + public void handleSetCreativeModeSlot(ServerboundSetCreativeModeSlotPacket packet) { handlePacketIn(packet); - oldListener.a(packet); + oldListener.handleSetCreativeModeSlot(packet); } @Override - public void a(PacketPlayInSetCommandBlock packet) { + public void handleSignUpdate(ServerboundSignUpdatePacket packet) { handlePacketIn(packet); - oldListener.a(packet); + oldListener.handleSignUpdate(packet); } @Override - public void a(PacketPlayInSetCommandMinecart packet) { + public void handleKeepAlive(ServerboundKeepAlivePacket packet) { handlePacketIn(packet); - oldListener.a(packet); + oldListener.handleKeepAlive(packet); } @Override - public void a(PacketPlayInSetJigsaw packet) { + public void handlePlayerAbilities(ServerboundPlayerAbilitiesPacket packet) { handlePacketIn(packet); - oldListener.a(packet); + oldListener.handlePlayerAbilities(packet); } @Override - public void a(PacketPlayInJigsawGenerate packet) { + public void handleClientInformation(ServerboundClientInformationPacket packet) { handlePacketIn(packet); - oldListener.a(packet); + oldListener.handleClientInformation(packet); } @Override - public void a(PacketPlayInDifficultyLock packet) { + public void handleCustomPayload(ServerboundCustomPayloadPacket packet) { handlePacketIn(packet); - oldListener.a(packet); + oldListener.handleCustomPayload(packet); } @Override - public void a(PacketPlayInDifficultyChange packet) { + public void handleChangeDifficulty(ServerboundChangeDifficultyPacket packet) { handlePacketIn(packet); - oldListener.a(packet); + oldListener.handleChangeDifficulty(packet); } @Override - public void a(IChatBaseComponent iChatBaseComponent) { - oldListener.a(iChatBaseComponent); - } - - @Override - public void a(Packet packet, @Nullable GenericFutureListener> genericfuturelistener) { - oldListener.a(packet, genericfuturelistener); + public void handleLockDifficulty(ServerboundLockDifficultyPacket packet) { + handlePacketIn(packet); + oldListener.handleLockDifficulty(packet); } } diff --git a/v1_17/src/main/java/com/denizenscript/denizen/nms/v1_17/impl/network/handlers/DenizenPacketListenerImpl.java b/v1_17/src/main/java/com/denizenscript/denizen/nms/v1_17/impl/network/handlers/DenizenPacketListenerImpl.java index 5a259877eb..d9d26823da 100644 --- a/v1_17/src/main/java/com/denizenscript/denizen/nms/v1_17/impl/network/handlers/DenizenPacketListenerImpl.java +++ b/v1_17/src/main/java/com/denizenscript/denizen/nms/v1_17/impl/network/handlers/DenizenPacketListenerImpl.java @@ -8,12 +8,11 @@ import com.denizenscript.denizen.scripts.commands.entity.FakeEquipCommand; import com.denizenscript.denizen.utilities.packets.DenizenPacketHandler; import com.denizenscript.denizencore.utilities.debugging.Debug; -import io.netty.util.concurrent.Future; -import io.netty.util.concurrent.GenericFutureListener; import com.denizenscript.denizen.nms.NMSHandler; import net.minecraft.core.BlockPos; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.protocol.Packet; +import net.minecraft.network.protocol.game.*; import net.minecraft.server.level.ServerPlayer; import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; @@ -22,7 +21,6 @@ import org.bukkit.event.block.SignChangeEvent; import org.bukkit.event.player.PlayerJoinEvent; -import javax.annotation.Nullable; import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.UUID; @@ -45,32 +43,32 @@ public static void enable(DenizenPacketHandler handler) { } @Override - public void a(final PacketPlayInSteerVehicle packet) { + public void handlePlayerInput(final ServerboundPlayerInputPacket packet) { if (!packetHandler.receivePacket(player.getBukkitEntity(), new PacketInSteerVehicleImpl(packet))) { - super.a(packet); + super.handlePlayerInput(packet); } } @Override - public void a(PacketPlayInResourcePackStatus packet) { + public void handleResourcePackResponse(ServerboundResourcePackPacket packet) { packetHandler.receivePacket(player.getBukkitEntity(), new PacketInResourcePackStatusImpl(packet)); - super.a(packet); + super.handleResourcePackResponse(packet); } @Override - public void a(PacketPlayInBlockPlace packet) { + public void handleUseItem(ServerboundUseItemPacket packet) { packetHandler.receivePlacePacket(player.getBukkitEntity()); - super.a(packet); + super.handleUseItem(packet); } @Override - public void a(PacketPlayInBlockDig packet) { + public void handlePlayerAction(ServerboundPlayerActionPacket packet) { packetHandler.receiveDigPacket(player.getBukkitEntity()); - super.a(packet); + super.handlePlayerAction(packet); } @Override - public void a(PacketPlayInArmAnimation packet) { + public void handleAnimate(ServerboundSwingPacket packet) { HashMap playersMap = FakeEquipCommand.overrides.get(player.getUUID()); if (playersMap != null) { FakeEquipCommand.EquipmentOverride override = playersMap.get(player.getUUID()); @@ -78,11 +76,11 @@ public void a(PacketPlayInArmAnimation packet) { player.getBukkitEntity().updateInventory(); } } - super.a(packet); + super.handleAnimate(packet); } @Override - public void a(PacketPlayInHeldItemSlot packet) { + public void handleSetCarriedItem(ServerboundSetCarriedItemPacket packet) { HashMap playersMap = FakeEquipCommand.overrides.get(player.getUUID()); if (playersMap != null) { FakeEquipCommand.EquipmentOverride override = playersMap.get(player.getUUID()); @@ -90,37 +88,37 @@ public void a(PacketPlayInHeldItemSlot packet) { Bukkit.getScheduler().runTaskLater(NMSHandler.getJavaPlugin(), player.getBukkitEntity()::updateInventory, 2); } } - super.a(packet); + super.handleSetCarriedItem(packet); } @Override - public void a(PacketPlayInWindowClick packet) { + public void handleContainerClick(ServerboundContainerClickPacket packet) { HashMap playersMap = FakeEquipCommand.overrides.get(player.getUUID()); if (playersMap != null) { FakeEquipCommand.EquipmentOverride override = playersMap.get(player.getUUID()); - if (override != null && packet.b() == 0) { + if (override != null && packet.getContainerId() == 0) { Bukkit.getScheduler().runTaskLater(NMSHandler.getJavaPlugin(), player.getBukkitEntity()::updateInventory, 1); } } - super.a(packet); + super.handleContainerClick(packet); } @Override - public void a(PacketPlayInCustomPayload packet) { + public void handleCustomPayload(ServerboundCustomPayloadPacket packet) { if (NMSHandler.debugPackets) { - Debug.log("Custom packet payload: " + packet.tag.toString() + " sent from " + player.getName()); + Debug.log("Custom packet payload: " + packet.identifier.toString() + " sent from " + player.getName()); } - if (packet.tag.getNamespace().equals("minecraft") && packet.tag.getKey().equals("brand")) { + if (packet.identifier.getNamespace().equals("minecraft") && packet.identifier.getPath().equals("brand")) { FriendlyByteBuf newData = new FriendlyByteBuf(packet.data.copy()); - int i = newData.i(); // read off the varInt of length to get rid of it + int i = newData.readVarInt(); // read off the varInt of length to get rid of it brand = StandardCharsets.UTF_8.decode(newData.nioBuffer()).toString(); } - super.a(packet); + super.handleCustomPayload(packet); } @Override - public void a(PacketPlayInUpdateSign packet) { - if (fakeSignExpected != null && packet.b().equals(fakeSignExpected)) { + public void handleSignUpdate(ServerboundSignUpdatePacket packet) { + if (fakeSignExpected != null && packet.getPos().equals(fakeSignExpected)) { fakeSignExpected = null; PlayerChangesSignScriptEvent evt = (PlayerChangesSignScriptEvent) PlayerChangesSignScriptEvent.instance.clone(); evt.cancelled = false; @@ -128,31 +126,26 @@ public void a(PacketPlayInUpdateSign packet) { evt.location = new LocationTag(getPlayer().getLocation()); LocationTag loc = evt.location.clone(); loc.setY(0); - evt.event = new SignChangeEvent(loc.getBlock(), getPlayer(), packet.c()); + evt.event = new SignChangeEvent(loc.getBlock(), getPlayer(), packet.getLines()); evt.fire(evt.event); } - super.a(packet); + super.handleSignUpdate(packet); } @Override - public void a(PacketPlayInFlying packet) { + public void handleMovePlayer(ServerboundMovePlayerPacket packet) { if (DenizenPacketHandler.forceNoclip.contains(player.getUUID())) { - player.noclip = true; + player.noPhysics = true; } - super.a(packet); + super.handleMovePlayer(packet); } // For compatibility with other plugins using Reflection weirdly... @Override - public void send(Packet packet) { + public void send(Packet packet) { super.send(packet); } - @Override - public void a(Packet packet, @Nullable GenericFutureListener> genericfuturelistener) { - super.a(packet, genericfuturelistener); - } - public static class PlayerEventListener implements Listener { @EventHandler(priority = EventPriority.LOWEST) public void onPlayerJoin(PlayerJoinEvent event) { diff --git a/v1_17/src/main/java/com/denizenscript/denizen/nms/v1_17/impl/network/handlers/FakeBlockHelper.java b/v1_17/src/main/java/com/denizenscript/denizen/nms/v1_17/impl/network/handlers/FakeBlockHelper.java index 1015abb310..668909c562 100644 --- a/v1_17/src/main/java/com/denizenscript/denizen/nms/v1_17/impl/network/handlers/FakeBlockHelper.java +++ b/v1_17/src/main/java/com/denizenscript/denizen/nms/v1_17/impl/network/handlers/FakeBlockHelper.java @@ -5,21 +5,26 @@ import com.denizenscript.denizen.utilities.blocks.FakeBlock; import com.denizenscript.denizen.utilities.debugging.Debug; import io.netty.buffer.Unpooled; +import net.minecraft.nbt.CompoundTag; import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.protocol.game.ClientboundLevelChunkPacket; +import net.minecraft.util.BitStorage; import net.minecraft.util.Mth; import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.chunk.LevelChunkSection; import org.bukkit.craftbukkit.v1_17_R1.block.data.CraftBlockData; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.List; +import java.util.ListIterator; public class FakeBlockHelper { - public static Field BITMASK_MAPCHUNK = ReflectionHelper.getFields(PacketPlayOutMapChunk.class).get("c"); - public static Field DATA_MAPCHUNK = ReflectionHelper.getFields(PacketPlayOutMapChunk.class).get("f"); - public static Field BLOCKENTITIES_MAPCHUNK = ReflectionHelper.getFields(PacketPlayOutMapChunk.class).get("g"); - public static Field BIOMESTORAGE_MAPCHUNK = ReflectionHelper.getFields(PacketPlayOutMapChunk.class).get("e"); + public static Field BITMASK_MAPCHUNK = ReflectionHelper.getFields(ClientboundLevelChunkPacket.class).get("c"); + public static Field DATA_MAPCHUNK = ReflectionHelper.getFields(ClientboundLevelChunkPacket.class).get("f"); + public static Field BLOCKENTITIES_MAPCHUNK = ReflectionHelper.getFields(ClientboundLevelChunkPacket.class).get("g"); + public static Field BIOMESTORAGE_MAPCHUNK = ReflectionHelper.getFields(ClientboundLevelChunkPacket.class).get("e"); public static BlockState getNMSState(FakeBlock block) { return ((CraftBlockData) block.material.getModernData()).getState(); @@ -38,7 +43,7 @@ public static boolean anyBlocksInSection(List blocks, int y) { } public static int indexInPalette(BlockState data) { - return ChunkSection.GLOBAL_PALETTE.a(data); + return LevelChunkSection.GLOBAL_BLOCKSTATE_PALETTE.idFor(data); } public static int blockArrayIndex(int x, int y, int z) { @@ -54,19 +59,20 @@ public static int getPaletteSubId(int[] palette, int id) { return -1; } - public static PacketPlayOutMapChunk handleMapChunkPacket(PacketPlayOutMapChunk originalPacket, List blocks) { + public static ClientboundLevelChunkPacket handleMapChunkPacket(ClientboundLevelChunkPacket originalPacket, List blocks) { try { - PacketPlayOutMapChunk packet = new PacketPlayOutMapChunk(); - DenizenNetworkManagerImpl.copyPacket(originalPacket, packet); + FriendlyByteBuf duplicator = new FriendlyByteBuf(Unpooled.buffer()); + originalPacket.write(duplicator); + ClientboundLevelChunkPacket packet = new ClientboundLevelChunkPacket(duplicator); // TODO: properly update HeightMap? int bitmask = BITMASK_MAPCHUNK.getInt(packet); byte[] data = (byte[]) DATA_MAPCHUNK.get(packet); FriendlyByteBuf serial = new FriendlyByteBuf(Unpooled.wrappedBuffer(data)); FriendlyByteBuf outputSerial = new FriendlyByteBuf(Unpooled.buffer(data.length)); - boolean isFull = packet.f(); + boolean isFull = true;//packet.f(); List blockEntities = new ArrayList<>((List) BLOCKENTITIES_MAPCHUNK.get(packet)); BLOCKENTITIES_MAPCHUNK.set(packet, blockEntities); - ListIterator iterator = blockEntities.listIterator(); + ListIterator iterator = blockEntities.listIterator(); while (iterator.hasNext()) { net.minecraft.nbt.CompoundTag blockEnt = iterator.next(); int x = blockEnt.getInt("x"); @@ -83,22 +89,22 @@ public static PacketPlayOutMapChunk handleMapChunkPacket(PacketPlayOutMapChunk o for (FakeBlock block : blocks) { LocationTag loc = block.location; net.minecraft.nbt.CompoundTag newCompound = new net.minecraft.nbt.CompoundTag(); - newCompound.setInt("x", loc.getBlockX()); - newCompound.setInt("y", loc.getBlockY()); - newCompound.setInt("z", loc.getBlockZ()); - newCompound.setString("id", block.material.getMaterial().getKey().toString()); + newCompound.putInt("x", loc.getBlockX()); + newCompound.putInt("y", loc.getBlockY()); + newCompound.putInt("z", loc.getBlockZ()); + newCompound.putString("id", block.material.getMaterial().getKey().toString()); blockEntities.add(newCompound); } for (int y = 0; y < 16; y++) { if ((bitmask & (1 << y)) != 0) { int blockCount = serial.readShort(); int width = serial.readUnsignedByte(); - int paletteLen = serial.i(); // readVarInt + int paletteLen = serial.readVarInt(); int[] palette = new int[paletteLen]; for (int p = 0; p < paletteLen; p++) { - palette[p] = serial.i(); + palette[p] = serial.readVarInt(); } - int dataLen = serial.i(); + int dataLen = serial.readVarInt(); long[] blockListHelper = new long[dataLen]; for (int i = 0; i < blockListHelper.length; i++) { blockListHelper[i] = serial.readLong(); @@ -106,11 +112,11 @@ public static PacketPlayOutMapChunk handleMapChunkPacket(PacketPlayOutMapChunk o outputSerial.writeShort(blockCount); if (!anyBlocksInSection(blocks, y)) { outputSerial.writeByte(width); - outputSerial.d(paletteLen); // writeVarInt + outputSerial.writeVarInt(paletteLen); for (int p = 0; p < paletteLen; p++) { - outputSerial.d(palette[p]); + outputSerial.writeVarInt(palette[p]); } - outputSerial.a(blockListHelper); // writeLongs + outputSerial.writeLongArray(blockListHelper); continue; } char dataBitsF = (char)(64 / width); @@ -119,7 +125,7 @@ public static PacketPlayOutMapChunk handleMapChunkPacket(PacketPlayOutMapChunk o return originalPacket; // This chunk is too-complex and is using non-standard chunk format. For now, just ignore it. // TODO: Add support for processing very-complex chunks (DataPaletteHash might be responsible for the unique format?) } - DataBits bits = new DataBits(width, 4096, blockListHelper); + BitStorage bits = new BitStorage(width, 4096, blockListHelper); int minY = y << 4; int maxY = (y << 4) + 16; for (FakeBlock block : blocks) { @@ -143,29 +149,29 @@ public static PacketPlayOutMapChunk handleMapChunkPacket(PacketPlayOutMapChunk o palette = newPalette; int newWidth = Mth.ceillog2(paletteLen); if (newWidth > width) { - DataBits newBits = new DataBits(newWidth, 4096); - for (int i = 0; i < bits.b(); i++) { - newBits.a(i, bits.a(i)); + BitStorage newBits = new BitStorage(newWidth, 4096); + for (int i = 0; i < bits.getSize(); i++) { + newBits.getAndSet(i, bits.get(i)); } bits = newBits; width = newWidth; } } - bits.a(blockIndex, subPaletteId); + bits.getAndSet(blockIndex, subPaletteId); } } outputSerial.writeByte(width); - outputSerial.d(paletteLen); + outputSerial.writeVarInt(paletteLen); for (int p = 0; p < palette.length; p++) { - outputSerial.d(palette[p]); + outputSerial.writeVarInt(palette[p]); } - outputSerial.a(bits.a()); + outputSerial.writeLongArray(bits.getRaw()); } } if (isFull) { int[] biomes = (int[]) BIOMESTORAGE_MAPCHUNK.get(packet); if (biomes != null) { - outputSerial.a(biomes); + outputSerial.writeVarIntArray(biomes); } } byte[] outputBytes = outputSerial.array(); diff --git a/v1_17/src/main/java/com/denizenscript/denizen/nms/v1_17/impl/network/packets/PacketInResourcePackStatusImpl.java b/v1_17/src/main/java/com/denizenscript/denizen/nms/v1_17/impl/network/packets/PacketInResourcePackStatusImpl.java index 9c0e820126..98a571bbb3 100644 --- a/v1_17/src/main/java/com/denizenscript/denizen/nms/v1_17/impl/network/packets/PacketInResourcePackStatusImpl.java +++ b/v1_17/src/main/java/com/denizenscript/denizen/nms/v1_17/impl/network/packets/PacketInResourcePackStatusImpl.java @@ -1,18 +1,18 @@ package com.denizenscript.denizen.nms.v1_17.impl.network.packets; import com.denizenscript.denizen.nms.interfaces.packets.PacketInResourcePackStatus; -import net.minecraft.network.protocol.game.PacketPlayInResourcePackStatus; +import net.minecraft.network.protocol.game.ServerboundResourcePackPacket; public class PacketInResourcePackStatusImpl implements PacketInResourcePackStatus { - private PacketPlayInResourcePackStatus internal; + private ServerboundResourcePackPacket internal; - public PacketInResourcePackStatusImpl(PacketPlayInResourcePackStatus internal) { + public PacketInResourcePackStatusImpl(ServerboundResourcePackPacket internal) { this.internal = internal; } @Override public String getStatus() { - return internal.status.name(); + return internal.action.name(); } } diff --git a/v1_17/src/main/java/com/denizenscript/denizen/nms/v1_17/impl/network/packets/PacketInSteerVehicleImpl.java b/v1_17/src/main/java/com/denizenscript/denizen/nms/v1_17/impl/network/packets/PacketInSteerVehicleImpl.java index d65fc7d7e1..fb424cac5f 100644 --- a/v1_17/src/main/java/com/denizenscript/denizen/nms/v1_17/impl/network/packets/PacketInSteerVehicleImpl.java +++ b/v1_17/src/main/java/com/denizenscript/denizen/nms/v1_17/impl/network/packets/PacketInSteerVehicleImpl.java @@ -1,33 +1,33 @@ package com.denizenscript.denizen.nms.v1_17.impl.network.packets; import com.denizenscript.denizen.nms.interfaces.packets.PacketInSteerVehicle; -import net.minecraft.network.protocol.game.PacketPlayInSteerVehicle; +import net.minecraft.network.protocol.game.ServerboundPlayerInputPacket; public class PacketInSteerVehicleImpl implements PacketInSteerVehicle { - private PacketPlayInSteerVehicle internal; + private ServerboundPlayerInputPacket internal; - public PacketInSteerVehicleImpl(PacketPlayInSteerVehicle internal) { + public PacketInSteerVehicleImpl(ServerboundPlayerInputPacket internal) { this.internal = internal; } @Override public float getLeftwardInput() { - return internal.b(); + return internal.getXxa(); } @Override public float getForwardInput() { - return internal.c(); + return internal.getZza(); } @Override public boolean getJumpInput() { - return internal.d(); + return internal.isJumping(); } @Override public boolean getDismountInput() { - return internal.e(); + return internal.isShiftKeyDown(); } }