Add option to shake items from player inventories

This commit is contained in:
TfT_02 2014-12-20 23:54:24 +01:00
parent d188224c06
commit d5a2dea06b
3 changed files with 37 additions and 0 deletions

View File

@ -176,6 +176,11 @@ public class TreasureConfig extends ConfigLoader {
else if (materialName.contains("INK_SACK")) { else if (materialName.contains("INK_SACK")) {
material = Material.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 { else {
material = Material.matchMaterial(materialName); 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 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()); } public double getEnchantmentDropRate(int tier, Rarity rarity) { return config.getDouble("Enchantment_Drop_Rates.Tier_" + tier + "." + rarity.toString()); }
} }

View File

@ -28,6 +28,7 @@ import org.bukkit.entity.TNTPrimed;
import org.bukkit.entity.ThrownPotion; import org.bukkit.entity.ThrownPotion;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.inventory.meta.SkullMeta; import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.material.Wool; import org.bukkit.material.Wool;
import org.bukkit.potion.Potion; import org.bukkit.potion.Potion;
@ -405,6 +406,28 @@ public class FishingManager extends SkillManager {
drop.setItemMeta(skullMeta); drop.setItemMeta(skullMeta);
break; 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: default:
break; break;

View File

@ -799,6 +799,10 @@ Shake:
XP: 0 XP: 0
Drop_Chance: 0.0 Drop_Chance: 0.0
Drop_Level: 0 Drop_Level: 0
INVENTORY:
Whole_Stacks: false
Drop_Chance: 0.0
Drop_Level: 0
SHEEP: SHEEP:
WOOL: WOOL:
Amount: 3 Amount: 3