diff --git a/src/main/java/de/t14d3/zones/listeners/CommandListener.java b/src/main/java/de/t14d3/zones/listeners/CommandListener.java index 42af767..d7d5527 100644 --- a/src/main/java/de/t14d3/zones/listeners/CommandListener.java +++ b/src/main/java/de/t14d3/zones/listeners/CommandListener.java @@ -82,6 +82,10 @@ public void execute(CommandSourceStack stack, String[] args) { case "set": handleSetCommand(player, args); break; + case "save": + handleSaveCommand(player, args); + case "load": + handleLoadCommand(player, args); default: player.sendMessage(miniMessage.deserialize(messages.get("invalidCommand"))); break; @@ -291,6 +295,26 @@ private void handleSetCommand(Player player, String[] args) { player.sendMessage(miniMessage.deserialize(messages.get("set.success"), parsed("permission", permission), parsed("value", value), parsed("region", regionKey))); } + private void handleSaveCommand(Player player, String[] args) { + if (player.hasPermission("zones.save")) { + regionManager.saveRegions(); + int count = regionManager.regions().size(); + player.sendMessage(miniMessage.deserialize(messages.get("commands.save"), parsed("count", String.valueOf(count)))); + } else { + player.sendMessage(miniMessage.deserialize(messages.get("commands.no-permission"))); + } + } + + private void handleLoadCommand(Player player, String[] args) { + if (player.hasPermission("zones.load")) { + regionManager.loadRegions(); + int count = regionManager.loadedRegions.size(); + player.sendMessage(miniMessage.deserialize(messages.get("commands.load"), parsed("count", String.valueOf(count)))); + } else { + player.sendMessage(miniMessage.deserialize(messages.get("commands.no-permission"))); + } + } + private Component regionInfo(Map.Entry entry, boolean showMembers) { var mm = MiniMessage.miniMessage(); Component comp = Component.text(""); diff --git a/src/main/resources/messages.yml b/src/main/resources/messages.yml index 30a1af4..b34aeed 100644 --- a/src/main/resources/messages.yml +++ b/src/main/resources/messages.yml @@ -32,6 +32,7 @@ messages: list: "List all regions." info: "Get information about a region." cancel: "Cancel the current selection." + no-permission: "You don't have permission to execute this command!" create: overlap: "Error: Region overlaps existing region." click_two_corners: "Click two corners to select the region." @@ -41,4 +42,6 @@ messages: subcreate: no_parent: "Error: No parent region found." outside_parent: "Error: Selection is outside parent region." - region_created: "Sub-region created successfully!" \ No newline at end of file + region_created: "Sub-region created successfully!" + load: "Loaded regions!" + save: "Saved regions to file" \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index e8d6e86..6147437 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -19,3 +19,9 @@ permissions: zones.info.other: description: Allow players to view information about other regions default: op + zones.save: + description: Allow players to save all regions to file + default: op + zones.load: + description: Allow players to load all regions from file + default: op \ No newline at end of file