Added protection.remove-infinite-stacks.

This commit is contained in:
sk89q 2011-04-11 12:34:11 -07:00
parent ad659cd32e
commit ffc5281d59
3 changed files with 28 additions and 0 deletions

View File

@ -23,6 +23,7 @@ pumpkin-scuba: off
protection:
item-durability: on
remove-infinite-stacks: off
simulation:
sponge:
@ -82,6 +83,9 @@ iconomy:
# Price per block for buying on claim
buy-on-claim-price: 2
chest-protection:
enable: off
blacklist:
use-as-whitelist: off
logging:

View File

@ -101,6 +101,7 @@ public class WorldConfiguration {
public int maxRegionCountPerPlayer;
public boolean antiWolfDumbness;
public boolean signChestProtection;
public boolean removeInfiniteStacks;
/* Configuration data end */
@ -135,6 +136,7 @@ private void loadConfiguration() {
enforceOneSession = config.getBoolean("protection.enforce-single-session", true);
itemDurability = config.getBoolean("protection.item-durability", true);
removeInfiniteStacks = config.getBoolean("protection.remove-infinite-stacks", false);
classicWater = config.getBoolean("simulation.classic-water", false);
simulateSponge = config.getBoolean("simulation.sponge.enable", true);

View File

@ -77,6 +77,7 @@ public void registerEvents() {
pm.registerEvent(Event.Type.PLAYER_BUCKET_FILL, this, Priority.High, plugin);
pm.registerEvent(Event.Type.PLAYER_BUCKET_EMPTY, this, Priority.High, plugin);
pm.registerEvent(Event.Type.PLAYER_RESPAWN, this, Priority.High, plugin);
pm.registerEvent(Event.Type.PLAYER_ITEM_HELD, this, Priority.High, plugin);
}
/**
@ -582,4 +583,25 @@ public void onPlayerRespawn(PlayerRespawnEvent event) {
}
}
}
/**
* Called when a player changes their held item.
*/
@Override
public void onItemHeldChange(PlayerItemHeldEvent event) {
Player player = event.getPlayer();
ConfigurationManager cfg = plugin.getGlobalConfiguration();
WorldConfiguration wcfg = cfg.get(player.getWorld());
if (wcfg.removeInfiniteStacks
&& !plugin.hasPermission(player, "worldguard.override.infinite-stack")) {
int newSlot = event.getNewSlot();
ItemStack heldItem = player.getInventory().getItem(newSlot);
if (heldItem.getAmount() < 0) {
player.getInventory().setItem(newSlot, null);
player.sendMessage(ChatColor.RED + "Infinite stack removed.");
}
}
}
}