mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-01 14:38:53 +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());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -32,7 +32,6 @@ import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@DisplayName("Message Serialization Tests")
|
||||
|
||||
@@ -31,7 +31,6 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@DisplayName("Normal Distribution Tests")
|
||||
public class NormalDistributionTests {
|
||||
|
||||
+1
-1
@@ -433,7 +433,7 @@ This is a table of HuskHomes commands, how to use them, and their required permi
|
||||
</table>
|
||||
|
||||
### Notes
|
||||
† — If [Permission Restricted Warps](restricted-warps) are in use, the `huskhomes.command.warp.(warp_name)` permission node will also be required to be able to view and use warps.
|
||||
† — If [Permission Restricted Warps](restricted-warps) are in use, the `huskhomes.warp.<name>` permission node will also be required to be able to list, use, edit and delete (but not set) warps. The `huskhomes.warp.*` wildcard permission grants the ability to access all warps.
|
||||
|
||||
‡ — Requires `return_by_death` to be enabled in [`config.yml`](config-files).
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ general:
|
||||
max_public_homes: 10
|
||||
# Whether permission limits (i.e. huskhomes.max_homes.<number>) should stack if the user inherits multiple nodes.
|
||||
stack_permission_limits: false
|
||||
# Whether users require a permission (huskhomes.command.warp.<warp_name>) to use warps
|
||||
# Whether users require a permission (huskhomes.warp.<warp_name>) to use warps
|
||||
permission_restrict_warps: false
|
||||
# How long a player has to stand still and not take damage for when teleporting (in seconds)
|
||||
teleport_warmup_time: 5
|
||||
|
||||
@@ -1,3 +1,28 @@
|
||||
HuskHomes supports restricting warps behind permission nodes. This means that players require a corresponding `huskhomes.command.warp.<name>` node to view and use warps, else they will see an error message.
|
||||
HuskHomes supports restricting warps behind permission nodes through the **Permission-Restrict Warps** feature.
|
||||
|
||||
To enable permission-restricted warps, set `permission_restrict_warps` to `true` under `general`. Don't forget to grant users the necessary permission nodes (`huskhomes.command.warp.<name>`).
|
||||
## Permissions
|
||||
With `permission_restrict_warps` enabled in [`config.yml`](config-files), players are required to have a corresponding `huskhomes.warp.<name>` node. Note that this is a _different permission_ from the one required to use the `/warp` command, which is `huskhomes.command.warp`.
|
||||
|
||||
With the `huskhomes.warp.<name>` permission node, where `<name>` is the name of the warp, users can:
|
||||
|
||||
* Teleport to the warp with `/warp <name>`
|
||||
* View the warp in the `/warplist`, or TAB-complete the warp
|
||||
* Delete, or edit warps with that name, if they have access to the respective [[commands]]
|
||||
|
||||
If users have permission to set warps, they will still be able to set warps with names they do not have permission for, but be advised they will not be able to edit or delete the warp once set without permission. If you're using permission restricted warps, we therefore recommend also granting the wildcard warp permission (see below).
|
||||
|
||||
Note that the name of the warp is case-sensitive (i.e. the `huskhomes.warp.Home` permission node is different to the `huskhomes.warp.home` permission node).
|
||||
|
||||
Users with the `huskhomes.warp.*` permission will be able to use all warps.
|
||||
|
||||
## Configuring
|
||||
To enable permission-restricted warps, set `permission_restrict_warps` to `true` under `general`. Don't forget to grant users the necessary permission nodes (`huskhomes.warp.<name>`).
|
||||
|
||||
<details>
|
||||
<summary>Permission Restrict Warps – config.yml</summary>
|
||||
|
||||
```yaml
|
||||
# Whether users require a permission (huskhomes.warp.<warp_name>) to use warps
|
||||
permission_restrict_warps: false
|
||||
```
|
||||
</details>
|
||||
Reference in new issue
Block a user