From 7c18e89249841f2c5532b194f9865977e51f54a4 Mon Sep 17 00:00:00 2001 From: Shaun Bennett Date: Mon, 15 Sep 2014 10:37:40 -0500 Subject: [PATCH 1/2] 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) { From 63b3621ae3ac0271c6ed3664b59c63bf56ad429d Mon Sep 17 00:00:00 2001 From: Shaun Bennett Date: Mon, 15 Sep 2014 13:34:21 -0500 Subject: [PATCH 2/2] Fix treasure open chest bug, added some animation touches --- .../src/mineplex/core/treasure/Treasure.java | 24 +++++-- .../core/treasure/TreasureManager.java | 19 ++++-- .../animation/TreasureRemoveAnimation.java | 62 +++++++++++++++++++ 3 files changed, 96 insertions(+), 9 deletions(-) create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/TreasureRemoveAnimation.java diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/Treasure.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/Treasure.java index e77ca3c45..90fead2df 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/Treasure.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/Treasure.java @@ -13,10 +13,8 @@ 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; import mineplex.core.common.util.UtilParticle; @@ -26,6 +24,7 @@ import mineplex.core.treasure.animation.ChestOpenAnimation; import mineplex.core.treasure.animation.ChestSpawnAnimation; import mineplex.core.treasure.animation.CircleAnimation; import mineplex.core.treasure.animation.FireworksAnimation; +import mineplex.core.treasure.animation.TreasureRemoveAnimation; import mineplex.core.treasure.reward.ITreasureReward; import mineplex.core.treasure.reward.RewardRarity; @@ -224,14 +223,21 @@ public class Treasure return _centerBlock.getRelative(BlockFace.UP); } - public void setBlock(Block block, Material material, byte data) + public void setBlock(Block block, Material material, byte data, boolean addToBlockRestoreMap) { - _blockRestoreMap.put(block, new BlockInfo(block.getTypeId(), block.getData())); + if (addToBlockRestoreMap) + _blockRestoreMap.put(block, new BlockInfo(block.getTypeId(), block.getData())); + block.setType(material); block.setData(data); block.getLocation().getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, block.getTypeId()); } + public void setBlock(Block block, Material material, byte data) + { + setBlock(block, material, data, true); + } + public void openChest(Block block) { ChestData data = getChestData(block); @@ -261,6 +267,8 @@ public class Treasure if (isFinished()) { + TreasureRemoveAnimation animation = new TreasureRemoveAnimation(this, _blockRestoreMap); + _animations.add(animation); _finished = true; } } @@ -278,6 +286,7 @@ public class Treasure for (Player player : players) { ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); + System.out.println("sending chest open packet"); } } @@ -333,9 +342,14 @@ public class Treasure Block block = entry.getKey(); BlockInfo data = entry.getValue(); + if (block.getType().equals(Material.CHEST)) + { + block.getLocation().getWorld().createExplosion(block.getLocation().add(0.5, 0.5, 0.5), 0F); + } + block.getLocation().getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, block.getTypeId()); + block.setTypeId(data.getId()); block.setData(data.getData()); - block.getLocation().getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, block.getTypeId()); } for (Animation animation : _animations) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/TreasureManager.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/TreasureManager.java index fb38c2c03..3978b60b6 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/TreasureManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/TreasureManager.java @@ -30,7 +30,6 @@ import mineplex.core.common.util.UtilBlock; import mineplex.core.common.util.UtilEnt; import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilPlayer; -import mineplex.core.common.util.UtilServer; import mineplex.core.donation.DonationManager; import mineplex.core.inventory.InventoryManager; import mineplex.core.treasure.event.TreasureFinishEvent; @@ -345,10 +344,22 @@ public class TreasureManager extends MiniPlugin @EventHandler public void join(PlayerJoinEvent event) { - for (Treasure treasure : _playerTreasureMap.values()) + final Player player = event.getPlayer(); + + _plugin.getServer().getScheduler().runTaskLater(_plugin, new Runnable() { - treasure.sendChestOpenPackets(event.getPlayer()); - } + @Override + public void run() + { + if (!player.isOnline()) + return; + + for (Treasure treasure : _playerTreasureMap.values()) + { + treasure.sendChestOpenPackets(player); + } + } + }, 10L); } @EventHandler diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/TreasureRemoveAnimation.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/TreasureRemoveAnimation.java new file mode 100644 index 000000000..be05e6f04 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/TreasureRemoveAnimation.java @@ -0,0 +1,62 @@ +package mineplex.core.treasure.animation; + +import java.util.Random; + +import org.bukkit.Material; +import org.bukkit.block.Block; + +import mineplex.core.common.util.NautHashMap; +import mineplex.core.treasure.BlockInfo; +import mineplex.core.treasure.Treasure; + +/** + * Created by shaun on 14-09-15. + */ +public class TreasureRemoveAnimation extends Animation +{ + private Random _random = new Random(); + + private NautHashMap _blockRestoreMap; + + public TreasureRemoveAnimation(Treasure treasure, NautHashMap blockRestoreMap) + { + super(treasure); + _blockRestoreMap = blockRestoreMap; + } + + @Override + protected void tick() + { + // first wait for 1 second + if (getTicks() <= 20) + return; + + if (getTicks() % 2 == 0) + { + if (_blockRestoreMap.size() > 4) + { + Block block; + do + { + Block[] keyArray = _blockRestoreMap.keySet().toArray(new Block[0]); + + block = keyArray[_random.nextInt(keyArray.length)]; + } + while (block.getType() == Material.CHEST); + + BlockInfo blockInfo = _blockRestoreMap.remove(block); + getTreasure().setBlock(block, Material.getMaterial(blockInfo.getId()), blockInfo.getData(), false); + } + else + { + finish(); + } + } + } + + @Override + protected void onFinish() + { + + } +}