diff --git a/src/main/java/com/gmail/nossr50/config/AdvancedConfig.java b/src/main/java/com/gmail/nossr50/config/AdvancedConfig.java index b6f2f2eee..2f7977b60 100644 --- a/src/main/java/com/gmail/nossr50/config/AdvancedConfig.java +++ b/src/main/java/com/gmail/nossr50/config/AdvancedConfig.java @@ -741,6 +741,7 @@ public class AdvancedConfig extends AutoUpdateConfigLoader { public double getIronArmMinBonus() { return config.getDouble("Skills.Unarmed.IronArm.BonusMin", 3.0D); } public double getIronArmMaxBonus() { return config.getDouble("Skills.Unarmed.IronArm.BonusMax", 8.0D); } public int getIronArmIncreaseLevel() { return config.getInt("Skills.Unarmed.IronArm.IncreaseLevel", 50); } + public boolean getDisarmProtected() { return config.getBoolean("Skills.Unarmed.Disarm.AntiTheft", false); } /* WOODCUTTING */ public int getLeafBlowUnlockLevel() { return config.getInt("Skills.Woodcutting.LeafBlower.UnlockLevel", 100); } diff --git a/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java b/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java index 90f82e46c..8740ceea9 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java +++ b/src/main/java/com/gmail/nossr50/datatypes/player/McMMOPlayer.java @@ -10,6 +10,7 @@ import org.bukkit.Server; import org.bukkit.Sound; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.scheduler.BukkitRunnable; import com.gmail.nossr50.mcMMO; @@ -87,11 +88,13 @@ public class McMMOPlayer { private Location teleportCommence; private boolean isUsingUnarmed; + private final FixedMetadataValue playerMetadata; public McMMOPlayer(Player player) { String playerName = player.getName(); this.player = player; + playerMetadata = new FixedMetadataValue(mcMMO.p, playerName); profile = mcMMO.getDatabaseManager().loadPlayerProfile(playerName, true); party = PartyManager.getPlayerParty(playerName); ptpRecord = new PartyTeleportRecord(); @@ -913,4 +916,8 @@ public class McMMOPlayer { public void resetCooldowns() { profile.resetCooldowns(); } + + public FixedMetadataValue getPlayerMetadata() { + return playerMetadata; + } } diff --git a/src/main/java/com/gmail/nossr50/listeners/InventoryListener.java b/src/main/java/com/gmail/nossr50/listeners/InventoryListener.java index 3def53269..e49609a66 100644 --- a/src/main/java/com/gmail/nossr50/listeners/InventoryListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/InventoryListener.java @@ -44,7 +44,7 @@ public class InventoryListener implements Listener { Block furnaceBlock = Misc.processInventoryOpenorCloseEvent(event); if (furnaceBlock != null && !furnaceBlock.hasMetadata(mcMMO.furnaceMetadataKey)) { - furnaceBlock.setMetadata(mcMMO.furnaceMetadataKey, new FixedMetadataValue(plugin, player.getName())); + furnaceBlock.setMetadata(mcMMO.furnaceMetadataKey, UserManager.getPlayer((Player) player).getPlayerMetadata()); } } diff --git a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java index 2171456ef..7a4117158 100644 --- a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java @@ -300,6 +300,14 @@ public class PlayerListener implements Listener { Item drop = event.getItem(); ItemStack dropStack = drop.getItemStack(); + if (drop.hasMetadata(mcMMO.disarmedItemKey)) { + if (!player.getName().equals(drop.getMetadata(mcMMO.disarmedItemKey).get(0).value())) { + event.setCancelled(true); + } + + return; + } + if (!drop.hasMetadata(mcMMO.droppedItemKey) && mcMMOPlayer.inParty() && ItemUtils.isSharable(dropStack)) { event.setCancelled(ShareHandler.handleItemShare(drop, mcMMOPlayer)); diff --git a/src/main/java/com/gmail/nossr50/mcMMO.java b/src/main/java/com/gmail/nossr50/mcMMO.java index 5025e899c..dbba7578e 100644 --- a/src/main/java/com/gmail/nossr50/mcMMO.java +++ b/src/main/java/com/gmail/nossr50/mcMMO.java @@ -105,6 +105,7 @@ public class mcMMO extends JavaPlugin { public final static String bowForceKey = "mcMMO: Bow Force"; public final static String arrowDistanceKey = "mcMMO: Arrow Distance"; public final static String customDamageKey = "mcMMO: Custom Damage"; + public final static String disarmedItemKey = "mcMMO: Disarmed Item"; public static FixedMetadataValue metadataValue; diff --git a/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java b/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java index 991146f73..fb18b6302 100644 --- a/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java +++ b/src/main/java/com/gmail/nossr50/skills/mining/MiningManager.java @@ -9,8 +9,6 @@ import org.bukkit.block.BlockState; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; import org.bukkit.entity.TNTPrimed; -import org.bukkit.metadata.FixedMetadataValue; - import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.config.Config; import com.gmail.nossr50.datatypes.player.McMMOPlayer; @@ -105,7 +103,7 @@ public class MiningManager extends SkillManager { SkillUtils.sendSkillMessage(player, AbilityType.BLAST_MINING.getAbilityPlayer(player)); player.sendMessage(LocaleLoader.getString("Mining.Blast.Boom")); - tnt.setMetadata(mcMMO.tntMetadataKey, new FixedMetadataValue(mcMMO.p, player.getName())); + tnt.setMetadata(mcMMO.tntMetadataKey, mcMMOPlayer.getPlayerMetadata()); tnt.setFuseTicks(0); targetBlock.setType(Material.AIR); diff --git a/src/main/java/com/gmail/nossr50/skills/unarmed/UnarmedManager.java b/src/main/java/com/gmail/nossr50/skills/unarmed/UnarmedManager.java index 05199be8b..25ef28168 100644 --- a/src/main/java/com/gmail/nossr50/skills/unarmed/UnarmedManager.java +++ b/src/main/java/com/gmail/nossr50/skills/unarmed/UnarmedManager.java @@ -2,12 +2,14 @@ package com.gmail.nossr50.skills.unarmed; import org.bukkit.Material; import org.bukkit.block.BlockState; +import org.bukkit.entity.Item; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.material.MaterialData; import org.bukkit.material.SmoothBrick; - +import com.gmail.nossr50.mcMMO; +import com.gmail.nossr50.config.AdvancedConfig; import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.skills.AbilityType; import com.gmail.nossr50.datatypes.skills.SecondaryAbility; @@ -18,6 +20,7 @@ import com.gmail.nossr50.skills.SkillManager; import com.gmail.nossr50.util.EventUtils; import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Permissions; +import com.gmail.nossr50.util.player.UserManager; import com.gmail.nossr50.util.skills.CombatUtils; import com.gmail.nossr50.util.skills.SkillUtils; @@ -87,7 +90,11 @@ public class UnarmedManager extends SkillManager { return; } - Misc.dropItem(defender.getLocation(), defender.getItemInHand()); + Item item = Misc.dropItem(defender.getLocation(), defender.getItemInHand()); + + if (item != null && AdvancedConfig.getInstance().getDisarmProtected()) { + item.setMetadata(mcMMO.disarmedItemKey, UserManager.getPlayer(defender).getPlayerMetadata()); + } defender.setItemInHand(new ItemStack(Material.AIR)); defender.sendMessage(LocaleLoader.getString("Skills.Disarmed")); diff --git a/src/main/java/com/gmail/nossr50/util/Misc.java b/src/main/java/com/gmail/nossr50/util/Misc.java index 1faa6712e..eb629e266 100644 --- a/src/main/java/com/gmail/nossr50/util/Misc.java +++ b/src/main/java/com/gmail/nossr50/util/Misc.java @@ -14,6 +14,7 @@ import org.bukkit.block.BlockState; import org.bukkit.block.Furnace; import org.bukkit.entity.Entity; import org.bukkit.entity.HumanEntity; +import org.bukkit.entity.Item; import org.bukkit.entity.NPC; import org.bukkit.entity.Player; import org.bukkit.event.inventory.InventoryEvent; @@ -172,10 +173,11 @@ public final class Misc { * * @param location The location to drop the item at * @param itemStack The item to drop + * @return Dropped Item entity or null if invalid or cancelled */ - public static void dropItem(Location location, ItemStack itemStack) { + public static Item dropItem(Location location, ItemStack itemStack) { if (itemStack.getType() == Material.AIR) { - return; + return null; } // We can't get the item until we spawn it and we want to make it cancellable, so we have a custom event. @@ -183,10 +185,10 @@ public final class Misc { mcMMO.p.getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { - return; + return null; } - location.getWorld().dropItemNaturally(location, itemStack); + return location.getWorld().dropItemNaturally(location, itemStack); } public static void profileCleanup(String playerName) { diff --git a/src/main/resources/advanced.yml b/src/main/resources/advanced.yml index 1ae0c4566..c7a71bd7e 100644 --- a/src/main/resources/advanced.yml +++ b/src/main/resources/advanced.yml @@ -456,8 +456,10 @@ Skills: Disarm: # ChanceMax: Maximum chance of disarming other players # MaxBonusLevel: Level when the maximum chance to disarm is reached + # AntiTheft: Determines if only the disarmed player can retrieve disarmed items ChanceMax: 33.0 MaxBonusLevel: 1000 + AntiTheft: false Deflect: # ChanceMax: Maximum chance of deflecting arrows