Skip to content

refactor: Brigadier commands - #18

Open
hcesaropz wants to merge 4 commits into
kaboomserver:masterfrom
hcesaropz:refactor/brigadier
Open

refactor: Brigadier commands#18
hcesaropz wants to merge 4 commits into
kaboomserver:masterfrom
hcesaropz:refactor/brigadier

Conversation

@hcesaropz

Copy link
Copy Markdown

No description provided.

@amyavi amyavi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a maintainer, but here's my review

import java.util.List;

public interface BrigadierCommand {
String getLabel();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spaces, not tabs

private final PlayerControl controlModule;

public CommandIcu(final PlayerControl controlModule) {
public CommandIcu(PlayerControl controlModule) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this final here dropped?

Comment on lines +26 to +33
TranslationStore.StringBased<MessageFormat> store =
TranslationStore.messageFormat(
Key.key("icontrolu", "translations")
);
ResourceBundle english = ResourceBundle.getBundle("lang.messages", Locale.US);
store.registerAll(Locale.US, english, true);
GlobalTranslator.translator().addSource(store);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given translations are not being used, this isn't required.

= Commands.literal(command.getLabel());
command.build(builder);
registrar.register(
builder.build(),command.getDescription(),command.getAliases()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spaces after the commas, please

Comment thread src/main/resources/plugin.yml Outdated
description: Control another player's movements, inventory and chat
permission: icu.command
api-version: '26.2'
version: master No newline at end of file

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep the newline at the end of file there

Comment on lines +73 to +76
.requires(src ->
src.getSender().hasPermission("icu.command")
&& src.getSender() instanceof Player
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be restricted, to prevent players from accidentally controlling others when clicking something in chat: https://docs.papermc.io/paper/dev/command-api/basics/requirements/#restricted-commands

Comment thread pom.xml Outdated
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.18.2-R0.1-SNAPSHOT</version>
<version>26.2.build.112-stable</version>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please consider using [26.2.build,) instead so we always target the latest Paper API.


import java.util.List;

public interface BrigadierCommand {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no use for such an interface if we only implement a single command. Additionally, it will be a pain to maintain updates to this interface across projects, if that is the plan, without some shared "common" plugin.

Therefore, I think it would be better to inline the builder, applying such abstractions to Brigadier commands is, in my opinion, a misbegotten attempt to stuff it into a Bukkit-style box.

Please take a look at https://github.com/kaboomserver/commandspy/blob/dd6d940d811d354d7e3a8693b9fef3aeb7b836c2/src/main/java/pw/kaboom/commandspy/Main.java#L59 for an example of such usage.

controlCommand(controller, label, args);
return true;
}
public void build(LiteralArgumentBuilder<CommandSourceStack> builder) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 145 to 151
private static Player getSender(CommandContext<CommandSourceStack> ctx)
throws CommandSyntaxException {
if (ctx.getSource().getSender() instanceof Player player) {
return player;
}
return true;
throw EX_NOT_PLAYER.create();
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The source will always be an instanceof Player, due to the earlier requires check. However, I recognize the utility of this function, so I think that it should be replaced with:

Suggested change
private static Player getSender(CommandContext<CommandSourceStack> ctx)
throws CommandSyntaxException {
if (ctx.getSource().getSender() instanceof Player player) {
return player;
}
return true;
throw EX_NOT_PLAYER.create();
}
private static Player getPlayer(CommandContext<CommandSourceStack> ctx)
return (Player) ctx.getSource().getSender();
}

Comment thread src/main/java/pw/kaboom/icontrolu/Main.java Outdated

if (args[0].equalsIgnoreCase("stop")) {
stopCommand(controller);
private static String getPlayerName(Object player) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wtf?

Co-authored-by: opt <173472493+OptimisticDeving@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants