Skip to content

Commit 6bd85d9

Browse files
committed
WiP sur le gestionnaire de commandes
1 parent ff0a9f7 commit 6bd85d9

File tree

9 files changed

+105
-48
lines changed

9 files changed

+105
-48
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@
2525

2626
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
2727
hs_err_pid*
28+
/docs/

pom.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@
4444
<groupId>org.apache.maven.plugins</groupId>
4545
<artifactId>maven-javadoc-plugin</artifactId>
4646
<version>3.2.0</version>
47+
<executions>
48+
<execution>
49+
<id>attach-javadocs</id>
50+
<goals>
51+
<goal>jar</goal>
52+
</goals>
53+
</execution>
54+
</executions>
4755
</plugin>
4856
<plugin>
4957
<groupId>org.apache.maven.plugins</groupId>

src/main/java/space/debian/WrapAPI/WrapAPI.java renamed to src/main/java/space/debian/WrapAPI/WPlugin.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
import org.bukkit.plugin.java.JavaPlugin;
44
import space.debian.WrapAPI.managers.CommandManager;
55
import space.debian.WrapAPI.managers.ListenerManager;
6-
import space.debian.WrapAPI.tools.logging.WrapLogger;
6+
import space.debian.WrapAPI.tools.logging.WLogger;
77

