mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2025-02-01 04:51:27 +01:00
Updated for Minecraft beta.
This commit is contained in:
parent
f30b413b46
commit
601e15db5a
43
src/ItemArrayUtil.java
Normal file
43
src/ItemArrayUtil.java
Normal file
@ -0,0 +1,43 @@
|
||||
// $Id$
|
||||
/*
|
||||
* WorldGuard
|
||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Inventory related functions.
|
||||
*
|
||||
* @author sk89q
|
||||
*/
|
||||
public class ItemArrayUtil {
|
||||
/**
|
||||
* Set the contents of an ItemArray.
|
||||
*
|
||||
* @param itemArray
|
||||
* @param contents
|
||||
*/
|
||||
public static void setContents(ItemArray<?> itemArray, Item[] contents) {
|
||||
int size = itemArray.getContentsSize();
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
if (contents[i] == null) {
|
||||
itemArray.removeItem(i);
|
||||
} else {
|
||||
itemArray.setSlot(contents[i], i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -60,16 +60,9 @@ public void initialize() {
|
||||
|
||||
registerHook("COMMAND", PluginListener.Priority.MEDIUM);
|
||||
registerHook("SERVERCOMMAND", PluginListener.Priority.MEDIUM);
|
||||
if (!registerHook("EXPLODE", PluginListener.Priority.HIGH)) {
|
||||
missingFeatures.add("disabling TNT or creeper explosions");
|
||||
}
|
||||
if (!registerHook("IGNITE", PluginListener.Priority.HIGH)) {
|
||||
missingFeatures.add("disabling fire or lava fire");
|
||||
}
|
||||
if (!registerHook("FLOW", PluginListener.Priority.HIGH)) {
|
||||
missingFeatures.add("controlling lava flow");
|
||||
missingFeatures.add("sponge simulation");
|
||||
}
|
||||
registerHook("EXPLODE", PluginListener.Priority.HIGH);
|
||||
registerHook("IGNITE", PluginListener.Priority.HIGH);
|
||||
registerHook("FLOW", PluginListener.Priority.HIGH);
|
||||
registerHook("LOGINCHECK", PluginListener.Priority.HIGH);
|
||||
registerHook("LOGIN", PluginListener.Priority.MEDIUM);
|
||||
registerHook("BLOCK_CREATED", PluginListener.Priority.HIGH);
|
||||
@ -78,38 +71,15 @@ public void initialize() {
|
||||
registerHook("BLOCK_PLACE", PluginListener.Priority.HIGH);
|
||||
registerHook("DISCONNECT", PluginListener.Priority.HIGH);
|
||||
registerHook("ITEM_DROP", PluginListener.Priority.HIGH);
|
||||
if (!registerHook("ITEM_USE", PluginListener.Priority.HIGH)) {
|
||||
missingFeatures.add("denying use of the lava or water buckets");
|
||||
}
|
||||
if (!registerHook("ITEM_PICK_UP", PluginListener.Priority.HIGH)) {
|
||||
missingFeatures.add("denying item pickups");
|
||||
missingFeatures.add("the item durability fix");
|
||||
} else {
|
||||
try {
|
||||
Method method =
|
||||
Item.class.getDeclaredMethod("setDamage", new Class[]{ Integer.class });
|
||||
if (method == null) {
|
||||
missingFeatures.add("the item durability fix");
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
missingFeatures.add("the item durability fix");
|
||||
}
|
||||
}
|
||||
registerHook("COMPLEX_BLOCK_CHANGE", PluginListener.Priority.HIGH);
|
||||
registerHook("COMPLEX_BLOCK_SEND", PluginListener.Priority.HIGH);
|
||||
registerHook("ITEM_USE", PluginListener.Priority.HIGH);
|
||||
registerHook("ITEM_PICK_UP", PluginListener.Priority.HIGH);
|
||||
registerHook("SIGN_CHANGE", PluginListener.Priority.HIGH);
|
||||
registerHook("OPEN_INVENTORY", PluginListener.Priority.HIGH);
|
||||
registerHook("INVENTORY_CHANGE", PluginListener.Priority.HIGH);
|
||||
if (!registerHook("BLOCK_PHYSICS", PluginListener.Priority.MEDIUM)) {
|
||||
missingFeatures.add("controlling the physics of gravel, sand, or portal blocks");
|
||||
}
|
||||
if (!registerHook("HEALTH_CHANGE", PluginListener.Priority.MEDIUM)) {
|
||||
missingFeatures.add("god mode");
|
||||
}
|
||||
if (!registerHook("DAMAGE", PluginListener.Priority.MEDIUM)) {
|
||||
missingFeatures.add("disabling fall, water, lava, and fire damage");
|
||||
}
|
||||
if (!registerHook("LIQUID_DESTROY", PluginListener.Priority.MEDIUM)) {
|
||||
missingFeatures.add("disabling water damage");
|
||||
}
|
||||
registerHook("BLOCK_PHYSICS", PluginListener.Priority.MEDIUM);
|
||||
registerHook("HEALTH_CHANGE", PluginListener.Priority.MEDIUM);
|
||||
registerHook("DAMAGE", PluginListener.Priority.MEDIUM);
|
||||
registerHook("LIQUID_DESTROY", PluginListener.Priority.MEDIUM);
|
||||
|
||||
if (missingFeatures.size() > 0) {
|
||||
logger.log(Level.WARNING, "WorldGuard: Your version of hMod does not support "
|
||||
@ -133,7 +103,7 @@ public boolean registerHook(String name, PluginListener.Priority priority) {
|
||||
etc.getLoader().addListener(hook, listener, this, priority);
|
||||
return true;
|
||||
} catch (IllegalArgumentException e) {
|
||||
//logger.log(Level.WARNING, "WorldGuard: Missing hook " + name + "!");
|
||||
logger.log(Level.WARNING, "WorldGuard: Missing hook " + name + "!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -82,7 +82,6 @@ public class WorldGuardListener extends PluginListener {
|
||||
private boolean disableAllFire;
|
||||
private boolean simulateSponge;
|
||||
private int spongeRadius;
|
||||
private boolean itemDurability;
|
||||
private Set<Integer> fireNoSpreadBlocks;
|
||||
private Set<Integer> allowedLavaSpreadOver;
|
||||
private Set<Integer> itemDropBlacklist;
|
||||
@ -193,7 +192,6 @@ public void loadConfiguration() {
|
||||
classicWater = properties.getBoolean("classic-water", false);
|
||||
simulateSponge = properties.getBoolean("simulate-sponge", true);
|
||||
spongeRadius = Math.max(1, properties.getInt("sponge-radius", 3)) - 1;
|
||||
itemDurability = properties.getBoolean("item-durability", false);
|
||||
noPhysicsGravel = properties.getBoolean("no-physics-gravel", false);
|
||||
noPhysicsSand = properties.getBoolean("no-physics-sand", false);
|
||||
allowPortalAnywhere = properties.getBoolean("allow-portal-anywhere", false);
|
||||
@ -401,48 +399,50 @@ public boolean onCommand(Player player, String[] split) {
|
||||
} else if ((split[0].equalsIgnoreCase("/stack")
|
||||
|| split[0].equalsIgnoreCase("/;"))
|
||||
&& player.canUseCommand("/stack")) {
|
||||
hn[] items = player.getInventory().getArray();
|
||||
Item[] items = player.getInventory().getContents();
|
||||
int len = items.length;
|
||||
|
||||
int affected = 0;
|
||||
|
||||
for (int i = 0; i < len; i++) {
|
||||
hn item = items[i];
|
||||
Item item = items[i];
|
||||
|
||||
// Avoid infinite stacks and stacks with durability
|
||||
if (item == null || item.a <= 0 || item.d > 0) {
|
||||
if (item == null || item.getAmount() <= 0
|
||||
|| shouldNotStack(item.getItemId())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Ignore buckets
|
||||
if (item.c >= 325 && item.c <= 327) {
|
||||
if (item.getItemId() >= 325 && item.getItemId() <= 327) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (item.a < 64) {
|
||||
int needed = 64 - item.a; // Number of needed items until 64
|
||||
if (item.getAmount() < 64) {
|
||||
int needed = 64 - item.getAmount(); // Number of needed items until 64
|
||||
|
||||
// Find another stack of the same type
|
||||
for (int j = i + 1; j < len; j++) {
|
||||
hn item2 = items[j];
|
||||
Item item2 = items[j];
|
||||
|
||||
// Avoid infinite stacks and stacks with durability
|
||||
if (item2 == null || item2.a <= 0 || item2.d > 0) {
|
||||
if (item2 == null || item2.getAmount() <= 0
|
||||
|| shouldNotStack(item.getItemId())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Same type?
|
||||
if (item2.c == item.c) {
|
||||
if (item2.getItemId() == item.getItemId()) {
|
||||
// This stack won't fit in the parent stack
|
||||
if (item2.a > needed) {
|
||||
item.a = 64;
|
||||
item2.a -= needed;
|
||||
if (item2.getAmount() > needed) {
|
||||
item.setAmount(64);
|
||||
item2.setAmount(item2.getAmount() - needed);
|
||||
break;
|
||||
// This stack will
|
||||
} else {
|
||||
items[j] = null;
|
||||
item.a += item2.a;
|
||||
needed = 64 - item.a;
|
||||
item.setAmount(item.getAmount() + item2.getAmount());
|
||||
needed = 64 - item.getAmount();
|
||||
}
|
||||
|
||||
affected++;
|
||||
@ -452,7 +452,7 @@ public boolean onCommand(Player player, String[] split) {
|
||||
}
|
||||
|
||||
if (affected > 0) {
|
||||
player.getInventory().updateInventory();
|
||||
ItemArrayUtil.setContents((ItemArray<?>)player.getInventory(), items);
|
||||
}
|
||||
|
||||
player.sendMessage(Colors.Yellow + "Items compacted into stacks!");
|
||||
@ -484,6 +484,24 @@ public boolean onCommand(Player player, String[] split) {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if an item should not be stacked.
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
private static boolean shouldNotStack(int id) {
|
||||
return (id >= 256 && id <= 259)
|
||||
|| id == 261
|
||||
|| (id >= 267 && id <= 279)
|
||||
|| (id >= 281 && id <= 286)
|
||||
|| (id >= 290 && id <= 294)
|
||||
|| (id >= 298 && id <= 317)
|
||||
|| (id >= 325 && id <= 327)
|
||||
|| id == 335
|
||||
|| id == 346;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called before the console command is parsed. Return true if you don't
|
||||
@ -582,12 +600,12 @@ public boolean onItemPickUp(Player player, Item item) {
|
||||
@Override
|
||||
public boolean onInventoryChange(Player player) {
|
||||
if (blacklist != null && blacklist.hasOnAcquire()) {
|
||||
hn[] items = player.getInventory().getArray();
|
||||
Item[] items = player.getInventory().getContents();
|
||||
boolean needUpdate = false;
|
||||
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
if (items[i] != null) {
|
||||
if (!blacklist.onAcquire(items[i].c, player)) {
|
||||
if (!blacklist.onAcquire(items[i].getItemId(), player)) {
|
||||
items[i] = null;
|
||||
needUpdate = true;
|
||||
}
|
||||
@ -595,7 +613,7 @@ public boolean onInventoryChange(Player player) {
|
||||
}
|
||||
|
||||
if (needUpdate) {
|
||||
player.getInventory().updateInventory();
|
||||
ItemArrayUtil.setContents((ItemArray<?>)player.getInventory(), items);
|
||||
}
|
||||
}
|
||||
|
||||
@ -718,77 +736,39 @@ public boolean onBlockBreak(Player player, Block block) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when either a sign, chest or furnace is changed.
|
||||
* Called when a player attempts to open an inventory; whether it's a
|
||||
* workbench, a chest or their own player inventory
|
||||
*
|
||||
* @param player
|
||||
* player who changed it
|
||||
* @param complexBlock
|
||||
* complex block that changed
|
||||
* @return true if you want any changes to be reverted
|
||||
* @param player user who attempted to open the inventory
|
||||
* @param inventory the inventory that they are attempting to open
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean onComplexBlockChange(Player player, ComplexBlock complexBlock) {
|
||||
if (blacklist != null) {
|
||||
if (complexBlock instanceof Chest) {
|
||||
Block block = new Block(54, complexBlock.getX(),
|
||||
complexBlock.getY(), complexBlock.getZ());
|
||||
|
||||
if (!blacklist.onSilentUse(block, player)) {
|
||||
return true;
|
||||
}
|
||||
} else if (complexBlock instanceof Furnace) {
|
||||
int id = etc.getServer().getBlockIdAt(complexBlock.getX(),
|
||||
complexBlock.getY(), complexBlock.getZ());
|
||||
Block block = new Block(id, complexBlock.getX(),
|
||||
complexBlock.getY(), complexBlock.getZ());
|
||||
|
||||
if (!blacklist.onSilentUse(block, player)) {
|
||||
return true;
|
||||
}
|
||||
} else if (complexBlock instanceof Sign) {
|
||||
int id = etc.getServer().getBlockIdAt(complexBlock.getX(),
|
||||
complexBlock.getY(), complexBlock.getZ());
|
||||
Block block = new Block(id, complexBlock.getX(),
|
||||
complexBlock.getY(), complexBlock.getZ());
|
||||
|
||||
if (!blacklist.onSilentUse(block, player)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
public boolean onOpenInventory(Player player, Inventory inventory) {
|
||||
/*Block block = new Block(54, complexBlock.getX(),
|
||||
complexBlock.getY(), complexBlock.getZ());
|
||||
|
||||
if (!blacklist.onSilentUse(block, player)) {
|
||||
return true;
|
||||
}*/
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when either a sign, chest or furnace is sent to a player
|
||||
*
|
||||
* @param player
|
||||
* player who the block is being sent to
|
||||
* @param complexBlock
|
||||
* complex block that's being sent
|
||||
* @return true if you want the chest, furnace or sign to be empty
|
||||
* Called when a sign is changed by a player (Usually, when they first place it)
|
||||
*
|
||||
* @param player Player who changed the sign
|
||||
* @param sign Sign which had changed
|
||||
* @return true if you wish to cancel this change
|
||||
*/
|
||||
@Override
|
||||
public boolean onSendComplexBlock(Player player, ComplexBlock complexBlock) {
|
||||
if (blacklist != null) {
|
||||
if (complexBlock instanceof Chest) {
|
||||
Block block = new Block(54, complexBlock.getX(),
|
||||
complexBlock.getY(), complexBlock.getZ());
|
||||
public boolean onSignChange(Player player, Sign sign) {
|
||||
int id = etc.getServer().getBlockIdAt(sign.getX(),
|
||||
sign.getY(), sign.getZ());
|
||||
Block block = new Block(id, sign.getX(),
|
||||
sign.getY(), sign.getZ());
|
||||
|
||||
if (!blacklist.onSilentUse(block, player)) {
|
||||
return true;
|
||||
}
|
||||
} else if (complexBlock instanceof Furnace) {
|
||||
int id = etc.getServer().getBlockIdAt(complexBlock.getX(),
|
||||
complexBlock.getY(), complexBlock.getZ());
|
||||
Block block = new Block(id, complexBlock.getX(),
|
||||
complexBlock.getY(), complexBlock.getZ());
|
||||
|
||||
if (!blacklist.onSilentUse(block, player)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (!blacklist.onSilentUse(block, player)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
Loading…
Reference in New Issue
Block a user