From 7c18e89249841f2c5532b194f9865977e51f54a4 Mon Sep 17 00:00:00 2001 From: Shaun Bennett Date: Mon, 15 Sep 2014 10:37:40 -0500 Subject: [PATCH] Send chest open packets for new players that join in the middle of a treasure --- .../src/mineplex/core/treasure/Treasure.java | 23 +++++++++++++++++++ .../core/treasure/TreasureManager.java | 10 ++++++++ 2 files changed, 33 insertions(+) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/Treasure.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/Treasure.java index 450bc5315..e77ca3c45 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/Treasure.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/Treasure.java @@ -10,8 +10,12 @@ import org.bukkit.Effect; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; +import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer; +import org.bukkit.craftbukkit.v1_7_R4.util.CraftMagicNumbers; import org.bukkit.entity.Player; +import net.minecraft.server.v1_7_R4.PacketPlayOutBlockAction; + import mineplex.core.common.util.C; import mineplex.core.common.util.F; import mineplex.core.common.util.NautHashMap; @@ -262,6 +266,25 @@ public class Treasure } } + public void sendChestOpenPackets(Player... players) + { + for (ChestData data : _chestData) + { + if (data.isOpened()) + { + Block block = data.getBlock(); + PacketPlayOutBlockAction packet = new PacketPlayOutBlockAction(block.getX(), block.getY(), block.getZ(), CraftMagicNumbers.getBlock(block), 1, 1); + + for (Player player : players) + { + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); + } + + } + } + + } + public ChestData getChestData(Block block) { for (ChestData data : _chestData) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/TreasureManager.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/TreasureManager.java index 08a4cb7f4..fb38c2c03 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/TreasureManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/TreasureManager.java @@ -14,6 +14,7 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.block.Action; import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.inventory.ItemStack; @@ -341,6 +342,15 @@ public class TreasureManager extends MiniPlugin } } + @EventHandler + public void join(PlayerJoinEvent event) + { + for (Treasure treasure : _playerTreasureMap.values()) + { + treasure.sendChestOpenPackets(event.getPlayer()); + } + } + @EventHandler public void quit(PlayerQuitEvent event) {