From 8ee5faf4d954dd5d50f7d82a85c0ea1bceb94895 Mon Sep 17 00:00:00 2001 From: AlexTheCoder Date: Mon, 12 Jun 2017 01:00:09 -0400 Subject: [PATCH] Change boxes more --- .../game/clans/clans/boxes/BoxManager.java | 63 +++++------ .../clans/clans/boxes/BoxOverviewPage.java | 2 +- .../clans/boxes/extra/BuilderBoxVerifier.java | 104 ++++++++++++++++++ .../clans/boxes/extra/DyeBoxSpinner.java | 7 +- 4 files changed, 138 insertions(+), 38 deletions(-) create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/boxes/extra/BuilderBoxVerifier.java diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/boxes/BoxManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/boxes/BoxManager.java index cef70aa3b..54b62deac 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/boxes/BoxManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/boxes/BoxManager.java @@ -1,7 +1,5 @@ package mineplex.game.clans.clans.boxes; -import java.util.HashMap; -import java.util.Map; import java.util.function.Consumer; import org.bukkit.DyeColor; @@ -17,26 +15,27 @@ import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.java.JavaPlugin; +import mineplex.core.Managers; import mineplex.core.MiniPlugin; import mineplex.core.command.CommandBase; -import mineplex.core.common.Pair; import mineplex.core.common.Rank; import mineplex.core.common.util.C; -import mineplex.core.common.util.F; -import mineplex.core.common.util.UtilMath; -import mineplex.core.common.util.UtilPlayer; import mineplex.core.itemstack.ItemBuilder; -import mineplex.game.clans.clans.ClansManager; +import mineplex.game.clans.clans.boxes.extra.BuilderBoxVerifier; import mineplex.game.clans.clans.boxes.extra.DyeBoxSpinner; public class BoxManager extends MiniPlugin { + private BuilderBoxVerifier _builderVerifier; + public BoxManager(JavaPlugin plugin) { super("Box Manager", plugin); final BoxShop shop = new BoxShop(this); + _builderVerifier = new BuilderBoxVerifier(this, shop); + addCommand(new CommandBase(this, Rank.ALL, "boxes", "box") { @Override @@ -68,6 +67,12 @@ public class BoxManager extends MiniPlugin return; } } + return; + } + if (event.getInventory().getResult().getType() == Material.INK_SACK) + { + event.getInventory().setResult(null); + return; } for (ItemStack item : event.getInventory().getMatrix()) { @@ -75,6 +80,10 @@ public class BoxManager extends MiniPlugin { continue; } + if (item.getType() != Material.INK_SACK) + { + continue; + } if (!item.hasItemMeta() || !item.getItemMeta().hasDisplayName() || !item.getItemMeta().getDisplayName().equals(C.cGold + "Dye")) { event.getInventory().setResult(null); @@ -103,6 +112,12 @@ public class BoxManager extends MiniPlugin return; } } + return; + } + if (event.getInventory().getResult().getType() == Material.INK_SACK) + { + event.setCancelled(true); + return; } for (ItemStack item : event.getInventory().getMatrix()) { @@ -110,10 +125,13 @@ public class BoxManager extends MiniPlugin { continue; } + if (item.getType() != Material.INK_SACK) + { + continue; + } if (!item.hasItemMeta() || !item.getItemMeta().hasDisplayName() || !item.getItemMeta().getDisplayName().equals(C.cGold + "Dye")) { event.setCancelled(true); - return; } } } @@ -151,31 +169,7 @@ public class BoxManager extends MiniPlugin public static enum BoxType { - @SuppressWarnings("deprecation") - BUILDER_BOX("Clans Builder Box", C.cGold + "Builder's Box", Material.GLOWSTONE, player -> - { - Map, ItemStack> replace = new HashMap<>(); - replace.put(Pair.create(Material.STONE, (byte)0), new ItemStack(Material.STAINED_CLAY)); - replace.put(Pair.create(Material.GLASS, (byte)0), new ItemStack(Material.STAINED_GLASS)); - replace.put(Pair.create(Material.THIN_GLASS, (byte)0), new ItemStack(Material.STAINED_GLASS_PANE)); - - for (int slot = 0; slot < player.getInventory().getSize(); slot++) - { - ItemStack item = player.getInventory().getItem(slot); - if (item == null) - { - continue; - } - ItemStack after = new ItemBuilder(replace.get(Pair.create(item.getType(), item.getData().getData()))).setData(DyeColor.values()[UtilMath.r(DyeColor.values().length)].getWoolData()).build(); - if (after != null) - { - after.setAmount(item.getAmount()); - player.getInventory().setItem(slot, after); - } - } - - UtilPlayer.message(player, F.main("Builder's Box", "You have redeemed your box contents!")); - }), + BUILDER_BOX("Clans Builder Box", C.cGold + "Builder's Box", Material.GLOWSTONE, Managers.get(BoxManager.class)._builderVerifier::showVerifier), @SuppressWarnings("deprecation") DYE_BOX("Clans Dye Box", C.cGreen + "Dye Box", Material.INK_SACK, DyeColor.RED.getDyeData(), DyeBoxSpinner::createSpinner), ; @@ -220,9 +214,8 @@ public class BoxManager extends MiniPlugin return newBuilder.addLore(C.cGreenB + "Owned: " + C.cWhite + owned).build(); } - public void generateRewards(Player player) + public void onUse(Player player) { - ClansManager.getInstance().getInventoryManager().addItemToInventory(player, getItemName(), -1); _itemGenerator.accept(player); } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/boxes/BoxOverviewPage.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/boxes/BoxOverviewPage.java index 76f74bb39..bd17da0de 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/boxes/BoxOverviewPage.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/boxes/BoxOverviewPage.java @@ -39,7 +39,7 @@ public class BoxOverviewPage extends ShopPageBase player.playSound(player.getLocation(), Sound.CHEST_OPEN, 1f, 1f); if (Recharge.Instance.use(player, "Clans Box Click", 1000, false, false)) { - type.generateRewards(player); + type.onUse(player); } } }; diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/boxes/extra/BuilderBoxVerifier.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/boxes/extra/BuilderBoxVerifier.java new file mode 100644 index 000000000..9bde6ee83 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/boxes/extra/BuilderBoxVerifier.java @@ -0,0 +1,104 @@ +package mineplex.game.clans.clans.boxes.extra; + +import java.util.HashMap; +import java.util.Map; + +import org.bukkit.DyeColor; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; + +import mineplex.core.Managers; +import mineplex.core.account.CoreClientManager; +import mineplex.core.common.Pair; +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilMath; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.donation.DonationManager; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.shop.confirmation.ConfirmationCallback; +import mineplex.core.shop.confirmation.ConfirmationPage; +import mineplex.core.shop.confirmation.ConfirmationProcessor; +import mineplex.game.clans.clans.ClansManager; +import mineplex.game.clans.clans.boxes.BoxManager; +import mineplex.game.clans.clans.boxes.BoxManager.BoxType; +import mineplex.game.clans.clans.boxes.BoxShop; + +public class BuilderBoxVerifier +{ + private BoxManager _manager; + private BoxShop _shop; + + public BuilderBoxVerifier(BoxManager manager, BoxShop shop) + { + _manager = manager; + _shop = shop; + } + + public void showVerifier(Player player) + { + _shop.openPageForPlayer(player, new ConfirmationPage(player, _manager, _shop, Managers.get(CoreClientManager.class), Managers.get(DonationManager.class), new ConfirmationProcessor() + { + @Override + public void init(Inventory inventory) {} + + @SuppressWarnings("deprecation") + @Override + public void process(ConfirmationCallback callback) + { + ClansManager.getInstance().getInventoryManager().addItemToInventory(player, BoxType.BUILDER_BOX.getItemName(), -1); + + Map, ItemStack> replace = new HashMap<>(); + replace.put(Pair.create(Material.STONE, (byte)0), new ItemStack(Material.STAINED_CLAY)); + replace.put(Pair.create(Material.GLASS, (byte)0), new ItemStack(Material.STAINED_GLASS)); + replace.put(Pair.create(Material.THIN_GLASS, (byte)0), new ItemStack(Material.STAINED_GLASS_PANE)); + replace.put(Pair.create(Material.WOOL, (byte)0), new ItemStack(Material.WOOL)); + replace.put(Pair.create(Material.CARPET, (byte)0), new ItemStack(Material.CARPET)); + replace.put(Pair.create(Material.RED_ROSE, (byte)0), new ItemStack(Material.RED_ROSE)); + replace.put(Pair.create(Material.RED_ROSE, (byte)1), new ItemStack(Material.RED_ROSE)); + replace.put(Pair.create(Material.RED_ROSE, (byte)2), new ItemStack(Material.RED_ROSE)); + replace.put(Pair.create(Material.RED_ROSE, (byte)3), new ItemStack(Material.RED_ROSE)); + replace.put(Pair.create(Material.RED_ROSE, (byte)4), new ItemStack(Material.RED_ROSE)); + replace.put(Pair.create(Material.RED_ROSE, (byte)5), new ItemStack(Material.RED_ROSE)); + replace.put(Pair.create(Material.RED_ROSE, (byte)6), new ItemStack(Material.RED_ROSE)); + replace.put(Pair.create(Material.RED_ROSE, (byte)7), new ItemStack(Material.RED_ROSE)); + replace.put(Pair.create(Material.RED_ROSE, (byte)8), new ItemStack(Material.RED_ROSE)); + replace.put(Pair.create(Material.COBBLE_WALL, (byte)0), new ItemStack(Material.COBBLE_WALL)); + + for (int slot = 0; slot < player.getInventory().getSize(); slot++) + { + ItemStack item = player.getInventory().getItem(slot); + if (item == null) + { + continue; + } + Pair pair = Pair.create(item.getType(), item.getData().getData()); + if (!replace.containsKey(pair)) + { + continue; + } + ItemBuilder after = new ItemBuilder(replace.get(pair)); + if (after.getType() == Material.RED_ROSE) + { + after.setData((short)UtilMath.r(9)); + } + else if (after.getType() == Material.COBBLE_WALL) + { + after.setData((short)1); + } + else + { + after.setData(UtilMath.randomElement(DyeColor.values()).getWoolData()); + } + after.setAmount(item.getAmount()); + player.getInventory().setItem(slot, after.build()); + } + callback.resolve("You have redeemed your box!"); + + UtilPlayer.message(player, F.main("Builder's Box", "You have redeemed your box!")); + } + }, new ItemBuilder(Material.BARRIER).setTitle(C.cDRedB + "WARNING").setLore(C.cRedB + "ALL " + C.cRed + "compatible items", C.cRed + "in your inventory", C.cRed + "will be converted!").build())); + } +} \ No newline at end of file diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/boxes/extra/DyeBoxSpinner.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/boxes/extra/DyeBoxSpinner.java index 03f5d5ead..0186f6b56 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/boxes/extra/DyeBoxSpinner.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/boxes/extra/DyeBoxSpinner.java @@ -24,6 +24,8 @@ import mineplex.core.common.util.UtilServer; import mineplex.core.itemstack.ItemBuilder; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; +import mineplex.game.clans.clans.ClansManager; +import mineplex.game.clans.clans.boxes.BoxManager.BoxType; public class DyeBoxSpinner implements Listener { @@ -82,11 +84,11 @@ public class DyeBoxSpinner implements Listener DyeColor color = null; if (Math.random() <= 0.05) { - color = rareColors.get(UtilMath.r(rareColors.size())); + color = UtilMath.randomElement(rareColors); } else { - color = commonColors.get(UtilMath.r(commonColors.size())); + color = UtilMath.randomElement(commonColors); } _items.add(new ItemBuilder(Material.INK_SACK).setData(color.getDyeData()).setTitle(C.cGold + "Dye").build()); @@ -164,6 +166,7 @@ public class DyeBoxSpinner implements Listener public static void createSpinner(Player player) { + ClansManager.getInstance().getInventoryManager().addItemToInventory(player, BoxType.DYE_BOX.getItemName(), -1); new DyeBoxSpinner(player); } } \ No newline at end of file