From 84ccabdf34b792b8defe6ec2948da943039a5aa7 Mon Sep 17 00:00:00 2001 From: sk89q Date: Wed, 24 Nov 2010 11:58:54 -0800 Subject: [PATCH] Improved missing feature detection. --- src/WorldGuard.java | 46 +++++++++++++++++++++++++++++-------- src/WorldGuardListener.java | 7 ++++-- 2 files changed, 41 insertions(+), 12 deletions(-) diff --git a/src/WorldGuard.java b/src/WorldGuard.java index 20147518..c0f38550 100644 --- a/src/WorldGuard.java +++ b/src/WorldGuard.java @@ -25,6 +25,7 @@ import java.util.ArrayList; import java.net.URL; import java.io.*; +import java.lang.reflect.*; /** * Entry point for the plugin for hey0's mod. @@ -67,7 +68,7 @@ public void initialize() { } if (!registerHook("FLOW", PluginListener.Priority.HIGH)) { missingFeatures.add("controlling lava flow"); - missingFeatures.add("sponges"); + missingFeatures.add("sponge simulation"); } registerHook("LOGINCHECK", PluginListener.Priority.HIGH); registerHook("LOGIN", PluginListener.Priority.MEDIUM); @@ -78,18 +79,28 @@ public void initialize() { registerHook("ITEM_DROP", PluginListener.Priority.HIGH); if (!registerHook("ITEM_PICK_UP", PluginListener.Priority.HIGH)) { missingFeatures.add("denying item pickups"); - missingFeatures.add("item durability fix"); + 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("INVENTORY_CHANGE", PluginListener.Priority.HIGH); if (!registerHook("BLOCK_PHYSICS", PluginListener.Priority.MEDIUM)) { - missingFeatures.add("controlling physics on gravel, sand, or portal blocks"); + missingFeatures.add("controlling the physics of gravel, sand, or portal blocks"); } if (missingFeatures.size() > 0) { logger.log(Level.WARNING, "WorldGuard: Your version of hMod does not support " - + joinString(missingFeatures, ", ", 0) + "."); + + concatMissingFeatures(missingFeatures) + "."); } } @@ -164,14 +175,29 @@ private String getVersion() { * @param delimiter * @return */ - private static String joinString(List str, String delimiter, - int initialIndex) { - if (str.size() == 0) { + private static String concatMissingFeatures(List str) { + if (str.isEmpty()) { return ""; } - StringBuilder buffer = new StringBuilder(str.get(0)); - for (int i = initialIndex + 1; i < str.size(); i++) { - buffer.append(delimiter).append(str.get(i)); + + int size = str.size(); + StringBuilder buffer = new StringBuilder(); + buffer.append("(1) "); + buffer.append(str.get(0)); + for (int i = 1; i < size; i++) { + if (i == size - 1) { + buffer.append(" or "); + buffer.append("("); + buffer.append(i + 1); + buffer.append(") "); + buffer.append(str.get(i)); + } else { + buffer.append(", "); + buffer.append("("); + buffer.append(i + 1); + buffer.append(") "); + buffer.append(str.get(i)); + } } return buffer.toString(); } diff --git a/src/WorldGuardListener.java b/src/WorldGuardListener.java index 36d2f6c0..79a6bb34 100644 --- a/src/WorldGuardListener.java +++ b/src/WorldGuardListener.java @@ -351,7 +351,10 @@ public boolean onItemDrop(Player player, Item item) { } if (!itemDurability) { - item.setDamage(0); + try { + item.setDamage(0); + } catch (java.lang.NoSuchMethodError e) { + } } return false; @@ -385,7 +388,7 @@ public boolean onItemPickUp(Player player, Item item) { */ public boolean onInventoryChange(Player player) { if (blacklist != null && blacklist.hasOnAcquire()) { - hj[] items = player.getInventory().getArray(); + hl[] items = player.getInventory().getArray(); boolean needUpdate = false; for (int i = 0; i < items.length; i++) {