diff --git a/Changelog.txt b/Changelog.txt index a1b4207c3..8a41a5296 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -41,6 +41,9 @@ Version 1.4.00-dev + Added "Holy Hound" ability to Taming + Added "Shroom Thumb" ability to Herbalism + Added child.yml config file to choose parents for child skills + + Added '/party itemshare ' command to choose party item share mode + + Added '/party itemshare ' command to control items that are shared + + Added itemweights.yml file to determine which items are more valuable for party itemshare = Fixed Green Thumb on wheat not working properly at rank 4 = Fixed Green Thumb and Green Terra consuming twice the amount of seed needed = Fixed Green Terra not also checking Green Thumb permissions diff --git a/src/main/java/com/gmail/nossr50/config/ItemWeightsConfig.java b/src/main/java/com/gmail/nossr50/config/ItemWeightsConfig.java new file mode 100644 index 000000000..9a1dbe00d --- /dev/null +++ b/src/main/java/com/gmail/nossr50/config/ItemWeightsConfig.java @@ -0,0 +1,34 @@ +package com.gmail.nossr50.config; + +import org.bukkit.Material; + +import com.gmail.nossr50.util.StringUtils; + +public class ItemWeightsConfig extends ConfigLoader { + private static ItemWeightsConfig instance; + + private ItemWeightsConfig() { + super("itemweights.yml"); + } + + public static ItemWeightsConfig getInstance() { + if (instance == null) { + instance = new ItemWeightsConfig(); + } + + return instance; + } + + @Override + protected void loadKeys() {} + + public int getItemWeight(Material material) { + String materialName = StringUtils.getPrettyItemString(material).replace(" ", "_"); + int itemWeight = config.getInt("Item_Weights.Default"); + + if (config.getInt("Item_Weights." + materialName) > 0) { + itemWeight = config.getInt("Item_Weights." + materialName); + } + return itemWeight; + } +} diff --git a/src/main/java/com/gmail/nossr50/datatypes/McMMOPlayer.java b/src/main/java/com/gmail/nossr50/datatypes/McMMOPlayer.java index 29e6b373a..ccc45af41 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/McMMOPlayer.java +++ b/src/main/java/com/gmail/nossr50/datatypes/McMMOPlayer.java @@ -28,6 +28,7 @@ public class McMMOPlayer { private boolean ptpEnabled = true; private boolean ptpConfirmRequired = Config.getInstance().getPTPCommandConfirmRequired(); private long ptpTimeout; + private int itemShareModifier; private boolean partyChatMode; private boolean adminChatMode; @@ -242,6 +243,20 @@ public class McMMOPlayer { ptpTimeout = (int) (System.currentTimeMillis() / Misc.TIME_CONVERSION_FACTOR); } + public int getItemShareModifier() { + if (itemShareModifier < 10) { + setItemShareModifier(10); + } + return itemShareModifier; + } + + public void setItemShareModifier(int modifier) { + if (modifier < 10) { + modifier = 10; + } + itemShareModifier = modifier; + } + public boolean getAdminChatMode() { return adminChatMode; } diff --git a/src/main/java/com/gmail/nossr50/party/Party.java b/src/main/java/com/gmail/nossr50/party/Party.java index b4a672bc2..6d7ccc7c9 100644 --- a/src/main/java/com/gmail/nossr50/party/Party.java +++ b/src/main/java/com/gmail/nossr50/party/Party.java @@ -14,6 +14,10 @@ public class Party { private boolean locked; private ShareHandler.ShareMode xpShareMode = ShareHandler.ShareMode.NONE; private ShareHandler.ShareMode itemShareMode = ShareHandler.ShareMode.NONE; + private boolean shareLootDrops = true; + private boolean shareMiningDrops = true; + private boolean shareHerbalismDrops = true; + private boolean shareWoodcuttingDrops = true; public List getMembers() { return members; @@ -47,6 +51,39 @@ public class Party { return locked; } + public boolean sharingLootDrops() { + return shareLootDrops; + } + + public boolean sharingMiningDrops() { + return shareMiningDrops; + } + + public boolean sharingHerbalismDrops() { + return shareHerbalismDrops; + } + + public boolean sharingWoodcuttingDrops() { + return shareWoodcuttingDrops; + } + + public List getItemShareCategories() { //TODO Locale the category names! + List shareCategories = new ArrayList(); + if (sharingLootDrops()) { + shareCategories.add("Loot"); + } + if (sharingMiningDrops()) { + shareCategories.add("Mining"); + } + if (sharingHerbalismDrops()) { + shareCategories.add("Herbalism"); + } + if (sharingWoodcuttingDrops()) { + shareCategories.add("Woodcutting"); + } + return shareCategories; + } + public void setName(String name) { this.name = name; } @@ -78,4 +115,20 @@ public class Party { public ShareHandler.ShareMode getItemShareMode() { return itemShareMode; } + + public void setSharingLootDrops(boolean enabled) { + this.shareLootDrops = enabled; + } + + public void setSharingMiningDrops(boolean enabled) { + this.shareMiningDrops = enabled; + } + + public void setSharingHerbalismDrops(boolean enabled) { + this.shareHerbalismDrops = enabled; + } + + public void setSharingWoodcuttingDrops(boolean enabled) { + this.shareWoodcuttingDrops = enabled; + } } diff --git a/src/main/java/com/gmail/nossr50/party/PartyManager.java b/src/main/java/com/gmail/nossr50/party/PartyManager.java index a4e543e56..72603d5f8 100644 --- a/src/main/java/com/gmail/nossr50/party/PartyManager.java +++ b/src/main/java/com/gmail/nossr50/party/PartyManager.java @@ -223,6 +223,7 @@ public final class PartyManager { if (mcMMOPlayer != null) { mcMMOPlayer.removeParty(); + mcMMOPlayer.setItemShareModifier(10); } } @@ -239,6 +240,7 @@ public final class PartyManager { if (mcMMOPlayer != null) { mcMMOPlayer.removeParty(); + mcMMOPlayer.setItemShareModifier(10); } } diff --git a/src/main/java/com/gmail/nossr50/party/ShareHandler.java b/src/main/java/com/gmail/nossr50/party/ShareHandler.java index 41431780a..d00f63bb2 100644 --- a/src/main/java/com/gmail/nossr50/party/ShareHandler.java +++ b/src/main/java/com/gmail/nossr50/party/ShareHandler.java @@ -8,8 +8,10 @@ import org.bukkit.event.player.PlayerPickupItemEvent; import org.bukkit.inventory.ItemStack; import com.gmail.nossr50.config.Config; +import com.gmail.nossr50.config.ItemWeightsConfig; import com.gmail.nossr50.datatypes.McMMOPlayer; import com.gmail.nossr50.skills.utilities.SkillType; +import com.gmail.nossr50.util.ItemChecks; import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Users; @@ -34,6 +36,9 @@ public final class ShareHandler { private ShareHandler() {} + private static List nearMembers; + private static int partySize; + /** * Distribute Xp amongst party members. * @@ -48,7 +53,7 @@ public final class ShareHandler { switch (party.getXpShareMode()) { case EQUAL: Player player = mcMMOPlayer.getPlayer(); - List nearMembers = PartyManager.getNearMembers(player, party, Config.getInstance().getPartyShareRange()); + nearMembers = PartyManager.getNearMembers(player, party, Config.getInstance().getPartyShareRange()); if (nearMembers.isEmpty()) { return false; @@ -86,38 +91,95 @@ public final class ShareHandler { Item item = event.getItem(); ItemStack itemStack = item.getItemStack(); Party party = mcMMOPlayer.getParty(); + Player player = mcMMOPlayer.getPlayer(); + Player winningPlayer = null; + + ItemStack newStack = itemStack.clone(); + newStack.setAmount(1); + + if (ItemChecks.isMobDrop(itemStack) && !party.sharingLootDrops()) { + return false; + } + else if (ItemChecks.isMiningDrop(itemStack) && !party.sharingMiningDrops()) { + return false; + } + else if (ItemChecks.isHerbalismDrop(itemStack) && !party.sharingHerbalismDrops()) { + return false; + } + else if (ItemChecks.isWoodcuttingDrop(itemStack) && !party.sharingWoodcuttingDrops()) { + return false; + } switch (party.getItemShareMode()) { case EQUAL: - - return false; - case RANDOM: - Player player = mcMMOPlayer.getPlayer(); - List nearMembers = PartyManager.getNearMembers(player, party, Config.getInstance().getPartyShareRange()); + McMMOPlayer mcMMOTarget; + nearMembers = PartyManager.getNearMembers(player, party, Config.getInstance().getPartyShareRange()); if (nearMembers.isEmpty()) { return false; } - int partySize = nearMembers.size() + 1; + nearMembers.add(player); + partySize = nearMembers.size(); + + event.setCancelled(true); + item.remove(); + int itemWeight = ItemWeightsConfig.getInstance().getItemWeight(itemStack.getType()); + + for (int i = 0; i < itemStack.getAmount(); i++) { + int highestRoll = 0; + + for (Player member : nearMembers) { + McMMOPlayer mcMMOMember = Users.getPlayer(member); + int itemShareModifier = mcMMOMember.getItemShareModifier(); + int diceRoll = Misc.getRandom().nextInt(itemShareModifier); + + if (diceRoll > highestRoll) { + highestRoll = diceRoll; + + if (winningPlayer != null) { + McMMOPlayer mcMMOWinning = Users.getPlayer(winningPlayer); + mcMMOWinning.setItemShareModifier(mcMMOWinning.getItemShareModifier() + itemWeight); + } + + winningPlayer = member; + } + else { + mcMMOMember.setItemShareModifier(itemShareModifier + itemWeight); + } + } + + mcMMOTarget = Users.getPlayer(winningPlayer); + mcMMOTarget.setItemShareModifier(mcMMOTarget.getItemShareModifier() - itemWeight); + + if (winningPlayer.getInventory().addItem(newStack).size() != 0) { + winningPlayer.getWorld().dropItemNaturally(winningPlayer.getLocation(), newStack); + } + winningPlayer.updateInventory(); + } + return true; + case RANDOM: + nearMembers = PartyManager.getNearMembers(player, party, Config.getInstance().getPartyShareRange()); + + if (nearMembers.isEmpty()) { + return false; + } + partySize = nearMembers.size() + 1; event.setCancelled(true); item.remove(); - Player targetPlayer; - - ItemStack newStack = itemStack.clone(); - newStack.setAmount(1); - - //TODO Improve this, if possible make this faster. for (int i = 0; i < itemStack.getAmount(); i++) { int randomMember = Misc.getRandom().nextInt(partySize); if (randomMember >= nearMembers.size()) { - targetPlayer = player; + winningPlayer = player; } else { - targetPlayer = nearMembers.get(randomMember); + winningPlayer = nearMembers.get(randomMember); } - targetPlayer.getInventory().addItem(newStack); - targetPlayer.updateInventory(); + + if (winningPlayer.getInventory().addItem(newStack).size() != 0) { + winningPlayer.getWorld().dropItemNaturally(winningPlayer.getLocation(), newStack); + } + winningPlayer.updateInventory(); } return true; case NONE: @@ -125,5 +187,4 @@ public final class ShareHandler { return false; } } -} - +} \ No newline at end of file diff --git a/src/main/java/com/gmail/nossr50/party/commands/PartyInfoCommand.java b/src/main/java/com/gmail/nossr50/party/commands/PartyInfoCommand.java index f5333109f..ac85a4e1a 100644 --- a/src/main/java/com/gmail/nossr50/party/commands/PartyInfoCommand.java +++ b/src/main/java/com/gmail/nossr50/party/commands/PartyInfoCommand.java @@ -12,6 +12,7 @@ import com.gmail.nossr50.datatypes.McMMOPlayer; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.party.Party; import com.gmail.nossr50.party.PartyManager; +import com.gmail.nossr50.party.ShareHandler; import com.gmail.nossr50.util.Users; public class PartyInfoCommand implements CommandExecutor { @@ -51,6 +52,7 @@ public class PartyInfoCommand implements CommandExecutor { private void displayShareModeInfo() { boolean xpShareEnabled = Config.getInstance().getExpShareEnabled(); boolean itemShareEnabled = Config.getInstance().getItemShareEnabled(); + boolean itemSharingActive = playerParty.getItemShareMode() != ShareHandler.ShareMode.NONE; if (!xpShareEnabled && !itemShareEnabled) { return; @@ -73,6 +75,9 @@ public class PartyInfoCommand implements CommandExecutor { } player.sendMessage(LocaleLoader.getString("Commands.Party.ShareMode") + expShareInfo + separator + itemShareInfo); + if (itemSharingActive) { + player.sendMessage(LocaleLoader.getString("Commands.Party.ItemShareCategories", playerParty.getItemShareCategories())); + } } private void displayPartyHeader() { diff --git a/src/main/java/com/gmail/nossr50/party/commands/PartyItemShareCommand.java b/src/main/java/com/gmail/nossr50/party/commands/PartyItemShareCommand.java index 903419295..c325b5df9 100644 --- a/src/main/java/com/gmail/nossr50/party/commands/PartyItemShareCommand.java +++ b/src/main/java/com/gmail/nossr50/party/commands/PartyItemShareCommand.java @@ -30,22 +30,50 @@ public class PartyItemShareCommand implements CommandExecutor { if (args[1].equalsIgnoreCase("none") || args[1].equalsIgnoreCase("off") || args[1].equalsIgnoreCase("false")) { handleChangingShareMode(ShareMode.NONE); } -// else if (args[1].equalsIgnoreCase("equal") || args[1].equalsIgnoreCase("even")) { -// handleChangingShareMode(ShareMode.EQUAL); -// } + else if (args[1].equalsIgnoreCase("equal") || args[1].equalsIgnoreCase("even")) { + handleChangingShareMode(ShareMode.EQUAL); + } else if (args[1].equalsIgnoreCase("random")) { handleChangingShareMode(ShareMode.RANDOM); } else { -// sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "itemshare", "")); - sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "itemshare", "")); + sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "itemshare", "")); } return true; + + case 3: + playerParty = Users.getPlayer((Player) sender).getParty(); + boolean toggle = false; + + if (args[2].equalsIgnoreCase("true") || args[2].equalsIgnoreCase("on")|| args[2].equalsIgnoreCase("enabled")) { + toggle = true; + } + else if (args[2].equalsIgnoreCase("false") || args[2].equalsIgnoreCase("off")|| args[2].equalsIgnoreCase("disabled")) { + toggle = false; + } + + if (args[1].equalsIgnoreCase("loot")) { + playerParty.setSharingLootDrops(toggle); + } + else if (args[1].equalsIgnoreCase("mining")) { + playerParty.setSharingMiningDrops(toggle); + } + else if (args[1].equalsIgnoreCase("herbalism")) { + playerParty.setSharingHerbalismDrops(toggle); + } + else if (args[1].equalsIgnoreCase("woodcutting")) { + playerParty.setSharingWoodcuttingDrops(toggle); + } + else { + sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "itemshare", " ")); + } + notifyToggleItemShareCategory((Player) sender, args, toggle); + return true; default: -// sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "itemshare", "")); - sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "itemshare", "")); + sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "itemshare", "")); + sender.sendMessage(LocaleLoader.getString("Commands.Usage.2", "party", "itemshare", " ")); return true; } } @@ -57,4 +85,15 @@ public class PartyItemShareCommand implements CommandExecutor { member.sendMessage(LocaleLoader.getString("Commands.Party.SetSharing", LocaleLoader.getString("Party.ShareType.Item"), LocaleLoader.getString("Party.ShareMode." + StringUtils.getCapitalized(mode.toString())))); } } + + private void notifyToggleItemShareCategory(Player sender, String[] args, boolean toggle) { + String state = "disabled"; + if (toggle) { + state = "enabled"; + } + + for (Player member : playerParty.getOnlineMembers()) { + member.sendMessage(LocaleLoader.getString("Commands.Party.ToggleShareCategory", StringUtils.getCapitalized(args[1]), state)); + } + } } \ No newline at end of file diff --git a/src/main/java/com/gmail/nossr50/util/ItemChecks.java b/src/main/java/com/gmail/nossr50/util/ItemChecks.java index 6ebc5edba..5f5c309ad 100644 --- a/src/main/java/com/gmail/nossr50/util/ItemChecks.java +++ b/src/main/java/com/gmail/nossr50/util/ItemChecks.java @@ -579,16 +579,23 @@ public class ItemChecks { case POTATO: case COCOA: case NETHER_WARTS: - case APPLE: case BROWN_MUSHROOM: case RED_MUSHROOM: case RED_ROSE: case YELLOW_FLOWER: case CACTUS: case SUGAR_CANE: - //TODO Add the rest + case MELON: + case PUMPKIN: + case WATER_LILY: + case VINE: return true; + case INK_SACK: + if (is.getData().getData() == DyeColor.BROWN.getDyeData()) { + return true; + } + default: return false; } @@ -635,6 +642,7 @@ public class ItemChecks { case LOG: case LEAVES: case SAPLING: + case APPLE: return true; default: diff --git a/src/main/resources/itemweights.yml b/src/main/resources/itemweights.yml new file mode 100644 index 000000000..7e4a36fa0 --- /dev/null +++ b/src/main/resources/itemweights.yml @@ -0,0 +1,16 @@ +Item_Weights: + Default: 5 + Emerald: 150 + Emerald_Ore: 150 + Diamond: 100 + Diamond_Ore: 100 + Gold_Ingot: 50 + Gold_Ore: 50 + Iron_Ingot: 40 + Iron_Ore: 40 + Lapis_Ore: 30 + Redstone: 30 + Redstone_Ore: 30 + Glowstone_Dust: 20 + Coal: 10 + Coal_Ore: 10 \ No newline at end of file diff --git a/src/main/resources/locale/locale_en_US.properties b/src/main/resources/locale/locale_en_US.properties index 12b685448..5177e7736 100644 --- a/src/main/resources/locale/locale_en_US.properties +++ b/src/main/resources/locale/locale_en_US.properties @@ -452,6 +452,7 @@ Commands.Party.Status=[[DARK_GRAY]]NAME: [[WHITE]]{0} {1} Commands.Party.ShareMode=[[DARK_GRAY]]SHARE MODE: Commands.Party.ItemShare=[[GRAY]]ITEM [[DARK_AQUA]]({0}) Commands.Party.ExpShare=[[GRAY]]EXP [[DARK_AQUA]]({0}) +Commands.Party.ItemShareCategories=[[DARK_GRAY]]Sharing Items: [[GRAY]][[ITALIC]]{0} Commands.Party.MembersNear=[[DARK_GRAY]]NEAR YOU [[DARK_AQUA]]{0}[[DARK_GRAY]]/[[DARK_AQUA]]{1} Commands.Party.Accept=[[RED]]- Accept party invite Commands.Party.Chat.Off=Party Chat only [[RED]]Off @@ -465,6 +466,7 @@ Commands.Party.Join=[[GRAY]]Joined Party: {0} Commands.Party.Create=[[GRAY]]Created Party: {0} Commands.Party.Rename=[[GRAY]]Party name changed to: [[WHITE]]{0} Commands.Party.SetSharing=[[GRAY]]Party {0} sharing set to: [[DARK_AQUA]]{1} +Commands.Party.ToggleShareCategory=[[GRAY]]Party item sharing for [[GOLD]]{0} [[GRAY]]has been [[DARK_AQUA]]{1} Commands.Party.AlreadyExists=[[DARK_RED]]Party {0} already exists! Commands.Party.Kick=[[RED]]You were kicked from party {0}! Commands.Party.Leave=[[RED]]You have left that party