Skip to content

Commit

Permalink
Update admin command to re-add owners (#36)
Browse files Browse the repository at this point in the history
* Update AssaultRepairCommand.java

* Update AssaultRepairCommand.java

* Add feedback

* Update AssaultRepairCommand.java
  • Loading branch information
TylerS1066 authored Jul 9, 2024
1 parent 5fdb34d commit 0ee493e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import net.countercraft.movecraft.warfare.MovecraftWarfare;
import net.countercraft.movecraft.warfare.config.Config;
import net.countercraft.movecraft.warfare.features.assault.AssaultData;
import net.countercraft.movecraft.warfare.features.assault.AssaultUtils;
import net.countercraft.movecraft.warfare.features.assault.events.AssaultBroadcastEvent;
import net.countercraft.movecraft.warfare.localisation.I18nSupport;
import net.countercraft.movecraft.worldguard.MovecraftWorldGuard;
Expand All @@ -10,13 +12,18 @@
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

import java.util.List;
import java.util.Set;
import java.util.UUID;

import static net.countercraft.movecraft.util.ChatUtils.ERROR_PREFIX;
import static net.countercraft.movecraft.util.ChatUtils.MOVECRAFT_COMMAND_PREFIX;

public class AssaultRepairCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) {
public boolean onCommand(@NotNull CommandSender commandSender, Command command, @NotNull String s, @NotNull String[] args) {
if (!command.getName().equalsIgnoreCase("assaultrepair"))
return false;

Expand Down Expand Up @@ -44,12 +51,13 @@ public boolean onCommand(CommandSender commandSender, Command command, String s,
}

String regionName = args[0];
if (MovecraftWorldGuard.getInstance().getWGUtils().regionExists(regionName, player.getWorld())) {
if (!MovecraftWorldGuard.getInstance().getWGUtils().regionExists(regionName, player.getWorld())) {
player.sendMessage(
MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Assault - Region Not Found"));
return true;
}

player.sendMessage(I18nSupport.getInternationalisedString("Assault - Repairing Region"));
if (!MovecraftWarfare.getInstance().getAssaultManager().getRepairUtils()
.repairRegionRepairState(player.getWorld(), regionName, player)) {
String broadcast = ERROR_PREFIX + " " + String
Expand All @@ -62,8 +70,24 @@ public boolean onCommand(CommandSender commandSender, Command command, String s,
Bukkit.getServer().getPluginManager().callEvent(event);
}

// TODO: Re-add owners
List<AssaultData> data = AssaultUtils.retrieveInfoFile(regionName, player.getWorld().getName());
if (data != null && !data.isEmpty()) {
Set<UUID> ownerSet = data.get(0).getOwners();
if (ownerSet != null && !ownerSet.isEmpty()) {
if (!MovecraftWorldGuard.getInstance().getWGUtils().addOwners(regionName, player.getWorld(), ownerSet)) {
String broadcast = String.format(I18nSupport.getInternationalisedString("Assault - Owners Failed"),
regionName);
Bukkit.getServer().broadcastMessage(broadcast);

// Note: there is no assault to pass here...
AssaultBroadcastEvent broadcastEvent = new AssaultBroadcastEvent(null, broadcast,
AssaultBroadcastEvent.Type.OWNER_FAIL);
Bukkit.getServer().getPluginManager().callEvent(broadcastEvent);
}
}
}

player.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("AssaultRepair - Successful"));
return true;
}
}
1 change: 1 addition & 0 deletions src/main/resources/localisation/mcwlang_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ AssaultInfo\ -\ Not\ Assaultable\ -\ Recently\ Assaulted=NOT ASSAULTABLE DUE TO
AssaultInfo\ -\ Not\ Assaultable\ -\ Insufficient\ Defenders=NOT ASSAULTABLE DUE TO INSUFFICIENT ONLINE DEFENDERS
AssaultInfo\ -\ Not\ Assaultable\ -\ You\ Are\ Member=NOT ASSAULTABLE BECAUSE YOU ARE A MEMBER
AssaultInfo\ -\ Assaultable=THIS REGION CAN BE ASSAULTED
AssaultRepair\ -\ Successful=Admin repair successful, please remember to remove the beacon manually
Siege\ -\ Siege\ Cost=Cost to siege\:
Siege\ -\ Daily\ Income=Daily income\:
Siege\ -\ Day\ of\ Week=Day of week\:
Expand Down

0 comments on commit 0ee493e

Please sign in to comment.