fix metrics bug

This commit is contained in:
aPunch 2012-02-12 04:02:36 -06:00
parent 29a8728829
commit 4956690096
4 changed files with 28 additions and 64 deletions

View File

@ -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);

View File

@ -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
}
}

View File

@ -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<Character> 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

View File

@ -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<? extends CitizensNPC> npcClass = types.get(type);
if (npcClass == null)
npcClass = CitizensHumanNPC.class;
try {
return npcClass.getConstructor(CitizensNPCManager.class, int.class, String.class).newInstance(npcManager,
id, name);