Skip to content

Commit 83c076e

Browse files
committed
Ajout d'un CommandManager et fix divers
1 parent 93df9f1 commit 83c076e

File tree

4 files changed

+76
-2
lines changed

4 files changed

+76
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import space.debian.WrapAPI.managers.ListenerManager;
55
import space.debian.WrapAPI.tools.logging.WrapLogger;
66

7-
public class WrapAPI extends JavaPlugin {
7+
public abstract class WrapAPI extends JavaPlugin {
88

99
private static WrapAPI instance;
1010

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package space.debian.WrapAPI.managers;
2+
3+
import org.bukkit.Bukkit;
4+
import org.bukkit.command.CommandExecutor;
5+
import org.bukkit.event.Listener;
6+
import space.debian.WrapAPI.WrapAPI;
7+
import space.debian.WrapAPI.objects.ICommand;
8+
import space.debian.WrapAPI.tools.logging.WrapLogger;
9+
10+
import java.util.ArrayList;
11+
12+
public class CommandManager {
13+
14+
private static CommandManager instance;
15+
16+
private ArrayList<Class<? extends ICommand>> commands = new ArrayList<>();
17+
18+
public CommandManager() {
19+
20+
instance = this;
21+
}
22+
23+
public void initCommands() {
24+
25+
WrapLogger.get().info("Instancing commands.");
26+
27+
commands.forEach((command) -> {
28+
try {
29+
30+
ICommand commandInstance = command.newInstance();
31+
Bukkit.getServer().getPluginCommand(commandInstance.getName()).setExecutor(commandInstance);
32+
33+
WrapLogger.get().info(command.getSimpleName() + " command instantiated.");
34+
} catch (InstantiationException | IllegalAccessException e) {
35+
36+
WrapLogger.get().severe("An error occured while instancing the " + command.getSimpleName() + " command.");
37+
WrapLogger.get().severe(e.getMessage());
38+
}
39+
});
40+
}
41+
42+
43+
44+
public void addCommand(Class<? extends ICommand> command) {
45+
46+
if (!commands.contains(command))
47+
commands.add(command);
48+
}
49+
50+
public ArrayList<Class<? extends ICommand>> getCommands() {
51+
return commands;
52+
}
53+
54+
public static CommandManager get() {
55+
56+
return instance;
57+
}
58+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public void initListeners() {
3030
WrapLogger.get().info(listener.getSimpleName() + " listener instantiated.");
3131
} catch (InstantiationException | IllegalAccessException e) {
3232

33-
WrapLogger.get().severe("An error occured while enabling " + listener.getSimpleName() + " listener.");
33+
WrapLogger.get().severe("An error occured while instancing " + listener.getSimpleName() + " listener.");
3434
WrapLogger.get().severe(e.getMessage());
3535
}
3636
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package space.debian.WrapAPI.objects;
2+
3+
import org.bukkit.command.CommandExecutor;
4+
5+
public abstract class ICommand implements CommandExecutor {
6+
7+
public String name;
8+
9+
public String getName() {
10+
return name;
11+
}
12+
13+
public void setName(String name) {
14+
this.name = name;
15+
}
16+
}

0 commit comments

Comments
 (0)