List commands, more refactoring work

This commit is contained in:
William278 committed 2023-03-17 17:00:44 +00:00
1 parent 9903503f03
commit f746d67339
23 files changed
+361 -450

No files matched your search

@@ -1,8 +1,5 @@
package net.william278.huskhomes.position;
import net.william278.huskhomes.user.OnlineUser;
import net.william278.huskhomes.util.Permission;
import org.intellij.lang.annotations.Subst;
import org.jetbrains.annotations.NotNull;
import java.util.UUID;
@@ -12,6 +9,8 @@ import java.util.UUID;
*/
public class Warp extends SavedPosition {
private static final String PERMISSION_PREFIX = "huskhomes.command.warp.";
public Warp(double x, double y, double z, float yaw, float pitch,
@NotNull World world, @NotNull String server,
@NotNull PositionMeta positionMeta, @NotNull UUID uuid) {
@@ -28,40 +27,19 @@ public class Warp extends SavedPosition {
super(position, meta);
}
/**
* Get the permission node for a warp
*
* @param warp The warp name
* @return The permission node
*/
@NotNull
@Subst("huskhomes.command.warp")
public static String getPermissionNode(@NotNull String warp) {
return Permission.COMMAND_WARP.node + "." + warp.toLowerCase();
public static String getPermission(@NotNull String warpName) {
return PERMISSION_PREFIX + warpName.toLowerCase();
}
/**
* Check if a {@link OnlineUser} has permission to teleport to this warp
*
* @param restrictWarps Whether to restrict warps to permission nodes
* @param user The {@link OnlineUser} to check
* @return true if the user has permission to teleport to this warp
*/
public boolean hasPermission(boolean restrictWarps, @NotNull OnlineUser user) {
return hasPermission(restrictWarps, user, getMeta().getName());
@NotNull
public String getPermission() {
return getPermission(getName());
}
/**
* Check if a {@link OnlineUser} has permission to teleport to this warp
*
* @param restrictWarps Whether to restrict warps to permission nodes
* @param user The {@link OnlineUser} to check
* @param warp The warp name to check
* @return true if the user has permission to teleport to this warp
*/
public static boolean hasPermission(boolean restrictWarps, @NotNull OnlineUser user, @NotNull String warp) {
return !restrictWarps || (user.hasPermission(Permission.COMMAND_SET_WARP.node)
|| user.hasPermission(getPermissionNode(warp)));
@NotNull
public static String getWildcardPermission() {
return PERMISSION_PREFIX + "*";
}
}