From 201c285091b024208535dee5cab29ba33d4fcc24 Mon Sep 17 00:00:00 2001 From: Dan Mulloy Date: Mon, 28 May 2018 11:52:19 -0400 Subject: [PATCH] Changes for 1.13 compatibility --- .../common/block/MultiBlockUpdaterAgent.java | 88 ++++++++++--------- .../core/common/util/UtilParticle.java | 23 +++-- .../core/disguise/DisguiseManager.java | 16 ++-- .../game/games/skyfall/Crumbleable.java | 4 +- 4 files changed, 70 insertions(+), 61 deletions(-) diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/block/MultiBlockUpdaterAgent.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/block/MultiBlockUpdaterAgent.java index 607288295..478f46f16 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/block/MultiBlockUpdaterAgent.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/block/MultiBlockUpdaterAgent.java @@ -31,37 +31,39 @@ import net.minecraft.server.v1_8_R3.WorldServer; public class MultiBlockUpdaterAgent { - + private Map> _chunks = new HashMap<>(); - + /** - * Add a block to the list of blocks to send to the player. The agent supports blocks across different chunks and + * Add a block to the list of blocks to send to the player. The agent supports blocks across different chunks and * will not send duplicates. + * * @param block The block to send. The block is stored using a BlockVector, meaning that when the send method is called, it will use - * the material and data found for the block at the moment you call the send method. + * the material and data found for the block at the moment you call the send method. * @see #send(Collection) */ public void addBlock(Block block) { - Chunk c = ((CraftChunk)block.getChunk()).getHandle(); - List list = _chunks.computeIfAbsent(c,chunk -> new ArrayList<>()); - - if(list.size() >= 64) return; - + Chunk c = ((CraftChunk) block.getChunk()).getHandle(); + List list = _chunks.computeIfAbsent(c, chunk -> new ArrayList<>()); + + if (list.size() >= 64) return; + BlockVector bv = block.getLocation().toVector().toBlockVector(); - if(list.contains(bv)) return; + if (list.contains(bv)) return; list.add(bv); } - + /** * Sends all the record blocks to all online players. Players out of range will not receive packets. + * * @see #send(Collection) */ public void send() { send(UtilServer.getPlayersCollection()); } - + /** * Clear all blocks for this agent. */ @@ -69,81 +71,81 @@ public class MultiBlockUpdaterAgent { _chunks.clear(); } - + /** * Send all the recorded blocks to the provided players. This will only send packets to players in range. If the blocks span multiple * chunks then players will only receive block updates for chunks close to them. + * * @param players The players which will the packets will be sent to. */ public void send(Collection players) { - for(Player p : players) + for (Player p : players) { - for(Chunk c : _chunks.keySet()) + for (Chunk c : _chunks.keySet()) { - if(!p.getWorld().equals(c.bukkitChunk.getWorld())) continue; - + if (!p.getWorld().equals(c.bukkitChunk.getWorld())) continue; + int x = p.getLocation().getChunk().getX(); int z = p.getLocation().getChunk().getZ(); - - int chunkDist = Math.max(Math.abs(c.locX-x), Math.abs(c.locZ-z)); - - if(chunkDist > Bukkit.getViewDistance()) continue; - + + int chunkDist = Math.max(Math.abs(c.locX - x), Math.abs(c.locZ - z)); + + if (chunkDist > Bukkit.getViewDistance()) continue; + sendPacket(c, p); } } } - - private void sendPacket(Chunk c, Player...players) + + private void sendPacket(Chunk c, Player... players) { List list = _chunks.get(c); - - if(list == null) return; - - if(list.size() >= 64) + + if (list == null) return; + + if (list.size() >= 64) { - for(Player p : players) + for (Player p : players) { - UtilPlayer.sendPacket(p, new PacketPlayOutMapChunk(c, true, 65535)); + int protocol = ((CraftPlayer) p).getHandle().getProtocol(); + UtilPlayer.sendPacket(p, new PacketPlayOutMapChunk(protocol, c, true, 65535)); } - } - else + } else { PacketPlayOutMultiBlockChange packet = new PacketPlayOutMultiBlockChange(); packet.a = new ChunkCoordIntPair(c.locX, c.locZ); packet.b = new MultiBlockChangeInfo[list.size()]; - for(int i = 0; i < list.size(); i++) + for (int i = 0; i < list.size(); i++) { BlockVector bv = list.get(i); - short xyz = (short)((bv.getBlockX() & 0xF) << 12 | (bv.getBlockZ() & 0xF) << 8 | bv.getBlockY()); + short xyz = (short) ((bv.getBlockX() & 0xF) << 12 | (bv.getBlockZ() & 0xF) << 8 | bv.getBlockY()); packet.b[i] = packet.new MultiBlockChangeInfo(xyz, c); } - - for(Player p : players) + + for (Player p : players) { UtilPlayer.sendPacket(p, packet); } } - + Packet[] tileEntities = new Packet[c.tileEntities.size()]; int i = 0; - for(TileEntity te : c.tileEntities.values()) + for (TileEntity te : c.tileEntities.values()) { tileEntities[i++] = te.getUpdatePacket(); } - for(Player p : players) + for (Player p : players) { UtilPlayer.sendPacket(p, tileEntities); - ((WorldServer)c.world).getTracker().untrackPlayer(((CraftPlayer)p).getHandle()); + ((WorldServer) c.world).getTracker().untrackPlayer(((CraftPlayer) p).getHandle()); } Bukkit.getScheduler().runTaskLater(UtilServer.getPlugin(), () -> { - for(Player p : players) + for (Player p : players) { - ((WorldServer)c.world).getTracker().a(((CraftPlayer)p).getHandle(), c); + ((WorldServer) c.world).getTracker().a(((CraftPlayer) p).getHandle(), c); } }, 5); } - } diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilParticle.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilParticle.java index cc58f5d0d..6fd97c5a9 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilParticle.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilParticle.java @@ -1,7 +1,10 @@ package mineplex.core.common.util; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; import net.minecraft.server.v1_8_R3.EnumParticle; import net.minecraft.server.v1_8_R3.PacketPlayOutWorldParticles; @@ -172,6 +175,16 @@ public class UtilParticle WATER_WAKE(EnumParticle.WATER_WAKE, "wake"); + private static final Map byName = new ConcurrentHashMap<>(); + + static + { + for (ParticleType type : values()) + { + byName.put(type.particleName, type); + } + } + public EnumParticle particle; public String particleName; private boolean _friendlyData; @@ -248,15 +261,7 @@ public class UtilParticle details[i] = Integer.parseInt(parts[i + 1]); } - ParticleType particleType = ParticleType.CRIT; - - for (ParticleType type : ParticleType.values()) - { - if (type.particleName.equalsIgnoreCase(parts[0])) - { - particleType = type; - } - } + ParticleType particleType = ParticleType.byName.getOrDefault(parts[0], ParticleType.CRIT); return new PacketPlayOutWorldParticles(particleType.particle, displayFar, (float) location.getX(), (float) location.getY(), (float) location.getZ(), offsetX, offsetY, offsetZ, speed, diff --git a/Plugins/Mineplex.Core/src/mineplex/core/disguise/DisguiseManager.java b/Plugins/Mineplex.Core/src/mineplex/core/disguise/DisguiseManager.java index 6a5e4fd54..4b2d7c537 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/disguise/DisguiseManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/disguise/DisguiseManager.java @@ -554,7 +554,7 @@ public class DisguiseManager extends MiniPlugin implements IPacketHandler if (pDisguise.getSleepingDirection() != null) { - for (Packet packet : getBedPackets(pDisguise)) + for (Packet packet : getBedPackets(protocol, pDisguise)) { handlePacket(packet, packetVerifier); } @@ -821,14 +821,15 @@ public class DisguiseManager extends MiniPlugin implements IPacketHandler { List packets = new ArrayList<>(); - PacketPlayOutMapChunk chunk = new PacketPlayOutMapChunk(_bedChunk, true, '\uffff'); + EntityPlayer nmsPlayer = ((CraftPlayer) player).getHandle(); + final int protocol = nmsPlayer.getProtocol(); + + PacketPlayOutMapChunk chunk = new PacketPlayOutMapChunk(protocol, _bedChunk, true, '\uffff'); chunk.a = BED_POS_NORTH[0] >> 4; chunk.b = BED_POS_NORTH[2] >> 4; packets.add(chunk); - EntityPlayer nmsPlayer = ((CraftPlayer) player).getHandle(); - _spawnPacketMap.entrySet().stream() .filter(entry -> entry.getValue().size() > 0 && entry.getValue().getFirst() instanceof DisguisePlayer && ((DisguisePlayer) entry.getValue().getFirst()).getSleepingDirection() != null) .filter(entry -> this.containsSpawnDisguise(player, entry.getValue().getFirst())) @@ -838,7 +839,7 @@ public class DisguiseManager extends MiniPlugin implements IPacketHandler if (tracker != null && tracker.trackedPlayers.contains(nmsPlayer)) { - packets.addAll(getBedPackets((DisguisePlayer) entry.getValue().getFirst())); + packets.addAll(getBedPackets(protocol, (DisguisePlayer) entry.getValue().getFirst())); } }); @@ -853,7 +854,7 @@ public class DisguiseManager extends MiniPlugin implements IPacketHandler * * fixme can we make this better at all?!?!?! */ - private List getBedPackets(DisguisePlayer playerDisguise) + private List getBedPackets(int protocol, DisguisePlayer playerDisguise) { int[] coords = getCoordsFor(playerDisguise); @@ -873,8 +874,7 @@ public class DisguiseManager extends MiniPlugin implements IPacketHandler double d1 = posY + (targetY - posY) / (double) partitions; double d2 = posZ + (targetZ - posZ) / (double) partitions; - - PacketPlayOutMapChunk chunk = new PacketPlayOutMapChunk(_bedChunk, true, '\uffff'); + PacketPlayOutMapChunk chunk = new PacketPlayOutMapChunk(protocol, _bedChunk, true, '\uffff'); chunk.a = (int) Math.floor(d0) >> 4; chunk.b = (int) Math.floor(d2) >> 4; packets.add(chunk); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skyfall/Crumbleable.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skyfall/Crumbleable.java index 35d61e3d4..af462a3b6 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skyfall/Crumbleable.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/skyfall/Crumbleable.java @@ -15,6 +15,7 @@ import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.craftbukkit.v1_8_R3.CraftChunk; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; import org.bukkit.entity.Player; import mineplex.core.common.util.MapUtil; @@ -153,7 +154,8 @@ public abstract class Crumbleable for (Player player : UtilServer.getPlayers()) { - UtilPlayer.sendPacket(player, new PacketPlayOutMapChunk(chunk, false, mask)); + int protocol = ((CraftPlayer) player).getHandle().getProtocol(); + UtilPlayer.sendPacket(player, new PacketPlayOutMapChunk(protocol, chunk, false, mask)); } _lastChunk = System.currentTimeMillis();