Skip to content

Commit 2ef7db2

Browse files
committed
Configurable commands, clean up some lang files
1 parent 729aa49 commit 2ef7db2

File tree

7 files changed

+32
-14
lines changed

7 files changed

+32
-14
lines changed

src/api/java/dev/compactmods/machines/api/core/CMCommands.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
public class CMCommands {
88
public static final ResourceLocation LEVEL_REGISTERED = new ResourceLocation(MOD_ID, "level_registered");
99
public static final ResourceLocation LEVEL_NOT_FOUND = new ResourceLocation(MOD_ID, "level_not_found");
10-
public static final ResourceLocation ROOM_DATA_NOT_FOUND = new ResourceLocation(MOD_ID, "room_data_not_found");
1110

1211
/**
1312
* Used for displaying the number of registered machines via summary commands.
@@ -21,12 +20,7 @@ public class CMCommands {
2120
public static final ResourceLocation ROOM_REG_COUNT = new ResourceLocation(MOD_ID, "room_reg_count");
2221
public static final ResourceLocation NOT_A_MACHINE_BLOCK = new ResourceLocation(MOD_ID, "not_a_machine_block");
2322
public static final ResourceLocation MACHINE_NOT_BOUND = new ResourceLocation(MOD_ID, "machine_not_bound");
24-
public static final ResourceLocation REBIND_HAS_TUNNEL_CONNECTED = new ResourceLocation(MOD_ID, "rebind_tunnel_connected");
2523

26-
public static final ResourceLocation CMD_ROOM_NOT_REGISTERED = new ResourceLocation(MOD_ID, "room_not_registered");
27-
public static final ResourceLocation CMD_MACHINE_NOT_REGISTERED = new ResourceLocation(MOD_ID, "machine_not_registered");
28-
public static final ResourceLocation CMD_BAD_STATE = new ResourceLocation(MOD_ID, "incorrect_machine_state");
29-
public static final ResourceLocation NO_PLAYER_HISTORY = new ResourceLocation(MOD_ID, "no_player_history");
3024
public static final ResourceLocation WRONG_DIMENSION = new ResourceLocation(MOD_ID, "not_in_compact_dimension");
3125
public static final ResourceLocation NOT_IN_COMPACT_DIMENSION = new ResourceLocation(MOD_ID, "not_in_compact_dim");
3226
public static final ResourceLocation FAILED_CMD_FILE_ERROR = new ResourceLocation(MOD_ID, "failed_command_file_error");

src/datagen/java/dev/compactmods/machines/datagen/lang/EnglishLangGenerator.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,10 @@ protected void addTranslations() {
3636
addCommand(CMCommands.FAILED_CMD_FILE_ERROR, "Failed to execute command; there was a file error. Check logs.");
3737
addCommand(CMCommands.MACHINE_NOT_BOUND, "Machine at %s does not have an associated ID.");
3838
addCommand(CMCommands.ROOM_REG_COUNT, "Number of registered rooms: %s");
39-
addCommand(CMCommands.MACHINE_REG_DIM, "Number of registered machines: %s");
39+
addCommand(CMCommands.MACHINE_REG_DIM, "[%s]: %s");
40+
addCommand(CMCommands.MACHINE_REG_TOTAL, "Total: %s");
4041
addCommand(CMCommands.LEVEL_REGISTERED, "Compact Machine dimension found.");
4142
addCommand(CMCommands.LEVEL_NOT_FOUND, "Compact Machine dimension could not be found.");
42-
addCommand(CMCommands.CMD_ROOM_NOT_REGISTERED, "");
43-
addCommand(CMCommands.ROOM_DATA_NOT_FOUND, "");
4443

4544
addAdvancementTranslations();
4645

src/main/java/dev/compactmods/machines/command/subcommand/CMEjectSubcommand.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
public class CMEjectSubcommand {
1616
public static ArgumentBuilder<CommandSourceStack, ?> make() {
1717
return Commands.literal("eject")
18-
.requires(cs -> cs.hasPermission(Commands.LEVEL_GAMEMASTERS))
1918
.executes(CMEjectSubcommand::execExecutingPlayer)
2019
.then(Commands.argument("player", EntityArgument.player())
2120
.executes(CMEjectSubcommand::execSpecificPlayer));

src/main/java/dev/compactmods/machines/command/subcommand/CMGiveMachineSubcommand.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import dev.compactmods.machines.CompactMachines;
77
import dev.compactmods.machines.api.core.CMCommands;
88
import dev.compactmods.machines.command.argument.RoomPositionArgument;
9+
import dev.compactmods.machines.config.ServerConfig;
910
import dev.compactmods.machines.core.MissingDimensionException;
1011
import dev.compactmods.machines.i18n.TranslationUtil;
1112
import dev.compactmods.machines.machine.CompactMachineItem;
@@ -22,7 +23,7 @@ public class CMGiveMachineSubcommand {
2223

2324
public static LiteralArgumentBuilder<CommandSourceStack> make() {
2425
final var subRoot = Commands.literal("give")
25-
.requires(cs -> cs.hasPermission(Commands.LEVEL_GAMEMASTERS));
26+
.requires(cs -> cs.hasPermission(ServerConfig.giveMachineLevel()));
2627

2728
subRoot.then(Commands.argument("player", EntityArgument.player())
2829
.then(Commands.argument("room", RoomPositionArgument.room())

src/main/java/dev/compactmods/machines/command/subcommand/CMRebindSubcommand.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import dev.compactmods.machines.CompactMachines;
77
import dev.compactmods.machines.api.core.CMCommands;
88
import dev.compactmods.machines.command.argument.RoomPositionArgument;
9+
import dev.compactmods.machines.config.ServerConfig;
910
import dev.compactmods.machines.core.Registration;
1011
import dev.compactmods.machines.machine.graph.DimensionMachineGraph;
1112
import dev.compactmods.machines.i18n.TranslationUtil;
@@ -20,7 +21,7 @@ public class CMRebindSubcommand {
2021

2122
public static LiteralArgumentBuilder<CommandSourceStack> make() {
2223
final var subRoot = Commands.literal("rebind")
23-
.requires(cs -> cs.hasPermission(Commands.LEVEL_GAMEMASTERS));
24+
.requires(cs -> cs.hasPermission(ServerConfig.rebindLevel()));
2425

2526
subRoot.then(Commands.argument("pos", BlockPosArgument.blockPos())
2627
.then(Commands.argument("bindTo", RoomPositionArgument.room())

src/main/java/dev/compactmods/machines/command/subcommand/CMSummarySubcommand.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@
1919
public class CMSummarySubcommand {
2020
public static ArgumentBuilder<CommandSourceStack, ?> make() {
2121
return Commands.literal("summary")
22-
// .requires(cs -> cs.hasPermission(Commands.LEVEL_ALL))
2322
.executes(CMSummarySubcommand::exec);
2423
}
2524

26-
private static int exec(CommandContext<CommandSourceStack> ctx) throws CommandSyntaxException {
25+
private static int exec(CommandContext<CommandSourceStack> ctx) {
2726
var src = ctx.getSource();
2827
var serv = src.getServer();
2928

src/main/java/dev/compactmods/machines/config/ServerConfig.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package dev.compactmods.machines.config;
22

33
import com.electronwill.nightconfig.core.EnumGetMethod;
4+
import dev.compactmods.machines.client.level.EmptyLevelEntityGetter;
45
import dev.compactmods.machines.core.EnumMachinePlayersBreakHandling;
6+
import net.minecraft.commands.Commands;
57
import net.minecraftforge.common.ForgeConfigSpec;
68

79
import java.util.Arrays;
@@ -15,6 +17,9 @@ public class ServerConfig {
1517

1618
public static ForgeConfigSpec.IntValue MACHINE_FLOOR_Y;
1719

20+
private static ForgeConfigSpec.IntValue REBIND_LEVEL;
21+
private static ForgeConfigSpec.IntValue GIVE_MACHINE;
22+
1823
static {
1924
generateConfig();
2025
}
@@ -46,6 +51,26 @@ private static void generateConfig() {
4651

4752
builder.pop();
4853

54+
builder
55+
.push("commands")
56+
.push("permLevels")
57+
.comment("Specifies requirements for running administrative commands. Requires a server restart to take effect.")
58+
.comment("0 = ALL, 1 = ADMIN, 2 = OP, 4 = OWNER");
59+
60+
61+
REBIND_LEVEL = builder.defineInRange("rebind", Commands.LEVEL_ALL, Commands.LEVEL_ALL, Commands.LEVEL_OWNERS);
62+
GIVE_MACHINE = builder.defineInRange("give", Commands.LEVEL_ALL, Commands.LEVEL_ALL, Commands.LEVEL_OWNERS);
63+
64+
builder.pop(2);
65+
4966
CONFIG = builder.build();
5067
}
68+
69+
public static int rebindLevel() {
70+
return REBIND_LEVEL.get();
71+
}
72+
73+
public static int giveMachineLevel() {
74+
return GIVE_MACHINE.get();
75+
}
5176
}

0 commit comments

Comments
 (0)