Skip to content

Commit

Permalink
Loading/Saving commands
Browse files Browse the repository at this point in the history
  • Loading branch information
T14D3 committed Jan 2, 2025
1 parent df36ae3 commit 2431b58
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
24 changes: 24 additions & 0 deletions src/main/java/de/t14d3/zones/listeners/CommandListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String, Region> entry, boolean showMembers) {
var mm = MiniMessage.miniMessage();
Component comp = Component.text("");
Expand Down
5 changes: 4 additions & 1 deletion src/main/resources/messages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ messages:
list: "<green>List all regions."
info: "<green>Get information about a region."
cancel: "<green>Cancel the current selection."
no-permission: "<red>You don't have permission to execute this command!"
create:
overlap: "<red>Error: Region overlaps existing region."
click_two_corners: "<yellow>Click two corners to select the region."
Expand All @@ -41,4 +42,6 @@ messages:
subcreate:
no_parent: "<red>Error: No parent region found."
outside_parent: "<red>Error: Selection is outside parent region."
region_created: "<green>Sub-region created successfully!"
region_created: "<green>Sub-region created successfully!"
load: "<green>Loaded <count> regions!"
save: "<green>Saved <count> regions to file"
6 changes: 6 additions & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 2431b58

Please sign in to comment.