Skip to content

Commit 868f5d4

Browse files
Update aliases to match parent's permission level
1 parent e69e1d5 commit 868f5d4

File tree

9 files changed

+38
-13
lines changed

9 files changed

+38
-13
lines changed

src/main/java/com/thepinkhacker/commandsplus/CommandsPlus.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public void onInitialize() {
4545
);
4646

4747
// Aliases
48-
AliasUtils.createAlias(dispatcher, "gamemode", "gm");
48+
AliasUtils.createAlias(dispatcher, "gamemode", "gm", 2);
4949
AliasUtils.createAlias(dispatcher, "help", "?");
5050

5151
LOGGER.info("Registered commands+.");

src/main/java/com/thepinkhacker/commandsplus/server/command/DayLockCommand.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@
1212
import net.minecraft.world.GameRules;
1313

1414
public class DayLockCommand implements CommandRegistrationCallback {
15+
private final int PERMISSION_LEVEL = 2;
1516
@Override
1617
public void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment environment) {
1718
LiteralCommandNode<ServerCommandSource> node = dispatcher.register(CommandManager.literal("daylock")
18-
.requires(source -> source.hasPermissionLevel(2))
19+
.requires(source -> source.hasPermissionLevel(PERMISSION_LEVEL))
1920
.then(CommandManager.argument("lock", BoolArgumentType.bool())
2021
.executes(context -> execute(
2122
context.getSource(),
@@ -28,7 +29,7 @@ public void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandR
2829
))
2930
);
3031

31-
AliasUtils.createAlias(dispatcher, node, "alwaysday");
32+
AliasUtils.createAlias(dispatcher, node, "alwaysday", PERMISSION_LEVEL);
3233
}
3334

3435
private static int execute(ServerCommandSource source, boolean dayLock) {

src/main/java/com/thepinkhacker/commandsplus/server/command/GameRulePresetCommand.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public class GameRulePresetCommand implements CommandRegistrationCallback {
2020
@Override
2121
public void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment environment) {
2222
dispatcher.register(CommandManager.literal("gamerulepreset")
23+
.requires(source -> source.hasPermissionLevel(2))
2324
.then(CommandManager.literal("save")
2425
.requires(source -> source.hasPermissionLevel(4))
2526
.then(CommandManager.argument("preset", GameRulePresetArgumentType.preset())
@@ -30,7 +31,6 @@ public void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandR
3031
)
3132
)
3233
.then(CommandManager.literal("load")
33-
.requires(source -> source.hasPermissionLevel(2))
3434
.then(CommandManager.argument("preset", GameRulePresetArgumentType.preset())
3535
.executes(context -> load(
3636
context.getSource(),

src/main/java/com/thepinkhacker/commandsplus/server/command/HeadCommand.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,15 @@
3131
import java.util.Collection;
3232

3333
public class HeadCommand implements CommandRegistrationCallback {
34+
private final int PERMISSION_LEVEL = 2;
35+
3436
private static final SimpleCommandExceptionType GIVE_EXCEPTION = new SimpleCommandExceptionType(Text.translatable("commands.head.give.fail"));
3537

3638
@Override
3739
public void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment environment) {
3840
LiteralCommandNode<ServerCommandSource> node = dispatcher.register(CommandManager.literal("head")
3941
.then(CommandManager.literal("give")
40-
.requires(source -> source.hasPermissionLevel(2))
42+
.requires(source -> source.hasPermissionLevel(PERMISSION_LEVEL))
4143
.then(CommandManager.argument("targets", EntityArgumentType.players())
4244
.then(CommandManager.argument("player", GameProfileArgumentType.gameProfile())
4345
.executes(context -> give(

src/main/java/com/thepinkhacker/commandsplus/server/command/HealthCommand.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@
1919
import java.util.Collection;
2020

2121
public class HealthCommand implements CommandRegistrationCallback {
22+
private final int PERMISSION_LEVEL = 2;
23+
2224
@Override
2325
public void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment environment) {
2426
LiteralCommandNode<ServerCommandSource> node = dispatcher.register(CommandManager.literal("health")
25-
.requires(source -> source.hasPermissionLevel(2))
27+
.requires(source -> source.hasPermissionLevel(PERMISSION_LEVEL))
2628
.then(CommandManager.literal("set")
2729
.then(CommandManager.argument("health", FloatArgumentType.floatArg(0.0f))
2830
.executes(context -> setHealth(
@@ -68,7 +70,7 @@ public void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandR
6870
)
6971
);
7072

71-
AliasUtils.createAlias(dispatcher, node, "hp");
73+
AliasUtils.createAlias(dispatcher, node, "hp", PERMISSION_LEVEL);
7274
}
7375

7476
private static int setHealth(ServerCommandSource source, Collection<? extends Entity> entities, float health) throws CommandSyntaxException {

src/main/java/com/thepinkhacker/commandsplus/server/command/HungerCommand.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@
2121
import java.util.Objects;
2222

2323
public class HungerCommand implements CommandRegistrationCallback {
24+
private final int PERMISSION_LEVEL = 2;
25+
2426
@Override
2527
public void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment environment) {
2628
LiteralCommandNode<ServerCommandSource> node = dispatcher.register(CommandManager.literal("hunger")
27-
.requires(source -> source.hasPermissionLevel(2))
29+
.requires(source -> source.hasPermissionLevel(PERMISSION_LEVEL))
2830
.then(CommandManager.literal("set")
2931
.then(CommandManager.literal("food")
3032
.then(CommandManager.argument("food", IntegerArgumentType.integer(0))
@@ -193,7 +195,7 @@ public void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandR
193195
)
194196
);
195197

196-
AliasUtils.createAlias(dispatcher, node, "food");
198+
AliasUtils.createAlias(dispatcher, node, "food", PERMISSION_LEVEL);
197199
}
198200

199201
private static int setFood(ServerCommandSource source, Collection<ServerPlayerEntity> players, int food) throws CommandSyntaxException {

src/main/java/com/thepinkhacker/commandsplus/server/command/RideCommand.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import java.util.Collection;
2828

2929
public class RideCommand implements CommandRegistrationCallback {
30+
private final int PERMISSION_LEVEL = 2;
31+
3032
private static final SimpleCommandExceptionType START_RIDING_FAILED = new SimpleCommandExceptionType(Text.translatable("commands.cpride.start_riding.fail"));
3133
private static final SimpleCommandExceptionType STOP_RIDING_FAILED = new SimpleCommandExceptionType(Text.translatable("commands.cpride.stop_riding.fail"));
3234
private static final SimpleCommandExceptionType EVICT_RIDERS_FAILED = new SimpleCommandExceptionType(Text.translatable("commands.cpride.evict_riders.fail"));
@@ -42,7 +44,7 @@ public void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandR
4244
* - rideRules
4345
*/
4446
LiteralCommandNode<ServerCommandSource> node = dispatcher.register(CommandManager.literal("cpride")
45-
.requires(source -> source.hasPermissionLevel(2))
47+
.requires(source -> source.hasPermissionLevel(PERMISSION_LEVEL))
4648
.then(CommandManager.argument("riders", EntityArgumentType.entities())
4749
.then(CommandManager.literal("start_riding")
4850
.then(CommandManager.argument("ride", EntityArgumentType.entity())
@@ -96,7 +98,7 @@ public void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandR
9698
)
9799
);
98100

99-
AliasUtils.createAlias(dispatcher, node, "mount");
101+
AliasUtils.createAlias(dispatcher, node, "mount", PERMISSION_LEVEL);
100102
}
101103

102104
/**

src/main/java/com/thepinkhacker/commandsplus/server/command/SetOwnerCommand.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@
1818
import java.util.Collection;
1919

2020
public class SetOwnerCommand implements CommandRegistrationCallback {
21+
private final int PERMISSION_LEVEL = 2;
22+
2123
@Override
2224
public void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment environment) {
2325
LiteralCommandNode<ServerCommandSource> node = dispatcher.register(CommandManager.literal("setowner")
24-
.requires(source -> source.hasPermissionLevel(2))
26+
.requires(source -> source.hasPermissionLevel(PERMISSION_LEVEL))
2527
.then(CommandManager.argument("pets", EntityArgumentType.entities())
2628
.then(CommandManager.argument("player", EntityArgumentType.player())
2729
.executes(context -> setOwner(
@@ -37,7 +39,7 @@ public void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandR
3739
)
3840
);
3941

40-
AliasUtils.createAlias(dispatcher, node, "tame");
42+
AliasUtils.createAlias(dispatcher, node, "tame", PERMISSION_LEVEL);
4143
}
4244

4345
private static int setOwner(ServerCommandSource source, Collection<? extends Entity> entities, ServerPlayerEntity player) throws CommandSyntaxException {

src/main/java/com/thepinkhacker/commandsplus/util/command/AliasUtils.java

+14
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,21 @@ public static void createAlias(CommandDispatcher<ServerCommandSource> dispatcher
1111
dispatcher.register(CommandManager.literal(alias).redirect(dispatcher.getRoot().getChild(original)));
1212
}
1313

14+
public static void createAlias(CommandDispatcher<ServerCommandSource> dispatcher, String original, String alias, int permissionLevel) {
15+
dispatcher.register(CommandManager.literal(alias)
16+
.redirect(dispatcher.getRoot().getChild(original))
17+
.requires(source -> source.hasPermissionLevel(permissionLevel))
18+
);
19+
}
20+
1421
public static void createAlias(CommandDispatcher<ServerCommandSource> dispatcher, LiteralCommandNode<ServerCommandSource> original, String alias) {
1522
dispatcher.register(CommandManager.literal(alias).redirect(original));
1623
}
24+
25+
public static void createAlias(CommandDispatcher<ServerCommandSource> dispatcher, LiteralCommandNode<ServerCommandSource> original, String alias, int permissionLevel) {
26+
dispatcher.register(CommandManager.literal(alias)
27+
.redirect(original)
28+
.requires(source -> source.hasPermissionLevel(permissionLevel))
29+
);
30+
}
1731
}

0 commit comments

Comments
 (0)