8-
public abstract class WrapAPI extends JavaPlugin {
8+
public abstract class WPlugin extends JavaPlugin {
99

10-
private static WrapAPI instance;
10+
private static WPlugin instance;
1111

1212
public void preEnable() {
1313
instance = this;
1414

15-
new WrapLogger(this);
15+
new WLogger(this);
1616

1717
new ListenerManager();
1818
new CommandManager();
@@ -30,12 +30,12 @@ public void postEnable() {
3030

3131
ListenerManager.get().initListeners();
3232

33-
WrapLogger.get().spacer();
33+
WLogger.get().spacer();
3434

3535
CommandManager.get().initCommands();
3636
}
3737

38-
public static WrapAPI get() {
38+
public static WPlugin get() {
3939

4040
return instance;
4141
}

src/main/java/space/debian/WrapAPI/managers/CommandManager.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
package space.debian.WrapAPI.managers;
22

33
import org.bukkit.Bukkit;
4-
import space.debian.WrapAPI.objects.ICommand;
5-
import space.debian.WrapAPI.tools.logging.WrapLogger;
4+
import space.debian.WrapAPI.objects.commands.WCommand;
5+
import space.debian.WrapAPI.tools.logging.WLogger;
66

77
import java.util.ArrayList;
88

99
public class CommandManager {
1010

1111
private static CommandManager instance;
1212

13-
private ArrayList<Class<? extends ICommand>> commands = new ArrayList<>();
13+
private ArrayList<Class<? extends WCommand>> commands = new ArrayList<>();
1414

1515
public CommandManager() {
1616

@@ -19,32 +19,32 @@ public CommandManager() {
1919

2020
public void initCommands() {
2121

22-
WrapLogger.get().info("Instancing commands.");
22+
WLogger.get().info("Instancing commands.");
2323

2424
commands.forEach((command) -> {
2525
try {
2626

27-
ICommand commandInstance = command.newInstance();
27+
WCommand commandInstance = command.newInstance();
2828
Bukkit.getServer().getPluginCommand(commandInstance.getName()).setExecutor(commandInstance);
2929

30-
WrapLogger.get().info(" " + command.getSimpleName() + " command instantiated.");
30+
WLogger.get().info(" " + command.getSimpleName() + " command instantiated.");
3131
} catch (InstantiationException | IllegalAccessException e) {
3232

33-
WrapLogger.get().severe(" An error occured while instancing the " + command.getSimpleName() + " command.");
34-
WrapLogger.get().severe(e.getMessage());
33+
WLogger.get().severe(" An error occured while instancing the " + command.getSimpleName() + " command.");
34+
WLogger.get().severe(e.getMessage());
3535
}
3636
});
3737
}
3838

3939

4040

41-
public void addCommand(Class<? extends ICommand> command) {
41+
public void addCommand(Class<? extends WCommand> command) {
4242

4343
if (!commands.contains(command))
4444
commands.add(command);
4545
}
4646

47-
public ArrayList<Class<? extends ICommand>> getCommands() {
47+
public ArrayList<Class<? extends WCommand>> getCommands() {
4848
return commands;
4949
}
5050

src/main/java/space/debian/WrapAPI/managers/ListenerManager.java

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

33
import org.bukkit.Bukkit;
44
import org.bukkit.event.Listener;
5-
import space.debian.WrapAPI.WrapAPI;
6-
import space.debian.WrapAPI.tools.logging.WrapLogger;
5+
import space.debian.WrapAPI.WPlugin;
6+
import space.debian.WrapAPI.tools.logging.WLogger;
77

88
import java.util.ArrayList;
99

@@ -20,18 +20,18 @@ public ListenerManager() {
2020

2121
public void initListeners() {
2222

23-
WrapLogger.get().info("Instancing listeners.");
23+
WLogger.get().info("Instancing listeners.");
2424

2525
eventListeners.forEach((listener) -> {
2626
try {
2727

28-
Bukkit.getServer().getPluginManager().registerEvents(listener.newInstance(), WrapAPI.get());
28+
Bukkit.getServer().getPluginManager().registerEvents(listener.newInstance(), WPlugin.get());
2929

30-
WrapLogger.get().info(" " + listener.getSimpleName() + " listener instantiated.");
30+
WLogger.get().info(" " + listener.getSimpleName() + " listener instantiated.");
3131
} catch (InstantiationException | IllegalAccessException e) {
3232

33-
WrapLogger.get().severe(" An error occured while instancing " + listener.getSimpleName() + " listener.");
34-
WrapLogger.get().severe(e.getMessage());
33+
WLogger.get().severe(" An error occured while instancing " + listener.getSimpleName() + " listener.");
34+
WLogger.get().severe(e.getMessage());
3535
}
3636
});
3737
}

src/main/java/space/debian/WrapAPI/objects/ICommand.java

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package space.debian.WrapAPI.objects.commands;
2+
3+
import org.bukkit.command.Command;
4+
import org.bukkit.command.CommandExecutor;
5+
import org.bukkit.command.CommandSender;
6+
7+
import java.util.ArrayList;
8+
import java.util.List;
9+
10+
public abstract class WCommand implements CommandExecutor {
11+
12+
private String name;
13+
private WSubCommand command;
14+
private List<WSubCommand> subCommands = new ArrayList<>();
15+
16+
/**
17+
* Create a new instance of a WCommand
18+
* @param name Command name, must be in plugin.yml's commands.
19+
*/
20+
public WCommand(String name) {
21+
22+
this.name = name;
23+
}
24+
25+
public String getName() {
26+
return name;
27+
}
28+
29+
/**
30+
* Bukkit's API onCommand override, only override this if you know what you're doing !
31+
* @param sender Command sender
32+
* @param command Command executed, a.k.a this
33+
* @param string Command name as executed, can be an aliase
34+
* @param args Command arguments
35+
* @return False if command is off, true otherwise
36+
*/
37+
@Override
38+
public boolean onCommand(CommandSender sender, Command command, String string, String[] args) {
39+
40+
return process(sender, command, string, args);
41+
}
42+
43+
/**
44+
* WrapAPI's command process method, override this method and build your command !
45+
* @param sender Command sender
46+
* @param command Command executed, a.k.a this
47+
* @param string Command name as executed, can be an aliase
48+
* @param args Command arguments
49+
* @return False if command is off, true otherwise
50+
*/
51+
public boolean process(CommandSender sender, Command command, String string, String[] args) {
52+
return true;
53+
}
54+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package space.debian.WrapAPI.objects.commands;
2+
3+
import org.bukkit.command.Command;
4+
import org.bukkit.command.CommandSender;
5+
6+
public class WSubCommand {
7+
8+
private String name;
9+
private boolean consoleOnly;
10+
11+
public boolean execute(CommandSender sender, Command command, String string, String[] args) {
12+
13+
return true;
14+
}
15+
}

src/main/java/space/debian/WrapAPI/tools/logging/WrapLogger.java renamed to src/main/java/space/debian/WrapAPI/tools/logging/WLogger.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@
55
import java.util.logging.Level;
66
import java.util.logging.Logger;
77

8-
public class WrapLogger extends Logger {
8+
public class WLogger extends Logger {
99

10-
private static WrapLogger instance;
10+
private static WLogger instance;
1111
private String pluginName;
1212

1313
/**
1414
* Creates a new PluginLogger that extracts the name from a plugin.
1515
*
1616
* @param context A reference to the plugin
1717
*/
18-
public WrapLogger(Plugin context) {
18+
public WLogger(Plugin context) {
1919
super(context.getClass().getCanonicalName(), null);
2020

2121
instance = this;
@@ -47,7 +47,7 @@ public void spacer() {
4747
super.log(Level.INFO, "\033[38;5;244m#~ ------------------------------------------------ ~#\033[0m");
4848
}
4949

50-
public static WrapLogger get() {
50+
public static WLogger get() {
5151
return instance;
5252
}
5353

0 commit comments

Comments
 (0)