Skip to content

Commit

Permalink
Update aliases to match parent's permission level
Browse files Browse the repository at this point in the history
  • Loading branch information
the-pink-hacker committed Feb 7, 2025
1 parent e69e1d5 commit 868f5d4
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void onInitialize() {
);

// Aliases
AliasUtils.createAlias(dispatcher, "gamemode", "gm");
AliasUtils.createAlias(dispatcher, "gamemode", "gm", 2);
AliasUtils.createAlias(dispatcher, "help", "?");

LOGGER.info("Registered commands+.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
import net.minecraft.world.GameRules;

public class DayLockCommand implements CommandRegistrationCallback {
private final int PERMISSION_LEVEL = 2;
@Override
public void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment environment) {
LiteralCommandNode<ServerCommandSource> node = dispatcher.register(CommandManager.literal("daylock")
.requires(source -> source.hasPermissionLevel(2))
.requires(source -> source.hasPermissionLevel(PERMISSION_LEVEL))
.then(CommandManager.argument("lock", BoolArgumentType.bool())
.executes(context -> execute(
context.getSource(),
Expand All @@ -28,7 +29,7 @@ public void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandR
))
);

AliasUtils.createAlias(dispatcher, node, "alwaysday");
AliasUtils.createAlias(dispatcher, node, "alwaysday", PERMISSION_LEVEL);
}

private static int execute(ServerCommandSource source, boolean dayLock) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class GameRulePresetCommand implements CommandRegistrationCallback {
@Override
public void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment environment) {
dispatcher.register(CommandManager.literal("gamerulepreset")
.requires(source -> source.hasPermissionLevel(2))
.then(CommandManager.literal("save")
.requires(source -> source.hasPermissionLevel(4))
.then(CommandManager.argument("preset", GameRulePresetArgumentType.preset())
Expand All @@ -30,7 +31,6 @@ public void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandR
)
)
.then(CommandManager.literal("load")
.requires(source -> source.hasPermissionLevel(2))
.then(CommandManager.argument("preset", GameRulePresetArgumentType.preset())
.executes(context -> load(
context.getSource(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@
import java.util.Collection;

public class HeadCommand implements CommandRegistrationCallback {
private final int PERMISSION_LEVEL = 2;

private static final SimpleCommandExceptionType GIVE_EXCEPTION = new SimpleCommandExceptionType(Text.translatable("commands.head.give.fail"));

@Override
public void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment environment) {
LiteralCommandNode<ServerCommandSource> node = dispatcher.register(CommandManager.literal("head")
.then(CommandManager.literal("give")
.requires(source -> source.hasPermissionLevel(2))
.requires(source -> source.hasPermissionLevel(PERMISSION_LEVEL))
.then(CommandManager.argument("targets", EntityArgumentType.players())
.then(CommandManager.argument("player", GameProfileArgumentType.gameProfile())
.executes(context -> give(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
import java.util.Collection;

public class HealthCommand implements CommandRegistrationCallback {
private final int PERMISSION_LEVEL = 2;

@Override
public void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment environment) {
LiteralCommandNode<ServerCommandSource> node = dispatcher.register(CommandManager.literal("health")
.requires(source -> source.hasPermissionLevel(2))
.requires(source -> source.hasPermissionLevel(PERMISSION_LEVEL))
.then(CommandManager.literal("set")
.then(CommandManager.argument("health", FloatArgumentType.floatArg(0.0f))
.executes(context -> setHealth(
Expand Down Expand Up @@ -68,7 +70,7 @@ public void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandR
)
);

AliasUtils.createAlias(dispatcher, node, "hp");
AliasUtils.createAlias(dispatcher, node, "hp", PERMISSION_LEVEL);
}

private static int setHealth(ServerCommandSource source, Collection<? extends Entity> entities, float health) throws CommandSyntaxException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
import java.util.Objects;

public class HungerCommand implements CommandRegistrationCallback {
private final int PERMISSION_LEVEL = 2;

@Override
public void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment environment) {
LiteralCommandNode<ServerCommandSource> node = dispatcher.register(CommandManager.literal("hunger")
.requires(source -> source.hasPermissionLevel(2))
.requires(source -> source.hasPermissionLevel(PERMISSION_LEVEL))
.then(CommandManager.literal("set")
.then(CommandManager.literal("food")
.then(CommandManager.argument("food", IntegerArgumentType.integer(0))
Expand Down Expand Up @@ -193,7 +195,7 @@ public void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandR
)
);

AliasUtils.createAlias(dispatcher, node, "food");
AliasUtils.createAlias(dispatcher, node, "food", PERMISSION_LEVEL);
}

private static int setFood(ServerCommandSource source, Collection<ServerPlayerEntity> players, int food) throws CommandSyntaxException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import java.util.Collection;

public class RideCommand implements CommandRegistrationCallback {
private final int PERMISSION_LEVEL = 2;

private static final SimpleCommandExceptionType START_RIDING_FAILED = new SimpleCommandExceptionType(Text.translatable("commands.cpride.start_riding.fail"));
private static final SimpleCommandExceptionType STOP_RIDING_FAILED = new SimpleCommandExceptionType(Text.translatable("commands.cpride.stop_riding.fail"));
private static final SimpleCommandExceptionType EVICT_RIDERS_FAILED = new SimpleCommandExceptionType(Text.translatable("commands.cpride.evict_riders.fail"));
Expand All @@ -42,7 +44,7 @@ public void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandR
* - rideRules
*/
LiteralCommandNode<ServerCommandSource> node = dispatcher.register(CommandManager.literal("cpride")
.requires(source -> source.hasPermissionLevel(2))
.requires(source -> source.hasPermissionLevel(PERMISSION_LEVEL))
.then(CommandManager.argument("riders", EntityArgumentType.entities())
.then(CommandManager.literal("start_riding")
.then(CommandManager.argument("ride", EntityArgumentType.entity())
Expand Down Expand Up @@ -96,7 +98,7 @@ public void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandR
)
);

AliasUtils.createAlias(dispatcher, node, "mount");
AliasUtils.createAlias(dispatcher, node, "mount", PERMISSION_LEVEL);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
import java.util.Collection;

public class SetOwnerCommand implements CommandRegistrationCallback {
private final int PERMISSION_LEVEL = 2;

@Override
public void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment environment) {
LiteralCommandNode<ServerCommandSource> node = dispatcher.register(CommandManager.literal("setowner")
.requires(source -> source.hasPermissionLevel(2))
.requires(source -> source.hasPermissionLevel(PERMISSION_LEVEL))
.then(CommandManager.argument("pets", EntityArgumentType.entities())
.then(CommandManager.argument("player", EntityArgumentType.player())
.executes(context -> setOwner(
Expand All @@ -37,7 +39,7 @@ public void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandR
)
);

AliasUtils.createAlias(dispatcher, node, "tame");
AliasUtils.createAlias(dispatcher, node, "tame", PERMISSION_LEVEL);
}

private static int setOwner(ServerCommandSource source, Collection<? extends Entity> entities, ServerPlayerEntity player) throws CommandSyntaxException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,21 @@ public static void createAlias(CommandDispatcher<ServerCommandSource> dispatcher
dispatcher.register(CommandManager.literal(alias).redirect(dispatcher.getRoot().getChild(original)));
}

public static void createAlias(CommandDispatcher<ServerCommandSource> dispatcher, String original, String alias, int permissionLevel) {
dispatcher.register(CommandManager.literal(alias)
.redirect(dispatcher.getRoot().getChild(original))
.requires(source -> source.hasPermissionLevel(permissionLevel))
);
}

public static void createAlias(CommandDispatcher<ServerCommandSource> dispatcher, LiteralCommandNode<ServerCommandSource> original, String alias) {
dispatcher.register(CommandManager.literal(alias).redirect(original));
}

public static void createAlias(CommandDispatcher<ServerCommandSource> dispatcher, LiteralCommandNode<ServerCommandSource> original, String alias, int permissionLevel) {
dispatcher.register(CommandManager.literal(alias)
.redirect(original)
.requires(source -> source.hasPermissionLevel(permissionLevel))
);
}
}

0 comments on commit 868f5d4

Please sign in to comment.