Skip to content

Commit 652a021

Browse files
committed
Added Commons as dependency (not all classes included) and new methods for arguments
1 parent 9e2cf13 commit 652a021

File tree

4 files changed

+42
-8
lines changed

4 files changed

+42
-8
lines changed

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ To add this project as a dependency to your project, add the following to your p
2828
<dependency>
2929
<groupId>com.github.Despical</groupId>
3030
<artifactId>CommandFramework</artifactId>
31-
<version>1.0.6</version>
31+
<version>1.0.7</version>
3232
<scope>compile</scope>
3333
</dependency>
3434
```
@@ -41,7 +41,7 @@ repositories {
4141
```
4242
```
4343
dependencies {
44-
compileOnly group: "com.github.Despical", name: "CommandFramework", version: "1.0.6";
44+
compileOnly group: "com.github.Despical", name: "CommandFramework", version: "1.0.7";
4545
}
4646
```
4747

@@ -65,7 +65,7 @@ public class ExampleClass extends JavaPlugin {
6565

6666
String label = arguments.getLabel(), arg = arguments.getArgument(0);
6767

68-
// StringMatcher is an external class from Despical's Commons library which is not in this framework
68+
// StringMatcher is an external class from Despical's Commons library which is used in this framework but not all the parts included
6969
List<StringMatcher.Match> matches = StringMatcher.match(arg, commandFramework.getCommands().stream().map(cmd -> cmd.name().replace(label + ".", "")).collect(Collectors.toList()));
7070

7171
if (!matches.isEmpty()) {
@@ -89,9 +89,8 @@ public class ExampleClass extends JavaPlugin {
8989
)
9090
public void exampleCommand(CommandArguments arguments) {
9191
// CommandArguments class contains basic things related Bukkit commands
92-
CommandSender sender = arguments.getSender();
9392
// And here it's all done, you've created command with properties above!
94-
sender.sendMessage("This is how you can create a example command using framework.");
93+
arguments.sendMessage("This is how you can create a example command using framework.");
9594
}
9695

9796
// Aliases don't need to be same with the command above

pom.xml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>me.despical</groupId>
55
<artifactId>command-framework</artifactId>
6-
<version>1.0.6</version>
6+
<version>1.0.7</version>
77

88
<properties>
99
<java.version>8</java.version>
@@ -32,6 +32,10 @@
3232
<id>papermc</id>
3333
<url>https://papermc.io/repo/repository/maven-public/</url>
3434
</repository>
35+
<repository>
36+
<id>jitpack.io</id>
37+
<url>https://jitpack.io</url>
38+
</repository>
3539
</repositories>
3640

3741
<dependencies>
@@ -41,6 +45,12 @@
4145
<version>1.16.5-R0.1-SNAPSHOT</version>
4246
<scope>provided</scope>
4347
</dependency>
48+
<dependency>
49+
<groupId>com.github.Despical</groupId>
50+
<artifactId>Commons</artifactId>
51+
<version>1.3.9</version>
52+
<scope>compile</scope>
53+
</dependency>
4454
</dependencies>
4555

4656
<build>

src/main/java/me/despical/commandframework/CommandArguments.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package me.despical.commandframework;
1919

20+
import me.despical.commons.number.NumberUtils;
2021
import org.bukkit.command.CommandSender;
2122
import org.bukkit.command.Command;
2223
import org.bukkit.entity.Player;
@@ -80,6 +81,8 @@ public String[] getArguments() {
8081
return arguments;
8182
}
8283

84+
// SOME GETTER METHODS FOR COMMON PRIMITIVE TYPES //
85+
8386
/**
8487
* @param i index
8588
* @return indexed element or null if index out of bounds
@@ -89,6 +92,28 @@ public String getArgument(int i) {
8992
return arguments.length > i && i >= 0 ? arguments[i] : null;
9093
}
9194

95+
/**
96+
* @param i index
97+
* @return Integer if indexed element is primitive type of int
98+
* or 0 if element is null.
99+
*/
100+
@NotNull
101+
public Integer getArgumentAsInt(int i) {
102+
return NumberUtils.getInt(this.getArgument(i));
103+
}
104+
105+
/**
106+
* @param i index
107+
* @return Double if indexed element is primitive type of double
108+
* or 0 if element is null.
109+
*/
110+
@NotNull
111+
public Double getArgumentAsDouble(int i) {
112+
return NumberUtils.getDouble(this.getArgument(i));
113+
}
114+
115+
// ---------------------------------------------- //
116+
92117
/**
93118
* @return true if command arguments are empty otherwise false
94119
*/

src/main/java/me/despical/commandframework/CommandFramework.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public void registerCommands(@NotNull Object instance) {
121121

122122
registerCommand(command, method, instance);
123123
} else if (method.getAnnotation(Completer.class) != null) {
124-
completions.put(method.getAnnotation(Completer.class), new AbstractMap.SimpleEntry<>(method, instance));
124+
completions.put(method.getAnnotation(Completer.class), me.despical.commons.util.Collections.mapEntry(method, instance));
125125
}
126126
}
127127
}
@@ -134,7 +134,7 @@ public void registerCommands(@NotNull Object instance) {
134134
* @param instance of the method above
135135
*/
136136
private void registerCommand(Command command, Method method, Object instance) {
137-
commands.put(command, new AbstractMap.SimpleEntry<>(method, instance));
137+
commands.put(command, me.despical.commons.util.Collections.mapEntry(method, instance));
138138

139139
try {
140140
Constructor<PluginCommand> constructor = PluginCommand.class.getDeclaredConstructor(String.class, Plugin.class);

0 commit comments

Comments
 (0)