From 6481ea948d0b93aa3a8eb28851bf77aff33b767b Mon Sep 17 00:00:00 2001 From: aPunch Date: Sun, 12 Feb 2012 04:02:36 -0600 Subject: [PATCH] fix metrics bug --- src/net/citizensnpcs/Citizens.java | 59 ++++++++----------- src/net/citizensnpcs/Template.java | 15 ----- .../command/command/NPCCommands.java | 15 +---- src/net/citizensnpcs/util/NPCBuilder.java | 3 +- 4 files changed, 28 insertions(+), 64 deletions(-) delete mode 100644 src/net/citizensnpcs/Template.java diff --git a/src/net/citizensnpcs/Citizens.java b/src/net/citizensnpcs/Citizens.java index 5abeafd1d..6129b4eb4 100644 --- a/src/net/citizensnpcs/Citizens.java +++ b/src/net/citizensnpcs/Citizens.java @@ -64,7 +64,6 @@ public class Citizens extends JavaPlugin { private final CommandManager commands = new CommandManager(); private Settings config; private Storage saves; - private Storage templates; private boolean compatible; private boolean suggestClosestModifier(CommandSender sender, String command, String modifier) { @@ -170,33 +169,6 @@ public class Citizens extends JavaPlugin { saves = new YamlStorage(getDataFolder() + File.separator + "saves.yml", "Citizens NPC Storage"); } - new Thread() { - @Override - public void run() { - try { - Metrics metrics = new Metrics(); - metrics.addCustomData(Citizens.this, new Metrics.Plotter() { - @Override - public int getValue() { - return Iterators.size(npcManager.iterator()); - } - - @Override - public String getColumnName() { - return "Total NPCs"; - } - }); - metrics.beginMeasuringPlugin(Citizens.this); - } catch (IOException ex) { - Messaging.log("Unable to load metrics"); - } - } - }.start(); - - // Templates - templates = new YamlStorage(getDataFolder() + File.separator + "templates.yml", "NPC Templates"); - templates.load(); - // Register API managers npcManager = new CitizensNPCManager(saves); CitizensAPI.setNPCManager(npcManager); @@ -231,6 +203,30 @@ public class Citizens extends JavaPlugin { Messaging.log(Level.SEVERE, "Issue enabling plugin. Disabling."); getServer().getPluginManager().disablePlugin(this); } + + // Run metrics last + new Thread() { + @Override + public void run() { + try { + Metrics metrics = new Metrics(); + metrics.addCustomData(Citizens.this, new Metrics.Plotter() { + @Override + public int getValue() { + return Iterators.size(npcManager.iterator()); + } + + @Override + public String getColumnName() { + return "Total NPCs"; + } + }); + metrics.beginMeasuringPlugin(Citizens.this); + } catch (IOException ex) { + Messaging.log("Unable to load metrics"); + } + } + }.start(); } public CitizensNPCManager getNPCManager() { @@ -249,10 +245,6 @@ public class Citizens extends JavaPlugin { return saves; } - public Storage getTemplates() { - return templates; - } - private void registerCommands() { commands.setInjector(new Injector(this)); @@ -276,8 +268,7 @@ public class Citizens extends JavaPlugin { throw new NPCLoadException("Could not find a name for the NPC with ID '" + id + "'."); String type = key.getString("traits.type").toUpperCase(); - NPC npc = npcManager.createNPC( - type.equalsIgnoreCase("DEFAULT") ? CreatureType.MONSTER : CreatureType.valueOf(type), id, + NPC npc = npcManager.createNPC(type.equalsIgnoreCase("DEFAULT") ? null : CreatureType.valueOf(type), id, key.getString("name"), null); try { npc.load(key); diff --git a/src/net/citizensnpcs/Template.java b/src/net/citizensnpcs/Template.java deleted file mode 100644 index 25ace8bf2..000000000 --- a/src/net/citizensnpcs/Template.java +++ /dev/null @@ -1,15 +0,0 @@ -package net.citizensnpcs; - -import net.citizensnpcs.api.util.DataKey; - -public class Template { - private final DataKey template; - - public Template(DataKey template) { - this.template = template; - } - - public void apply(DataKey to) { - // TODO - } -} \ No newline at end of file diff --git a/src/net/citizensnpcs/command/command/NPCCommands.java b/src/net/citizensnpcs/command/command/NPCCommands.java index 2681e4765..7fdbc5c1b 100644 --- a/src/net/citizensnpcs/command/command/NPCCommands.java +++ b/src/net/citizensnpcs/command/command/NPCCommands.java @@ -2,7 +2,6 @@ package net.citizensnpcs.command.command; import net.citizensnpcs.Citizens; import net.citizensnpcs.Settings.Setting; -import net.citizensnpcs.Template; import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.trait.Character; import net.citizensnpcs.api.npc.trait.DefaultInstanceFactory; @@ -26,12 +25,10 @@ import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; @Requirements(selected = true, ownership = true) public class NPCCommands { - private final Citizens plugin; private final CitizensNPCManager npcManager; private final DefaultInstanceFactory characterManager; public NPCCommands(Citizens plugin) { - this.plugin = plugin; npcManager = plugin.getNPCManager(); characterManager = plugin.getCharacterManager(); } @@ -51,7 +48,7 @@ public class NPCCommands { Messaging.sendError(player, "NPC names cannot be longer than 16 characters. The name has been shortened."); name = name.substring(0, 15); } - CreatureType type = CreatureType.MONSTER; // Default NPC type + CreatureType type = null; if (args.hasValueFlag("type")) try { type = CreatureType.valueOf(args.getFlag("type").toUpperCase().replace('-', '_')); @@ -73,16 +70,6 @@ public class NPCCommands { successMsg += " with the character " + StringHelper.wrap(args.getFlag("char")); } } - if (args.hasValueFlag("temp")) { - String template = args.getFlag("temp"); - if (!plugin.getTemplates().getKey("templates").keyExists(template)) { - Messaging.sendError(player, "The template '" + template - + "' does not exist. Did you type the name incorrectly?"); - return; - } - new Template(plugin.getTemplates().getKey("templates." + template)).apply(plugin.getStorage().getKey( - "npc." + npc.getId())); - } successMsg += " at your location."; // Set the owner diff --git a/src/net/citizensnpcs/util/NPCBuilder.java b/src/net/citizensnpcs/util/NPCBuilder.java index dc5deff9e..60a4ce27d 100644 --- a/src/net/citizensnpcs/util/NPCBuilder.java +++ b/src/net/citizensnpcs/util/NPCBuilder.java @@ -46,7 +46,6 @@ public class NPCBuilder { types.put(CreatureType.GHAST, CitizensGhastNPC.class); types.put(CreatureType.GIANT, CitizensGiantNPC.class); types.put(CreatureType.MAGMA_CUBE, CitizensMagmaCubeNPC.class); - types.put(CreatureType.MONSTER, CitizensHumanNPC.class); types.put(CreatureType.MUSHROOM_COW, CitizensMushroomCowNPC.class); types.put(CreatureType.PIG, CitizensPigNPC.class); types.put(CreatureType.PIG_ZOMBIE, CitizensPigZombieNPC.class); @@ -64,6 +63,8 @@ public class NPCBuilder { public CitizensNPC getByType(CreatureType type, CitizensNPCManager npcManager, int id, String name) { Class npcClass = types.get(type); + if (npcClass == null) + npcClass = CitizensHumanNPC.class; try { return npcClass.getConstructor(CitizensNPCManager.class, int.class, String.class).newInstance(npcManager, id, name);