add save & load commands

This commit is contained in:
Pyrbu 2023-05-12 08:28:10 +01:00
parent a3778ffe9c
commit ea732105a3
3 changed files with 59 additions and 0 deletions

@ -14,6 +14,8 @@ import lol.pyr.znpcsplus.commands.parsers.EntityPropertyParser;
import lol.pyr.znpcsplus.commands.parsers.NamedTextColorParser;
import lol.pyr.znpcsplus.commands.parsers.NpcEntryParser;
import lol.pyr.znpcsplus.commands.parsers.NpcTypeParser;
import lol.pyr.znpcsplus.commands.storage.LoadAllCommand;
import lol.pyr.znpcsplus.commands.storage.SaveAllCommand;
import lol.pyr.znpcsplus.config.Configs;
import lol.pyr.znpcsplus.entity.EntityPropertyImpl;
import lol.pyr.znpcsplus.interaction.InteractionPacketListener;
@ -197,6 +199,9 @@ public class ZNpcsPlus extends JavaPlugin {
.addSubcommand("teleport", new TeleportCommand())
.addSubcommand("list", new ListCommand())
.addSubcommand("near", new NearCommand())
.addSubcommand("storage", new MultiCommand()
.addSubcommand("save", new SaveAllCommand())
.addSubcommand("load", new LoadAllCommand()))
.addSubcommand("holo", new MultiCommand()
.addSubcommand("add", new HoloAddCommand())
.addSubcommand("delete", new HoloDeleteCommand())

@ -0,0 +1,27 @@
package lol.pyr.znpcsplus.commands.storage;
import lol.pyr.director.adventure.command.CommandContext;
import lol.pyr.director.adventure.command.CommandHandler;
import lol.pyr.director.common.command.CommandExecutionException;
import lol.pyr.znpcsplus.npc.NpcRegistryImpl;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CompletableFuture;
public class LoadAllCommand implements CommandHandler {
@Override
public void run(CommandContext context) throws CommandExecutionException {
CompletableFuture.runAsync(() -> {
NpcRegistryImpl.get().reload();
context.send(Component.text("All NPCs have been re-loaded from storage", NamedTextColor.GREEN));
});
}
@Override
public List<String> suggest(CommandContext context) throws CommandExecutionException {
return Collections.emptyList();
}
}

@ -0,0 +1,27 @@
package lol.pyr.znpcsplus.commands.storage;
import lol.pyr.director.adventure.command.CommandContext;
import lol.pyr.director.adventure.command.CommandHandler;
import lol.pyr.director.common.command.CommandExecutionException;
import lol.pyr.znpcsplus.npc.NpcRegistryImpl;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CompletableFuture;
public class SaveAllCommand implements CommandHandler {
@Override
public void run(CommandContext context) throws CommandExecutionException {
CompletableFuture.runAsync(() -> {
NpcRegistryImpl.get().save();
context.send(Component.text("All NPCs have been saved to storage", NamedTextColor.GREEN));
});
}
@Override
public List<String> suggest(CommandContext context) throws CommandExecutionException {
return Collections.emptyList();
}
}