Skip to content

Commit

Permalink
feat: made /ftbquests open_book available to all players
Browse files Browse the repository at this point in the history
All other /ftbquests subcommands still require op or ftbquests.editor rank

FTBTeam/FTB-Mods-Issues#1466
  • Loading branch information
desht committed Jan 23, 2025
1 parent d01d986 commit 35e37e8
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,8 @@ public class FTBQuestsCommands {
public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
//noinspection ConstantValue
dispatcher.register(Commands.literal("ftbquests")
// s.getServer() *can* be null here, whatever the IDE thinks!
.requires(s -> s.getServer() != null && s.getServer().isSingleplayer() || hasEditorPermission(s))
.then(Commands.literal("editing_mode")
.requires(FTBQuestsCommands::isSSPOrEditor)
.executes(c -> editingMode(c.getSource(), c.getSource().getPlayerOrException(), null))
.then(Commands.argument("enabled", BoolArgumentType.bool())
.executes(c -> editingMode(c.getSource(), c.getSource().getPlayerOrException(), BoolArgumentType.getBool(c, "enabled")))
Expand All @@ -68,6 +67,7 @@ public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
)
)
.then(Commands.literal("locked")
.requires(FTBQuestsCommands::hasEditorPermission)
.executes(c -> locked(c.getSource(), c.getSource().getPlayerOrException(), null))
.then(Commands.argument("enabled", BoolArgumentType.bool())
.executes(c -> locked(c.getSource(), c.getSource().getPlayerOrException(), BoolArgumentType.getBool(c, "enabled")))
Expand All @@ -77,6 +77,7 @@ public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
)
)
.then(Commands.literal("delete_empty_reward_tables")
.requires(FTBQuestsCommands::hasEditorPermission)
.executes(context -> deleteEmptyRewardTables(context.getSource()))
)
.then(Commands.literal("change_progress")
Expand Down Expand Up @@ -131,13 +132,15 @@ public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
)
)
.then(Commands.literal("generate_chapter_with_all_items_in_game")
.requires(FTBQuestsCommands::hasEditorPermission)
.executes(context -> generateAllItemChapter(context.getSource()))
)
.then(Commands.literal("reload")
.requires(FTBQuestsCommands::hasEditorPermission)
.executes(context -> doReload(context.getSource()))
)
.then(Commands.literal("block_rewards")
.requires(FTBQuestsCommands::hasEditorPermission)
.executes(c -> toggleRewardBlocking(c.getSource(), c.getSource().getPlayerOrException(), null))
.then(Commands.argument("enabled", BoolArgumentType.bool())
.executes(c -> toggleRewardBlocking(c.getSource(), c.getSource().getPlayerOrException(), BoolArgumentType.getBool(c, "enabled")))
Expand All @@ -159,6 +162,12 @@ public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
);
}

private static boolean isSSPOrEditor(CommandSourceStack s) {
// s.getServer() *can* be null here, whatever the IDE thinks!
//noinspection ConstantValue
return s.getServer() != null && s.getServer().isSingleplayer() || hasEditorPermission(s);
}

private static boolean hasEditorPermission(CommandSourceStack stack) {
//noinspection DataFlowIssue
return stack.hasPermission(2)
Expand Down

0 comments on commit 35e37e8

Please sign in to comment.