mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-26 04:35:50 +01:00
added save command
This commit is contained in:
parent
1bbe64181d
commit
93cb0010ff
@ -136,8 +136,7 @@ public class Citizens extends JavaPlugin {
|
|||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
// Don't bother with this part if MC versions are not compatible
|
// Don't bother with this part if MC versions are not compatible
|
||||||
if (compatible) {
|
if (compatible) {
|
||||||
config.save();
|
save();
|
||||||
saveNPCs();
|
|
||||||
for (NPC npc : npcManager)
|
for (NPC npc : npcManager)
|
||||||
npc.despawn();
|
npc.despawn();
|
||||||
getServer().getScheduler().cancelTasks(this);
|
getServer().getScheduler().cancelTasks(this);
|
||||||
@ -232,6 +231,13 @@ public class Citizens extends JavaPlugin {
|
|||||||
}.start();
|
}.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void save() {
|
||||||
|
config.save();
|
||||||
|
for (NPC npc : npcManager)
|
||||||
|
npc.save(saves.getKey("npc." + npc.getId()));
|
||||||
|
saves.save();
|
||||||
|
}
|
||||||
|
|
||||||
public void reload() throws NPCLoadException {
|
public void reload() throws NPCLoadException {
|
||||||
getServer().getScheduler().cancelTasks(this);
|
getServer().getScheduler().cancelTasks(this);
|
||||||
Editor.leaveAll();
|
Editor.leaveAll();
|
||||||
@ -269,12 +275,6 @@ public class Citizens extends JavaPlugin {
|
|||||||
commands.register(NPCCommands.class);
|
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 {
|
private void setupNPCs() throws NPCLoadException {
|
||||||
int created = 0, spawned = 0;
|
int created = 0, spawned = 0;
|
||||||
for (DataKey key : saves.getKey("npc").getIntegerSubKeys()) {
|
for (DataKey key : saves.getKey("npc").getIntegerSubKeys()) {
|
||||||
|
@ -40,7 +40,6 @@ public class AdminCommands {
|
|||||||
permission = "admin")
|
permission = "admin")
|
||||||
@ServerCommand
|
@ServerCommand
|
||||||
public void reload(CommandContext args, CommandSender sender, NPC npc) {
|
public void reload(CommandContext args, CommandSender sender, NPC npc) {
|
||||||
// TODO possibly could be made more safe
|
|
||||||
Messaging.send(sender, "<e>Reloading Citizens...");
|
Messaging.send(sender, "<e>Reloading Citizens...");
|
||||||
try {
|
try {
|
||||||
plugin.reload();
|
plugin.reload();
|
||||||
@ -50,4 +49,19 @@ public class AdminCommands {
|
|||||||
e.printStackTrace();
|
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.");
|
||||||
|
}
|
||||||
}
|
}
|
@ -43,10 +43,11 @@ public class EquipmentEditor extends Editor {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
|
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
|
||||||
if (plugin.getNPCManager().isNPC(event.getRightClicked())
|
if (!plugin.getNPCManager().isNPC(event.getRightClicked())
|
||||||
&& plugin.getNPCManager().getNPC(event.getRightClicked()).equals(npc)
|
|| !plugin.getNPCManager().getNPC(event.getRightClicked()).equals(npc)
|
||||||
&& event.getPlayer().getName().equals(player.getName())) {
|
|| !event.getPlayer().getName().equals(player.getName()))
|
||||||
npc.chat("You clicked me!");
|
return;
|
||||||
}
|
|
||||||
|
npc.chat("You clicked me!");
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user