Skip to content

Commit a655692

Browse files
modified return types of getPlayer and getEntity to remove the exception type
1 parent 83230ad commit a655692

File tree

9 files changed

+141
-5
lines changed

9 files changed

+141
-5
lines changed

src/main/java/com/datasiqn/commandcore/CommandCore.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,12 @@ public static CommandCore getInstance() {
115115
return instance;
116116
}
117117

118+
/**
119+
* Sends command usage to {@code sender}
120+
* @param sender The sender
121+
* @param commandName The name of the command
122+
* @throws IllegalArgumentException If {@code commandName} is not the name of a command
123+
*/
118124
public void sendCommandHelp(@NotNull CommandSender sender, @NotNull String commandName) {
119125
if (!commandManager.hasCommand(commandName)) throw new IllegalArgumentException("Command " + commandName + " does not exist");
120126
Command command = commandManager.getCommand(commandName);
@@ -124,6 +130,10 @@ public void sendCommandHelp(@NotNull CommandSender sender, @NotNull String comma
124130
sender.sendMessage(getUsagesFor(commandName, 2).toArray(new String[0]));
125131
}
126132

133+
/**
134+
* Sends the help menu to {@code sender}
135+
* @param sender The sender
136+
*/
127137
public void sendHelpMenu(@NotNull CommandSender sender) {
128138
sender.sendMessage(ChatColor.GOLD + (options.hasCustomPluginName() ? options.getPluginName() : plugin.getName()) + " Commands");
129139
commandManager.allCommands().keySet().stream().sorted().forEach(name -> {
@@ -132,6 +142,13 @@ public void sendHelpMenu(@NotNull CommandSender sender) {
132142
});
133143
}
134144

145+
/**
146+
* Generates a formatted string for each usage of a command
147+
* @param commandName The name of the command
148+
* @param spaces The # of spaces to add before each usage string
149+
* @return A list of formatted strings representing all usages for the command
150+
* @throws IllegalArgumentException If {@code commandName} is not the name of a command
151+
*/
135152
@NotNull
136153
public List<String> getUsagesFor(String commandName, int spaces) {
137154
if (!commandManager.hasCommand(commandName))
@@ -153,6 +170,10 @@ public List<String> getUsagesFor(String commandName, int spaces) {
153170
return usages;
154171
}
155172

173+
/**
174+
* Gets the options used to initialize {@code CommandCore}
175+
* @return The options used to initialize {@code CommandCore}
176+
*/
156177
public InitOptions getOptions() {
157178
return options;
158179
}

src/main/java/com/datasiqn/commandcore/InitOptions.java

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,28 @@
22

33
import org.jetbrains.annotations.Contract;
44
import org.jetbrains.annotations.NotNull;
5+
import org.jetbrains.annotations.Nullable;
56
import org.jetbrains.annotations.UnmodifiableView;
67

78
import java.util.Arrays;
89
import java.util.Collections;
910
import java.util.List;
1011

12+
/**
13+
* Initialization options used when initializing {@code CommandCore}. Cannot be created directly, and must use a {@code Builder} to create one.
14+
* @see Builder
15+
*/
1116
public class InitOptions {
1217
private final String rootCommand;
1318
private final String pluginName;
1419
private final boolean helpCommand;
1520
private final boolean legacyExecutor;
1621
private final List<String> aliases;
1722

23+
/**
24+
* Creates an {@code InitOptions} from a {@code Builder}
25+
* @param builder The builder
26+
*/
1827
@Contract(pure = true)
1928
public InitOptions(@NotNull Builder builder) {
2029
this.rootCommand = builder.rootCommand;
@@ -24,67 +33,127 @@ public InitOptions(@NotNull Builder builder) {
2433
this.legacyExecutor = builder.legacyExecutor;
2534
}
2635

36+
/**
37+
* Gets the root command
38+
* @return The root command
39+
*/
2740
public String getRootCommand() {
2841
return rootCommand;
2942
}
3043

44+
/**
45+
* Gets whether the user has defined a custom plugin name or not
46+
* @return True if there is a custom plugin name, false otherwise
47+
*/
3148
public boolean hasCustomPluginName() {
3249
return pluginName != null;
3350
}
3451

35-
public String getPluginName() {
52+
/**
53+
* Gets the custom plugin name
54+
* @return The custom plugin name, or null if there is none
55+
*/
56+
public @Nullable String getPluginName() {
3657
return pluginName;
3758
}
3859

60+
/**
61+
* Gets all the command's aliases
62+
* @return An unmodifiable view of all the command's aliases
63+
*/
3964
@UnmodifiableView
4065
public List<String> getAliases() {
4166
return Collections.unmodifiableList(aliases);
4267
}
4368

69+
/**
70+
* Gets whether a help command should be generated or not
71+
* @return True if a help command should be generated, false otherwise
72+
*/
4473
public boolean createHelpCommand() {
4574
return helpCommand;
4675
}
4776

77+
/**
78+
* Gets whether the legacy executor should be used or not
79+
* @return True if the legacy executor should be used, false otherwise
80+
*/
4881
public boolean useLegacyExecutor() {
4982
return legacyExecutor;
5083
}
5184

85+
/**
86+
* Builder class to create an {@code InitOptions} object
87+
*/
5288
public static class Builder {
5389
private final String rootCommand;
5490
private String pluginName;
5591
private boolean helpCommand = true;
5692
private boolean legacyExecutor = false;
5793
private String[] aliases = new String[0];
5894

95+
/**
96+
* Creates a new {@code Builder} class
97+
* @param rootCommand The name of the root command that be the root all {@code CommandCore} commands
98+
*/
5999
public Builder(String rootCommand) {
60100
this.rootCommand = rootCommand;
61101
}
62102

103+
/**
104+
* Sets whether a help command should be created or not
105+
* @param flag True if a help command should be created, false if it shouldn't
106+
* @return The builder, for chaining
107+
*/
63108
public Builder createHelpCommand(boolean flag) {
64109
this.helpCommand = flag;
65110
return this;
66111
}
67112

113+
/**
114+
* Sets the custom plugin name that appears when showing the help screen
115+
* @param name The custom plugin name
116+
* @return The builder, for chaining
117+
*/
68118
public Builder pluginName(String name) {
69119
this.pluginName = name;
70120
return this;
71121
}
72122

123+
/**
124+
* Sets the aliases of the root command
125+
* @param aliases The aliases
126+
* @return The builder, for chaining
127+
*/
73128
public Builder aliases(String... aliases) {
74129
this.aliases = aliases;
75130
return this;
76131
}
77132

133+
/**
134+
* Tells {@code CommandCore} to use the legacy executor when executing a command
135+
* @deprecated You should not use this ever, since the legacy executor is very buggy and can cause lots of problems if used
136+
* @return The builder, for chaining
137+
*/
78138
@Deprecated
79139
public Builder useLegacyExecutor() {
80140
this.legacyExecutor = true;
81141
return this;
82142
}
83143

144+
/**
145+
* Creates a new {@code InitOptions} based off this builder
146+
* @return The newly created {@code InitOptions} instance
147+
*/
84148
public InitOptions build() {
85149
return new InitOptions(this);
86150
}
87151

152+
/**
153+
* Creates a new {@code Builder} instance. This is identical to calling {@code new Builder(rootCommand)}.
154+
* @param rootCommand The name of the root command that will be the root of all {@code CommandCore} commands
155+
* @return The newly created {@code Builder} instance
156+
*/
88157
@Contract(value = "_ -> new", pure = true)
89158
public static @NotNull Builder create(@NotNull String rootCommand) {
90159
return new Builder(rootCommand);

src/main/java/com/datasiqn/commandcore/arguments/ListArguments.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
public class ListArguments implements Arguments {
99
protected final List<String> allArguments;
1010

11+
/**
12+
* Creates a new {@code ListArguments}
13+
* @param args The arguments in a string list
14+
*/
1115
public ListArguments(List<String> args) {
1216
allArguments = args;
1317
}

src/main/java/com/datasiqn/commandcore/commands/Command.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,9 @@ public interface Command {
3333
*/
3434
@NotNull List<String> getUsages();
3535

36+
/**
37+
* Gets the aliases of this command
38+
* @return The aliases
39+
*/
3640
@NotNull String[] getAliases();
3741
}

src/main/java/com/datasiqn/commandcore/commands/CommandExecutor.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
import java.util.ArrayList;
99
import java.util.List;
1010

11+
/**
12+
* Represents an executor for a command
13+
*/
1114
public interface CommandExecutor {
1215
/**
1316
* Executes this command executor

src/main/java/com/datasiqn/commandcore/commands/CommandSource.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
package com.datasiqn.commandcore.commands;
22

3+
import com.datasiqn.commandcore.commands.builder.CommandLink;
34
import com.datasiqn.resultapi.Result;
45
import org.bukkit.command.CommandSender;
56
import org.bukkit.entity.Entity;
67
import org.bukkit.entity.Player;
78
import org.bukkit.permissions.Permission;
89
import org.jetbrains.annotations.NotNull;
910

11+
/**
12+
* Represents the source of a command
13+
*/
1014
public interface CommandSource {
1115
/**
1216
* Gets the player executing command
@@ -22,9 +26,23 @@ public interface CommandSource {
2226
@NotNull
2327
Result<Entity, String> getEntity();
2428

25-
@NotNull CommandSender getSender();
26-
27-
boolean hasPermission(Permission permissible);
29+
/**
30+
* Gets the sender of the command
31+
* @return The sender
32+
*/
33+
@NotNull
34+
CommandSender getSender();
2835

36+
/**
37+
* Gets whether the source of the command has a permission or not
38+
* @param permission The permission
39+
* @return True if the source has {@code permission}, false otherwise
40+
*/
41+
boolean hasPermission(Permission permission);
42+
/**
43+
* Gets whether the source of the command has a permission or not
44+
* @param permission The permission
45+
* @return True if the source has {@code permission}, false otherwise
46+
*/
2947
boolean hasPermission(String permission);
3048
}

src/main/java/com/datasiqn/commandcore/commands/builder/CommandBuilder.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ public CommandBuilder description(String description) {
4444
return this;
4545
}
4646

47+
/**
48+
* Sets the command's aliases
49+
* @param aliases The aliases
50+
* @return The builder, for chaining
51+
*/
4752
public CommandBuilder alias(String... aliases) {
4853
this.aliases = aliases;
4954
return this;

src/main/java/com/datasiqn/commandcore/managers/CommandManager.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
import java.util.HashMap;
1010
import java.util.Map;
1111

12+
/**
13+
* Class that manages all commands
14+
*/
1215
public class CommandManager {
1316
private final Map<String, Command> executableCommands = new HashMap<>();
1417
private final Map<String, Command> commandMap = new HashMap<>();

src/main/java/com/datasiqn/commandcore/util/ParseUtil.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,19 @@
22

33
import org.jetbrains.annotations.NotNull;
44

5+
/**
6+
* A utility class that contains parsing methods
7+
*/
58
public final class ParseUtil {
69
private ParseUtil() {}
710

8-
public static boolean strictParseBoolean(@NotNull String str) throws IllegalArgumentException {
11+
/**
12+
* Strictly parses {@code str} as a boolean
13+
* @param str The string to parse
14+
* @return {@code true} if {@code str} equals "true", or {@code false} if {@code str} equals "false"
15+
* @throws IllegalArgumentException If {@code str} does not equal "true" or "false"
16+
*/
17+
public static boolean strictParseBoolean(@NotNull String str) {
918
if (str.equalsIgnoreCase("true")) return true;
1019
else if (str.equalsIgnoreCase("false")) return false;
1120
throw new IllegalArgumentException("String '" + str + "' is not a boolean");

0 commit comments

Comments
 (0)