added save command

This commit is contained in:
aPunch 2012-02-28 01:41:15 -06:00
parent 1bbe64181d
commit 93cb0010ff
3 changed files with 29 additions and 14 deletions

View File

@ -136,8 +136,7 @@ public class Citizens extends JavaPlugin {
public void onDisable() {
// Don't bother with this part if MC versions are not compatible
if (compatible) {
config.save();
saveNPCs();
save();
for (NPC npc : npcManager)
npc.despawn();
getServer().getScheduler().cancelTasks(this);
@ -232,6 +231,13 @@ public class Citizens extends JavaPlugin {
}.start();
}
public void save() {
config.save();
for (NPC npc : npcManager)
npc.save(saves.getKey("npc." + npc.getId()));
saves.save();
}
public void reload() throws NPCLoadException {
getServer().getScheduler().cancelTasks(this);
Editor.leaveAll();
@ -269,12 +275,6 @@ public class Citizens extends JavaPlugin {
commands.register(NPCCommands.class);
}
private void saveNPCs() {
for (NPC npc : npcManager)
npc.save(saves.getKey("npc." + npc.getId()));
saves.save();
}
private void setupNPCs() throws NPCLoadException {
int created = 0, spawned = 0;
for (DataKey key : saves.getKey("npc").getIntegerSubKeys()) {

View File

@ -40,7 +40,6 @@ public class AdminCommands {
permission = "admin")
@ServerCommand
public void reload(CommandContext args, CommandSender sender, NPC npc) {
// TODO possibly could be made more safe
Messaging.send(sender, "<e>Reloading Citizens...");
try {
plugin.reload();
@ -50,4 +49,19 @@ public class AdminCommands {
e.printStackTrace();
}
}
@Command(
aliases = { "citizens" },
usage = "save",
desc = "Save NPCs",
modifiers = { "save" },
min = 1,
max = 1,
permission = "admin")
@ServerCommand
public void save(CommandContext args, CommandSender sender, NPC npc) {
Messaging.send(sender, "<e>Saving Citizens...");
plugin.save();
Messaging.send(sender, "<e>Citizens saved.");
}
}

View File

@ -43,10 +43,11 @@ public class EquipmentEditor extends Editor {
@EventHandler
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
if (plugin.getNPCManager().isNPC(event.getRightClicked())
&& plugin.getNPCManager().getNPC(event.getRightClicked()).equals(npc)
&& event.getPlayer().getName().equals(player.getName())) {
npc.chat("You clicked me!");
}
if (!plugin.getNPCManager().isNPC(event.getRightClicked())
|| !plugin.getNPCManager().getNPC(event.getRightClicked()).equals(npc)
|| !event.getPlayer().getName().equals(player.getName()))
return;
npc.chat("You clicked me!");
}
}