Skip to content

Commit 894ec18

Browse files
Remove aliases
1 parent 3670ce2 commit 894ec18

15 files changed

+34
-108
lines changed

src/main/java/com/thepinkhacker/decree/Decree.java

-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import com.thepinkhacker.decree.server.command.*;
66
import com.thepinkhacker.decree.server.dedicated.command.CommandRegistrationCallbackDedicated;
77
import com.thepinkhacker.decree.server.dedicated.command.StopCommand;
8-
import com.thepinkhacker.decree.util.command.DecreeUtils;
98
import com.thepinkhacker.decree.world.DecreeGameRules;
109
import net.fabricmc.api.ModInitializer;
1110
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
@@ -43,10 +42,6 @@ public void onInitialize() {
4342
new StopCommand()
4443
);
4544

46-
// Aliases
47-
DecreeUtils.createAlias(dispatcher, "gamemode", "gm", 2);
48-
DecreeUtils.createAlias(dispatcher, "help", "?");
49-
5045
LOGGER.info("Registered commands+.");
5146
});
5247
}

src/main/java/com/thepinkhacker/decree/data/command/CommandConfig.java

+3-5
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@
22

33
public class CommandConfig {
44
public final CommandPrefix prefix;
5-
public final String[] aliases;
65

7-
private CommandConfig(CommandPrefix prefix, String[] aliases) {
6+
private CommandConfig(CommandPrefix prefix) {
87
this.prefix = prefix;
9-
this.aliases = aliases;
108
}
119

12-
public static CommandConfig of(CommandPrefix prefix, String[] aliases) {
13-
return new CommandConfig(prefix, aliases);
10+
public static CommandConfig of(CommandPrefix prefix) {
11+
return new CommandConfig(prefix);
1412
}
1513
}

src/main/java/com/thepinkhacker/decree/server/command/ClearSpawnPointCommand.java

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

1919
public class ClearSpawnPointCommand implements CommandRegistrationCallback {
20-
private static final int PERMISSION = 2;
21-
2220
@Override
2321
public void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment environment) {
24-
DecreeUtils.register(dispatcher, CommandConfigs.CLEAR_SPAWN_POINT, PERMISSION, command -> command
25-
.requires(source -> source.hasPermissionLevel(PERMISSION))
22+
DecreeUtils.register(dispatcher, CommandConfigs.CLEAR_SPAWN_POINT, command -> command
23+
.requires(source -> source.hasPermissionLevel(2))
2624
.then(CommandManager.argument("targets", EntityArgumentType.players())
2725
.executes(context -> clearSpawnPoint(
2826
context.getSource(),

src/main/java/com/thepinkhacker/decree/server/command/CommandConfigs.java

+9-9
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,27 @@
1111

1212
public class CommandConfigs {
1313
public static final RegistryKey<CommandConfig> CLEAR_SPAWN_POINT = register("clearspawnpoint");
14-
public static final RegistryKey<CommandConfig> DAY_LOCK = register("daylock", "alwaysday");
14+
public static final RegistryKey<CommandConfig> DAY_LOCK = register("daylock");
1515
public static final RegistryKey<CommandConfig> GAME_RULE_PRESET = register("gamerulepreset");
16-
public static final RegistryKey<CommandConfig> HEAD = register("head", "skull");
17-
public static final RegistryKey<CommandConfig> HEALTH = register("health", "hp");
18-
public static final RegistryKey<CommandConfig> HUNGER = register("hunger", "food");
16+
public static final RegistryKey<CommandConfig> HEAD = register("head");
17+
public static final RegistryKey<CommandConfig> HEALTH = register("health");
18+
public static final RegistryKey<CommandConfig> HUNGER = register("hunger");
1919
public static final RegistryKey<CommandConfig> NAME = register("name");
20-
public static final RegistryKey<CommandConfig> RIDE = register("ride", false, "mount");
20+
public static final RegistryKey<CommandConfig> RIDE = register("ride", false);
2121
public static final RegistryKey<CommandConfig> SET_OWNER = register("setowner");
2222
public static final RegistryKey<CommandConfig> TOGGLE_DOWNFALL = register("toggledownfall");
2323
public static final RegistryKey<CommandConfig> STOP = register("stop", false);
2424

25-
private static RegistryKey<CommandConfig> register(String id, String... aliases) {
26-
return register(id, true, aliases);
25+
private static RegistryKey<CommandConfig> register(String id) {
26+
return register(id, true);
2727
}
2828

29-
private static RegistryKey<CommandConfig> register(String id, boolean prefixOptional, String... aliases) {
29+
private static RegistryKey<CommandConfig> register(String id, boolean prefixOptional) {
3030
Identifier decreeId = Decree.id(id);
3131
Registry.register(
3232
DecreeRegistries.COMMAND_CONFIG,
3333
decreeId,
34-
CommandConfig.of(CommandPrefix.of(decreeId.getNamespace(), prefixOptional), aliases)
34+
CommandConfig.of(CommandPrefix.of(decreeId.getNamespace(), prefixOptional))
3535
);
3636
return RegistryKey.of(DecreeRegistryKeys.COMMAND_CONFIG, decreeId);
3737
}

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

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

1414
public class DayLockCommand implements CommandRegistrationCallback {
15-
private final int PERMISSION_LEVEL = 2;
16-
1715
@Override
1816
public void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment environment) {
19-
LiteralCommandNode<ServerCommandSource> node = DecreeUtils.register(dispatcher, CommandConfigs.DAY_LOCK, PERMISSION_LEVEL, command -> command
20-
.requires(source -> source.hasPermissionLevel(PERMISSION_LEVEL))
17+
LiteralCommandNode<ServerCommandSource> node = DecreeUtils.register(dispatcher, CommandConfigs.DAY_LOCK, command -> command
18+
.requires(source -> source.hasPermissionLevel(2))
2119
.then(CommandManager.argument("lock", BoolArgumentType.bool())
2220
.executes(context -> execute(
2321
context.getSource(),

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

+2-3
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@
1616
import java.nio.file.Path;
1717

1818
public class GameRulePresetCommand implements CommandRegistrationCallback {
19-
private static final int PERMISSION = 2;
2019
private static final DynamicCommandExceptionType FAILED_TO_LOAD_EXCEPTION = new DynamicCommandExceptionType(preset -> Text.translatable("commands.decree.gamerulepreset.load.fail", preset));
2120

2221
@Override
2322
public void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment environment) {
24-
DecreeUtils.register(dispatcher, CommandConfigs.GAME_RULE_PRESET, PERMISSION, command -> command
25-
.requires(source -> source.hasPermissionLevel(PERMISSION))
23+
DecreeUtils.register(dispatcher, CommandConfigs.GAME_RULE_PRESET, command -> command
24+
.requires(source -> source.hasPermissionLevel(2))
2625
.then(CommandManager.literal("save")
2726
.requires(source -> source.hasPermissionLevel(4))
2827
.then(CommandManager.argument("preset", GameRulePresetArgumentType.preset())

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

+2-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import com.mojang.brigadier.exceptions.CommandSyntaxException;
66
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
77
import com.mojang.brigadier.tree.LiteralCommandNode;
8-
import com.thepinkhacker.decree.data.command.CommandConfig;
98
import com.thepinkhacker.decree.util.command.DecreeUtils;
109
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
1110
import net.minecraft.block.entity.SkullBlockEntity;
@@ -32,15 +31,14 @@
3231
import java.util.Collection;
3332

3433
public class HeadCommand implements CommandRegistrationCallback {
35-
private final int PERMISSION_LEVEL = 2;
3634

3735
private static final SimpleCommandExceptionType GIVE_EXCEPTION = new SimpleCommandExceptionType(Text.translatable("commands.decree.head.give.failed"));
3836

3937
@Override
4038
public void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment environment) {
41-
LiteralCommandNode<ServerCommandSource> node = DecreeUtils.register(dispatcher, CommandConfigs.HEAD, PERMISSION_LEVEL, command -> command
39+
LiteralCommandNode<ServerCommandSource> node = DecreeUtils.register(dispatcher, CommandConfigs.HEAD, command -> command
4240
.then(CommandManager.literal("give")
43-
.requires(source -> source.hasPermissionLevel(PERMISSION_LEVEL))
41+
.requires(source -> source.hasPermissionLevel(2))
4442
.then(CommandManager.argument("targets", EntityArgumentType.players())
4543
.then(CommandManager.argument("player", GameProfileArgumentType.gameProfile())
4644
.executes(context -> give(

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

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

2121
public class HealthCommand implements CommandRegistrationCallback {
22-
private final int PERMISSION_LEVEL = 2;
23-
2422
@Override
2523
public void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment environment) {
26-
LiteralCommandNode<ServerCommandSource> node = DecreeUtils.register(dispatcher, CommandConfigs.HEALTH, PERMISSION_LEVEL, command -> command
27-
.requires(source -> source.hasPermissionLevel(PERMISSION_LEVEL))
24+
LiteralCommandNode<ServerCommandSource> node = DecreeUtils.register(dispatcher, CommandConfigs.HEALTH, command -> command
25+
.requires(source -> source.hasPermissionLevel(2))
2826
.then(CommandManager.literal("set")
2927
.then(CommandManager.argument("health", FloatArgumentType.floatArg(0.0f))
3028
.executes(context -> setHealth(
@@ -69,8 +67,6 @@ public void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandR
6967
.executes(context -> queryHealth(context.getSource()))
7068
)
7169
);
72-
73-
DecreeUtils.createAlias(dispatcher, node, "hp", PERMISSION_LEVEL);
7470
}
7571

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

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

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

2323
public class HungerCommand implements CommandRegistrationCallback {
24-
private final int PERMISSION_LEVEL = 2;
25-
2624
@Override
2725
public void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment environment) {
28-
LiteralCommandNode<ServerCommandSource> node = DecreeUtils.register(dispatcher, CommandConfigs.HUNGER, PERMISSION_LEVEL, command -> command
29-
.requires(source -> source.hasPermissionLevel(PERMISSION_LEVEL))
26+
LiteralCommandNode<ServerCommandSource> node = DecreeUtils.register(dispatcher, CommandConfigs.HUNGER, command -> command
27+
.requires(source -> source.hasPermissionLevel(2))
3028
.then(CommandManager.literal("set")
3129
.then(CommandManager.literal("food")
3230
.then(CommandManager.argument("food", IntegerArgumentType.integer(0))

src/main/java/com/thepinkhacker/decree/server/command/NameCommand.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import java.util.Collection;
2222

2323
public class NameCommand implements CommandRegistrationCallback {
24-
private static final int PERMISSION = 2;
2524
public static final SimpleCommandExceptionType ITEM_FAILED = new SimpleCommandExceptionType(Text.translatable("commands.decree.name.item.name.failed"));
2625
public static final SimpleCommandExceptionType ITEM_REMOVE_FAILED = new SimpleCommandExceptionType(Text.translatable("commands.decree.name.item.remove.failed"));
2726
public static final SimpleCommandExceptionType ENTITY_FAILED = new SimpleCommandExceptionType(Text.translatable("commands.decree.name.entity.name.failed"));
@@ -33,8 +32,8 @@ public void register(
3332
CommandRegistryAccess registryAccess,
3433
CommandManager.RegistrationEnvironment environment
3534
) {
36-
DecreeUtils.register(dispatcher, CommandConfigs.NAME, PERMISSION, command -> command
37-
.requires(source -> source.hasPermissionLevel(PERMISSION))
35+
DecreeUtils.register(dispatcher, CommandConfigs.NAME, command -> command
36+
.requires(source -> source.hasPermissionLevel(2))
3837
.then(CommandManager.literal("item")
3938
.then(CommandManager.argument("targets", EntityArgumentType.entities())
4039
.executes(context -> removeNameItem(

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

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

2929
public class RideCommand implements CommandRegistrationCallback {
30-
private final int PERMISSION_LEVEL = 2;
3130
private static final SimpleCommandExceptionType START_RIDING_FAILED = new SimpleCommandExceptionType(Text.translatable("commands.decree.ride.start_riding.failed"));
3231
private static final SimpleCommandExceptionType STOP_RIDING_FAILED = new SimpleCommandExceptionType(Text.translatable("commands.decree.ride.stop_riding.failed"));
3332
private static final SimpleCommandExceptionType EVICT_RIDERS_FAILED = new SimpleCommandExceptionType(Text.translatable("commands.decree.ride.evict_riders.failed"));
@@ -42,8 +41,8 @@ public void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandR
4241
* - nameTag
4342
* - rideRules
4443
*/
45-
LiteralCommandNode<ServerCommandSource> node = DecreeUtils.register(dispatcher, CommandConfigs.RIDE, PERMISSION_LEVEL, command -> command
46-
.requires(source -> source.hasPermissionLevel(PERMISSION_LEVEL))
44+
LiteralCommandNode<ServerCommandSource> node = DecreeUtils.register(dispatcher, CommandConfigs.RIDE, command -> command
45+
.requires(source -> source.hasPermissionLevel(2))
4746
.then(CommandManager.argument("riders", EntityArgumentType.entities())
4847
.then(CommandManager.literal("start_riding")
4948
.then(CommandManager.argument("ride", EntityArgumentType.entity())

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

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

2020
public class SetOwnerCommand implements CommandRegistrationCallback {
21-
private final int PERMISSION_LEVEL = 2;
22-
2321
@Override
2422
public void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment environment) {
25-
LiteralCommandNode<ServerCommandSource> node = DecreeUtils.register(dispatcher, CommandConfigs.SET_OWNER, PERMISSION_LEVEL, command -> command
26-
.requires(source -> source.hasPermissionLevel(PERMISSION_LEVEL))
23+
LiteralCommandNode<ServerCommandSource> node = DecreeUtils.register(dispatcher, CommandConfigs.SET_OWNER, command -> command
24+
.requires(source -> source.hasPermissionLevel(2))
2725
.then(CommandManager.argument("pets", EntityArgumentType.entities())
2826
.then(CommandManager.argument("player", EntityArgumentType.player())
2927
.executes(context -> setOwner(
@@ -38,8 +36,6 @@ public void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandR
3836
)
3937
)
4038
);
41-
42-
DecreeUtils.createAlias(dispatcher, node, "tame", PERMISSION_LEVEL);
4339
}
4440

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

src/main/java/com/thepinkhacker/decree/server/command/ToggleDownfallCommand.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@
1010
import net.minecraft.text.Text;
1111

1212
public class ToggleDownfallCommand implements CommandRegistrationCallback {
13-
private static final int PERMISSION = 2;
14-
1513
@Override
1614
public void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment environment) {
17-
DecreeUtils.register(dispatcher, CommandConfigs.TOGGLE_DOWNFALL, PERMISSION, command -> command
18-
.requires(source -> source.hasPermissionLevel(PERMISSION))
15+
DecreeUtils.register(dispatcher, CommandConfigs.TOGGLE_DOWNFALL, command -> command
16+
.requires(source -> source.hasPermissionLevel(2))
1917
.executes(context -> execute(context.getSource()))
2018
);
2119
}

src/main/java/com/thepinkhacker/decree/server/dedicated/command/StopCommand.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,13 @@
1616
import net.minecraft.text.Text;
1717

1818
public class StopCommand implements CommandRegistrationCallbackDedicated {
19-
private static final int PERMISSION = 4;
2019
private static volatile int timeLeft;
2120
private static final SimpleCommandExceptionType FAILED_CANCEL = new SimpleCommandExceptionType(Text.translatable("commands.decree.stop.cancel.failed"));
2221

2322
@Override
2423
public void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment environment) {
25-
DecreeUtils.register(dispatcher, CommandConfigs.STOP, PERMISSION, command -> command
26-
.requires(source -> source.hasPermissionLevel(PERMISSION))
24+
DecreeUtils.register(dispatcher, CommandConfigs.STOP, command -> command
25+
.requires(source -> source.hasPermissionLevel(4))
2726
.then(CommandManager.literal("cancel")
2827
.executes(context -> cancel())
2928
)

src/main/java/com/thepinkhacker/decree/util/command/DecreeUtils.java

-45
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,19 @@
33
import com.mojang.brigadier.CommandDispatcher;
44
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
55
import com.mojang.brigadier.tree.LiteralCommandNode;
6-
import com.thepinkhacker.decree.Decree;
76
import com.thepinkhacker.decree.data.command.CommandConfig;
87
import com.thepinkhacker.decree.registry.DecreeRegistries;
9-
import net.minecraft.registry.Registry;
108
import net.minecraft.registry.RegistryKey;
119
import net.minecraft.server.command.CommandManager;
1210
import net.minecraft.server.command.ServerCommandSource;
1311

14-
import java.util.Optional;
1512
import java.util.function.Function;
1613

1714
public class DecreeUtils {
1815
public static LiteralCommandNode<ServerCommandSource> register(
1916
CommandDispatcher<ServerCommandSource> dispatcher,
2017
RegistryKey<CommandConfig> key,
2118
Function<LiteralArgumentBuilder<ServerCommandSource>, LiteralArgumentBuilder<ServerCommandSource>> command
22-
) {
23-
return register(dispatcher, key, 0, command);
24-
}
25-
26-
public static LiteralCommandNode<ServerCommandSource> register(
27-
CommandDispatcher<ServerCommandSource> dispatcher,
28-
RegistryKey<CommandConfig> key,
29-
int permissionLevel,
30-
Function<LiteralArgumentBuilder<ServerCommandSource>, LiteralArgumentBuilder<ServerCommandSource>> command
3119
) {
3220
// TODO: Check for collisions
3321
LiteralArgumentBuilder<ServerCommandSource> builtCommand = command.apply(CommandManager.literal(key.getValue().getPath()));
@@ -37,39 +25,6 @@ public static LiteralCommandNode<ServerCommandSource> register(
3725
dispatcher.register(builtCommand);
3826
}
3927

40-
if (permissionLevel == 0) {
41-
for (String alias : config.aliases) {
42-
createAlias(dispatcher, builtCommand.getLiteral(), alias);
43-
}
44-
} else {
45-
for (String alias : config.aliases) {
46-
createAlias(dispatcher, builtCommand.getLiteral(), alias, permissionLevel);
47-
}
48-
}
49-
5028
return dispatcher.register(CommandManager.literal(config.prefix.prefix).then(builtCommand));
5129
}
52-
53-
// TODO: Fix issue with blank aliases
54-
public static void createAlias(CommandDispatcher<ServerCommandSource> dispatcher, String original, String alias) {
55-
dispatcher.register(CommandManager.literal(alias).redirect(dispatcher.getRoot().getChild(original)));
56-
}
57-
58-
public static void createAlias(CommandDispatcher<ServerCommandSource> dispatcher, String original, String alias, int permissionLevel) {
59-
dispatcher.register(CommandManager.literal(alias)
60-
.redirect(dispatcher.getRoot().getChild(original))
61-
.requires(source -> source.hasPermissionLevel(permissionLevel))
62-
);
63-
}
64-
65-
public static void createAlias(CommandDispatcher<ServerCommandSource> dispatcher, LiteralCommandNode<ServerCommandSource> original, String alias) {
66-
dispatcher.register(CommandManager.literal(alias).redirect(original));
67-
}
68-
69-
public static void createAlias(CommandDispatcher<ServerCommandSource> dispatcher, LiteralCommandNode<ServerCommandSource> original, String alias, int permissionLevel) {
70-
dispatcher.register(CommandManager.literal(alias)
71-
.redirect(original)
72-
.requires(source -> source.hasPermissionLevel(permissionLevel))
73-
);
74-
}
7530
}

0 commit comments

Comments
 (0)