Skip to content

Commit d60d1b9

Browse files
authored
Add files via upload
1 parent 7ffc095 commit d60d1b9

File tree

10 files changed

+1014
-0
lines changed

10 files changed

+1014
-0
lines changed

plugin.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: PluginManager
2+
version: 1.0.3
3+
main: de.buddelbubi.PluginManagerInstance
4+
api: 1.0.13
5+
author: Buddelbubi
6+
description: PluginManager is a plugin management plugin for nukkit.
7+
load: STARTUP
8+
website: https://www.cloudburstmc.org/resources/pluginmanager.776/
9+
permissions:
10+
pluginmanager.ui:
11+
description: "The permission to open the PluginManager UI"
12+
default: op
13+
pluginmanager.load:
14+
description: "The permission to be able to load a plugin"
15+
default: op
16+
pluginmanager.unload:
17+
description: "The permission to be able to unload a plugin"
18+
default: op
19+
pluginmanager.enable:
20+
description: "The permission to be able to enable a plugin"
21+
default: op
22+
pluginmanager.disable:
23+
description: "The permission to be able to disable a plugin"
24+
default: op
25+
pluginmanager.reload:
26+
description: "The permission to be able to reload a plugin"
27+
default: op
28+
pluginmanager.config.*:
29+
description: "e.g. pluginmanager.config.home.server.plugins.exampleplugin.config.yml"
30+
default: op
31+
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package de.buddelbubi;
2+
3+
import cn.nukkit.Server;
4+
5+
import cn.nukkit.command.Command;
6+
import cn.nukkit.plugin.Plugin;
7+
import cn.nukkit.plugin.PluginBase;
8+
import cn.nukkit.plugin.PluginManager;
9+
import de.buddelbubi.commands.PluginManagerCommand;
10+
import de.buddelbubi.commands.PluginManagerReloadCommand;
11+
import de.buddelbubi.listeners.UIListener;
12+
13+
public class PluginManagerInstance extends PluginBase {
14+
15+
public static Plugin plugin;
16+
17+
public static final String prefix = "§ePluginManager §8» §7";
18+
19+
public void onEnable() {
20+
21+
plugin = this;
22+
23+
Command command = new PluginManagerCommand("pluginmanager");
24+
command.setAliases(new String[] {"pm"});
25+
command.setDescription("The main PluginManager command.");
26+
27+
getServer().getCommandMap().register(command.getName(), command);
28+
29+
Command reload = new PluginManagerReloadCommand("reload");
30+
reload.setAliases(new String[] {"rl"});
31+
reload.setPermission("nukkit.command.reload");
32+
getServer().getCommandMap().register(reload.getName(), reload);
33+
34+
getServer().getPluginManager().registerEvents(new UIListener(), this);
35+
36+
37+
38+
}
39+
40+
41+
42+
public static PluginManager getPluginManager() {
43+
return Server.getInstance().getPluginManager();
44+
}
45+
46+
}
Lines changed: 250 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,250 @@
1+
package de.buddelbubi.commands;
2+
3+
import java.io.File;
4+
5+
import cn.nukkit.Player;
6+
import cn.nukkit.Server;
7+
import cn.nukkit.command.Command;
8+
import cn.nukkit.command.CommandSender;
9+
import cn.nukkit.plugin.Plugin;
10+
import de.buddelbubi.PluginManagerInstance;
11+
import de.buddelbubi.utils.TextFormat;
12+
import de.buddelbubi.utils.WindowFactory;
13+
import de.buddelbubi.utils.WorkArounds;
14+
15+
public class PluginManagerCommand extends Command{
16+
17+
public PluginManagerCommand(String name) {
18+
super(name);
19+
20+
}
21+
22+
@Override
23+
public boolean execute(CommandSender arg0, String arg1, String[] args) {
24+
25+
26+
String prefix = PluginManagerInstance.prefix;
27+
28+
29+
30+
31+
if(args.length >= 1) {
32+
33+
if(!arg0.hasPermission("pluginmanager." + args[0])) {
34+
35+
arg0.sendMessage(prefix + "§cYou are lacking the permission 'pluginmanager." + args[0] + "'.");
36+
return false;
37+
}
38+
39+
switch (args[0]) {
40+
case "load":
41+
42+
if(args.length == 2) {
43+
44+
File file = new File(Server.getInstance().getPluginPath(), (args[1].contains(".jar") ? args[1] : args[1] + ".jar"));
45+
if(file.exists()) {
46+
47+
Plugin plugin = Server.getInstance().getPluginManager().loadPlugin(file);
48+
49+
if(plugin != null) {
50+
51+
for(String depend : plugin.getDescription().getDepend()) {
52+
53+
if(Server.getInstance().getPluginManager().getPlugin(depend) == null) {
54+
arg0.sendMessage(prefix + "§cCould not enable " + TextFormat.getFormatedPluginName(plugin) + " due a missing dependency: §4" + depend + ".jar");
55+
return false;
56+
}
57+
}
58+
59+
Server.getInstance().getPluginManager().enablePlugin(plugin);
60+
arg0.sendMessage(prefix + TextFormat.getFormatedPluginName(plugin) + " loaded successully.");
61+
62+
} else arg0.sendMessage(prefix + "§cSomething went wrong while loading the plugin.");
63+
64+
} else arg0.sendMessage(prefix + "There is no file called " + file.getName() + ".");
65+
66+
} else arg0.sendMessage(prefix + "§cDo /pluginmanager load [filename]");
67+
68+
break;
69+
70+
case "unload":
71+
72+
if(args.length == 2) {
73+
74+
75+
Plugin plugin = Server.getInstance().getPluginManager().getPlugin(args[1]);
76+
77+
if(plugin == PluginManagerInstance.plugin) {
78+
arg0.sendMessage(prefix + "§cYou can not disable PluginManager.");
79+
return false;
80+
}
81+
82+
if(plugin != null) {
83+
84+
85+
WorkArounds.unregisterPlugin(plugin);
86+
Server.getInstance().getPluginManager().disablePlugin(plugin);
87+
88+
arg0.sendMessage(prefix + TextFormat.getFormatedPluginName(plugin) + " unloaded successully.");
89+
90+
} else arg0.sendMessage(prefix + "§cThere is no plugin called " + args[1] + ".");
91+
92+
93+
94+
} else arg0.sendMessage(prefix + "§cDo /pluginmanager unload [filename]");
95+
96+
break;
97+
98+
case "enable":
99+
100+
if(args.length == 2) {
101+
102+
Plugin plugin = Server.getInstance().getPluginManager().getPlugin(args[1]);
103+
104+
if(plugin != null) {
105+
106+
if(plugin.isEnabled()) {
107+
arg0.sendMessage(prefix + "§c" + TextFormat.getFormatedPluginName(plugin) + " is already enabled.");
108+
return false;
109+
}
110+
111+
for(String depend : plugin.getDescription().getDepend()) {
112+
113+
if(Server.getInstance().getPluginManager().getPlugin(depend) == null) {
114+
arg0.sendMessage(prefix + "§cCould not enable " + TextFormat.getFormatedPluginName(plugin) + " due a missing dependency: §4" + depend + ".jar");
115+
return false;
116+
}
117+
}
118+
119+
Server.getInstance().getPluginManager().enablePlugin(plugin);
120+
arg0.sendMessage(prefix + TextFormat.getFormatedPluginName(plugin) + " enabled successully.");
121+
122+
} else arg0.sendMessage(prefix + "§cThere is no Plugin called " + args[1] + ".");
123+
124+
} else arg0.sendMessage(prefix + "§cDo /pluginmanager enable [Plugin]");
125+
126+
break;
127+
128+
case "disable":
129+
130+
if(args.length == 2) {
131+
132+
Plugin plugin = Server.getInstance().getPluginManager().getPlugin(args[1]);
133+
134+
if(plugin == PluginManagerInstance.plugin) {
135+
arg0.sendMessage(prefix + "§cYou can not disable PluginManager.");
136+
return false;
137+
}
138+
139+
if(plugin != null) {
140+
141+
if(!plugin.isEnabled()) {
142+
arg0.sendMessage(prefix + "§c" + TextFormat.getFormatedPluginName(plugin) + " is already disabled.");
143+
return false;
144+
}
145+
146+
Server.getInstance().getPluginManager().disablePlugin(plugin);
147+
148+
149+
arg0.sendMessage(prefix + TextFormat.getFormatedPluginName(plugin) + " disabled successully.");
150+
151+
} else arg0.sendMessage(prefix + "§cThere is no Plugin called " + args[1] + ".");
152+
153+
} else arg0.sendMessage(prefix + "§cDo /pluginmanager disable [Plugin]");
154+
155+
break;
156+
157+
case "reload":
158+
159+
if(args.length == 2) {
160+
161+
Plugin plugin = Server.getInstance().getPluginManager().getPlugin(args[1]);
162+
163+
if(plugin == PluginManagerInstance.plugin) {
164+
arg0.sendMessage(prefix + "§cYou can not disable PluginManager.");
165+
return false;
166+
}
167+
168+
if(plugin != null) {
169+
170+
File file = new File(plugin.getClass().getProtectionDomain().getCodeSource().getLocation().getPath());
171+
172+
long millis = System.currentTimeMillis();
173+
174+
WorkArounds.unregisterPlugin(plugin);
175+
176+
for(String depend : plugin.getDescription().getDepend()) {
177+
178+
if(Server.getInstance().getPluginManager().getPlugin(depend) == null) {
179+
arg0.sendMessage(prefix + "§cCould not enable " + TextFormat.getFormatedPluginName(plugin) + " due a missing dependency: §4" + depend + ".jar");
180+
return false;
181+
}
182+
}
183+
Server.getInstance().getPluginManager().disablePlugin(plugin);
184+
try {
185+
Server.getInstance().enablePlugin(Server.getInstance().getPluginManager().loadPlugin(file));
186+
} catch (Exception e) {
187+
arg0.sendMessage(prefix + "§cCouldn't load Plugin " + plugin.getName() + ". File renamed or deleted?");
188+
}
189+
190+
191+
arg0.sendMessage(prefix + TextFormat.getFormatedPluginName(plugin) + " reloaded successully. (" + (System.currentTimeMillis() - millis) + " milliseconds)");
192+
193+
} else arg0.sendMessage(prefix + "§cThere is no Plugin called " + args[1] + ".");
194+
195+
} else if(args.length == 1) {
196+
197+
198+
new Thread(new Runnable() {
199+
200+
@Override
201+
public void run() {
202+
long millis = System.currentTimeMillis();
203+
Server.getInstance().broadcastMessage(PluginManagerInstance.prefix + "§eReloading the Server...");
204+
Server.getInstance().reload();
205+
Server.getInstance().broadcastMessage(PluginManagerInstance.prefix + "§eServer reloaded in " + (System.currentTimeMillis() - millis) + " milliseconds.");
206+
207+
}
208+
}).start();
209+
210+
} else arg0.sendMessage(prefix + "§cDo /pluginmanager reload [Plugin]");
211+
break;
212+
213+
case "help":
214+
215+
arg0.sendMessage(prefix + "Help Page\n"
216+
+ "§e/pluginmanager §7opens an UI to manage all plugins ingame.\n"
217+
+ "§e/pluginmanager load [file] §7loads a plugin from a .jar file.\n"
218+
+ "§e/pluginmanager unload [plugin] §7unloads a plugin from your server.\n"
219+
+ "§e/pluginmanager reload [plugin] §7reloads a plugin without reloading the whole server.\n"
220+
+ "§e/pluginmanager enable [plugin] §7enables a disabled plugin.\n"
221+
+ "§e/pluginmanager disable [plugin] §7disables a plugin.\n"
222+
+ "§e/reload [plugin] §7reloads a single plugin.");
223+
224+
225+
break;
226+
227+
default:
228+
arg0.sendMessage(prefix + "§cDo /pluginmanager help");
229+
break;
230+
}
231+
232+
} else {
233+
if(arg0 instanceof Player) {
234+
235+
Player p = (Player) arg0;
236+
237+
if(p.hasPermission("pluginmanager.ui"))
238+
239+
WindowFactory.openPluginListWindow(p);
240+
241+
else p.sendMessage(prefix + "§cYou are lacking the permission 'pluginmanager.ui'");
242+
243+
} else arg0.sendMessage(prefix + "§cDo /pluginmanager help");
244+
}
245+
246+
247+
return false;
248+
}
249+
250+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package de.buddelbubi.commands;
2+
3+
import cn.nukkit.Server;
4+
5+
import cn.nukkit.command.Command;
6+
import cn.nukkit.command.CommandSender;
7+
import de.buddelbubi.utils.PluginManagerAPI;
8+
9+
public class PluginManagerReloadCommand extends Command {
10+
11+
public PluginManagerReloadCommand(String name) {
12+
super(name);
13+
// TODO Auto-generated constructor stub
14+
}
15+
16+
17+
18+
@Override
19+
public boolean execute(CommandSender arg0, String arg1, String[] args) {
20+
21+
if(args.length == 0) {
22+
23+
PluginManagerAPI.reloadServer();
24+
25+
} else {
26+
Server.getInstance().dispatchCommand(arg0, "pluginmanager reload " + args[0]);
27+
}
28+
29+
return false;
30+
}
31+
32+
}

0 commit comments

Comments
 (0)