Skip to content

Commit

Permalink
Add click event to /siege list (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
TylerS1066 authored Jul 25, 2024
1 parent 75ea90b commit 78eeba2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import net.countercraft.movecraft.warfare.localisation.I18nSupport;
import net.countercraft.movecraft.worldguard.MovecraftWorldGuard;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.event.ClickEvent;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
Expand Down Expand Up @@ -232,9 +233,10 @@ private String secondsIntToString(int seconds) {
return String.format("%02d", seconds / 60) + ":" + String.format("%02d", seconds % 60);
}

private boolean listCommand(CommandSender commandSender, String[] args) {
if (!commandSender.hasPermission("movecraft.siege.list")) {
commandSender.sendMessage(MOVECRAFT_COMMAND_PREFIX + I18nSupport.getInternationalisedString("Insufficient Permissions"));
private boolean listCommand(@NotNull CommandSender sender, String[] args) {
if (!sender.hasPermission("movecraft.siege.list")) {
sender.sendMessage(ChatUtils.commandPrefix().append(
I18nSupport.getInternationalisedComponent("Insufficient Permissions")));
return true;
}

Expand All @@ -246,28 +248,33 @@ private boolean listCommand(CommandSender commandSender, String[] args) {
else
page = Integer.parseInt(args[1]);
} catch (NumberFormatException e) {
commandSender.sendMessage(MOVECRAFT_COMMAND_PREFIX
+ I18nSupport.getInternationalisedString("Paginator - Invalid Page") + " \"" + args[1] + "\"");
sender.sendMessage(Component.empty()
.append(ChatUtils.commandPrefix())
.append(net.countercraft.movecraft.localisation.I18nSupport.getInternationalisedComponent("Paginator - Invalid page"))
.append(Component.text(" \""))
.append(Component.text(args[1]))
.append(Component.text("\"")));
return true;
}

ComponentPaginator paginator = new ComponentPaginator(
Component.text("Sieges"),
pageNumber -> "/siege list " + pageNumber);
for (Siege siege : siegeManager.getSieges()) {
paginator.addLine(Component.text("- ").append(Component.text(siege.getName())));
paginator.addLine(Component.text("- ").append(
Component.text(siege.getName()).clickEvent(ClickEvent.runCommand("/siege info " + siege.getName()))));
}
if (!paginator.isInBounds(page)) {
commandSender.sendMessage(Component.empty()
sender.sendMessage(Component.empty()
.append(ChatUtils.commandPrefix())
.append(net.countercraft.movecraft.localisation.I18nSupport.getInternationalisedComponent("Paginator - Invalid page"))
.append(Component.text(" \""))
.append(Component.text(args[0]))
.append(Component.text(args[1]))
.append(Component.text("\"")));
return true;
}
for (Component line : paginator.getPage(page))
commandSender.sendMessage(line);
sender.sendMessage(line);
return true;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.countercraft.movecraft.warfare.features.assault;

import net.countercraft.movecraft.MovecraftLocation;
import net.countercraft.movecraft.repair.MovecraftRepair;
import net.countercraft.movecraft.repair.util.WarfareUtils;
import net.countercraft.movecraft.util.Pair;
import net.countercraft.movecraft.warfare.MovecraftWarfare;
Expand Down Expand Up @@ -54,6 +55,7 @@ public boolean repairRegionRepairState(World world, String regionName, @Nullable

ChunkRepairTask repairTask = new ChunkRepairTask(world, regionName, chunks, saveDirectory, regionTester, player);
repairTask.runTaskTimer(MovecraftWarfare.getInstance(), 2, Config.AssaultChunkRepairPeriod);
MovecraftRepair.getInstance().getLogger().info("Repairing region " + regionName + " in " + world.getName() + (player != null ? " for " + player.getName() : ""));
return true;
}

Expand Down

0 comments on commit 78eeba2

Please sign in to comment.