Skip to content

Commit cae2e19

Browse files
committed
Change class name from context to command-entry
1 parent 32966de commit cae2e19

13 files changed

Lines changed: 70 additions & 70 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ implementation "cc.dreamcode.command:{platform}:2.1.3"
5252
@Permission("example.permission.base")
5353
// adds console/client requirement to all executors (optional)
5454
@Sender(DreamSender.Type.CLIENT)
55-
// provide command context (label/name, aliases) using annotation @Command
55+
// provide command entry (label/name, aliases) using annotation @Command
5656
// description is used by custom help/usage-builder
5757
@Command(name = "example", description = "Example command.")
5858
public class ExampleCommand implements CommandBase {

bukkit/src/main/java/cc/dreamcode/command/bukkit/BukkitCommandRegistry.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package cc.dreamcode.command.bukkit;
22

3-
import cc.dreamcode.command.CommandContext;
3+
import cc.dreamcode.command.CommandEntry;
44
import cc.dreamcode.command.CommandMeta;
55
import cc.dreamcode.command.CommandRegistry;
66
import lombok.NonNull;
@@ -26,13 +26,13 @@ public BukkitCommandRegistry(@NonNull Plugin plugin, @NonNull BukkitCommandProvi
2626
}
2727

2828
@Override
29-
public void register(@NonNull CommandContext commandContext, @NonNull CommandMeta commandMeta) {
30-
final BukkitCommandWrapper bukkitCommandWrapper = new BukkitCommandWrapper(this.plugin, commandContext, this.bukkitCommandProvider);
31-
this.bukkitCommandMap.register(commandContext.getName(), this.plugin.getName(), bukkitCommandWrapper);
29+
public void register(@NonNull CommandEntry commandEntry, @NonNull CommandMeta commandMeta) {
30+
final BukkitCommandWrapper bukkitCommandWrapper = new BukkitCommandWrapper(this.plugin, commandEntry, this.bukkitCommandProvider);
31+
this.bukkitCommandMap.register(commandEntry.getName(), this.plugin.getName(), bukkitCommandWrapper);
3232
}
3333

3434
@Override
35-
public void unregister(@NonNull CommandContext commandContext) {
36-
this.bukkitCommandMap.getCommand(commandContext.getName()).unregister(this.bukkitCommandMap);
35+
public void unregister(@NonNull CommandEntry commandEntry) {
36+
this.bukkitCommandMap.getCommand(commandEntry.getName()).unregister(this.bukkitCommandMap);
3737
}
3838
}

bukkit/src/main/java/cc/dreamcode/command/bukkit/BukkitCommandWrapper.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package cc.dreamcode.command.bukkit;
22

3-
import cc.dreamcode.command.CommandContext;
3+
import cc.dreamcode.command.CommandEntry;
44
import cc.dreamcode.command.CommandInput;
55
import lombok.NonNull;
66
import org.bukkit.command.Command;
@@ -14,18 +14,18 @@
1414
public class BukkitCommandWrapper extends Command implements PluginIdentifiableCommand {
1515

1616
private final Plugin plugin;
17-
private final CommandContext commandContext;
17+
private final CommandEntry commandEntry;
1818
private final BukkitCommandProvider bukkitCommandProvider;
1919

20-
public BukkitCommandWrapper(@NonNull Plugin plugin, @NonNull CommandContext context, @NonNull BukkitCommandProvider bukkitCommandProvider) {
21-
super(context.getName());
20+
public BukkitCommandWrapper(@NonNull Plugin plugin, @NonNull CommandEntry commandEntry, @NonNull BukkitCommandProvider bukkitCommandProvider) {
21+
super(commandEntry.getName());
2222

2323
this.plugin = plugin;
24-
this.commandContext = context;
24+
this.commandEntry = commandEntry;
2525
this.bukkitCommandProvider = bukkitCommandProvider;
2626

27-
this.setDescription(context.getDescription());
28-
this.setAliases(Arrays.asList(context.getAliases()));
27+
this.setDescription(commandEntry.getDescription());
28+
this.setAliases(Arrays.asList(commandEntry.getAliases()));
2929
}
3030

3131
@Override
@@ -36,7 +36,7 @@ public Plugin getPlugin() {
3636
@Override
3737
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
3838
final BukkitSender bukkitSender = new BukkitSender(sender);
39-
final CommandInput commandInput = new CommandInput(this.commandContext.getName(), args, false);
39+
final CommandInput commandInput = new CommandInput(this.commandEntry.getName(), args, false);
4040

4141
this.bukkitCommandProvider.call(bukkitSender, commandInput);
4242
return true;
@@ -45,7 +45,7 @@ public boolean execute(CommandSender sender, String commandLabel, String[] args)
4545
@Override
4646
public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
4747
final BukkitSender bukkitSender = new BukkitSender(sender);
48-
final CommandInput commandInput = new CommandInput(this.commandContext.getName(), args, false);
48+
final CommandInput commandInput = new CommandInput(this.commandEntry.getName(), args, false);
4949

5050
return this.bukkitCommandProvider.getSuggestion(bukkitSender, commandInput);
5151
}

bungee/src/main/java/cc/dreamcode/command/bungee/BungeeCommandRegistry.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package cc.dreamcode.command.bungee;
22

3-
import cc.dreamcode.command.CommandContext;
3+
import cc.dreamcode.command.CommandEntry;
44
import cc.dreamcode.command.CommandMeta;
55
import cc.dreamcode.command.CommandRegistry;
66
import lombok.NonNull;
@@ -16,17 +16,17 @@ public class BungeeCommandRegistry implements CommandRegistry {
1616
private final BungeeCommandProvider bungeeCommandProvider;
1717

1818
@Override
19-
public void register(@NonNull CommandContext commandContext, @NonNull CommandMeta commandMeta) {
20-
final BungeeCommandWrapper bungeeCommandWrapper = new BungeeCommandWrapper(this.bungeeCommandProvider, commandContext);
19+
public void register(@NonNull CommandEntry commandEntry, @NonNull CommandMeta commandMeta) {
20+
final BungeeCommandWrapper bungeeCommandWrapper = new BungeeCommandWrapper(this.bungeeCommandProvider, commandEntry);
2121
this.plugin.getProxy().getPluginManager().registerCommand(this.plugin, bungeeCommandWrapper);
2222
}
2323

2424
@Override
25-
public void unregister(@NonNull CommandContext commandContext) {
26-
this.bungeeCommandProvider.unregister(commandContext);
25+
public void unregister(@NonNull CommandEntry commandEntry) {
26+
this.bungeeCommandProvider.unregister(commandEntry);
2727
this.plugin.getProxy().getPluginManager().getCommands()
2828
.stream()
29-
.filter(entry -> entry.getKey().equals(commandContext.getName().toLowerCase(Locale.ROOT)))
29+
.filter(entry -> entry.getKey().equals(commandEntry.getName().toLowerCase(Locale.ROOT)))
3030
.forEach(entry -> this.plugin.getProxy().getPluginManager().unregisterCommand(entry.getValue()));
3131
}
3232
}

bungee/src/main/java/cc/dreamcode/command/bungee/BungeeCommandWrapper.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package cc.dreamcode.command.bungee;
22

3-
import cc.dreamcode.command.CommandContext;
3+
import cc.dreamcode.command.CommandEntry;
44
import cc.dreamcode.command.CommandInput;
55
import lombok.NonNull;
66
import net.md_5.bungee.api.CommandSender;
@@ -10,27 +10,27 @@
1010
public class BungeeCommandWrapper extends Command implements TabExecutor {
1111

1212
private final BungeeCommandProvider bungeeCommandProvider;
13-
private final CommandContext commandContext;
13+
private final CommandEntry commandEntry;
1414

15-
public BungeeCommandWrapper(@NonNull BungeeCommandProvider bungeeCommandProvider, @NonNull CommandContext context) {
16-
super(context.getName(), null, context.getAliases());
15+
public BungeeCommandWrapper(@NonNull BungeeCommandProvider bungeeCommandProvider, @NonNull CommandEntry commandEntry) {
16+
super(commandEntry.getName(), null, commandEntry.getAliases());
1717

1818
this.bungeeCommandProvider = bungeeCommandProvider;
19-
this.commandContext = context;
19+
this.commandEntry = commandEntry;
2020
}
2121

2222
@Override
2323
public void execute(CommandSender sender, String[] args) {
2424
final BungeeSender bungeeSender = new BungeeSender(sender);
25-
final CommandInput commandInput = new CommandInput(this.commandContext.getName(), args, false);
25+
final CommandInput commandInput = new CommandInput(this.commandEntry.getName(), args, false);
2626

2727
this.bungeeCommandProvider.call(bungeeSender, commandInput);
2828
}
2929

3030
@Override
3131
public Iterable<String> onTabComplete(CommandSender sender, String[] args) {
3232
final BungeeSender bungeeSender = new BungeeSender(sender);
33-
final CommandInput commandInput = new CommandInput(this.commandContext.getName(), args, false);
33+
final CommandInput commandInput = new CommandInput(this.commandEntry.getName(), args, false);
3434

3535
return this.bungeeCommandProvider.getSuggestion(bungeeSender, commandInput);
3636
}

core/src/main/java/cc/dreamcode/command/CommandArgument.java renamed to core/src/main/java/cc/dreamcode/command/ArgumentEntry.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import lombok.Data;
44

55
@Data
6-
public class CommandArgument {
6+
public class ArgumentEntry {
77

88
private final Type type;
99
private final String value;

core/src/main/java/cc/dreamcode/command/CommandContext.java renamed to core/src/main/java/cc/dreamcode/command/CommandEntry.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77

88
@Data
99
@RequiredArgsConstructor
10-
public class CommandContext {
10+
public class CommandEntry {
1111

1212
private final String name;
1313
private final String[] aliases;
1414
private final String description;
1515

16-
public CommandContext(@NonNull Command command) {
16+
public CommandEntry(@NonNull Command command) {
1717
this.name = command.name();
1818
this.aliases = command.aliases();
1919
this.description = command.description();

core/src/main/java/cc/dreamcode/command/CommandExecutor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public void execute(@NonNull CommandScheduler commandScheduler, @NonNull Resolve
141141
}
142142
}
143143
catch (IllegalAccessException | InvocationTargetException e) {
144-
throw new RuntimeException("Cannot invoke command-path /" + this.commandMeta.getCommandContext().getName() + " " + this.commandPathMeta.getPath(), e);
144+
throw new RuntimeException("Cannot invoke command-path /" + this.commandMeta.getCommandEntry().getName() + " " + this.commandPathMeta.getPath(), e);
145145
}
146146
};
147147

core/src/main/java/cc/dreamcode/command/CommandMeta.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
@Data
2525
public class CommandMeta {
2626

27-
private final CommandContext commandContext;
27+
private final CommandEntry commandEntry;
2828
private final CommandBase commandBase;
2929
private final Object commandInstance;
3030

@@ -37,10 +37,10 @@ public class CommandMeta {
3737
private final SuggestionService suggestionService;
3838
private final ResolverService resolverService;
3939

40-
public CommandMeta(@NonNull SuggestionService suggestionService, @NonNull ResolverService resolverService, @NonNull CommandContext commandContext, @NonNull CommandBase commandBase, @NonNull Object commandInstance) {
40+
public CommandMeta(@NonNull SuggestionService suggestionService, @NonNull ResolverService resolverService, @NonNull CommandEntry commandEntry, @NonNull CommandBase commandBase, @NonNull Object commandInstance) {
4141
this.suggestionService = suggestionService;
4242
this.resolverService = resolverService;
43-
this.commandContext = commandContext;
43+
this.commandEntry = commandEntry;
4444
this.commandBase = commandBase;
4545
this.commandInstance = commandInstance;
4646

core/src/main/java/cc/dreamcode/command/CommandPathMeta.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ public class CommandPathMeta {
4141
// ignore binds
4242
private final Map<Integer, Annotation[]> argAnnotations;
4343
private final Map<Integer, Class<?>> argClasses;
44-
private final Map<Integer, CommandArgument> argNames;
45-
private final Map<Integer, CommandArgument> argDisplayNames;
44+
private final Map<Integer, ArgumentEntry> argNames;
45+
private final Map<Integer, ArgumentEntry> argDisplayNames;
4646

4747
// all parameters
4848
private final Map<Integer, Annotation[]> paramAnnotations;
@@ -89,8 +89,8 @@ public CommandPathMeta(@NonNull CommandMeta commandMeta, @NonNull Method method,
8989
final String name = Objects.equals(arg.value(), "") ? parameter.getName() : arg.value();
9090

9191
this.argClasses.put(atomicNameIndex.get(), parameter.getType());
92-
this.argNames.put(atomicNameIndex.get(), new CommandArgument(CommandArgument.Type.ARG, name));
93-
this.argDisplayNames.put(atomicNameIndex.getAndIncrement(), new CommandArgument(CommandArgument.Type.ARG, "<" + name + ">"));
92+
this.argNames.put(atomicNameIndex.get(), new ArgumentEntry(ArgumentEntry.Type.ARG, name));
93+
this.argDisplayNames.put(atomicNameIndex.getAndIncrement(), new ArgumentEntry(ArgumentEntry.Type.ARG, "<" + name + ">"));
9494

9595
continue;
9696
}
@@ -104,8 +104,8 @@ public CommandPathMeta(@NonNull CommandMeta commandMeta, @NonNull Method method,
104104
final String name = Objects.equals(args.value(), "") ? parameter.getName() : args.value();
105105

106106
this.argClasses.put(atomicNameIndex.get(), parameter.getType());
107-
this.argNames.put(atomicNameIndex.get(), new CommandArgument(CommandArgument.Type.ARGS, name));
108-
this.argDisplayNames.put(atomicNameIndex.getAndIncrement(), new CommandArgument(CommandArgument.Type.ARGS, "(" + name + ")"));
107+
this.argNames.put(atomicNameIndex.get(), new ArgumentEntry(ArgumentEntry.Type.ARGS, name));
108+
this.argDisplayNames.put(atomicNameIndex.getAndIncrement(), new ArgumentEntry(ArgumentEntry.Type.ARGS, "(" + name + ")"));
109109

110110
continue;
111111
}
@@ -131,8 +131,8 @@ public CommandPathMeta(@NonNull CommandMeta commandMeta, @NonNull Method method,
131131
}
132132

133133
this.argClasses.put(atomicNameIndex.get(), rawType);
134-
this.argNames.put(atomicNameIndex.get(), new CommandArgument(CommandArgument.Type.OPTIONAL_ARG, name));
135-
this.argDisplayNames.put(atomicNameIndex.getAndIncrement(), new CommandArgument(CommandArgument.Type.OPTIONAL_ARG, "[" + name + "]"));
134+
this.argNames.put(atomicNameIndex.get(), new ArgumentEntry(ArgumentEntry.Type.OPTIONAL_ARG, name));
135+
this.argDisplayNames.put(atomicNameIndex.getAndIncrement(), new ArgumentEntry(ArgumentEntry.Type.OPTIONAL_ARG, "[" + name + "]"));
136136
}
137137
}
138138

@@ -240,15 +240,15 @@ public List<DreamSender.Type> getSendersType() {
240240
public String getUsage() {
241241

242242
final List<String> listBuilder = new ArrayList<>();
243-
listBuilder.add("/" + this.commandMeta.getCommandContext().getName());
243+
listBuilder.add("/" + this.commandMeta.getCommandEntry().getName());
244244

245245
if (!this.path.isEmpty()) {
246246
listBuilder.addAll(Arrays.asList(this.path.split(" ")));
247247
}
248248

249249
this.argDisplayNames.values()
250250
.stream()
251-
.map(CommandArgument::getValue)
251+
.map(ArgumentEntry::getValue)
252252
.forEach(listBuilder::add);
253253

254254
return StringUtil.join(listBuilder, " ");
@@ -308,15 +308,15 @@ public List<String> getSuggestion(@NonNull SuggestionService suggestionService,
308308
return listBuilder.build();
309309
}
310310

311-
final CommandArgument commandArgument = this.argNames.get(argumentParamLength);
311+
final ArgumentEntry argumentEntry = this.argNames.get(argumentParamLength);
312312
final Optional<Completion> optionalCompletion = Arrays.stream(this.method.getAnnotationsByType(Completion.class))
313-
.filter(completion -> Objects.equals(completion.arg(), commandArgument.getValue()))
313+
.filter(completion -> Objects.equals(completion.arg(), argumentEntry.getValue()))
314314
.findAny();
315315

316316
if (!optionalCompletion.isPresent()) {
317-
final CommandArgument commandDisplayArgument = this.argDisplayNames.get(argumentParamLength);
317+
final ArgumentEntry commandDisplayArgument = this.argDisplayNames.get(argumentParamLength);
318318

319-
if (!commandDisplayArgument.getType().equals(CommandArgument.Type.ARGS)) {
319+
if (!commandDisplayArgument.getType().equals(ArgumentEntry.Type.ARGS)) {
320320
listBuilder.add(commandDisplayArgument.getValue());
321321
}
322322

0 commit comments

Comments
 (0)