Add delwarp

This commit is contained in:
zontreck 2025-04-06 14:44:03 -07:00
parent a244de0169
commit be6bea27c3
7 changed files with 116 additions and 9 deletions

View file

@ -95,6 +95,12 @@ public class AriasServerEssentials extends JavaPlugin implements Listener {
getConfig().set("warps", warps);
}
public static Component getPrefix() {
return Component.text("[", NamedTextColor.YELLOW)
.append(Component.text("ASE", NamedTextColor.DARK_PURPLE))
.append(Component.text("] ", NamedTextColor.YELLOW));
}
@Override
public void onDisable() {
plugin = null;

View file

@ -14,6 +14,7 @@ import dev.zontreck.ase.commands.tpa.TPACommand;
import dev.zontreck.ase.commands.tpa.TPAHereCommand;
import dev.zontreck.ase.commands.tpa.TPAcceptCommand;
import dev.zontreck.ase.commands.tpa.TPDenyCommand;
import dev.zontreck.ase.commands.warps.DelWarpCommand;
import dev.zontreck.ase.commands.warps.SetWarpCommand;
import io.papermc.paper.command.brigadier.Commands;
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
@ -118,5 +119,15 @@ public class CommandRegistry {
.build()
);
cmds.register(Commands.literal("delwarp")
.requires(x -> x.getSender().isPermissionSet(DelWarpCommand.PERMISSION)
|| x.getSender().isOp())
.then(Commands.argument("name", StringArgumentType.string())
.executes(ctx -> DelWarpCommand.execute(ctx.getSource(),
StringArgumentType.getString(ctx, "name"))))
.build()
);
}
}

View file

@ -0,0 +1,67 @@
package dev.zontreck.ase.commands.warps;
import org.bukkit.entity.Player;
import com.mojang.brigadier.Command;
import dev.zontreck.ase.AriasServerEssentials;
import dev.zontreck.ase.warps.Warp;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.md_5.bungee.api.ChatColor;
public class DelWarpCommand {
public static final String PERMISSION = "ase.commands.delwarp";
public static final String OTHERPERMISSION = "ase.commands.delwarp.other";
public static int execute(CommandSourceStack ctx, String warpName) {
Player player = (Player) ctx.getSender();
Component noWarp = AriasServerEssentials.getPrefix()
.append(Component.text("No such warp exists", NamedTextColor.DARK_RED));
Component noPermission = AriasServerEssentials.getPrefix()
.append(Component.text("You lack permission to delete the specified warp", NamedTextColor.DARK_RED));
Component yourWarpDeleted = AriasServerEssentials.getPrefix().append(Component.text(
"Your warp '" + ChatColor.YELLOW + warpName + ChatColor.DARK_PURPLE + "' has been deleted",
NamedTextColor.DARK_PURPLE));
// 1. Check if the warp exists
if (AriasServerEssentials.getSelf().warps.containsKey(warpName)) {
// 2. Check owner of warp, or if current player is operator
Warp warp = AriasServerEssentials.getSelf().warps.get(warpName);
if (warp.playerIsOwner(player) || player.isOp()
|| player.isPermissionSet(OTHERPERMISSION)) {
// 3. Check if the current player isn't owner.
boolean isDifferentPlayer = !warp.playerIsOwner(player);
if (isDifferentPlayer) {
player.sendMessage(AriasServerEssentials.getPrefix().append(Component.text(
"The warp owned by '" + ChatColor.YELLOW + warp.getOwner().getName() + ChatColor.DARK_GREEN
+ "' has been deleted. They have been notified if they are online.",
NamedTextColor.DARK_GREEN)));
if (warp.tryGetOnlineOwner() != null) {
warp.tryGetOnlineOwner()
.sendMessage(AriasServerEssentials.getPrefix()
.append(Component.text(
"An administrator has deleted your warp '" + ChatColor.YELLOW
+ warp.warpName + ChatColor.DARK_RED + "'",
NamedTextColor.DARK_RED)));
warp.tryGetOnlineOwner().sendMessage(yourWarpDeleted);
}
} else {
player.sendMessage(yourWarpDeleted);
}
AriasServerEssentials.getSelf().warps.remove(warpName);
AriasServerEssentials.getSelf().SaveConfiguration();
} else {
player.sendMessage(noPermission);
}
} else {
player.sendMessage(noWarp);
}
return Command.SINGLE_SUCCESS;
}
}

View file

@ -18,16 +18,12 @@ public class SetWarpCommand {
Warp newWarp = Warp.create(warpName, player);
AriasServerEssentials ASE = AriasServerEssentials.getSelf();
Component permissionDenied = Component.text("[", NamedTextColor.YELLOW)
.append(Component.text("ASE", NamedTextColor.DARK_PURPLE))
.append(Component.text("] ", NamedTextColor.YELLOW)).append(Component.text(
"The warp could not be created, or updated, because the warp already exists and is owned by someone else.",
NamedTextColor.DARK_RED));
Component permissionDenied = AriasServerEssentials.getPrefix().append(Component.text(
"The warp could not be created, or updated, because the warp already exists and is owned by someone else.",
NamedTextColor.DARK_RED));
Component warpCreatedOrUpdated = Component.text("[", NamedTextColor.YELLOW)
.append(Component.text("ASE", NamedTextColor.DARK_PURPLE))
.append(Component.text("] ", NamedTextColor.YELLOW)).append(Component.text(
"The warp was successfully created or updated!", NamedTextColor.DARK_GREEN));
Component warpCreatedOrUpdated = AriasServerEssentials.getPrefix().append(Component.text(
"The warp was successfully created or updated!", NamedTextColor.DARK_GREEN));
if (ASE.warps.containsKey(newWarp.warpName)) {
// Check if current player is the owner

View file

@ -27,6 +27,15 @@ public class Warp {
return Bukkit.getOfflinePlayer(owningPlayer);
}
/**
* Tries to retrieve the owner of the warp if they are online
*
* @return An online player instance, or null if offline
*/
public Player tryGetOnlineOwner() {
return Bukkit.getPlayer(owningPlayer);
}
public Warp() {
}
@ -52,4 +61,8 @@ public class Warp {
allowedPlayers.add(UUID.fromString(id));
}
}
public boolean playerIsOwner(Player player) {
return owningPlayer.toString().equals(player.getUniqueId().toString());
}
}

View file

@ -48,6 +48,9 @@ commands:
setwarp:
description: Create or update a named warp
usage: "- /setwarp [name] -"
delwarp:
description: Delete a named warp
usage: "- /delwarp [name] -"
permissions:
ase.commands.*:
description: Allow all commands
@ -64,6 +67,8 @@ permissions:
ase.commands.tpahere: true
ase.commands.shareitem: true
ase.commands.asecredits: true
ase.commands.setwarp: true
ase.commands.delwarp: true
ase.commands.home:
description: Allows usage of the /home command
default: true
@ -106,3 +111,6 @@ permissions:
ase.commands.setwarp:
description: Allows creating or updating warps
default: false
ase.commands.delwarp:
description: Allows deleting warps
default: false

View file

@ -48,6 +48,9 @@ commands:
setwarp:
description: Create or update a named warp
usage: "- /setwarp [name] -"
delwarp:
description: Delete a named warp
usage: "- /delwarp [name] -"
permissions:
ase.commands.*:
description: Allow all commands
@ -106,3 +109,6 @@ permissions:
ase.commands.setwarp:
description: Allows creating or updating warps
default: false
ase.commands.delwarp:
description: Allows deleting warps
default: false