From 2eee51d03a3f59640e68ef07dc6dfbcef4a9da14 Mon Sep 17 00:00:00 2001 From: Brianna Date: Sat, 16 May 2020 11:50:14 -0400 Subject: [PATCH 1/2] Cleanup the kit give system. --- .../com/songoda/ultimatekits/kit/Kit.java | 49 ++++++------------- 1 file changed, 16 insertions(+), 33 deletions(-) diff --git a/src/main/java/com/songoda/ultimatekits/kit/Kit.java b/src/main/java/com/songoda/ultimatekits/kit/Kit.java index 3a68148..035e13c 100644 --- a/src/main/java/com/songoda/ultimatekits/kit/Kit.java +++ b/src/main/java/com/songoda/ultimatekits/kit/Kit.java @@ -80,14 +80,6 @@ public class Kit { } } - private List getItemContents() { - List items = new ArrayList<>(); - for (KitItem item : this.getContents()) { - if (item.getContent() instanceof KitContentItem) - items.add(((KitContentItem) item.getContent()).getItemStack()); - } - return items; - } private boolean hasRoom(Player player, int itemAmount) { int space = 0; @@ -281,7 +273,7 @@ public class Kit { } public boolean giveKit(Player player) { - return giveKit(player, getItemContents().size(), -1); + return giveKit(player, getContents().size(), -1); } private boolean giveKit(Player player, Key key) { @@ -308,42 +300,35 @@ public class Kit { int itemGiveAmount = itemAmount > 0 ? itemAmount : kitSize; if (kitAmount > 0) itemGiveAmount = itemGiveAmount * kitAmount; - return generateRandomItem(innerContents, itemGiveAmount, player, -1); + return generateRandomItem(innerContents, itemGiveAmount, player); } - private boolean generateRandomItem(List innerContents, int itemGiveAmount, Player player, int forceSelect) { - if (getContents().size() != itemGiveAmount || kitAnimation != KitAnimation.NONE) + private boolean generateRandomItem(List innerContents, int itemGiveAmount, Player player) { + + if (innerContents.size() != itemGiveAmount || kitAnimation != KitAnimation.NONE) Collections.shuffle(innerContents); - int canChoose = 0; for (KitItem item : innerContents) { if (itemGiveAmount == 0) break; - double ch = canChoose++ == forceSelect || item.getChance() == 0 ? 100 : item.getChance(); + double ch = item.getChance() == 0 ? 100 : item.getChance(); double rand = Math.random() * 100; if (rand < ch || ch == 100) { - - if (item.getContent() instanceof KitContentEconomy - || item.getContent() instanceof KitContentCommand) { - item.getContent().process(player); - itemGiveAmount--; - continue; - } - - ItemStack parseStack = item.getContent().process(player); - - if (parseStack.getType() == Material.AIR) continue; - itemGiveAmount--; + ItemStack parseStack = item.getContent().process(player); if (kitAnimation != KitAnimation.NONE) { // TODO: this is a very bad way to solve this problem. // Giving the player kit rewards really should be done outside of the Kit class. - plugin.getGuiManager().showGUI(player, new AnimatedKitGui(plugin, player, this, item.getItem())); + plugin.getGuiManager().showGUI(player, new AnimatedKitGui(plugin, player, this, parseStack)); return true; } else { - if (Settings.AUTO_EQUIP_ARMOR.getBoolean() && ArmorType.equip(player, item.getItem())) continue; + if (item.getContent() instanceof KitContentEconomy + || item.getContent() instanceof KitContentCommand) + continue; - Map overfilled = player.getInventory().addItem(item.getItem()); + if (Settings.AUTO_EQUIP_ARMOR.getBoolean() && ArmorType.equip(player, parseStack)) continue; + + Map overfilled = player.getInventory().addItem(parseStack); for (ItemStack item2 : overfilled.values()) { player.getWorld().dropItemNaturally(player.getLocation(), item2); } @@ -351,10 +336,8 @@ public class Kit { } } - if (itemGiveAmount != 0 && canChoose != 0 && forceSelect == -1) { - return generateRandomItem(innerContents, itemGiveAmount, player, (int) (Math.random() * canChoose)); - } else if (itemGiveAmount != 0) { - return false; + if (itemGiveAmount != 0) { + return generateRandomItem(innerContents, itemGiveAmount, player); } player.updateInventory(); From 620b12566baf40476d9214c90a333126efe56abe Mon Sep 17 00:00:00 2001 From: Brianna Date: Sat, 16 May 2020 12:18:10 -0400 Subject: [PATCH 2/2] version 2.6.5 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index aad8ca5..a9dde66 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ com.songoda UltimateKits 4.0.0 - 2.6.4 + 2.6.5 clean install UltimateKits-${project.version}