mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2025-01-26 01:51:19 +01:00
Now a very proactive (but not still reserved) infinite stack checker.
This commit is contained in:
parent
24cc2d3b36
commit
9790ab29a2
@ -77,7 +77,6 @@ public void registerEvents() {
|
||||
pm.registerEvent(Event.Type.PLAYER_ITEM_HELD, this, Priority.High, plugin);
|
||||
pm.registerEvent(Event.Type.PLAYER_BED_ENTER, this, Priority.High, plugin);
|
||||
pm.registerEvent(Event.Type.PLAYER_MOVE, this, Priority.High, plugin);
|
||||
pm.registerEvent(Event.Type.PLAYER_INVENTORY, this, Priority.High, plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -343,6 +342,23 @@ private void handleBlockRightClick(PlayerInteractEvent event) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Infinite stack removal
|
||||
if ((type == Material.CHEST
|
||||
|| type == Material.JUKEBOX
|
||||
|| type == Material.DISPENSER
|
||||
|| type == Material.FURNACE
|
||||
|| type == Material.BURNING_FURNACE)
|
||||
&& wcfg.removeInfiniteStacks
|
||||
&& !plugin.hasPermission(player, "worldguard.override.infinite-stack")) {
|
||||
for (int slot = 0; slot < 40; slot++) {
|
||||
ItemStack heldItem = player.getInventory().getItem(slot);
|
||||
if (heldItem != null && heldItem.getAmount() < 0) {
|
||||
player.getInventory().setItem(slot, null);
|
||||
player.sendMessage(ChatColor.RED + "Infinite stack in slot #" + slot + " removed.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (wcfg.useRegions) {
|
||||
Vector pt = toVector(block);
|
||||
@ -827,26 +843,4 @@ public void onPlayerBedEnter(PlayerBedEnterEvent event) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a player opens an inventory.
|
||||
*/
|
||||
@Override
|
||||
public void onInventoryOpen(PlayerInventoryEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(player.getWorld());
|
||||
|
||||
if (wcfg.removeInfiniteStacks
|
||||
&& !plugin.hasPermission(player, "worldguard.override.infinite-stack")) {
|
||||
for (int slot = 0; slot < player.getInventory().getSize(); slot++) {
|
||||
ItemStack heldItem = player.getInventory().getItem(slot);
|
||||
if (heldItem.getAmount() < 0) {
|
||||
player.getInventory().setItem(slot, null);
|
||||
player.sendMessage(ChatColor.RED + "Infinite stack in slot #" + slot + " removed.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user