mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-02 14:38:52 +00:00
refactor: Improve perm-restricted warps, close #763
* Changes permission restricted warps to use `huskhomes.warp.<name>` for better compat, without the `.command.` subnode * Fixes wildcard permission support: `huskhomes.warp.*` * Improves documentation
This commit is contained in:
1 parent
cf7ea31536
commit
473c5e77cc
11 files changed
+54
-31
No files matched your search
@@ -49,9 +49,7 @@ public class DelWarpCommand extends SavedPositionCommand<Warp> {
|
||||
|
||||
@Override
|
||||
public void execute(@NotNull CommandUser executor, @NotNull Warp warp, @NotNull String[] args) {
|
||||
if (plugin.getSettings().getGeneral().isPermissionRestrictWarps()
|
||||
&& !executor.hasPermission(warp.getPermission())
|
||||
&& !executor.hasPermission(Warp.getWildcardPermission())) {
|
||||
if (plugin.getSettings().getGeneral().isPermissionRestrictWarps() && !warp.hasPermission(executor)) {
|
||||
plugin.getLocales().getLocale("error_no_permission")
|
||||
.ifPresent(executor::sendMessage);
|
||||
return;
|
||||
|
||||
@@ -54,13 +54,11 @@ public class WarpCommand extends SavedPositionCommand<Warp> {
|
||||
|
||||
@Override
|
||||
public void execute(@NotNull CommandUser executor, @NotNull Warp warp, @NotNull String[] args) {
|
||||
if (plugin.getSettings().getGeneral().isPermissionRestrictWarps()) {
|
||||
if (!executor.hasPermission(warp.getPermission())
|
||||
&& !executor.hasPermission(Warp.getWildcardPermission())) {
|
||||
plugin.getLocales().getLocale("error_no_permission")
|
||||
.ifPresent(executor::sendMessage);
|
||||
return;
|
||||
}
|
||||
// Check permission restricted warps
|
||||
if (plugin.getSettings().getGeneral().isPermissionRestrictWarps() && !warp.hasPermission(executor)) {
|
||||
plugin.getLocales().getLocale("error_no_permission")
|
||||
.ifPresent(executor::sendMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
final Optional<Teleportable> optionalTeleporter = resolveTeleporter(executor, args);
|
||||
|
||||
@@ -92,9 +92,8 @@ public class WarpListCommand extends ListCommand {
|
||||
@NotNull
|
||||
private List<Warp> getItems(@NotNull CommandUser executor) {
|
||||
List<Warp> warps = plugin.getDatabase().getWarps();
|
||||
if (plugin.getSettings().getGeneral().isPermissionRestrictWarps()
|
||||
&& !executor.hasPermission(Warp.getWildcardPermission())) {
|
||||
warps = warps.stream().filter(warp -> executor.hasPermission(warp.getPermission())).toList();
|
||||
if (plugin.getSettings().getGeneral().isPermissionRestrictWarps()) {
|
||||
warps = warps.stream().filter(warp -> warp.hasPermission(executor)).toList();
|
||||
}
|
||||
return warps;
|
||||
}
|
||||
|
||||
@@ -131,7 +131,7 @@ public final class Settings {
|
||||
+ "if the user inherits multiple nodes.")
|
||||
private boolean stackPermissionLimits = false;
|
||||
|
||||
@Comment("Whether users require a permission (huskhomes.command.warp.<warp_name>) to use warps")
|
||||
@Comment("Whether users require a permission (huskhomes.warp.<warp_name>) to use warps")
|
||||
private boolean permissionRestrictWarps = false;
|
||||
|
||||
@Comment("How long a player has to stand still and not take damage for when teleporting (in seconds) ")
|
||||
|
||||
@@ -100,12 +100,11 @@ public class WarpsManager {
|
||||
|
||||
@NotNull
|
||||
public List<String> getUsableWarps(@NotNull CommandUser user) {
|
||||
if (!plugin.getSettings().getGeneral().isPermissionRestrictWarps()
|
||||
|| user.hasPermission(Warp.getWildcardPermission())) {
|
||||
if (!plugin.getSettings().getGeneral().isPermissionRestrictWarps()) {
|
||||
return getWarps();
|
||||
}
|
||||
return warps.stream()
|
||||
.filter(warp -> user.hasPermission(warp.getPermission()))
|
||||
.filter(warp -> warp.hasPermission(user))
|
||||
.map(Warp::getName)
|
||||
.toList();
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
package net.william278.huskhomes.position;
|
||||
|
||||
import net.william278.huskhomes.user.CommandUser;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.UUID;
|
||||
@@ -28,7 +29,8 @@ import java.util.UUID;
|
||||
*/
|
||||
public class Warp extends SavedPosition {
|
||||
|
||||
private static final String PERMISSION_PREFIX = "huskhomes.command.warp.";
|
||||
private static final String USE_PERMISSION_FORMAT = "huskhomes.warp.%s";
|
||||
private static final String USE_PERMISSION_WILDCARD = "huskhomes.warp.*";
|
||||
|
||||
private Warp(double x, double y, double z, float yaw, float pitch, @NotNull World world, @NotNull String server,
|
||||
@NotNull PositionMeta positionMeta, @NotNull UUID uuid) {
|
||||
@@ -67,17 +69,21 @@ public class Warp extends SavedPosition {
|
||||
|
||||
@NotNull
|
||||
public static String getPermission(@NotNull String warpName) {
|
||||
return PERMISSION_PREFIX + warpName.toLowerCase();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getPermission() {
|
||||
return getPermission(getName());
|
||||
return USE_PERMISSION_FORMAT.formatted(warpName);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String getWildcardPermission() {
|
||||
return PERMISSION_PREFIX + "*";
|
||||
return USE_PERMISSION_WILDCARD;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getPermission() {
|
||||
return Warp.getPermission(getName());
|
||||
}
|
||||
|
||||
public boolean hasPermission(@NotNull CommandUser user) {
|
||||
return user.hasPermission(Warp.getWildcardPermission()) || user.hasPermission(getPermission());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user