Skip to content

Commit

Permalink
Add new group option
Browse files Browse the repository at this point in the history
  • Loading branch information
samolego committed Jun 9, 2022
1 parent 63062dc commit b330c42
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,51 +53,54 @@ public static void registerNode(CommandDispatcher<CommandSourceStack> dispatcher
)
.then(literal("group")
.requires(src -> Taterzens.getInstance().getPlatform().checkPermission(src, "taterzens.npc.edit.commands.group", config.perms.npcCommandPermissionLevel))
.then(argument("group number", IntegerArgumentType.integer(0))
.then(literal("delete")
.requires(src -> Taterzens.getInstance().getPlatform().checkPermission(src, "taterzens.npc.edit.commands.group.delete", config.perms.npcCommandPermissionLevel))
.executes(CommandsCommand::deleteGroup)
)
.then(literal("removeCommand")
.requires(src -> Taterzens.getInstance().getPlatform().checkPermission(src, "taterzens.npc.edit.commands.remove", config.perms.npcCommandPermissionLevel))
.then(argument("command id", IntegerArgumentType.integer()).executes(CommandsCommand::removeCommandFromGroup))
)
.then(literal("add")
.requires(src -> Taterzens.getInstance().getPlatform().checkPermission(src, "taterzens.npc.edit.commands.add", config.perms.npcCommandPermissionLevel))
.then(literal("minecraft")
.requires(src -> Taterzens.getInstance().getPlatform().checkPermission(src, "taterzens.npc.edit.commands.add.minecraft", config.perms.npcCommandPermissionLevel))
.redirect(dispatcher.getRoot(), context -> {
// Really ugly, but ... works :P
String cmd = addCommand(context);
throw new SimpleCommandExceptionType(
cmd == null ?
noSelectedTaterzenError() :
joinText("taterzens.command.commands.set", ChatFormatting.GOLD, ChatFormatting.GRAY, "/" + cmd)
).create();
})
.then(literal("new").executes(CommandsCommand::newGroup))
.then(literal("id")
.then(argument("group number", IntegerArgumentType.integer(0))
.then(literal("delete")
.requires(src -> Taterzens.getInstance().getPlatform().checkPermission(src, "taterzens.npc.edit.commands.group.delete", config.perms.npcCommandPermissionLevel))
.executes(CommandsCommand::deleteGroup)
)
.then(literal("bungee")
.requires(src -> Taterzens.getInstance().getPlatform().checkPermission(src, "taterzens.npc.edit.commands.add.bungee", config.perms.npcCommandPermissionLevel))
.then(argument("command", string())
.suggests(BUNGEE_COMMANDS)
.then(argument("player", string())
.suggests(PLAYERS)
.then(argument("argument", string())
.suggests((context, builder) -> SharedSuggestionProvider.suggest(AVAILABLE_SERVERS, builder))
.then(literal("removeCommand")
.requires(src -> Taterzens.getInstance().getPlatform().checkPermission(src, "taterzens.npc.edit.commands.remove", config.perms.npcCommandPermissionLevel))
.then(argument("command id", IntegerArgumentType.integer()).executes(CommandsCommand::removeCommandFromGroup))
)
.then(literal("add")
.requires(src -> Taterzens.getInstance().getPlatform().checkPermission(src, "taterzens.npc.edit.commands.add", config.perms.npcCommandPermissionLevel))
.then(literal("minecraft")
.requires(src -> Taterzens.getInstance().getPlatform().checkPermission(src, "taterzens.npc.edit.commands.add.minecraft", config.perms.npcCommandPermissionLevel))
.redirect(dispatcher.getRoot(), context -> {
// Really ugly, but ... works :P
String cmd = addCommand(context);
throw new SimpleCommandExceptionType(
cmd == null ?
noSelectedTaterzenError() :
joinText("taterzens.command.commands.set", ChatFormatting.GOLD, ChatFormatting.GRAY, "/" + cmd)
).create();
})
)
.then(literal("bungee")
.requires(src -> Taterzens.getInstance().getPlatform().checkPermission(src, "taterzens.npc.edit.commands.add.bungee", config.perms.npcCommandPermissionLevel))
.then(argument("command", string())
.suggests(BUNGEE_COMMANDS)
.then(argument("player", string())
.suggests(PLAYERS)
.then(argument("argument", string())
.suggests((context, builder) -> SharedSuggestionProvider.suggest(AVAILABLE_SERVERS, builder))
.executes(CommandsCommand::addBungeeCommand)
)
.executes(CommandsCommand::addBungeeCommand)
)
.executes(CommandsCommand::addBungeeCommand)
)
)
)
)
.then(literal("clear")
.requires(src -> Taterzens.getInstance().getPlatform().checkPermission(src, "taterzens.npc.edit.commands.clear", config.perms.npcCommandPermissionLevel))
.executes(CommandsCommand::clearGroupCommands)
)
.then(literal("list")
.requires(src -> Taterzens.getInstance().getPlatform().checkPermission(src, "taterzens.npc.edit.commands.list", config.perms.npcCommandPermissionLevel))
.executes(CommandsCommand::listGroupCommands)
.then(literal("clear")
.requires(src -> Taterzens.getInstance().getPlatform().checkPermission(src, "taterzens.npc.edit.commands.clear", config.perms.npcCommandPermissionLevel))
.executes(CommandsCommand::clearGroupCommands)
)
.then(literal("list")
.requires(src -> Taterzens.getInstance().getPlatform().checkPermission(src, "taterzens.npc.edit.commands.list", config.perms.npcCommandPermissionLevel))
.executes(CommandsCommand::listGroupCommands)
)
)
)
)
Expand Down Expand Up @@ -144,6 +147,14 @@ public static void registerNode(CommandDispatcher<CommandSourceStack> dispatcher
editNode.addChild(commandsNode);
}

private static int newGroup(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
CommandSourceStack source = context.getSource();
return NpcCommand.selectedTaterzenExecutor(source.getEntityOrException(), taterzen -> {
int ix = taterzen.getCommandGroups().createGroup();
source.sendSuccess(successText("taterzens.command.commands.group.created", String.valueOf(ix + 1)), false);
});
}

private static int listGroupCommands(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
CommandSourceStack source = context.getSource();
int groupIndex = IntegerArgumentType.getInteger(context, "group number") - 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,10 @@ public void fromOldTag(ListTag minecraftCommands, ListTag bungeeCommands) {
}
this.add(cmds);
}

public int createGroup() {
this.add(new ArrayList<>());
this.groupIndex = this.size() - 1;
return this.groupIndex;
}
}
1 change: 1 addition & 0 deletions common/src/main/resources/data/taterzens/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"taterzens.command.commands.group.removed": "Group %s has been removed successfully.",
"taterzens.command.commands.error.group.404": "No group with id %s was found.",
"taterzens.command.commands.group.cleared": "Commands for group %s have been cleared.",
"taterzens.command.commands.group.created": "Successfully switched to new group with index %s.",
"taterzens.command.commands.group": "Command group %s:",
"taterzens.command.preset.export.success": "Taterzen has been exported to %s.",
"taterzens.command.preset.import.success": "Taterzen was successfully loaded from %s.",
Expand Down

0 comments on commit b330c42

Please sign in to comment.