From 822e40bc1f9f7bf718c524c14f014d275134d072 Mon Sep 17 00:00:00 2001 From: TfT_02 Date: Wed, 17 Apr 2013 16:03:34 +0200 Subject: [PATCH] Added a new Party item share category "Misc" which contains a list of configurable items. --- Changelog.txt | 1 + .../config/party/ItemWeightConfig.java | 19 ++++++++ .../gmail/nossr50/datatypes/party/Party.java | 9 ++++ .../com/gmail/nossr50/party/ShareHandler.java | 3 ++ .../com/gmail/nossr50/util/ItemUtils.java | 38 +++++++++++++++- src/main/resources/itemweights.yml | 43 ++++++++++++++++++- 6 files changed, 111 insertions(+), 2 deletions(-) diff --git a/Changelog.txt b/Changelog.txt index c646cefec..dda6ee9d5 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -15,6 +15,7 @@ Version 1.4.06-dev + Added new API method to McMMOPlayerLevelUpEvent to set levels gained + Added new permission node for /ptp; mcmmo.commands.ptp.send (enabled by default) + Added configurable cooldown and warmup times when using /ptp + + Added a new Party item share category "Misc" which contains a list of configurable items. (By default all tools and armor) = Fixed bug where players were able to join the same party multiple times = Fixed displaying partial names when trying to use /ptp = Fixed wolves from Call of the Wild only having 8 health diff --git a/src/main/java/com/gmail/nossr50/config/party/ItemWeightConfig.java b/src/main/java/com/gmail/nossr50/config/party/ItemWeightConfig.java index 446f718d5..267b8a060 100644 --- a/src/main/java/com/gmail/nossr50/config/party/ItemWeightConfig.java +++ b/src/main/java/com/gmail/nossr50/config/party/ItemWeightConfig.java @@ -1,5 +1,8 @@ package com.gmail.nossr50.config.party; +import java.util.HashSet; +import java.util.List; + import org.bukkit.Material; import com.gmail.nossr50.config.ConfigLoader; @@ -30,6 +33,22 @@ public class ItemWeightConfig extends ConfigLoader { return itemWeight; } + public HashSet getMiscItems() { + HashSet miscItems = new HashSet(); + + List itemList = config.getStringList("Party_Shareables.Misc_Items"); + + for (String item : itemList) { + String materialName = item.toUpperCase(); + Material material = Material.getMaterial(materialName); + + if (material != null) { + miscItems.add(material); + } + } + return miscItems; + } + @Override protected void loadKeys() {} } diff --git a/src/main/java/com/gmail/nossr50/datatypes/party/Party.java b/src/main/java/com/gmail/nossr50/datatypes/party/Party.java index 135ad10bf..eed882981 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/party/Party.java +++ b/src/main/java/com/gmail/nossr50/datatypes/party/Party.java @@ -24,6 +24,7 @@ public class Party { private boolean shareMiningDrops = true; private boolean shareHerbalismDrops = true; private boolean shareWoodcuttingDrops = true; + private boolean shareMiscDrops = true; public LinkedHashSet getMembers() { return members; @@ -74,6 +75,10 @@ public class Party { return shareWoodcuttingDrops; } + public boolean sharingMiscDrops() { + return shareMiscDrops; + } + public List getItemShareCategories() { List shareCategories = new ArrayList(); @@ -94,6 +99,10 @@ public class Party { shareCategories.add("Woodcutting"); } + if (sharingMiscDrops()) { + shareCategories.add("Misc"); + } + return shareCategories; } diff --git a/src/main/java/com/gmail/nossr50/party/ShareHandler.java b/src/main/java/com/gmail/nossr50/party/ShareHandler.java index d67242c8a..2a1bf8a31 100644 --- a/src/main/java/com/gmail/nossr50/party/ShareHandler.java +++ b/src/main/java/com/gmail/nossr50/party/ShareHandler.java @@ -111,6 +111,9 @@ public final class ShareHandler { else if (ItemUtils.isWoodcuttingDrop(itemStack) && !party.sharingWoodcuttingDrops()) { return false; } + else if (ItemUtils.isMiscDrop(itemStack) && !party.sharingMiscDrops()) { + return false; + } switch (party.getItemShareMode()) { case EQUAL: diff --git a/src/main/java/com/gmail/nossr50/util/ItemUtils.java b/src/main/java/com/gmail/nossr50/util/ItemUtils.java index 55a43a51a..9f882e2b1 100644 --- a/src/main/java/com/gmail/nossr50/util/ItemUtils.java +++ b/src/main/java/com/gmail/nossr50/util/ItemUtils.java @@ -1,5 +1,6 @@ package com.gmail.nossr50.util; +import java.util.HashSet; import java.util.List; import org.bukkit.ChatColor; @@ -13,6 +14,7 @@ import com.gmail.nossr50.api.SpoutToolsAPI; import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.mods.CustomArmorConfig; import com.gmail.nossr50.config.mods.CustomToolConfig; +import com.gmail.nossr50.config.party.ItemWeightConfig; public class ItemUtils { private static Config configInstance = Config.getInstance(); @@ -535,7 +537,7 @@ public class ItemUtils { * @return True if the item can be shared. */ public static boolean isShareable(ItemStack is) { - return isMiningDrop(is) || isWoodcuttingDrop(is) || isMobDrop(is) || isHerbalismDrop(is); + return isMiningDrop(is) || isWoodcuttingDrop(is) || isMobDrop(is) || isHerbalismDrop(is) || isMiscDrop(is); } /** @@ -572,6 +574,12 @@ public class ItemUtils { } } + /** + * Checks to see if an item is a herbalism drop. + * + * @param is Item to check + * @return true if the item is a herbalism drop, false otherwise + */ public static boolean isHerbalismDrop(ItemStack is) { switch (is.getType()) { case WHEAT: @@ -599,6 +607,12 @@ public class ItemUtils { } } + /** + * Checks to see if an item is a mob drop. + * + * @param is Item to check + * @return true if the item is a mob drop, false otherwise + */ public static boolean isMobDrop(ItemStack is) { switch (is.getType()) { case STRING: @@ -635,6 +649,12 @@ public class ItemUtils { } } + /** + * Checks to see if an item is a woodcutting drop. + * + * @param is Item to check + * @return true if the item is a woodcutting drop, false otherwise + */ public static boolean isWoodcuttingDrop(ItemStack is) { switch (is.getType()) { case LOG: @@ -648,6 +668,22 @@ public class ItemUtils { } } + /** + * Checks to see if an item is a miscellaneous drop. These items are read from the config file + * + * @param is Item to check + * @return true if the item is a miscellaneous drop, false otherwise + */ + public static boolean isMiscDrop(ItemStack is) { + HashSet miscItems = ItemWeightConfig.getInstance().getMiscItems(); + + if (miscItems.contains(is.getType())) { + return true; + } else { + return false; + } + } + public static boolean isMcMMOItem(ItemStack is) { if (!is.hasItemMeta()) { return false; diff --git a/src/main/resources/itemweights.yml b/src/main/resources/itemweights.yml index 657e75e80..b17ff437a 100644 --- a/src/main/resources/itemweights.yml +++ b/src/main/resources/itemweights.yml @@ -23,4 +23,45 @@ Item_Weights: Redstone_Ore: 30 Glowstone_Dust: 20 Coal: 10 - Coal_Ore: 10 \ No newline at end of file + Coal_Ore: 10 + +# Items in this section will get added to the Misc share category. +# Case insensitive, though the name must be exactly the same as set in the Bukkit Material enum. +Party_Shareables: + Misc_Items: + - Diamond_Sword + - Diamond_Spade + - Diamond_Pickaxe + - Diamond_Axe + - Gold_Sword + - Gold_Spade + - Gold_Pickaxe + - Gold_Axe + - Iron_Sword + - Iron_Spade + - Iron_Pickaxe + - Iron_Axe + - Stone_Sword + - Stone_Spade + - Stone_Pickaxe + - Stone_Axe + - Wood_Sword + - Wood_Spade + - Wood_Pickaxe + - Wood_Axe + - Diamond_Helmet + - Diamond_Chestplate + - Diamond_Leggings + - Diamond_Boots + - Gold_Helmet + - Gold_Chestplate + - Gold_Leggings + - Gold_Boots + - Iron_Helmet + - Iron_Chestplate + - Iron_Leggings + - Iron_Boots + - Leather_Helmet + - Leather_Chestplate + - Leather_Leggings + - Leather_Boots \ No newline at end of file