Skip to content

Commit 1d987ff

Browse files
authored
Add files via upload
1 parent 41e040e commit 1d987ff

File tree

3 files changed

+74
-27
lines changed

3 files changed

+74
-27
lines changed

src/de/buddelbubi/commands/PluginManagerCommand.java

Lines changed: 57 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public boolean execute(CommandSender arg0, String arg1, String[] args) {
2727

2828
if(args.length >= 1) {
2929

30-
if(!arg0.hasPermission("pluginmanager." + args[0])) {
30+
if(!arg0.hasPermission("pluginmanager." + args[0]) && !arg0.hasPermission("pluginmanager.admin")) {
3131

3232
arg0.sendMessage(prefix + "§cYou are lacking the permission 'pluginmanager." + args[0] + "'.");
3333
return false;
@@ -39,8 +39,28 @@ public boolean execute(CommandSender arg0, String arg1, String[] args) {
3939
if(args.length == 2) {
4040

4141
File file = new File(Server.getInstance().getPluginPath(), (args[1].contains(".jar") ? args[1] : args[1] + ".jar"));
42+
43+
if(!file.exists()) {
44+
45+
for(File f : new File(Server.getInstance().getPluginPath()).listFiles()) {
46+
if(f.getName().startsWith(args[1])) {
47+
file = f;
48+
break;
49+
}
50+
}
51+
52+
}
53+
4254
if(file.exists()) {
4355

56+
for(Plugin plugin : Server.getInstance().getPluginManager().getPlugins().values()) {
57+
File pluginfile = new File(plugin.getClass().getProtectionDomain().getCodeSource().getLocation().getPath());
58+
if(file.getName().equals(pluginfile.getName())) {
59+
arg0.sendMessage(prefix + "§c " + plugin.getName() + " is already loaded. Use /pluginmanager reload instead.");
60+
return false;
61+
}
62+
}
63+
4464
Plugin plugin = Server.getInstance().getPluginManager().loadPlugin(file);
4565

4666
if(plugin != null) {
@@ -79,7 +99,7 @@ public boolean execute(CommandSender arg0, String arg1, String[] args) {
7999
}
80100

81101
if(plugin == PluginManagerInstance.plugin) {
82-
arg0.sendMessage(prefix + "§cYou can not disable PluginManager.");
102+
arg0.sendMessage(prefix + "§cYou can not unload PluginManager.");
83103
return false;
84104
}
85105

@@ -143,11 +163,6 @@ public boolean execute(CommandSender arg0, String arg1, String[] args) {
143163

144164
Plugin plugin = Server.getInstance().getPluginManager().getPlugin(args[1]);
145165

146-
if(plugin == PluginManagerInstance.plugin) {
147-
arg0.sendMessage(prefix + "§cYou can not disable PluginManager.");
148-
return false;
149-
}
150-
151166
if(plugin == null) {
152167
for(Plugin pl : Server.getInstance().getPluginManager().getPlugins().values()) {
153168
if(pl.getName().toLowerCase().startsWith(args[1].toLowerCase())) {
@@ -156,6 +171,11 @@ public boolean execute(CommandSender arg0, String arg1, String[] args) {
156171
}
157172
}
158173

174+
if(plugin == PluginManagerInstance.plugin) {
175+
arg0.sendMessage(prefix + "§cYou can not disable PluginManager.");
176+
return false;
177+
}
178+
159179
if(plugin != null) {
160180

161181
if(!plugin.isEnabled()) {
@@ -180,23 +200,22 @@ public boolean execute(CommandSender arg0, String arg1, String[] args) {
180200

181201
Plugin plugin = Server.getInstance().getPluginManager().getPlugin(args[1]);
182202

183-
if(plugin == PluginManagerInstance.plugin) {
184-
arg0.sendMessage(prefix + "§cYou can not disable PluginManager.");
185-
return false;
186-
}
187-
188203
if(plugin == null) {
189204
for(Plugin pl : Server.getInstance().getPluginManager().getPlugins().values()) {
190205
if(pl.getName().toLowerCase().startsWith(args[1].toLowerCase())) {
191206
plugin = pl;
192207
}
193208
}
194209
}
210+
211+
if(plugin == PluginManagerInstance.plugin) {
212+
arg0.sendMessage(prefix + "§cYou can not reload PluginManager.");
213+
return false;
214+
}
215+
195216

196217
if(plugin != null) {
197-
198-
199-
218+
200219
File file = new File(plugin.getClass().getProtectionDomain().getCodeSource().getLocation().getPath());
201220

202221
long millis = System.currentTimeMillis();
@@ -214,7 +233,6 @@ public boolean execute(CommandSender arg0, String arg1, String[] args) {
214233
try {
215234
Server.getInstance().enablePlugin(Server.getInstance().getPluginManager().loadPlugin(file));
216235
} catch (Exception e) {
217-
arg0.sendMessage(prefix + "§cCouldn't load Plugin " + plugin.getName() + ". File renamed or deleted?");
218236
}
219237

220238

@@ -255,7 +273,28 @@ public void run() {
255273
break;
256274

257275
default:
258-
arg0.sendMessage(prefix + "§cDo /pluginmanager help");
276+
if(arg0 instanceof Player) {
277+
Player p = (Player) arg0;
278+
279+
if(p.hasPermission("pluginmanager.ui")|| p.hasPermission("pluginmanager.admin")) {
280+
281+
Plugin plugin = Server.getInstance().getPluginManager().getPlugin(args[0]);
282+
283+
if(plugin == null) {
284+
for(Plugin pl : Server.getInstance().getPluginManager().getPlugins().values()) {
285+
if(pl.getName().toLowerCase().startsWith(args[0].toLowerCase())) {
286+
plugin = pl;
287+
}
288+
}
289+
}
290+
if(plugin != null) {
291+
292+
WindowFactory.openPluginWindow(p, plugin);
293+
294+
} else arg0.sendMessage(prefix + "§cCould not find a plugin called " + args[0]+ ". Do /pluginmanager help");
295+
} else p.sendMessage(prefix + "§cYou are lacking the permission 'pluginmanager.ui'");
296+
} else arg0.sendMessage(prefix + "§cDo /pluginmanager help");
297+
259298
break;
260299
}
261300

@@ -264,7 +303,7 @@ public void run() {
264303

265304
Player p = (Player) arg0;
266305

267-
if(p.hasPermission("pluginmanager.ui"))
306+
if(p.hasPermission("pluginmanager.ui") || p.hasPermission("pluginmanager.admin"))
268307

269308
WindowFactory.openPluginListWindow(p);
270309

src/de/buddelbubi/listeners/UIListener.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import de.buddelbubi.PluginManagerInstance;
2525
import de.buddelbubi.utils.PluginManagerAPI;
2626
import de.buddelbubi.utils.TextFormat;
27+
import de.buddelbubi.utils.WindowFactory;
2728
import de.buddelbubi.utils.WorkArounds;
2829

2930
public class UIListener implements Listener{
@@ -39,14 +40,8 @@ public void on(PlayerFormRespondedEvent e) {
3940
if(fwresponse.getTitle().equals(PluginManagerInstance.prefix + "§eInstalled Plugins")) {
4041

4142
String plugin = fwresponse.getResponse().getClickedButton().getText().split("\\s+")[0].replace("§7", "");
42-
FormWindowSimple fw = new FormWindowSimple(PluginManagerInstance.prefix + "§e" + plugin, "§7§1§3");
43-
fw.addButton(new ElementButton("Plugin Info",new ElementButtonImageData("path", "textures/ui/infobulb_darkborder_small.png")));
44-
fw.addButton(new ElementButton("Config Files", new ElementButtonImageData("path", "textures/ui/settings_glyph_color_2x.png")));
45-
46-
if(!PluginManagerInstance.plugin.getName().equals(plugin))
47-
fw.addButton(new ElementButton("Management", new ElementButtonImageData("path", "textures/ui/op.png")));
48-
49-
e.getPlayer().showFormWindow(fw);
43+
Plugin pl = Server.getInstance().getPluginManager().getPlugin(plugin);
44+
WindowFactory.openPluginWindow(e.getPlayer(), pl);
5045

5146

5247
//yup. I will think about this again xd
@@ -248,7 +243,7 @@ public void run() {
248243
Config c = new Config(file);
249244
FormWindowCustom fw = new FormWindowCustom("§5§9§e" + file.getAbsolutePath());
250245

251-
if(!e.getPlayer().hasPermission("pluginmanager.config." + file.getAbsolutePath().replace("/", "."))) {
246+
if(!e.getPlayer().hasPermission("pluginmanager.config." + file.getAbsolutePath().replace("/", ".")) && !e.getPlayer().hasPermission("pluginmanager.admin")) {
252247

253248
e.getPlayer().sendMessage(PluginManagerInstance.prefix + "§cYou are lacking the permission 'pluginmanager.config." + file.getAbsolutePath().replace("/", ".") + "'.");
254249
return;

src/de/buddelbubi/utils/WindowFactory.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,17 @@ public static void openPluginListWindow(Player p) {
3333

3434
}
3535

36+
public static void openPluginWindow(Player p, Plugin plugin) {
37+
38+
FormWindowSimple fw = new FormWindowSimple(PluginManagerInstance.prefix + "§e" + plugin.getName(), "§7§1§3");
39+
fw.addButton(new ElementButton("Plugin Info",new ElementButtonImageData("path", "textures/ui/infobulb_darkborder_small.png")));
40+
fw.addButton(new ElementButton("Config Files", new ElementButtonImageData("path", "textures/ui/settings_glyph_color_2x.png")));
41+
42+
if(!PluginManagerInstance.plugin.getName().equals(plugin.getName()))
43+
fw.addButton(new ElementButton("Management", new ElementButtonImageData("path", "textures/ui/op.png")));
44+
45+
p.showFormWindow(fw);
46+
47+
}
48+
3649
}

0 commit comments

Comments
 (0)