diff --git a/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/button/TreasureButton.java b/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/button/TreasureButton.java deleted file mode 100644 index 05855bcde..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/button/TreasureButton.java +++ /dev/null @@ -1,44 +0,0 @@ -package mineplex.core.cosmetic.ui.button; - -import org.bukkit.entity.Player; -import org.bukkit.event.inventory.ClickType; - -import mineplex.core.cosmetic.ui.page.Menu; -import mineplex.core.shop.item.IButton; - -public class TreasureButton implements IButton -{ - private Menu _menu; - private boolean _hasEnoughChests; - private boolean _hasEnoughKeys; - private boolean _canPurchaseKey; - - public TreasureButton(Menu menu, boolean hasEnoughChests, boolean hasEnoughKeys, boolean canPurchaseKey) - { - _menu = menu; - _hasEnoughChests = hasEnoughChests; - _hasEnoughKeys = hasEnoughKeys; - _canPurchaseKey = canPurchaseKey; - } - - public void onClick(Player player, ClickType clickType) - { - if (clickType.isLeftClick()) - { - if (_hasEnoughChests && _hasEnoughKeys) - { - _menu.openTreasure(player); - player.closeInventory(); - } - else if (_hasEnoughChests && _canPurchaseKey) - { - _menu.attemptPurchaseKey(player); - } - } - else if (clickType.isRightClick()) - { - if (_canPurchaseKey) - _menu.attemptPurchaseKey(player); - } - } -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/page/Menu.java b/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/page/Menu.java index b012cc6ac..0e7253a2c 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/page/Menu.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/cosmetic/ui/page/Menu.java @@ -1,7 +1,5 @@ package mineplex.core.cosmetic.ui.page; -import java.util.ArrayList; - import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.entity.Creature; @@ -12,8 +10,6 @@ import org.bukkit.event.inventory.ClickType; import mineplex.core.account.CoreClientManager; import mineplex.core.common.CurrencyType; import mineplex.core.common.util.C; -import mineplex.core.common.util.F; -import mineplex.core.common.util.UtilPlayer; import mineplex.core.cosmetic.CosmeticManager; import mineplex.core.cosmetic.ui.CosmeticShop; import mineplex.core.cosmetic.ui.button.OpenCostumes; @@ -23,7 +19,6 @@ import mineplex.core.cosmetic.ui.button.OpenMounts; import mineplex.core.cosmetic.ui.button.OpenMusic; import mineplex.core.cosmetic.ui.button.OpenParticles; import mineplex.core.cosmetic.ui.button.OpenPets; -import mineplex.core.cosmetic.ui.button.TreasureButton; import mineplex.core.donation.DonationManager; import mineplex.core.gadget.types.Gadget; import mineplex.core.gadget.types.GadgetType; @@ -33,7 +28,6 @@ import mineplex.core.shop.item.ShopItem; import mineplex.core.shop.page.ConfirmationPage; import mineplex.core.shop.page.ShopPageBase; import mineplex.core.treasure.TreasureKey; -import mineplex.core.treasure.TreasureManager; public class Menu extends ShopPageBase { @@ -47,7 +41,7 @@ public class Menu extends ShopPageBase @Override protected void BuildPage() { - AddItem(2, new ShopItem(175, DonationManager.Get(Player.getName()).getCoins() + " Coins", new String[] + AddItem(4, new ShopItem(175, DonationManager.Get(Player.getName()).getCoins() + " Coins", new String[] { " ", ChatColor.RESET + C.cYellow + "Purchase Coins", @@ -60,54 +54,6 @@ public class Menu extends ShopPageBase ChatColor.RESET + "Receives 15000 Coins per Month", }, 1, false)); - int treasureChestCount = Plugin.getInventoryManager().Get(Player).getItemCount("Treasure Chest"); - int treasureKeyCount = Plugin.getInventoryManager().Get(Player).getItemCount("Treasure Key"); - boolean canPurchaseKey = DonationManager.Get(Player.getName()).GetBalance(CurrencyType.Coins) >= 1000; - - ArrayList lore = new ArrayList(); - - lore.add(ChatColor.RESET + "You can find all kinds of rare"); - lore.add(ChatColor.RESET + "and exciting loot inside!"); - lore.add(" "); - lore.add(ChatColor.RESET + C.cYellow + "Treasure Chests: " + ChatColor.RESET + treasureChestCount); - lore.add(ChatColor.RESET + C.cYellow + "Treasure Keys: " + ChatColor.RESET + treasureKeyCount); - lore.add(" "); - - if (treasureChestCount > 0 && treasureKeyCount > 0) - { - lore.add(ChatColor.RESET + C.cGreen + "Left-Click to open Treasure Chest"); - lore.add(ChatColor.RESET + " Uses 1 Treasure Chest"); - lore.add(ChatColor.RESET + " Uses 1 Treasure Key"); - } - - else if (treasureChestCount > 0) - { - lore.add(ChatColor.RESET + C.cRed + "Left-Click to open Treasure Chest"); - lore.add(ChatColor.RESET + " This requires 1 Treasure Key"); - lore.add(ChatColor.RESET + " You do not have any Treasure Keys"); - } - else - { - lore.add(ChatColor.RESET + C.cRed + "Left-Click to open Treasure Chest"); - lore.add(ChatColor.RESET + " This requires 1 Treasure Chest"); - lore.add(ChatColor.RESET + " Find Treasure Chests by playing games"); - } - - - lore.add(" "); - if (canPurchaseKey) - { - lore.add(ChatColor.RESET + C.cGreen + "Right-Click to purchase Treasure Key"); - lore.add(ChatColor.RESET + " Costs 1000 Coins"); - } - else - { - lore.add(ChatColor.RESET + C.cRed + "Right-Click to purchase Treasure Key"); - lore.add(ChatColor.RESET + " Costs 1000 Coins"); - lore.add(ChatColor.RESET + " You cannot afford a Treasure Key"); - } - - AddButton(4, new ShopItem(Material.CHEST, ChatColor.RESET + C.cGreen + C.Bold + "Treasure Chest", lore.toArray(new String[0]), 1, false), new TreasureButton(this, treasureChestCount > 0, treasureKeyCount > 0, canPurchaseKey)); AddButton(18, new ShopItem(Material.NETHER_STAR, "Particle Effects", 1, false), new OpenParticles(this)); AddButton(20, new ShopItem(Material.BOW, "Gadgets", 1, false), new OpenGadgets(this)); AddButton(22, new ShopItem(Material.LEATHER, "Morphs", 1, false), new OpenMorphs(this)); @@ -212,19 +158,6 @@ public class Menu extends ShopPageBase Shop.OpenPageForPlayer(player, new MusicPage(Plugin, Shop, ClientManager, DonationManager, "Music", player)); } - public void openTreasure(Player player) - { - TreasureManager treasureManager = Plugin.getTreasureManager(); - if (treasureManager == null) - { - UtilPlayer.message(player, F.main("Treasure", "You cannot open Treasure Chests on this server")); - } - else - { - treasureManager.attemptOpenTreasure(player); - } - } - public void attemptPurchaseKey(Player player) { Shop.OpenPageForPlayer(player, new ConfirmationPage(Plugin, Shop, ClientManager, DonationManager, new Runnable() diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/BlockInfo.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/BlockInfo.java index 8bcd13f37..894705556 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/BlockInfo.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/BlockInfo.java @@ -33,16 +33,4 @@ public class BlockInfo { return _data; } - - @Override - public int hashCode() - { - return _block.hashCode(); - } - - @Override - public boolean equals(Object obj) - { - return _block.equals(obj); - } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/ChestData.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/ChestData.java index b5b93540a..43c970262 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/ChestData.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/ChestData.java @@ -2,22 +2,15 @@ package mineplex.core.treasure; import org.bukkit.block.Block; -import mineplex.core.reward.Reward; - -/** - * Created by Shaun on 8/29/2014. - */ public class ChestData { private Block _block; - private Reward _reward; private boolean _opened; - public ChestData(Block block, Reward reward) + public ChestData(Block block) { _block = block; _opened = false; - _reward = reward; } public boolean isOpened() @@ -35,9 +28,4 @@ public class ChestData return _block; } - public Reward getReward() - { - return _reward; - } - } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/Treasure.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/Treasure.java index 46099fb23..abef020d7 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/Treasure.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/Treasure.java @@ -1,21 +1,20 @@ package mineplex.core.treasure; -import java.util.HashSet; +import java.util.ArrayList; import java.util.Iterator; import java.util.LinkedList; +import java.util.List; import java.util.Random; -import java.util.Set; import org.bukkit.Bukkit; 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.blockrestore.BlockRestore; import mineplex.core.common.util.C; import mineplex.core.common.util.F; @@ -25,6 +24,7 @@ import mineplex.core.reward.Reward; import mineplex.core.reward.RewardData; import mineplex.core.reward.RewardRarity; import mineplex.core.treasure.animation.Animation; +import mineplex.core.treasure.animation.BlockChangeAnimation; import mineplex.core.treasure.animation.ChestOpenAnimation; import mineplex.core.treasure.animation.ChestSpawnAnimation; import mineplex.core.treasure.animation.LegendaryAnimation; @@ -39,135 +39,59 @@ public class Treasure { private BlockRestore _blockRestore; - // Decay Sets - private HashSet _wallsBlockInfo = new HashSet<>(); - private HashSet _outerRingBlockInfo = new HashSet<>(); - private HashSet _centerBlockInfo = new HashSet<>(); - private HashSet _chestBlockInfo = new HashSet<>(); + private List _chestBlockInfo = new ArrayList(); + private List _openedChestBlockInfo = new ArrayList(); + private List _otherBlockInfo = new ArrayList(); private Player _player; private Random _random; private Block _centerBlock; private int _tickCount; + private TreasureType _treasureType; + private ChestData[] _chestData; + private int _currentChest; + + private Reward[] _rewards; + private int _currentReward; private boolean _finished; private int _finishedTickCount; private LinkedList _animations; - private TreasureStyle _style; private HologramManager _hologramManager; - public Treasure(Player player, Reward[] rewards, BlockRestore blockRestore, HologramManager hologramManager) + public Treasure(Player player, Reward[] rewards, Block centerBlock, Block[] chestBlocks, TreasureType treasureType, BlockRestore blockRestore, HologramManager hologramManager) { - this(player, new Random(), rewards, hologramManager); + this(player, new Random(), rewards, centerBlock, chestBlocks, treasureType, hologramManager); _blockRestore = blockRestore; } - public Treasure(Player player, Random seed, Reward[] rewards, HologramManager hologramManager) + public Treasure(Player player, Random seed, Reward[] rewards, Block centerBlock, Block[] chestBlocks, TreasureType treasureType, HologramManager hologramManager) { _player = player; _random = seed; - _style = TreasureStyle.values()[_random.nextInt(TreasureStyle.values().length)]; + _treasureType = treasureType; - _centerBlock = player.getLocation().getBlock().getRelative(BlockFace.DOWN); + _centerBlock = centerBlock; _animations = new LinkedList(); _hologramManager = hologramManager; -// _animations.add(new ParticleAnimation(this)); + _currentChest = 0; + _currentReward = 0; + _rewards = rewards; - _chestData = new ChestData[4]; - _chestData[0] = new ChestData(_centerBlock.getRelative(2, 1, 0), rewards[0]); - _chestData[1] = new ChestData(_centerBlock.getRelative(-2, 1, 0), rewards[1]); - _chestData[2] = new ChestData(_centerBlock.getRelative(0, 1, 2), rewards[2]); - _chestData[3] = new ChestData(_centerBlock.getRelative(0, 1, -2), rewards[3]); - } - - private void createCenterClay() - { - for (int x = -1; x <= 1; x++) + _chestData = new ChestData[chestBlocks.length]; + for (int i = 0; i < _chestData.length; i++) { - for (int z = -1; z <= 1; z++) - { - if (Math.abs(x) == 1 || Math.abs(z) == 1) - { - Block block = _centerBlock.getRelative(x, 0, z); - - _blockRestore.Restore(block); - - _centerBlockInfo.add(new BlockInfo(block)); - setBlock(block, _style.getPrimaryMaterial(), _style.getPrimaryData()); - } - } - } - } - - private void createOuterClay() - { - for (int x = -2; x <= 2; x++) - { - { - Block block = _centerBlock.getRelative(x, 0, -2); - - _blockRestore.Restore(block); - - _outerRingBlockInfo.add(new BlockInfo(block)); - setBlock(block, _style.getSecondaryMaterial(), _style.getSecondaryData()); - } - - { - Block block = _centerBlock.getRelative(x, 0, 2); - - _blockRestore.Restore(block); - - _outerRingBlockInfo.add(new BlockInfo(block)); - setBlock(block, _style.getSecondaryMaterial(), _style.getSecondaryData()); - } + _chestData[i] = new ChestData(chestBlocks[i]); } - for (int z = -1; z <= 1; z++) - { - { - Block block = _centerBlock.getRelative(-2, 0, z); - - _blockRestore.Restore(block); - - _outerRingBlockInfo.add(new BlockInfo(block)); - setBlock(block, _style.getSecondaryMaterial(), _style.getSecondaryData()); - } - - { - Block block = _centerBlock.getRelative(2, 0, z); - - _blockRestore.Restore(block); - - _outerRingBlockInfo.add(new BlockInfo(block)); - setBlock(block, _style.getSecondaryMaterial(), _style.getSecondaryData()); - } - } - } - - private void createWalls() - { - for (int z = -2; z <= 2; z++) - { - for (int x = -2; x <= 2; x++) - { - if ((Math.abs(x) == 2 || Math.abs(z) == 2) && (x != 0 && z != 0)) - { - Block playerBlock = getPlayerBlock(); - Block block = playerBlock.getRelative(x, 0, z); - - _blockRestore.Restore(block); - - _wallsBlockInfo.add(new BlockInfo(block)); - setBlock(block, _style.getWallMaterial(), _style.getWallData()); - } - } - } + if (_treasureType == TreasureType.HEROIC || _treasureType == TreasureType.LEGENDARY) + _animations.add(new BlockChangeAnimation(this, _otherBlockInfo)); } public int getFinishedTickCount() @@ -182,59 +106,21 @@ public class Treasure _finishedTickCount++; } - if (_tickCount == 5) + if (_tickCount % 10 == 0 && _currentChest < _chestData.length) { - Block block = _centerBlock; - - _blockRestore.Restore(block); - - _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); + Block block = _chestData[_currentChest].getBlock(); + ChestSpawnAnimation chestSpawn = new ChestSpawnAnimation(this, block, _chestBlockInfo); + _animations.add(chestSpawn); + + _currentChest++; } - else if (_tickCount == 10) - { - createCenterClay(); - } - else if (_tickCount == 20) - { - createOuterClay(); - } - else if (_tickCount == 30) - { - createWalls(); - } - else if (_tickCount == 50) - { - Block block = getPlayerBlock().getRelative(2, 0, 0); - 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, _chestBlockInfo); - _animations.add(task); - } - else if (_tickCount == 110) - { - Block block = getPlayerBlock().getRelative(0, 0, 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, _chestBlockInfo); - _animations.add(task); - } - else if (_tickCount == 60 * 20) + + if (_tickCount == 60 * 20) { for (BlockInfo blockInfo : _chestBlockInfo) { Block block = blockInfo.getBlock(); - openChest(block); + openChest(block, false); } } @@ -271,11 +157,6 @@ public class Treasure return _centerBlock; } - public Block getPlayerBlock() - { - return _centerBlock.getRelative(BlockFace.UP); - } - public void setBlock(Block block, Material material, byte data) { block.setType(material); @@ -284,27 +165,41 @@ public class Treasure } public void openChest(Block block) + { + openChest(block, true); + } + + public void openChest(Block block, boolean swapList) { ChestData data = getChestData(block); - if (data != null && !data.isOpened()) + if (data != null && !data.isOpened() && _currentReward < _rewards.length) { - RewardData rewardData = data.getReward().giveReward("Treasure", _player); + Reward reward = _rewards[_currentReward]; + RewardData rewardData = reward.giveReward("Treasure", _player); + _currentReward++; + + if (swapList) + { + BlockInfo info = getBlockInfo(block); + _chestBlockInfo.remove(info); + _openedChestBlockInfo.add(info); + } data.setOpened(true); ChestOpenAnimation chestOpenTask = new ChestOpenAnimation(this, data, rewardData, _hologramManager); _animations.add(chestOpenTask); // Extra effects based off the rarity of the treasure - if (data.getReward().getRarity() == RewardRarity.UNCOMMON) + if (reward.getRarity() == RewardRarity.UNCOMMON) { _animations.add(new UncommonAnimation(this, data.getBlock())); } - else if (data.getReward().getRarity() == RewardRarity.RARE) + else if (reward.getRarity() == RewardRarity.RARE) { _animations.add(new RareAnimation(this, data.getBlock().getLocation().add(0.5, 1.5, 0.5))); Bukkit.broadcastMessage(F.main("Treasure", F.name(_player.getName()) + " found " + C.cGold + "Rare " + rewardData.getFriendlyName())); } - else if (data.getReward().getRarity() == RewardRarity.LEGENDARY) + else if (reward.getRarity() == RewardRarity.LEGENDARY) { _animations.add(new LegendaryAnimation(this, data.getBlock())); Bukkit.broadcastMessage(F.main("Treasure", F.name(_player.getName()) + " found " + C.cRed + "Legendary " + rewardData.getFriendlyName())); @@ -312,13 +207,23 @@ public class Treasure if (isFinished()) { - TreasureRemoveAnimation animation = new TreasureRemoveAnimation(this, _centerBlockInfo, _outerRingBlockInfo, _wallsBlockInfo); + TreasureRemoveAnimation animation = new TreasureRemoveAnimation(this, _openedChestBlockInfo, _chestBlockInfo); _animations.add(animation); _finished = true; } } } + public BlockInfo getBlockInfo(Block block) + { + for (BlockInfo blockInfo : _chestBlockInfo) + { + if (blockInfo.getBlock().equals(block)) + return blockInfo; + } + return null; + } + public void sendChestOpenPackets(Player... players) { for (ChestData data : _chestData) @@ -357,35 +262,21 @@ public class Treasure public boolean isFinished() { - boolean allOpened = true; - for (int i = 0; i < _chestData.length; i++) - { - if (!_chestData[i].isOpened()) - allOpened = false; - } - - return allOpened; + return _currentReward == _rewards.length; } public void cleanup() { - for (ChestData chestData : _chestData) + + for (int i = _currentReward; i < _rewards.length; i++) { - // Give any unopened rewards to the player - // This only applies if they leave the server - // while opening a treasure - if (!chestData.isOpened()) - { - chestData.setOpened(true); - chestData.getReward().giveReward("Treasure", _player); - } + _rewards[_currentReward].giveReward("Treasure", _player); } // Remove any extra blocks - resetBlockInfo(_wallsBlockInfo); - resetBlockInfo(_centerBlockInfo); - resetBlockInfo(_outerRingBlockInfo); resetBlockInfo(_chestBlockInfo); + resetBlockInfo(_openedChestBlockInfo); + resetBlockInfo(_otherBlockInfo); for (Animation animation : _animations) { @@ -394,40 +285,33 @@ public class Treasure _animations.clear(); } - public void resetBlockInfo(Set blockInfoSet) + public void resetBlockInfo(List blockInfoSet) { for (BlockInfo blockInfo : blockInfoSet) { - Block block = blockInfo.getBlock(); - - if (block.getType().equals(Material.CHEST)) - { - UtilParticle.PlayParticle(UtilParticle.ParticleType.LARGE_SMOKE, block.getLocation().add(0.5, 0.5, 0.5), 0.5F, 0.5F, 0.5F, 0.1F, 10); -// 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()); + resetBlockInfo(blockInfo); } blockInfoSet.clear(); } + public void resetBlockInfo(BlockInfo blockInfo) + { + Block block = blockInfo.getBlock(); + + if (block.getType().equals(Material.CHEST)) + { + UtilParticle.PlayParticle(UtilParticle.ParticleType.LARGE_SMOKE, block.getLocation().add(0.5, 0.5, 0.5), 0.5F, 0.5F, 0.5F, 0.1F, 10); +// 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()); + } + public boolean containsBlock(Block block) { - for (BlockInfo info : _wallsBlockInfo) - if (info.getBlock().equals(block)) - return true; - - for (BlockInfo info : _outerRingBlockInfo) - if (info.getBlock().equals(block)) - return true; - - for (BlockInfo info : _centerBlockInfo) - if (info.getBlock().equals(block)) - return true; - for (BlockInfo info : _chestBlockInfo) if (info.getBlock().equals(block)) return true; @@ -435,9 +319,8 @@ public class Treasure return false; } - public TreasureStyle getStyle() + public TreasureType getTreasureType() { - return _style; + return _treasureType; } - } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/TreasureLocation.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/TreasureLocation.java new file mode 100644 index 000000000..60b3f1338 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/TreasureLocation.java @@ -0,0 +1,322 @@ +package mineplex.core.treasure; + +import java.util.List; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; +import org.bukkit.event.inventory.InventoryOpenEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.event.player.PlayerVelocityEvent; + +import mineplex.core.account.CoreClientManager; +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilAction; +import mineplex.core.common.util.UtilAlg; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilTextMiddle; +import mineplex.core.donation.DonationManager; +import mineplex.core.gadget.event.GadgetBlockEvent; +import mineplex.core.hologram.Hologram; +import mineplex.core.hologram.HologramManager; +import mineplex.core.inventory.InventoryManager; +import mineplex.core.reward.Reward; +import mineplex.core.treasure.event.TreasureFinishEvent; +import mineplex.core.treasure.event.TreasureStartEvent; +import mineplex.core.treasure.gui.TreasureShop; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; + +public class TreasureLocation implements Listener +{ + private TreasureManager _treasureManager; + private InventoryManager _inventoryManager; + private Hologram _hologram; + private HologramManager _hologramManager; + private Treasure _currentTreasure; + private Block _chestBlock; + private byte _chestBlockData; + private Block[] _chestSpawns; + private TreasureShop _shop; + private Location _resetLocation; + + public TreasureLocation(TreasureManager treasureManager, InventoryManager inventoryManager, CoreClientManager clientManager, DonationManager donationManager, Block chestBlock, Block[] chestSpawns, Location resetLocation, HologramManager hologramManager) + { + _treasureManager = treasureManager; + _resetLocation = resetLocation; + _inventoryManager = inventoryManager; + _chestBlock = chestBlock; + _chestBlockData = _chestBlock.getData(); + _chestSpawns = chestSpawns; + _hologramManager = hologramManager; + _currentTreasure = null; + _hologram = new Hologram(_hologramManager, chestBlock.getLocation().add(0.5, 2.5, 0.5), C.cGreen + C.Bold + "Open Treasure"); + setHoloChestVisible(true); + _shop = new TreasureShop(treasureManager, _inventoryManager, clientManager, donationManager, this); + } + + @EventHandler + public void onInteract(PlayerInteractEvent event) + { + if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock().equals(_chestBlock)) + { + openShop(event.getPlayer()); + event.setCancelled(true); + } + } + + public void attemptOpenTreasure(Player player, TreasureType treasureType) + { + if (isTreasureInProgress()) + { + player.sendMessage(F.main("Treasure", "Please wait for the current chest to be opened")); + return; + } + + if (!chargeAccount(player, treasureType)) + { + player.sendMessage(F.main("Treasure", "You dont have any chests to open!")); + return; + } + + TreasureStartEvent event = new TreasureStartEvent(player); + Bukkit.getPluginManager().callEvent(event); + + if (event.isCancelled()) + { + return; + } + + setHoloChestVisible(false); + + if (treasureType == TreasureType.HEROIC || treasureType == TreasureType.LEGENDARY) + Bukkit.broadcastMessage(F.main("Treasure", F.name(player.getName()) + " is opening a " + treasureType.getName())); + + Reward[] rewards = _treasureManager.getRewards(player, treasureType.getRewardType()); + Treasure treasure = new Treasure(player, rewards, _chestBlock, _chestSpawns, treasureType, _treasureManager.getBlockRestore(), _hologramManager); + _currentTreasure = treasure; + + UtilTextMiddle.display(treasureType.getName(), "Choose 4 Chests To Open", 20, 180, 20, player); + UtilPlayer.message(player, F.main("Treasure", "Choose 4 Chests To Open")); + + Location teleportLocation = treasure.getCenterBlock().getLocation().add(0.5, 0, 0.5); + teleportLocation.setPitch(player.getLocation().getPitch()); + teleportLocation.setYaw(player.getLocation().getYaw()); + + for (Entity entity : player.getNearbyEntities(3, 3, 3)) + { + UtilAction.velocity(entity, UtilAlg.getTrajectory(entity.getLocation(), treasure.getCenterBlock().getLocation()).multiply(-1), 1.5, true, 0.8, 0, 1.0, true); + } + + player.teleport(teleportLocation); + + } + + private boolean chargeAccount(Player player, TreasureType treasureType) + { + int itemCount = _inventoryManager.Get(player).getItemCount(treasureType.getItemName()); + if (itemCount > 0) + { + _inventoryManager.addItemToInventory(player, "Item", treasureType.getItemName(), -1); + return true; + } + return false; + } + + private void setHoloChestVisible(boolean visible) + { + if (visible) + { + _hologram.start(); + _chestBlock.setType(Material.CHEST); + _chestBlock.setData(_chestBlockData); + } + else + { + _hologram.stop(); + _chestBlock.setType(Material.AIR); + } + } + + public void cleanup() + { + if (_currentTreasure != null) + { + _currentTreasure.cleanup(); + _currentTreasure = null; + } + } + + @EventHandler + public void update(UpdateEvent event) + { + if (event.getType() != UpdateType.TICK) + return; + + if (isTreasureInProgress()) + { + Treasure treasure = _currentTreasure; + + treasure.update(); + + if (treasure.isFinished() && treasure.getFinishedTickCount() >= 80) + { + treasure.cleanup(); + + TreasureFinishEvent finishEvent = new TreasureFinishEvent(treasure.getPlayer(), treasure); + Bukkit.getPluginManager().callEvent(finishEvent); + } + } + } + + @EventHandler + public void onTreasureFinish(TreasureFinishEvent event) + { + if (event.getTreasure().equals(_currentTreasure)) + { + Player player = _currentTreasure.getPlayer(); + player.teleport(_resetLocation); + _currentTreasure = null; + setHoloChestVisible(true); + } + } + + @EventHandler + public void preventGadgetBlockEvent(GadgetBlockEvent event) + { + if (isTreasureInProgress()) + { + List blocks = event.getBlocks(); + + for (Block block : blocks) + { + if (_currentTreasure.containsBlock(block)) + { + event.setCancelled(true); + return; + } + } + } + } + + @EventHandler(priority = EventPriority.HIGH) + public void interact(PlayerInteractEvent event) + { + Player player = event.getPlayer(); + if (isTreasureInProgress()) + { + if (_currentTreasure.getPlayer().equals(player)) + { + if (event.getAction() == Action.RIGHT_CLICK_BLOCK) + { + _currentTreasure.openChest(event.getClickedBlock()); + } + event.setCancelled(true); + } + else if (event.getAction() == Action.RIGHT_CLICK_BLOCK) + { + ChestData chestData = _currentTreasure.getChestData(event.getClickedBlock()); + if (chestData != null) + { + event.setCancelled(true); + } + } + } + } + + @EventHandler + public void inventoryOpen(InventoryOpenEvent event) + { + if (isTreasureInProgress() && event.getPlayer().equals(_currentTreasure.getPlayer())) + { + event.setCancelled(true); + } + } + + @EventHandler + public void cancelMove(PlayerMoveEvent event) + { + Player player = event.getPlayer(); + if (isTreasureInProgress()) + { + if (_currentTreasure.getPlayer().equals(player)) + { + Treasure treasure = _currentTreasure; + Location centerLocation = treasure.getCenterBlock().getLocation().add(0.5, 0.5, 0.5); + if (event.getTo().distanceSquared(centerLocation) > 9) + { + Location newTo = event.getFrom(); + newTo.setPitch(event.getTo().getPitch()); + newTo.setYaw(event.getTo().getYaw()); + event.setTo(newTo); + } + } + else + { + Location fromLocation = event.getFrom(); + Location toLocation = event.getTo(); + Location centerLocation = _currentTreasure.getCenterBlock().getLocation().add(0.5, 1.5, 0.5); + double toDistanceFromCenter = centerLocation.distanceSquared(toLocation); + + if (toDistanceFromCenter <= 16 && player.getVelocity().lengthSquared() < 10) + { + // Only cancel movement if they are moving towards the center + double fromDistanceFromCenter = centerLocation.distanceSquared(fromLocation); + if (toDistanceFromCenter < fromDistanceFromCenter) + { + Location spawnLocation = new Location(player.getWorld(), 0, 64, 0); + UtilAction.velocity(player, UtilAlg.getTrajectory(player.getLocation(), spawnLocation).multiply(-1), 1.5, true, 0.8, 0, 1.0, true); + event.setTo(event.getFrom()); + } + } + } + } + } + + @EventHandler + public void cancelVelocity(PlayerVelocityEvent event) + { + Player player = event.getPlayer(); + if (isTreasureInProgress() && _currentTreasure.getPlayer().equals(player)) + { + event.setCancelled(true); + } + } + + @EventHandler + public void quit(PlayerQuitEvent event) + { + if (isTreasureInProgress() && _currentTreasure.getPlayer().equals(event.getPlayer())) + { + reset(); + } + } + + public boolean isTreasureInProgress() + { + return _currentTreasure != null; + } + + public void reset() + { + cleanup(); + _chestBlock.setType(Material.CHEST); + _chestBlock.setData(_chestBlockData); + _hologram.start(); + } + + public void openShop(Player player) + { + _shop.attemptShopOpen(player); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/TreasureManager.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/TreasureManager.java index b08c111d7..dbcf16f21 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/TreasureManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/TreasureManager.java @@ -1,462 +1,132 @@ package mineplex.core.treasure; -import java.util.Iterator; +import java.util.ArrayList; import java.util.List; import org.bukkit.Bukkit; import org.bukkit.Location; -import org.bukkit.Material; +import org.bukkit.World; import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; -import org.bukkit.entity.Entity; 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.inventory.InventoryOpenEvent; -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.plugin.java.JavaPlugin; import mineplex.core.MiniPlugin; +import mineplex.core.account.CoreClientManager; import mineplex.core.blockrestore.BlockRestore; -import mineplex.core.common.util.C; -import mineplex.core.common.util.F; -import mineplex.core.common.util.NautHashMap; -import mineplex.core.common.util.UtilAction; -import mineplex.core.common.util.UtilAlg; -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.donation.DonationManager; -import mineplex.core.event.StackerEvent; -import mineplex.core.gadget.event.GadgetBlockEvent; import mineplex.core.hologram.HologramManager; import mineplex.core.inventory.InventoryManager; import mineplex.core.pet.PetManager; import mineplex.core.reward.Reward; import mineplex.core.reward.RewardManager; -import mineplex.core.reward.RewardRarity; import mineplex.core.reward.RewardType; -import mineplex.core.treasure.event.TreasureFinishEvent; -import mineplex.core.treasure.event.TreasureStartEvent; -import mineplex.core.updater.UpdateType; -import mineplex.core.updater.event.UpdateEvent; /** * Created by Shaun on 8/27/2014. */ public class TreasureManager extends MiniPlugin { - private NautHashMap _playerTreasureMap; private RewardManager _rewardManager; private InventoryManager _inventoryManager; private BlockRestore _blockRestore; private HologramManager _hologramManager; + private List _treasureLocations; - public TreasureManager(JavaPlugin plugin, DonationManager donationManager, InventoryManager inventoryManager, PetManager petManager, BlockRestore blockRestore, HologramManager hologramManager) + public TreasureManager(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager, InventoryManager inventoryManager, PetManager petManager, BlockRestore blockRestore, HologramManager hologramManager) { super("Treasure", plugin); - _playerTreasureMap = new NautHashMap(); _inventoryManager = inventoryManager; _blockRestore = blockRestore; _hologramManager = hologramManager; - _rewardManager = new RewardManager(donationManager, inventoryManager, petManager, + _rewardManager = new RewardManager(donationManager, inventoryManager, petManager, 100, 250, 500, 1000, 1500, 2500, 6000, 12000, true); + + World world = Bukkit.getWorlds().get(0); + + _treasureLocations = new ArrayList(); + { + Block chestBlock = world.getBlockAt(-19, 72, -19); + Block chestLoc1 = world.getBlockAt(-16, 72, -20); + Block chestLoc2 = world.getBlockAt(-18, 72, -22); + Block chestLoc3 = world.getBlockAt(-20, 72, -22); + Block chestLoc4 = world.getBlockAt(-22, 72, -20); + Block chestLoc5 = world.getBlockAt(-22, 72, -18); + Block chestLoc6 = world.getBlockAt(-20, 72, -16); + Block chestLoc7 = world.getBlockAt(-18, 72, -16); + Block chestLoc8 = world.getBlockAt(-16, 72, -18); + Location resetLocation = new Location(world, -23.5, 72, -23.5); + _treasureLocations.add(new TreasureLocation(this, _inventoryManager, clientManager, donationManager, chestBlock, new Block[]{chestLoc1, chestLoc2, chestLoc3, chestLoc4, chestLoc5, chestLoc6, chestLoc7, chestLoc8}, resetLocation, _hologramManager)); + } + + { + Block chestBlock = world.getBlockAt(19, 72, 19); + Block chestLoc1 = world.getBlockAt(16, 72, 20); + Block chestLoc2 = world.getBlockAt(18, 72, 22); + Block chestLoc3 = world.getBlockAt(20, 72, 22); + Block chestLoc4 = world.getBlockAt(22, 72, 20); + Block chestLoc5 = world.getBlockAt(22, 72, 18); + Block chestLoc6 = world.getBlockAt(20, 72, 16); + Block chestLoc7 = world.getBlockAt(18, 72, 16); + Block chestLoc8 = world.getBlockAt(16, 72, 18); + Location resetLocation = new Location(world, 23.5, 72, 23.5); + _treasureLocations.add(new TreasureLocation(this, _inventoryManager, clientManager, donationManager, chestBlock, new Block[]{chestLoc1, chestLoc2, chestLoc3, chestLoc4, chestLoc5, chestLoc6, chestLoc7, chestLoc8}, resetLocation, _hologramManager)); + } + + { + Block chestBlock = world.getBlockAt(19, 72, -19); + Block chestLoc1 = world.getBlockAt(16, 72, -20); + Block chestLoc2 = world.getBlockAt(18, 72, -22); + Block chestLoc3 = world.getBlockAt(20, 72, -22); + Block chestLoc4 = world.getBlockAt(22, 72, -20); + Block chestLoc5 = world.getBlockAt(22, 72, -18); + Block chestLoc6 = world.getBlockAt(20, 72, -16); + Block chestLoc7 = world.getBlockAt(18, 72, -16); + Block chestLoc8 = world.getBlockAt(16, 72, -18); + Location resetLocation = new Location(world, 23.5, 72, -23.5); + _treasureLocations.add(new TreasureLocation(this, _inventoryManager, clientManager, donationManager, chestBlock, new Block[]{chestLoc1, chestLoc2, chestLoc3, chestLoc4, chestLoc5, chestLoc6, chestLoc7, chestLoc8}, resetLocation, _hologramManager)); + } + + { + Block chestBlock = world.getBlockAt(-19, 72, 19); + Block chestLoc1 = world.getBlockAt(-16, 72, 20); + Block chestLoc2 = world.getBlockAt(-18, 72, 22); + Block chestLoc3 = world.getBlockAt(-20, 72, 22); + Block chestLoc4 = world.getBlockAt(-22, 72, 20); + Block chestLoc5 = world.getBlockAt(-22, 72, 18); + Block chestLoc6 = world.getBlockAt(-20, 72, 16); + Block chestLoc7 = world.getBlockAt(-18, 72, 16); + Block chestLoc8 = world.getBlockAt(-16, 72, 18); + Location resetLocation = new Location(world, -23.5, 72, 23.5); + _treasureLocations.add(new TreasureLocation(this, _inventoryManager, clientManager, donationManager, chestBlock, new Block[]{chestLoc1, chestLoc2, chestLoc3, chestLoc4, chestLoc5, chestLoc6, chestLoc7, chestLoc8}, resetLocation, _hologramManager)); + } + + for (TreasureLocation treasureLocation : _treasureLocations) + { + _plugin.getServer().getPluginManager().registerEvents(treasureLocation, _plugin); + } } @Override public void Disable() { - for (Treasure treasure : _playerTreasureMap.values()) + for (TreasureLocation treasureLocation : _treasureLocations) { - treasure.cleanup(); + treasureLocation.cleanup(); } } - public void attemptOpenTreasure(Player player) + public Reward[] getRewards(Player player, RewardType rewardType) { - attemptOpenTreasure(player, false); + return _rewardManager.getRewards(player, rewardType); } - private void attemptOpenTreasure(Player player, boolean ignoreKey) + public BlockRestore getBlockRestore() { - if (checkNearbyBlocks(player) || checkNearSpawn(player) || checkInAir(player) || checkNearbyTreasure(player) || (!ignoreKey && checkNoTreasureAndKey(player))) - return; - - TreasureStartEvent event = new TreasureStartEvent(player); - Bukkit.getPluginManager().callEvent(event); - - if (event.isCancelled()) - { - return; - } - - if (!ignoreKey) - { - // Remove a treasure and a key - _inventoryManager.addItemToInventory(player, "Treasure", "Treasure Key", -1); - _inventoryManager.addItemToInventory(player, "Utility", "Treasure Chest", -1); - } - - Bukkit.broadcastMessage(F.main("Treasure", F.name(player.getName()) + " is opening a " + C.cGreen + "Treasure Chest")); - - Reward[] rewards = _rewardManager.getRewards(player, RewardType.HeroicChest); - Treasure treasure = new Treasure(player, rewards, _blockRestore, _hologramManager); - _playerTreasureMap.put(player, treasure); - - Location teleportLocation = treasure.getPlayerBlock().getLocation().add(0.5, 0, 0.5); - teleportLocation.setPitch(player.getLocation().getPitch()); - teleportLocation.setYaw(player.getLocation().getYaw()); - - for (Entity entity : player.getNearbyEntities(3, 3, 3)) - { - UtilAction.velocity(entity, UtilAlg.getTrajectory(entity.getLocation(), treasure.getCenterBlock().getLocation()).multiply(-1), 1.5, true, 0.8, 0, 1.0, true); - } - - player.teleport(teleportLocation); - + return _blockRestore; } - - private boolean checkNoTreasureAndKey(Player player) - { - int treasureCount = _inventoryManager.Get(player).getItemCount("Treasure Chest"); - int treasureKeyCount = _inventoryManager.Get(player).getItemCount("Treasure Key"); - - if (treasureCount < 1) - { - UtilPlayer.message(player, F.main("Treasure", "You don't have any treasure chests.")); - } - else if (treasureKeyCount < 1) - { - UtilPlayer.message(player, F.main("Treasure", "You don't have any treasure keys.")); - } - - return (treasureCount < 1 || treasureKeyCount < 1); - } - - private boolean checkNearbyTreasure(Player player) - { - boolean nearTreasure = false; - - for (Treasure treasure : _playerTreasureMap.values()) - { - if (UtilMath.offset2d(treasure.getCenterBlock().getLocation(), player.getLocation()) <= 10) - nearTreasure = true; - } - - if (nearTreasure) - UtilPlayer.message(player, F.main("Treasure", "You are too close to another players treasure.")); - - return nearTreasure; - } - - private boolean checkNearbyBlocks(Player player) - { - //todo improve this - Block centerBlock = player.getLocation().getBlock(); - - for (int y = 0; y <= 3; y++) - { - for (int x = -3; x <= 3; x++) - { - for (int z = -3; z <= 3; z++) - { - Block block = centerBlock.getRelative(x, y, z); - if (UtilBlock.solid(block)) - { - UtilPlayer.message(player, F.main("Treasure", "You need a clear area to open Treasure Chests.")); - return true; - } - } - } - } - - // Check for blocks that may disappear if modifying them - for (int y = -3; y <= 0; y++) - { - for (int x = -2; x <= 2; x++) - { - for (int z = -2; z <= 2; z++) - { - Material mat = centerBlock.getRelative(x, y, z).getType(); - - if (mat == Material.LADDER || mat == Material.TRAP_DOOR || mat == Material.TRIPWIRE_HOOK || mat == Material.PORTAL || mat == Material.ENDER_PORTAL) - { - UtilPlayer.message(player, F.main("Treasure", "You need a clear area to open Treasure Chests.")); - return true; - } - } - } - } - - // Could now check if the redstone torch can be placed on something, but its not a large deal. - - return false; - } - - private boolean checkInAir(Player player) - { - boolean grounded = UtilEnt.isGrounded(player); - - if (!grounded) - UtilPlayer.message(player, F.main("Treasure", "You can't open chests while in the air.")); - - return !grounded; - } - - private boolean checkNearSpawn(Player player) - { - boolean nearSpawn = UtilMath.offset2d(new Location(player.getWorld(), 0, 0, 0), player.getLocation()) < 10; - - if (nearSpawn) - UtilPlayer.message(player, F.main("Treasure", "You can't open chests near spawn.")); - - return nearSpawn; - } - - @EventHandler - public void update(UpdateEvent event) - { - if (event.getType() != UpdateType.TICK) - return; - - Iterator iterator = _playerTreasureMap.values().iterator(); - while(iterator.hasNext()) - { - Treasure treasure = iterator.next(); - - treasure.update(); - - if (treasure.isFinished() && treasure.getFinishedTickCount() >= 80) - { - treasure.cleanup(); - iterator.remove(); - - TreasureFinishEvent finishEvent = new TreasureFinishEvent(treasure.getPlayer(), treasure); - Bukkit.getPluginManager().callEvent(finishEvent); - } - } - } - - @EventHandler - public void join(PlayerJoinEvent event) - { - final Player player = event.getPlayer(); - - _plugin.getServer().getScheduler().runTaskLater(_plugin, new Runnable() - { - @Override - public void run() - { - if (!player.isOnline()) - return; - - for (Treasure treasure : _playerTreasureMap.values()) - { - treasure.sendChestOpenPackets(player); - } - } - }, 10L); - } - - @EventHandler - public void quit(PlayerQuitEvent event) - { - if (_playerTreasureMap.containsKey(event.getPlayer())) - { - Treasure treasure = _playerTreasureMap.remove(event.getPlayer()); - treasure.cleanup(); - } - } - - @EventHandler - public void cancelMove(PlayerMoveEvent event) - { - Player player = event.getPlayer(); - if (_playerTreasureMap.containsKey(player)) - { - Treasure treasure = _playerTreasureMap.get(player); - if (!event.getTo().getBlock().getRelative(BlockFace.DOWN).equals(treasure.getCenterBlock())) - { - Location newTo = treasure.getCenterBlock().getLocation().add(0.5, 1.1, 0.5); - newTo.setPitch(event.getTo().getPitch()); - newTo.setYaw(event.getTo().getYaw()); - event.setTo(newTo); - } - } - else - { - 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); - - double toDistanceFromCenter = centerLocation.distanceSquared(toLocation); - - if (toDistanceFromCenter <= 9) - { - // 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 - public void inventoryOpen(InventoryOpenEvent event) - { - // Prevent players in treasures from opening inventories - if (event.getPlayer() instanceof Player) - { - if (_playerTreasureMap.containsKey(((Player) event.getPlayer()))) - { - event.setCancelled(true); - } - } - } - - @EventHandler(priority = EventPriority.HIGH) - public void interact(PlayerInteractEvent event) - { - Player player = event.getPlayer(); - if (_playerTreasureMap.containsKey(player)) - { - if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock().getType() == Material.CHEST) - { - 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) - { - for (Treasure treasure : _playerTreasureMap.values()) - { - ChestData data = treasure.getChestData(event.getClickedBlock()); - if (data != null) - { - event.setCancelled(true); - } - } - } - } - - @EventHandler - public void preventGadgetBlockEvent(GadgetBlockEvent event) - { - List blocks = event.getBlocks(); - - for (Block block : blocks) - { - for (Treasure treasure : _playerTreasureMap.values()) - { - if (treasure.containsBlock(block)) - { - event.setCancelled(true); - return; - } - } - } - } - - @EventHandler - public void treasureFinish(TreasureFinishEvent event) - { - _playerTreasureMap.remove(event.getPlayer()); - } - - @EventHandler - public void command(PlayerCommandPreprocessEvent event) - { - if (!event.getPlayer().isOp()) - return; - - if (event.getMessage().startsWith("/treasurechest")) - { - event.getPlayer().sendMessage(C.cGreen + C.Bold + "Received 10 Treasure Chest..."); - _inventoryManager.addItemToInventory(event.getPlayer(), "Utility", "Treasure Chest", 10); - event.setCancelled(true); - } - - if (event.getMessage().startsWith("/treasuredebug")) - { - event.getPlayer().sendMessage(C.cGreen + C.Bold + "Treasure Debug..."); - attemptOpenTreasure(event.getPlayer(), true); - event.setCancelled(true); - } - - if (event.getMessage().startsWith("/rewardchest") || event.getMessage().startsWith("/rewardgame")) - { - int common = 0; - int uncommon = 0; - int rare = 0; - int legend = 0; - - int toTest = 10000000; - - for (int i=0 ; i _blockInfoList; + + public BlockChangeAnimation(Treasure treasure, List blockInfoList) + { + super(treasure); + + _currentRadius = 0; + _blockInfoList = blockInfoList; + } + + @Override + protected void tick() + { + if (_currentRadius == MAX_RADIUS) + { + finish(); + return; + } + else if (getTicks() % 10 == 0) + { + Block centerBlock = getTreasure().getCenterBlock().getRelative(BlockFace.DOWN); + + for (int x = -_currentRadius; x <= _currentRadius; x++) + { + for (int y = 0; y <= _currentRadius; y++) + { + for (int z = -_currentRadius; z <= _currentRadius; z++) + { + Block b = centerBlock.getRelative(x, y, z); + if (y > 0 && b.getType() == Material.SMOOTH_BRICK || b.getType() == Material.STEP || b.getType() == Material.SMOOTH_STAIRS) + { + _blockInfoList.add(new BlockInfo(b)); + b.setType(Material.AIR); + } + else if (b.getType() == Material.SMOOTH_BRICK) + { + Material newMaterial = getTreasure().getTreasureType() == TreasureType.HEROIC ? Material.NETHER_BRICK : Material.QUARTZ_BLOCK; + _blockInfoList.add(new BlockInfo(b)); + b.setType(newMaterial); + } + else if (b.getType() == Material.SMOOTH_STAIRS || b.getType() == Material.COBBLESTONE_STAIRS) + { + Material newMaterial = getTreasure().getTreasureType() == TreasureType.HEROIC ? Material.NETHER_BRICK_STAIRS : Material.QUARTZ_STAIRS; + _blockInfoList.add(new BlockInfo(b)); + b.setType(newMaterial); + } + } + } + } + _currentRadius++; + } + } + + @Override + protected void onFinish() + { + + } +} 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 434460ab0..c4298c5cf 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/ChestSpawnAnimation.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/ChestSpawnAnimation.java @@ -1,9 +1,8 @@ package mineplex.core.treasure.animation; -import java.util.HashSet; +import java.util.List; 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; @@ -18,22 +17,39 @@ import mineplex.core.treasure.Treasure; */ public class ChestSpawnAnimation extends Animation { - private static final int ANIMATION_DURATION = 30; + private static final int ANIMATION_DURATION = 10; private Block _block; private byte _direction; private Location _centerLocation; - private HashSet _chestBlockInfo; + private List _chestBlockInfo; - public ChestSpawnAnimation(Treasure tresure, Block block, byte direction, HashSet chestBlockInfo) + public ChestSpawnAnimation(Treasure tresure, Block block, List chestBlockInfo) { super(tresure); _block = block; - _direction = direction; + int relX = getTreasure().getCenterBlock().getX() - block.getX(); + int relZ = getTreasure().getCenterBlock().getZ() - block.getZ(); + if (Math.abs(relX) > Math.abs(relZ)) + { + if (relX > 0) + _direction = (byte) 5; + else + _direction = (byte) 4; + } + else + { + if (relZ > 0) + _direction = (byte) 3; + else + _direction = (byte) 2; + } _centerLocation = block.getLocation().clone().add(0.5, 0.5, 0.5); _centerLocation.getWorld().playSound(_centerLocation, Sound.LAVA, 1, 1); _chestBlockInfo = chestBlockInfo; + + } @Override @@ -49,16 +65,16 @@ public class ChestSpawnAnimation extends Animation double lead = i * ((2d * Math.PI)/2); float x = (float) (Math.sin(getTicks()/4D + lead)); float z = (float) (Math.cos(getTicks()/4D + lead)); - UtilParticle.PlayParticle(getTreasure().getStyle().getSecondaryParticle(), _centerLocation.clone().add(x * width, y, z * width), 0f, 0f, 0f, 0, 1); + UtilParticle.PlayParticle(getTreasure().getTreasureType().getStyle().getSecondaryParticle(), _centerLocation.clone().add(x * width, y, z * width), 0f, 0f, 0f, 0, 1); } if (getTicks() >= ANIMATION_DURATION) { _chestBlockInfo.add(new BlockInfo(_block)); - getTreasure().setBlock(_block, Material.CHEST, _direction); + getTreasure().setBlock(_block, getTreasure().getTreasureType().getMaterial(), _direction); _block.getLocation().getWorld().playSound(_centerLocation, Sound.ANVIL_LAND, 0.5f, 1f); - UtilParticle.ParticleType particleType = getTreasure().getStyle().getChestSpawnParticle(); + UtilParticle.ParticleType particleType = getTreasure().getTreasureType().getStyle().getChestSpawnParticle(); if (particleType != null) { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/ParticleAnimation.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/ParticleAnimation.java index 40745a47f..9dc89ea02 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/ParticleAnimation.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/ParticleAnimation.java @@ -54,7 +54,7 @@ public class ParticleAnimation extends Animation { Vector position = PATH.get(pathPosition); - UtilParticle.PlayParticle(getTreasure().getStyle().getPrimaryParticle(), getTreasure().getCenterBlock().getLocation().add(0.5, 0, 0.5).add(position), 0, 0, 0, 0, 1); + UtilParticle.PlayParticle(getTreasure().getTreasureType().getStyle().getPrimaryParticle(), getTreasure().getCenterBlock().getLocation().add(0.5, 0, 0.5).add(position), 0, 0, 0, 0, 1); pathPosition = (pathPosition + 1) % PATH.size(); } 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 74da014dd..a97d29f14 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/TreasureRemoveAnimation.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/animation/TreasureRemoveAnimation.java @@ -1,6 +1,6 @@ package mineplex.core.treasure.animation; -import java.util.HashSet; +import java.util.List; import java.util.Random; import mineplex.core.treasure.BlockInfo; @@ -12,66 +12,38 @@ import mineplex.core.treasure.Treasure; public class TreasureRemoveAnimation extends Animation { private Random _random = new Random(); + private List _openedChests; + private List _otherChests; - private HashSet _wallsBlockInfo; - private HashSet _outerRingBlockInfo; - private HashSet _centerBlockInfo; - - public TreasureRemoveAnimation(Treasure treasure, HashSet centerBlockInfo, HashSet outerRingBlockInfo, HashSet wallsBlockInfo) + public TreasureRemoveAnimation(Treasure treasure, List openedChests, List otherChests) { super(treasure); - _wallsBlockInfo = wallsBlockInfo; - _centerBlockInfo = centerBlockInfo; - _outerRingBlockInfo = outerRingBlockInfo; + _openedChests = openedChests; + _otherChests = otherChests; } @Override protected void tick() { - // Chests go away at 100 ticks - HashSet blockInfoSet = null; - - if (getTicks() == 40) + if (getTicks() >= 20 && getTicks() % 10 == 0) { - 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) + if (!_otherChests.isEmpty()) { - 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); + BlockInfo info = _otherChests.remove(_random.nextInt(_otherChests.size())); + getTreasure().resetBlockInfo(info); +// System.out.println("otherchests"); } +// else if (!_openedChests.isEmpty()) +// { +// System.out.println("openchests"); +// BlockInfo info = _openedChests.remove(_random.nextInt(_openedChests.size())); +// getTreasure().resetBlockInfo(info); +// } else { finish(); } } - */ } @Override diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/gui/OpenTreasureButton.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/gui/OpenTreasureButton.java new file mode 100644 index 000000000..1914e2b8b --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/gui/OpenTreasureButton.java @@ -0,0 +1,30 @@ +package mineplex.core.treasure.gui; + +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; + +import mineplex.core.shop.item.IButton; +import mineplex.core.treasure.TreasureLocation; +import mineplex.core.treasure.TreasureType; + +public class OpenTreasureButton implements IButton +{ + + private Player _player; + private TreasureLocation _treasureLocation; + private TreasureType _treasureType; + + public OpenTreasureButton(Player player, TreasureLocation treasureLocation, TreasureType treasureType) + { + _player = player; + _treasureLocation = treasureLocation; + _treasureType = treasureType; + } + + @Override + public void onClick(Player player, ClickType clickType) + { + _treasureLocation.attemptOpenTreasure(player, _treasureType); + player.closeInventory(); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/gui/TreasurePage.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/gui/TreasurePage.java new file mode 100644 index 000000000..d8ebf78c9 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/gui/TreasurePage.java @@ -0,0 +1,73 @@ +package mineplex.core.treasure.gui; + +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.Player; + +import mineplex.core.account.CoreClientManager; +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.donation.DonationManager; +import mineplex.core.inventory.InventoryManager; +import mineplex.core.shop.item.ShopItem; +import mineplex.core.shop.page.ShopPageBase; +import mineplex.core.treasure.TreasureLocation; +import mineplex.core.treasure.TreasureManager; +import mineplex.core.treasure.TreasureType; + +public class TreasurePage extends ShopPageBase +{ + private TreasureLocation _treasureLocation; + private InventoryManager _inventoryManager; + + public TreasurePage(TreasureManager plugin, TreasureShop shop, TreasureLocation treasureLocation, CoreClientManager clientManager, DonationManager donationManager, InventoryManager inventoryManager, Player player) + { + super(plugin, shop, clientManager, donationManager, "Open Treasure", player, 9); + + _treasureLocation = treasureLocation; + _inventoryManager = inventoryManager; + + BuildPage(); + } + + @Override + protected void BuildPage() + { + int basicCount = _inventoryManager.Get(Player).getItemCount(TreasureType.BASIC.getItemName()); + int heroicCount = _inventoryManager.Get(Player).getItemCount(TreasureType.HEROIC.getItemName()); + int legendaryCount = _inventoryManager.Get(Player).getItemCount(TreasureType.LEGENDARY.getItemName()); + + List basicLore = new ArrayList(); + basicLore.add(" "); + basicLore.add(F.value("Basic Chests Owned", "" + basicCount)); + basicLore.add(" "); + if (basicCount > 0) + basicLore.add(ChatColor.RESET + "Click to open!"); + + List heroicLore = new ArrayList(); + heroicLore.add(" "); + heroicLore.add(F.value("Heroic Chests Owned", "" + heroicCount)); + heroicLore.add(" "); + if (heroicCount > 0) + heroicLore.add(ChatColor.RESET + "Click to open!"); + + List legendaryLore = new ArrayList(); + legendaryLore.add(" "); + legendaryLore.add(F.value("Legendary Chests Owned", "" + legendaryCount)); + legendaryLore.add(" "); + if (legendaryCount > 0) + legendaryLore.add(ChatColor.RESET + "Click to open!"); + + + ShopItem basic = new ShopItem(Material.CHEST, C.cGreen + C.Bold + "Basic Chest", basicLore.toArray(new String[0]), 0, false, false); + ShopItem heroic = new ShopItem(Material.TRAPPED_CHEST, C.cGold + C.Bold + "Heroic Chest", heroicLore.toArray(new String[0]), 0, false, false); + ShopItem legendary = new ShopItem(Material.ENDER_CHEST, C.cRed + C.Bold + "Legendary Chest", legendaryLore.toArray(new String[0]), 0, false, false); + + AddButton(2, basic, new OpenTreasureButton(Player, _treasureLocation, TreasureType.BASIC)); + AddButton(4, heroic, new OpenTreasureButton(Player, _treasureLocation, TreasureType.HEROIC)); + AddButton(6, legendary, new OpenTreasureButton(Player, _treasureLocation, TreasureType.LEGENDARY)); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/treasure/gui/TreasureShop.java b/Plugins/Mineplex.Core/src/mineplex/core/treasure/gui/TreasureShop.java new file mode 100644 index 000000000..644b94497 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/treasure/gui/TreasureShop.java @@ -0,0 +1,30 @@ +package mineplex.core.treasure.gui; + +import org.bukkit.entity.Player; + +import mineplex.core.account.CoreClientManager; +import mineplex.core.donation.DonationManager; +import mineplex.core.inventory.InventoryManager; +import mineplex.core.shop.ShopBase; +import mineplex.core.shop.page.ShopPageBase; +import mineplex.core.treasure.TreasureLocation; +import mineplex.core.treasure.TreasureManager; + +public class TreasureShop extends ShopBase +{ + private TreasureLocation _treasureLocation; + private InventoryManager _inventoryManager; + + public TreasureShop(TreasureManager plugin, InventoryManager inventoryManager, CoreClientManager clientManager, DonationManager donationManager, TreasureLocation treasureLocation) + { + super(plugin, clientManager, donationManager, "Treasure Shop"); + _treasureLocation = treasureLocation; + _inventoryManager = inventoryManager; + } + + @Override + protected ShopPageBase> BuildPagesFor(Player player) + { + return new TreasurePage(Plugin, this, _treasureLocation, ClientManager, DonationManager, _inventoryManager, player); + } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java index 1b141a485..01f0ff5fa 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java @@ -1,5 +1,8 @@ package mineplex.game.clans; +import org.bukkit.plugin.java.JavaPlugin; +import net.minecraft.server.v1_7_R4.MinecraftServer; + import mineplex.core.account.CoreClientManager; import mineplex.core.antihack.AntiHack; import mineplex.core.blockrestore.BlockRestore; @@ -25,9 +28,6 @@ import mineplex.core.updater.Updater; import mineplex.game.clans.clans.ClansManager; import mineplex.game.clans.shop.building.BuildingShop; import mineplex.game.clans.shop.pvp.PvpShop; -import net.minecraft.server.v1_7_R4.MinecraftServer; - -import org.bukkit.plugin.java.JavaPlugin; public class Clans extends JavaPlugin { diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java index d8016d055..03ff5fa6f 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/HubManager.java @@ -45,7 +45,6 @@ import mineplex.core.MiniClientPlugin; import mineplex.core.account.CoreClient; import mineplex.core.account.CoreClientManager; import mineplex.core.achievement.AchievementManager; -import mineplex.core.benefit.BenefitManager; import mineplex.core.blockrestore.BlockRestore; import mineplex.core.common.Rank; import mineplex.core.common.util.C; @@ -85,7 +84,6 @@ import mineplex.hub.commands.ForcefieldRadius; import mineplex.hub.commands.GadgetToggle; import mineplex.hub.commands.GameModeCommand; import mineplex.hub.commands.NewsCommand; -import mineplex.hub.mail.MailManager; import mineplex.hub.modules.ForcefieldManager; import mineplex.hub.modules.JumpManager; import mineplex.hub.modules.MapManager; @@ -95,7 +93,6 @@ import mineplex.hub.modules.TextManager; import mineplex.hub.modules.UHCManager; import mineplex.hub.modules.VisibilityManager; import mineplex.hub.modules.WorldManager; -import mineplex.hub.notification.NotificationManager; import mineplex.hub.party.Party; import mineplex.hub.party.PartyManager; import mineplex.hub.poll.PollManager; @@ -182,7 +179,7 @@ public class HubManager extends MiniClientPlugin _inventoryManager = new InventoryManager(plugin, clientManager); //new BenefitManager(plugin, clientManager, _inventoryManager); _gadgetManager = new GadgetManager(_plugin, clientManager, donationManager, _inventoryManager, _mountManager, petManager, preferences, disguiseManager, blockRestore, new ProjectileManager(plugin)); - _treasureManager = new TreasureManager(_plugin, donationManager, _inventoryManager, petManager, _blockRestore, hologramManager); + _treasureManager = new TreasureManager(_plugin, clientManager, donationManager, _inventoryManager, petManager, _blockRestore, hologramManager); new CosmeticManager(_plugin, clientManager, donationManager, _inventoryManager, _gadgetManager, _mountManager, petManager, _treasureManager); _petManager = petManager;