mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-24 11:38:26 +01:00
Save immediately on shutdown
This commit is contained in:
parent
2b08e7dbeb
commit
8f1b6d7c33
@ -171,7 +171,7 @@ public class Citizens extends JavaPlugin implements CitizensPlugin {
|
|||||||
tearDownScripting();
|
tearDownScripting();
|
||||||
// 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) {
|
||||||
save();
|
save(true);
|
||||||
despawnNPCs();
|
despawnNPCs();
|
||||||
npcRegistry = null;
|
npcRegistry = null;
|
||||||
}
|
}
|
||||||
@ -276,12 +276,16 @@ public class Citizens extends JavaPlugin implements CitizensPlugin {
|
|||||||
getServer().getPluginManager().callEvent(new CitizensReloadEvent());
|
getServer().getPluginManager().callEvent(new CitizensReloadEvent());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save() {
|
public void save(boolean immediate) {
|
||||||
if (saves == null)
|
if (saves == null)
|
||||||
return;
|
return;
|
||||||
for (NPC npc : npcRegistry)
|
for (NPC npc : npcRegistry)
|
||||||
((CitizensNPC) npc).save(saves.getKey("npc." + npc.getId()));
|
((CitizensNPC) npc).save(saves.getKey("npc." + npc.getId()));
|
||||||
|
|
||||||
|
if (immediate) {
|
||||||
|
saves.save();
|
||||||
|
return;
|
||||||
|
}
|
||||||
new Thread() {
|
new Thread() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
@ -294,7 +298,7 @@ public class Citizens extends JavaPlugin implements CitizensPlugin {
|
|||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
|
Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
save();
|
save(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -179,48 +179,6 @@ public class CommandManager {
|
|||||||
return cmds;
|
return cmds;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class CommandInfo {
|
|
||||||
private final Command commandAnnotation;
|
|
||||||
private final Requirements requirements;
|
|
||||||
|
|
||||||
public CommandInfo(Command commandAnnotation, Requirements requirements) {
|
|
||||||
this.commandAnnotation = commandAnnotation;
|
|
||||||
this.requirements = requirements;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Command getCommandAnnotation() {
|
|
||||||
return commandAnnotation;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Requirements getRequirements() {
|
|
||||||
return requirements;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return 31 + ((commandAnnotation == null) ? 0 : commandAnnotation.hashCode());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object obj) {
|
|
||||||
if (this == obj) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (obj == null || getClass() != obj.getClass()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
CommandInfo other = (CommandInfo) obj;
|
|
||||||
if (commandAnnotation == null) {
|
|
||||||
if (other.commandAnnotation != null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else if (!commandAnnotation.equals(other.commandAnnotation)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the usage string for a command.
|
// Get the usage string for a command.
|
||||||
private String getUsage(String[] args, Command cmd) {
|
private String getUsage(String[] args, Command cmd) {
|
||||||
StringBuilder command = new StringBuilder();
|
StringBuilder command = new StringBuilder();
|
||||||
@ -323,6 +281,48 @@ public class CommandManager {
|
|||||||
this.injector = injector;
|
this.injector = injector;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class CommandInfo {
|
||||||
|
private final Command commandAnnotation;
|
||||||
|
private final Requirements requirements;
|
||||||
|
|
||||||
|
public CommandInfo(Command commandAnnotation, Requirements requirements) {
|
||||||
|
this.commandAnnotation = commandAnnotation;
|
||||||
|
this.requirements = requirements;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (obj == null || getClass() != obj.getClass()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
CommandInfo other = (CommandInfo) obj;
|
||||||
|
if (commandAnnotation == null) {
|
||||||
|
if (other.commandAnnotation != null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else if (!commandAnnotation.equals(other.commandAnnotation)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Command getCommandAnnotation() {
|
||||||
|
return commandAnnotation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Requirements getRequirements() {
|
||||||
|
return requirements;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return 31 + ((commandAnnotation == null) ? 0 : commandAnnotation.hashCode());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Logger for general errors.
|
// Logger for general errors.
|
||||||
private static final Logger logger = Logger.getLogger(CommandManager.class.getCanonicalName());
|
private static final Logger logger = Logger.getLogger(CommandManager.class.getCanonicalName());
|
||||||
}
|
}
|
@ -52,15 +52,17 @@ public class AdminCommands {
|
|||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
aliases = { "citizens" },
|
aliases = { "citizens" },
|
||||||
usage = "save",
|
usage = "save (-a)",
|
||||||
desc = "Save NPCs",
|
desc = "Save NPCs",
|
||||||
modifiers = { "save" },
|
modifiers = { "save" },
|
||||||
min = 1,
|
min = 1,
|
||||||
max = 1,
|
max = 1,
|
||||||
|
flags = "a",
|
||||||
permission = "admin")
|
permission = "admin")
|
||||||
public void save(CommandContext args, CommandSender sender, NPC npc) {
|
public void save(CommandContext args, CommandSender sender, NPC npc) {
|
||||||
Messaging.send(sender, "<e>Saving Citizens...");
|
Messaging.send(sender, "<e>Saving Citizens...");
|
||||||
plugin.save();
|
boolean async = args.hasFlag('a');
|
||||||
|
plugin.save(!async);
|
||||||
Messaging.send(sender, "<e>Citizens saved.");
|
Messaging.send(sender, "<e>Citizens saved.");
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user