From cba533f317390656aaed49b7b8227467cd0abe16 Mon Sep 17 00:00:00 2001 From: aPunch Date: Thu, 22 Mar 2012 04:37:36 -0500 Subject: [PATCH] Small cleanup --- .../npc/CitizensTraitManager.java | 2 - .../trait/waypoint/Waypoints.java | 8 +- .../java/net/citizensnpcs/util/ByIdArray.java | 7 -- .../java/net/citizensnpcs/util/Metrics.java | 96 ++----------------- .../net/citizensnpcs/util/NPCBuilder.java | 22 ++--- 5 files changed, 21 insertions(+), 114 deletions(-) diff --git a/src/main/java/net/citizensnpcs/npc/CitizensTraitManager.java b/src/main/java/net/citizensnpcs/npc/CitizensTraitManager.java index de663ba27..a0cbefb6d 100644 --- a/src/main/java/net/citizensnpcs/npc/CitizensTraitManager.java +++ b/src/main/java/net/citizensnpcs/npc/CitizensTraitManager.java @@ -80,8 +80,6 @@ public class CitizensTraitManager implements TraitManager { @SuppressWarnings("unchecked") public T getTrait(String name, NPC npc) { - // TODO: we could replace NPC with Object... and search for the - // constructor Class clazz = registered.get(name); if (clazz == null) return null; diff --git a/src/main/java/net/citizensnpcs/trait/waypoint/Waypoints.java b/src/main/java/net/citizensnpcs/trait/waypoint/Waypoints.java index dbd217f4f..15a8a7470 100644 --- a/src/main/java/net/citizensnpcs/trait/waypoint/Waypoints.java +++ b/src/main/java/net/citizensnpcs/trait/waypoint/Waypoints.java @@ -20,8 +20,6 @@ public class Waypoints extends Trait { public Waypoints(NPC npc) { this.npc = npc; npc.getAI().registerNavigationCallback(provider.getCallback()); - // TODO: this is necessary because traits aren't loaded when added - // manually so we may be in an uninitialised state. } public Editor getEditor(Player player) { @@ -53,8 +51,7 @@ public class Waypoints extends Trait { } /** - * Sets the current {@link WaypointProvider} by using the given class. The - * class should have been registered using + * Sets the current {@link WaypointProvider} by using the given class. The class should have been registered using * {@link Waypoints#registerWaypointProvider(Class, String)}. * * @param provider @@ -80,8 +77,7 @@ public class Waypoints extends Trait { private static final Map, String> providers = new HashMap, String>(); /** - * Registers a {@link WaypointProvider}, which can be subsequently used by - * NPCs. + * Registers a {@link WaypointProvider}, which can be subsequently used by NPCs. * * @param clazz * The class of the waypoint provider diff --git a/src/main/java/net/citizensnpcs/util/ByIdArray.java b/src/main/java/net/citizensnpcs/util/ByIdArray.java index 32d76e673..4ded73f2d 100644 --- a/src/main/java/net/citizensnpcs/util/ByIdArray.java +++ b/src/main/java/net/citizensnpcs/util/ByIdArray.java @@ -24,13 +24,6 @@ public class ByIdArray implements Iterable { elementData = new Object[capacity]; } - /** - * Uses a linear search to insert an object at the first available space. - * - * @param t - * The object to add - * @return The index the object was added at - */ public int add(T t) { int index = 0; while (elementData[index++] != null) { diff --git a/src/main/java/net/citizensnpcs/util/Metrics.java b/src/main/java/net/citizensnpcs/util/Metrics.java index ef994fdc6..bf195b996 100644 --- a/src/main/java/net/citizensnpcs/util/Metrics.java +++ b/src/main/java/net/citizensnpcs/util/Metrics.java @@ -48,25 +48,16 @@ import org.bukkit.Bukkit; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.plugin.Plugin; -/** - * Tooling to post to metrics.griefcraft.com - */ public class Metrics { + private static final String BASE_URL = "http://metrics.griefcraft.com"; + private static final String CONFIG_FILE = "plugins/PluginMetrics/config.yml"; + private final static int PING_INTERVAL = 10; + private static final String REPORT_URL = "/report/%s"; + private final static int REVISION = 4; - /** - * The plugin configuration file - */ private final YamlConfiguration configuration; - - /** - * A map of the custom data plotters for plugins - */ private final Map> customData = Collections .synchronizedMap(new HashMap>()); - - /** - * Unique server id - */ private final String guid; public Metrics() throws IOException { @@ -88,12 +79,6 @@ public class Metrics { guid = configuration.getString("guid"); } - /** - * Adds a custom data plotter for a given plugin - * - * @param plugin - * @param plotter - */ public void addCustomData(Plugin plugin, Plotter plotter) { Set plotters = customData.get(plugin); @@ -105,11 +90,6 @@ public class Metrics { plotters.add(plotter); } - /** - * Begin measuring a plugin - * - * @param plugin - */ public void beginMeasuringPlugin(final Plugin plugin) throws IOException { // Did we opt out? if (configuration.getBoolean("opt-out", false)) { @@ -132,12 +112,6 @@ public class Metrics { }, PING_INTERVAL * 1200, PING_INTERVAL * 1200); } - /** - * Check if mineshafter is present. If it is, we need to bypass it to send - * POST requests - * - * @return - */ private boolean isMineshafterPresent() { try { Class.forName("mineshafter.MineServer"); @@ -147,11 +121,6 @@ public class Metrics { } } - /** - * Generic method that posts a plugin to the metrics website - * - * @param plugin - */ private void postPlugin(Plugin plugin, boolean isPing) throws IOException { // Construct the post data String response = "ERR No response"; @@ -220,9 +189,6 @@ public class Metrics { // optional description if everything goes right } - /** - * Interface used to collect custom data for a plugin - */ public static abstract class Plotter { @Override @@ -235,66 +201,20 @@ public class Metrics { return plotter.getColumnName().equals(getColumnName()) && plotter.getValue() == getValue(); } - /** - * Get the column name for the plotted point - * - * @return the plotted point's column name - */ public abstract String getColumnName(); - /** - * Get the current value for the plotted point - * - * @return - */ public abstract int getValue(); + public void reset() { + } + @Override public int hashCode() { return getColumnName().hashCode() + getValue(); } - - /** - * Called after the website graphs have been updated - */ - public void reset() { - } - } - /** - * The base url of the metrics domain - */ - private static final String BASE_URL = "http://metrics.griefcraft.com"; - - /** - * The file where guid and opt out is stored in - */ - private static final String CONFIG_FILE = "plugins/PluginMetrics/config.yml"; - - /** - * Interval of time to ping in minutes - */ - private final static int PING_INTERVAL = 10; - - /** - * The url used to report a server's status - */ - private static final String REPORT_URL = "/report/%s"; - - /** - * The metrics revision number - */ - private final static int REVISION = 4; - - /** - * Encode text as UTF-8 - * - * @param text - * @return - */ private static String encode(String text) throws UnsupportedEncodingException { return URLEncoder.encode(text, "UTF-8"); } - } \ No newline at end of file diff --git a/src/main/java/net/citizensnpcs/util/NPCBuilder.java b/src/main/java/net/citizensnpcs/util/NPCBuilder.java index 85b768cfe..fbe538585 100644 --- a/src/main/java/net/citizensnpcs/util/NPCBuilder.java +++ b/src/main/java/net/citizensnpcs/util/NPCBuilder.java @@ -35,17 +35,6 @@ import net.citizensnpcs.npc.entity.CitizensZombieNPC; import org.bukkit.entity.EntityType; public class NPCBuilder { - public CitizensNPC getByType(EntityType type, CitizensNPCManager npcManager, int id, String name) { - Class npcClass = types.get(type); - try { - return npcClass.getConstructor(CitizensNPCManager.class, int.class, String.class).newInstance(npcManager, - id, name); - } catch (Exception ex) { - ex.printStackTrace(); - } - return null; - } - private static final Map> types = new HashMap>(); static { @@ -76,4 +65,15 @@ public class NPCBuilder { types.put(EntityType.WOLF, CitizensWolfNPC.class); types.put(EntityType.ZOMBIE, CitizensZombieNPC.class); } + + public CitizensNPC getByType(EntityType type, CitizensNPCManager npcManager, int id, String name) { + Class npcClass = types.get(type); + try { + return npcClass.getConstructor(CitizensNPCManager.class, int.class, String.class).newInstance(npcManager, + id, name); + } catch (Exception ex) { + ex.printStackTrace(); + } + return null; + } } \ No newline at end of file