Inventory checks now won't be used if there are no on-acquire events.

This commit is contained in:
sk89q 2010-11-21 01:25:59 -08:00
parent 339bf1a06d
commit 881f050f0d
2 changed files with 22 additions and 3 deletions

View File

@ -45,6 +45,11 @@ public class Blacklist {
*/ */
private BlacklistLogger blacklistLogger = new BlacklistLogger(); private BlacklistLogger blacklistLogger = new BlacklistLogger();
/**
* Blacklist contains on-acquire events.
*/
private boolean hasOnAcquire;
/** /**
* Returns whether the list is empty. * Returns whether the list is empty.
* *
@ -277,6 +282,8 @@ public void load(File file) throws IOException {
input = new FileReader(file); input = new FileReader(file);
BufferedReader buff = new BufferedReader(input); BufferedReader buff = new BufferedReader(input);
hasOnAcquire = false;
String line; String line;
List<BlacklistEntry> currentEntries = null; List<BlacklistEntry> currentEntries = null;
while ((line = buff.readLine()) != null) { while ((line = buff.readLine()) != null) {
@ -347,6 +354,7 @@ public void load(File file) throws IOException {
} else if (parts[0].equalsIgnoreCase("on-drop")) { } else if (parts[0].equalsIgnoreCase("on-drop")) {
entry.setDropActions(parts[1].split(",")); entry.setDropActions(parts[1].split(","));
} else if (parts[0].equalsIgnoreCase("on-acquire")) { } else if (parts[0].equalsIgnoreCase("on-acquire")) {
hasOnAcquire = true;
entry.setAcquireActions(parts[1].split(",")); entry.setAcquireActions(parts[1].split(","));
} else if (parts[0].equalsIgnoreCase("message")) { } else if (parts[0].equalsIgnoreCase("message")) {
entry.setMessage(parts[1].trim()); entry.setMessage(parts[1].trim());
@ -377,4 +385,13 @@ public void load(File file) throws IOException {
} }
} }
} }
/**
* Blacklist contains on-acquire events.
*
* @return
*/
public boolean hasOnAcquire() {
return hasOnAcquire;
}
} }

View File

@ -367,8 +367,10 @@ public boolean onItemDrop(Player player, Item item) {
* @return true if you want to leave the item where it was * @return true if you want to leave the item where it was
*/ */
public boolean onItemPickUp(Player player, Item item) { public boolean onItemPickUp(Player player, Item item) {
if (!blacklist.onSilentAcquire(item.getItemId(), player)) { if (blacklist != null && blacklist.hasOnAcquire()) {
return true; if (!blacklist.onSilentAcquire(item.getItemId(), player)) {
return true;
}
} }
return false; return false;
@ -382,7 +384,7 @@ public boolean onItemPickUp(Player player, Item item) {
* @return true if you want any changes to be reverted * @return true if you want any changes to be reverted
*/ */
public boolean onInventoryChange(Player player) { public boolean onInventoryChange(Player player) {
if (blacklist != null) { if (blacklist != null && blacklist.hasOnAcquire()) {
hj[] items = player.getInventory().getArray(); hj[] items = player.getInventory().getArray();
boolean needUpdate = false; boolean needUpdate = false;