Add /warp

This commit is contained in:
zontreck 2025-04-06 14:59:57 -07:00
parent be6bea27c3
commit 496525760d
8 changed files with 100 additions and 8 deletions

View file

@ -16,6 +16,7 @@ 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 dev.zontreck.ase.commands.warps.WarpCommand;
import io.papermc.paper.command.brigadier.Commands;
import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
import io.papermc.paper.command.brigadier.argument.resolvers.selector.PlayerSelectorArgumentResolver;
@ -129,5 +130,15 @@ public class CommandRegistry {
.build()
);
cmds.register(Commands.literal("warp")
.requires(x -> x.getSender().isPermissionSet(WarpCommand.PERMISSION)
|| x.getSender().isOp())
.then(Commands.argument("name", StringArgumentType.string())
.executes(ctx -> WarpCommand.execute(ctx.getSource(),
StringArgumentType.getString(ctx, "name"))))
.build()
);
}
}

View file

@ -17,8 +17,6 @@ public class DelWarpCommand {
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));
@ -59,7 +57,7 @@ public class DelWarpCommand {
}
} else {
player.sendMessage(noWarp);
player.sendMessage(WarpConsts.noWarp);
}
return Command.SINGLE_SUCCESS;

View file

@ -18,10 +18,6 @@ public class SetWarpCommand {
Warp newWarp = Warp.create(warpName, player);
AriasServerEssentials ASE = AriasServerEssentials.getSelf();
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 = AriasServerEssentials.getPrefix().append(Component.text(
"The warp was successfully created or updated!", NamedTextColor.DARK_GREEN));
@ -37,7 +33,7 @@ public class SetWarpCommand {
player.sendMessage(warpCreatedOrUpdated);
} else {
player.sendMessage(permissionDenied);
player.sendMessage(WarpConsts.permissionDenied);
}
} else {
ASE.warps.put(warpName, newWarp);

View file

@ -0,0 +1,38 @@
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;
public class WarpCommand {
public static final String PERMISSION = "ase.commands.warp";
public static final String OTHERPERMISSION = "ase.commands.warp.bypass";
public static int execute(CommandSourceStack source, String warpName) {
Player player = (Player) source.getSender();
Component warping = Component.text("Warping to destination!", NamedTextColor.DARK_GREEN);
if (AriasServerEssentials.getSelf().warps.containsKey(warpName)) {
// Check access to the warp
Warp warp = AriasServerEssentials.getSelf().warps.get(warpName);
if (warp.hasAccess(player) || player.isPermissionSet(OTHERPERMISSION)) {
player.teleport(warp.location);
player.sendMessage(warping);
} else {
// Access Denied
player.sendMessage(WarpConsts.permissionDenied);
}
} else {
player.sendMessage(WarpConsts.noWarp);
}
return Command.SINGLE_SUCCESS;
}
}

View file

@ -0,0 +1,15 @@
package dev.zontreck.ase.commands.warps;
import dev.zontreck.ase.AriasServerEssentials;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
public class WarpConsts {
public static final Component noWarp = AriasServerEssentials.getPrefix()
.append(Component.text("No such warp exists", NamedTextColor.DARK_RED));
public static final Component permissionDenied = AriasServerEssentials.getPrefix().append(Component.text(
"You lack permission to access, edit, or remove this warp.",
NamedTextColor.DARK_RED));
}

View file

@ -65,4 +65,19 @@ public class Warp {
public boolean playerIsOwner(Player player) {
return owningPlayer.toString().equals(player.getUniqueId().toString());
}
public boolean hasAccess(Player player) {
if (isPublic)
return true;
if (playerIsOwner(player))
return true;
for (UUID uuid : allowedPlayers) {
if (uuid.toString().equals(player.getUniqueId().toString()))
return true;
}
return false;
}
}

View file

@ -51,6 +51,9 @@ commands:
delwarp:
description: Delete a named warp
usage: "- /delwarp [name] -"
warp:
description: Go to warp
usage: "- /warp [name] -"
permissions:
ase.commands.*:
description: Allow all commands
@ -69,6 +72,7 @@ permissions:
ase.commands.asecredits: true
ase.commands.setwarp: true
ase.commands.delwarp: true
ase.commands.warp: true
ase.commands.home:
description: Allows usage of the /home command
default: true
@ -114,3 +118,9 @@ permissions:
ase.commands.delwarp:
description: Allows deleting warps
default: false
ase.commands.warp:
description: Allows going to warps
default: true
ase.commands.warp.bypass:
description: Administrative access to private warps. This permission also will show private warps inside the /warps listing.
default: false

View file

@ -51,6 +51,9 @@ commands:
delwarp:
description: Delete a named warp
usage: "- /delwarp [name] -"
warp:
description: Go to warp
usage: "- /warp [name] -"
permissions:
ase.commands.*:
description: Allow all commands
@ -67,6 +70,9 @@ permissions:
ase.commands.tpahere: true
ase.commands.shareitem: true
ase.commands.asecredits: true
ase.commands.setwarp: true
ase.commands.delwarp: true
ase.commands.warp: true
ase.commands.home:
description: Allows usage of the /home command
default: true
@ -112,3 +118,6 @@ permissions:
ase.commands.delwarp:
description: Allows deleting warps
default: false
ase.commands.warp:
description: Allows going to warps
default: true