From 918a8172831e8f4956d34fe8367c8134fbbb1482 Mon Sep 17 00:00:00 2001 From: Shaun Bennett Date: Tue, 16 Sep 2014 15:04:42 -0500 Subject: [PATCH 1/2] More treasure bug fixes and animation touches --- .../src/mineplex/core/treasure/BlockInfo.java | 22 ++++- .../src/mineplex/core/treasure/Treasure.java | 89 +++++++++++-------- .../core/treasure/TreasureManager.java | 53 +++++++++-- .../animation/ChestSpawnAnimation.java | 11 ++- .../animation/TreasureRemoveAnimation.java | 40 ++++++--- .../treasure/reward/rewards/CoinReward.java | 4 +- .../reward/rewards/UnknownPackageReward.java | 3 +- 7 files changed, 158 insertions(+), 64 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/BlockInfo.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/BlockInfo.java index 13e40df3b..09c46f93d 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/BlockInfo.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/BlockInfo.java @@ -1,17 +1,27 @@ package mineplex.core.treasure; +import org.bukkit.block.Block; + /** * Created by Shaun on 8/28/2014. */ public class BlockInfo { + private Block _block; + private int _id; private byte _data; - public BlockInfo(int id, byte data) + public BlockInfo(Block block) { - _id = id; - _data = data; + _block = block; + _id = block.getTypeId(); + _data = block.getData(); + } + + public Block getBlock() + { + return _block; } public int getId() @@ -23,4 +33,10 @@ public class BlockInfo { return _data; } + + @Override + public int hashCode() + { + return _block.hashCode(); + } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/Treasure.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/Treasure.java index 90fead2df..c1d0fb1a4 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/Treasure.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/Treasure.java @@ -1,9 +1,10 @@ package mineplex.core.treasure; +import java.util.HashSet; import java.util.Iterator; import java.util.LinkedList; -import java.util.Map; import java.util.Random; +import java.util.Set; import org.bukkit.Bukkit; import org.bukkit.Effect; @@ -16,7 +17,6 @@ import org.bukkit.entity.Player; import net.minecraft.server.v1_7_R4.PacketPlayOutBlockAction; import mineplex.core.common.util.F; -import mineplex.core.common.util.NautHashMap; import mineplex.core.common.util.UtilParticle; import mineplex.core.treasure.animation.Animation; import mineplex.core.treasure.animation.ChestExplodeAnimation; @@ -33,7 +33,13 @@ import mineplex.core.treasure.reward.RewardRarity; */ public class Treasure { - private NautHashMap _blockRestoreMap = new NautHashMap(); + + // Decay Sets + private HashSet _wallsBlockInfo = new HashSet<>(); + private HashSet _outerRingBlockInfo = new HashSet<>(); + private HashSet _centerBlockInfo = new HashSet<>(); + private HashSet _chestBlockInfo = new HashSet<>(); + private Player _player; private Random _random; private Block _centerBlock; @@ -80,6 +86,7 @@ public class Treasure if (Math.abs(x) == 1 || Math.abs(z) == 1) { Block block = _centerBlock.getRelative(x, 0, z); + _centerBlockInfo.add(new BlockInfo(block)); setBlock(block, _style.getPrimaryMaterial(), _style.getPrimaryData()); } } @@ -92,11 +99,13 @@ public class Treasure { { Block block = _centerBlock.getRelative(x, 0, -2); + _outerRingBlockInfo.add(new BlockInfo(block)); setBlock(block, _style.getSecondaryMaterial(), _style.getSecondaryData()); } { Block block = _centerBlock.getRelative(x, 0, 2); + _outerRingBlockInfo.add(new BlockInfo(block)); setBlock(block, _style.getSecondaryMaterial(), _style.getSecondaryData()); } } @@ -105,17 +114,19 @@ public class Treasure { { Block block = _centerBlock.getRelative(-2, 0, z); + _outerRingBlockInfo.add(new BlockInfo(block)); setBlock(block, _style.getSecondaryMaterial(), _style.getSecondaryData()); } { Block block = _centerBlock.getRelative(2, 0, z); + _outerRingBlockInfo.add(new BlockInfo(block)); setBlock(block, _style.getSecondaryMaterial(), _style.getSecondaryData()); } } } - private void createGlass() + private void createWalls() { for (int z = -2; z <= 2; z++) { @@ -125,6 +136,7 @@ public class Treasure { Block playerBlock = getPlayerBlock(); Block block = playerBlock.getRelative(x, 0, z); + _wallsBlockInfo.add(new BlockInfo(block)); setBlock(block, _style.getWallMaterial(), _style.getWallData()); } } @@ -146,7 +158,10 @@ public class Treasure if (_tickCount == 5) { Block block = _centerBlock; - setBlock(block, _style.getPrimaryMaterial(), _style.getPrimaryData()); + _centerBlockInfo.add(new BlockInfo(block)); + _centerBlockInfo.add(new BlockInfo(block.getRelative(BlockFace.DOWN))); + setBlock(block, Material.REDSTONE_LAMP_ON, (byte) 0); + setBlock(block.getRelative(BlockFace.DOWN), Material.REDSTONE_TORCH_ON, (byte) 0); } else if (_tickCount == 10) { @@ -158,30 +173,30 @@ public class Treasure } else if (_tickCount == 30) { - createGlass(); + createWalls(); } else if (_tickCount == 50) { Block block = getPlayerBlock().getRelative(2, 0, 0); - ChestSpawnAnimation task = new ChestSpawnAnimation(this, block, (byte)4); + ChestSpawnAnimation task = new ChestSpawnAnimation(this, block, (byte)4, _chestBlockInfo); _animations.add(task); } else if (_tickCount == 80) { Block block = getPlayerBlock().getRelative(-2, 0, 0); - ChestSpawnAnimation task = new ChestSpawnAnimation(this, block, (byte)5); + ChestSpawnAnimation task = new ChestSpawnAnimation(this, block, (byte)5, _chestBlockInfo); _animations.add(task); } else if (_tickCount == 110) { Block block = getPlayerBlock().getRelative(0, 0, 2); - ChestSpawnAnimation task = new ChestSpawnAnimation(this, block, (byte)2); + ChestSpawnAnimation task = new ChestSpawnAnimation(this, block, (byte)2, _chestBlockInfo); _animations.add(task); } else if (_tickCount == 140) { Block block = getPlayerBlock().getRelative(0, 0, -2); - ChestSpawnAnimation task = new ChestSpawnAnimation(this, block, (byte)3); + ChestSpawnAnimation task = new ChestSpawnAnimation(this, block, (byte)3, _chestBlockInfo); _animations.add(task); } @@ -223,21 +238,13 @@ public class Treasure return _centerBlock.getRelative(BlockFace.UP); } - public void setBlock(Block block, Material material, byte data, boolean addToBlockRestoreMap) + public void setBlock(Block block, Material material, byte data) { - 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); @@ -257,17 +264,17 @@ public class Treasure else if (data.getReward().getRarity() == RewardRarity.RARE) { _animations.add(new CircleAnimation(this, data.getBlock().getLocation().add(0.5, 1.5, 0.5))); - Bukkit.broadcastMessage(F.main("Treasure", F.name(_player.getName()) + " opened a Rare treasure!")); + Bukkit.broadcastMessage(F.main("Treasure", F.name(_player.getName()) + " opened the Rare treasure " + text)); } else if (data.getReward().getRarity() == RewardRarity.VERY_RARE) { _animations.add(new ChestExplodeAnimation(this, data.getBlock())); - Bukkit.broadcastMessage(F.main("Treasure", F.name(_player.getName()) + " opened a Legendary treasure!")); + Bukkit.broadcastMessage(F.main("Treasure", F.name(_player.getName()) + " opened the Legendary treasure " + text)); } if (isFinished()) { - TreasureRemoveAnimation animation = new TreasureRemoveAnimation(this, _blockRestoreMap); + TreasureRemoveAnimation animation = new TreasureRemoveAnimation(this, _centerBlockInfo, _outerRingBlockInfo, _wallsBlockInfo); _animations.add(animation); _finished = true; } @@ -337,20 +344,11 @@ public class Treasure } } - for (Map.Entry entry : _blockRestoreMap.entrySet()) - { - 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()); - } + // Remove any extra blocks + resetBlockInfo(_wallsBlockInfo); + resetBlockInfo(_centerBlockInfo); + resetBlockInfo(_outerRingBlockInfo); + resetBlockInfo(_chestBlockInfo); for (Animation animation : _animations) { @@ -359,6 +357,25 @@ public class Treasure _animations.clear(); } + public void resetBlockInfo(Set blockInfoSet) + { + for (BlockInfo blockInfo : blockInfoSet) + { + Block block = blockInfo.getBlock(); + + 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(blockInfo.getId()); + block.setData(blockInfo.getData()); + } + + blockInfoSet.clear(); + } + public TreasureStyle getStyle() { return _style; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/TreasureManager.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/TreasureManager.java index 3978b60b6..1f4e16978 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/TreasureManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/TreasureManager.java @@ -11,12 +11,14 @@ import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; 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.event.player.PlayerVelocityEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.java.JavaPlugin; @@ -31,6 +33,7 @@ import mineplex.core.common.util.UtilEnt; import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilPlayer; import mineplex.core.donation.DonationManager; +import mineplex.core.event.StackerEvent; import mineplex.core.inventory.InventoryManager; import mineplex.core.treasure.event.TreasureFinishEvent; import mineplex.core.treasure.event.TreasureStartEvent; @@ -66,7 +69,7 @@ public class TreasureManager extends MiniPlugin { // Coins { - _rewardManager.addReward(new CoinReward(donationManager, 2000, 5000, 25, RewardRarity.VERY_RARE)); + _rewardManager.addReward(new CoinReward(donationManager, 10000, 20000, 25, RewardRarity.VERY_RARE)); } // Mounts { @@ -330,7 +333,7 @@ public class TreasureManager extends MiniPlugin treasure.update(); - if (treasure.isFinished() && treasure.getFinishedTickCount() >= 100) + if (treasure.isFinished() && treasure.getFinishedTickCount() >= 80) { treasure.cleanup(); iterator.remove(); @@ -391,17 +394,52 @@ public class TreasureManager extends MiniPlugin { for (Treasure treasure : _playerTreasureMap.values()) { + Location fromLocation = event.getFrom(); + Location toLocation = event.getTo(); Location centerLocation = treasure.getCenterBlock().getLocation().add(0.5, 1.5, 0.5); - if (centerLocation.distanceSquared(event.getTo()) <= 9) + + double toDistanceFromCenter = centerLocation.distanceSquared(toLocation); + + if (toDistanceFromCenter <= 9) { - UtilAction.velocity(player, UtilAlg.getTrajectory(player.getLocation(), centerLocation).multiply(-1), 1.5, true, 0.8, 0, 1.0, true); - event.setTo(event.getFrom()); + // Only cancel movement if they are moving towards the center + double fromDistanceFromCenter = centerLocation.distanceSquared(fromLocation); + if (toDistanceFromCenter < fromDistanceFromCenter) + { + UtilAction.velocity(player, UtilAlg.getTrajectory(player.getLocation(), centerLocation).multiply(-1), 1.5, true, 0.8, 0, 1.0, true); + event.setTo(event.getFrom()); + } } } } } @EventHandler + public void cancelVelocity(PlayerVelocityEvent event) + { + // Need to prevent players + + Player player = event.getPlayer(); + if (_playerTreasureMap.containsKey(player)) + { + event.setCancelled(true); + } + } + + @EventHandler + public void cancelStacker(StackerEvent event) + { + if (event.getEntity() instanceof Player) + { + Player player = ((Player) event.getEntity()); + if (_playerTreasureMap.containsKey(player)) + { + event.setCancelled(true); + } + } + } + + @EventHandler(priority = EventPriority.HIGH) public void interact(PlayerInteractEvent event) { Player player = event.getPlayer(); @@ -409,11 +447,12 @@ public class TreasureManager extends MiniPlugin { if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock().getType() == Material.CHEST) { - event.setCancelled(true); - Treasure treasure = _playerTreasureMap.get(player); treasure.openChest(event.getClickedBlock()); } + + // Always cancel interact for treasure players, prevents players from being able to open up cosmetic menu and other menus + event.setCancelled(true); } else if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock().getType() == Material.CHEST) { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/ChestSpawnAnimation.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/ChestSpawnAnimation.java index 28aa01e07..434460ab0 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/ChestSpawnAnimation.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/ChestSpawnAnimation.java @@ -1,15 +1,16 @@ package mineplex.core.treasure.animation; +import java.util.HashSet; + import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.block.Block; import org.bukkit.craftbukkit.v1_7_R4.CraftWorld; - import net.minecraft.server.v1_7_R4.MathHelper; -import net.minecraft.server.v1_7_R4.PacketPlayOutWorldEvent; import mineplex.core.common.util.UtilParticle; +import mineplex.core.treasure.BlockInfo; import mineplex.core.treasure.Treasure; /** @@ -23,13 +24,16 @@ public class ChestSpawnAnimation extends Animation private byte _direction; private Location _centerLocation; - public ChestSpawnAnimation(Treasure tresure, Block block, byte direction) + private HashSet _chestBlockInfo; + + public ChestSpawnAnimation(Treasure tresure, Block block, byte direction, HashSet chestBlockInfo) { super(tresure); _block = block; _direction = direction; _centerLocation = block.getLocation().clone().add(0.5, 0.5, 0.5); _centerLocation.getWorld().playSound(_centerLocation, Sound.LAVA, 1, 1); + _chestBlockInfo = chestBlockInfo; } @Override @@ -50,6 +54,7 @@ public class ChestSpawnAnimation extends Animation if (getTicks() >= ANIMATION_DURATION) { + _chestBlockInfo.add(new BlockInfo(_block)); getTreasure().setBlock(_block, Material.CHEST, _direction); _block.getLocation().getWorld().playSound(_centerLocation, Sound.ANVIL_LAND, 0.5f, 1f); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/TreasureRemoveAnimation.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/TreasureRemoveAnimation.java index be05e6f04..74da014dd 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/TreasureRemoveAnimation.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/TreasureRemoveAnimation.java @@ -1,11 +1,8 @@ package mineplex.core.treasure.animation; +import java.util.HashSet; 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; @@ -16,21 +13,43 @@ public class TreasureRemoveAnimation extends Animation { private Random _random = new Random(); - private NautHashMap _blockRestoreMap; + private HashSet _wallsBlockInfo; + private HashSet _outerRingBlockInfo; + private HashSet _centerBlockInfo; - public TreasureRemoveAnimation(Treasure treasure, NautHashMap blockRestoreMap) + public TreasureRemoveAnimation(Treasure treasure, HashSet centerBlockInfo, HashSet outerRingBlockInfo, HashSet wallsBlockInfo) { super(treasure); - _blockRestoreMap = blockRestoreMap; + _wallsBlockInfo = wallsBlockInfo; + _centerBlockInfo = centerBlockInfo; + _outerRingBlockInfo = outerRingBlockInfo; } @Override protected void tick() { - // first wait for 1 second - if (getTicks() <= 20) - return; + // Chests go away at 100 ticks + HashSet blockInfoSet = null; + if (getTicks() == 40) + { + blockInfoSet = _wallsBlockInfo; + } + else if (getTicks() == 50) + { + blockInfoSet = _outerRingBlockInfo; + } + else if (getTicks() == 60) + { + blockInfoSet = _centerBlockInfo; + } + + if (blockInfoSet != null) + { + getTreasure().resetBlockInfo(blockInfoSet); + } + + /* if (getTicks() % 2 == 0) { if (_blockRestoreMap.size() > 4) @@ -52,6 +71,7 @@ public class TreasureRemoveAnimation extends Animation finish(); } } + */ } @Override diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/reward/rewards/CoinReward.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/reward/rewards/CoinReward.java index e5b3a6b2f..9f52c1474 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/reward/rewards/CoinReward.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/reward/rewards/CoinReward.java @@ -6,11 +6,9 @@ package mineplex.core.treasure.reward.rewards; import java.util.Random; -import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; -import mineplex.core.common.util.C; import mineplex.core.common.util.Callback; import mineplex.core.donation.DonationManager; import mineplex.core.treasure.reward.RewardRarity; @@ -32,7 +30,7 @@ public class CoinReward extends AbstractReward public CoinReward(DonationManager donationManager, int minCoinCount, int maxCoinCount, int weight, RewardRarity rarity, Random random) { - super(new ItemStack(Material.GOLD_INGOT), rarity, weight); + super(new ItemStack(175), rarity, weight); _donationManager = donationManager; _minCoinCount = minCoinCount; _maxCoinCount = maxCoinCount; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/reward/rewards/UnknownPackageReward.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/reward/rewards/UnknownPackageReward.java index 0968e71d0..6fae49898 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/reward/rewards/UnknownPackageReward.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/reward/rewards/UnknownPackageReward.java @@ -1,6 +1,5 @@ package mineplex.core.treasure.reward.rewards; -import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -35,7 +34,7 @@ public class UnknownPackageReward extends AbstractReward @Override public boolean canGiveReward(Player player) { - return _donationManager.Get(player.getName()).OwnsUnknownPackage(_packageName); + return !_donationManager.Get(player.getName()).OwnsUnknownPackage(_packageName); } protected String getPackageName() From 50fa8b02f1c4458f01e0c419ac78e179a7947aa2 Mon Sep 17 00:00:00 2001 From: Shaun Bennett Date: Tue, 16 Sep 2014 17:57:34 -0500 Subject: [PATCH 2/2] Use explosion particles instead of createExplosion --- Plugins/Mineplex.Core/src/mineplex/core/treasure/Treasure.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/Treasure.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/Treasure.java index c1d0fb1a4..e6ca1372a 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/Treasure.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/Treasure.java @@ -365,7 +365,8 @@ public class Treasure if (block.getType().equals(Material.CHEST)) { - block.getLocation().getWorld().createExplosion(block.getLocation().add(0.5, 0.5, 0.5), 0F); + UtilParticle.PlayParticle(UtilParticle.ParticleType.EXPLODE, block.getLocation().add(0.5, 0.5, 0.5), 0F, 0F, 0F, 0F, 1); +// 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());