From d5a2dea06b04588e06ece67eb4b1ef806e88bb7b Mon Sep 17 00:00:00 2001 From: TfT_02 Date: Sat, 20 Dec 2014 23:54:24 +0100 Subject: [PATCH] Add option to shake items from player inventories --- .../config/treasure/TreasureConfig.java | 10 ++++++++ .../skills/fishing/FishingManager.java | 23 +++++++++++++++++++ src/main/resources/treasures.yml | 4 ++++ 3 files changed, 37 insertions(+) diff --git a/src/main/java/com/gmail/nossr50/config/treasure/TreasureConfig.java b/src/main/java/com/gmail/nossr50/config/treasure/TreasureConfig.java index 0808dc2ab..9e23ca2da 100644 --- a/src/main/java/com/gmail/nossr50/config/treasure/TreasureConfig.java +++ b/src/main/java/com/gmail/nossr50/config/treasure/TreasureConfig.java @@ -176,6 +176,11 @@ public class TreasureConfig extends ConfigLoader { else if (materialName.contains("INK_SACK")) { material = Material.INK_SACK; } + else if (materialName.contains("INVENTORY")) { + // Use magic material BED_BLOCK to know that we're grabbing something from the inventory and not a normal treasure + shakeFromPlayer.add(new ShakeTreasure(new ItemStack(Material.BED_BLOCK, 1, (byte) 0), 1, getInventoryStealDropChance(), getInventoryStealDropLevel())); + continue; + } else { material = Material.matchMaterial(materialName); } @@ -476,6 +481,11 @@ public class TreasureConfig extends ConfigLoader { } } + public boolean getInventoryStealEnabled() { return config.contains("Shake.PLAYER.INVENTORY"); } + public boolean getInventoryStealStacks() { return config.getBoolean("Shake.PLAYER.INVENTORY.Whole_Stacks"); } + public double getInventoryStealDropChance() { return config.getDouble("Shake.PLAYER.INVENTORY.Drop_Chance"); } + public int getInventoryStealDropLevel() { return config.getInt("Shake.PLAYER.INVENTORY.Drop_Level"); } + public double getItemDropRate(int tier, Rarity rarity) { return config.getDouble("Item_Drop_Rates.Tier_" + tier + "." + rarity.toString()); } public double getEnchantmentDropRate(int tier, Rarity rarity) { return config.getDouble("Enchantment_Drop_Rates.Tier_" + tier + "." + rarity.toString()); } } diff --git a/src/main/java/com/gmail/nossr50/skills/fishing/FishingManager.java b/src/main/java/com/gmail/nossr50/skills/fishing/FishingManager.java index f0e7ef8bb..ef78c31ed 100644 --- a/src/main/java/com/gmail/nossr50/skills/fishing/FishingManager.java +++ b/src/main/java/com/gmail/nossr50/skills/fishing/FishingManager.java @@ -28,6 +28,7 @@ import org.bukkit.entity.TNTPrimed; import org.bukkit.entity.ThrownPotion; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.PlayerInventory; import org.bukkit.inventory.meta.SkullMeta; import org.bukkit.material.Wool; import org.bukkit.potion.Potion; @@ -405,6 +406,28 @@ public class FishingManager extends SkillManager { drop.setItemMeta(skullMeta); break; + case BED_BLOCK: + if (TreasureConfig.getInstance().getInventoryStealEnabled()) { + PlayerInventory inventory = targetPlayer.getInventory(); + int length = inventory.getContents().length; + int slot = Misc.getRandom().nextInt(length); + drop = inventory.getItem(slot); + + if (drop == null) { + break; + } + + if (TreasureConfig.getInstance().getInventoryStealStacks()) { + inventory.setItem(slot, null); + } + else { + inventory.setItem(slot, (drop.getAmount() > 1) ? new ItemStack(drop.getType(), drop.getAmount() - 1) : null); + drop.setAmount(1); + } + + targetPlayer.updateInventory(); + } + break; default: break; diff --git a/src/main/resources/treasures.yml b/src/main/resources/treasures.yml index 772c73937..606e2ee22 100644 --- a/src/main/resources/treasures.yml +++ b/src/main/resources/treasures.yml @@ -799,6 +799,10 @@ Shake: XP: 0 Drop_Chance: 0.0 Drop_Level: 0 + INVENTORY: + Whole_Stacks: false + Drop_Chance: 0.0 + Drop_Level: 0 SHEEP: WOOL: Amount: 3