Skip to content

Commit 41e040e

Browse files
authored
Now you dont have to write out the full plugin name when using commands.
1 parent d60d1b9 commit 41e040e

File tree

5 files changed

+100
-48
lines changed

5 files changed

+100
-48
lines changed

plugin.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: PluginManager
2-
version: 1.0.3
2+
version: 1.0.5
33
main: de.buddelbubi.PluginManagerInstance
44
api: 1.0.13
55
author: Buddelbubi

src/de/buddelbubi/commands/PluginManagerCommand.java

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ public boolean execute(CommandSender arg0, String arg1, String[] args) {
2525

2626
String prefix = PluginManagerInstance.prefix;
2727

28-
29-
30-
3128
if(args.length >= 1) {
3229

3330
if(!arg0.hasPermission("pluginmanager." + args[0])) {
@@ -71,9 +68,16 @@ public boolean execute(CommandSender arg0, String arg1, String[] args) {
7168

7269
if(args.length == 2) {
7370

74-
7571
Plugin plugin = Server.getInstance().getPluginManager().getPlugin(args[1]);
7672

73+
if(plugin == null) {
74+
for(Plugin pl : Server.getInstance().getPluginManager().getPlugins().values()) {
75+
if(pl.getName().toLowerCase().startsWith(args[1].toLowerCase())) {
76+
plugin = pl;
77+
}
78+
}
79+
}
80+
7781
if(plugin == PluginManagerInstance.plugin) {
7882
arg0.sendMessage(prefix + "§cYou can not disable PluginManager.");
7983
return false;
@@ -101,6 +105,14 @@ public boolean execute(CommandSender arg0, String arg1, String[] args) {
101105

102106
Plugin plugin = Server.getInstance().getPluginManager().getPlugin(args[1]);
103107

108+
if(plugin == null) {
109+
for(Plugin pl : Server.getInstance().getPluginManager().getPlugins().values()) {
110+
if(pl.getName().toLowerCase().startsWith(args[1].toLowerCase())) {
111+
plugin = pl;
112+
}
113+
}
114+
}
115+
104116
if(plugin != null) {
105117

106118
if(plugin.isEnabled()) {
@@ -135,6 +147,14 @@ public boolean execute(CommandSender arg0, String arg1, String[] args) {
135147
arg0.sendMessage(prefix + "§cYou can not disable PluginManager.");
136148
return false;
137149
}
150+
151+
if(plugin == null) {
152+
for(Plugin pl : Server.getInstance().getPluginManager().getPlugins().values()) {
153+
if(pl.getName().toLowerCase().startsWith(args[1].toLowerCase())) {
154+
plugin = pl;
155+
}
156+
}
157+
}
138158

139159
if(plugin != null) {
140160

@@ -164,9 +184,19 @@ public boolean execute(CommandSender arg0, String arg1, String[] args) {
164184
arg0.sendMessage(prefix + "§cYou can not disable PluginManager.");
165185
return false;
166186
}
187+
188+
if(plugin == null) {
189+
for(Plugin pl : Server.getInstance().getPluginManager().getPlugins().values()) {
190+
if(pl.getName().toLowerCase().startsWith(args[1].toLowerCase())) {
191+
plugin = pl;
192+
}
193+
}
194+
}
167195

168196
if(plugin != null) {
169197

198+
199+
170200
File file = new File(plugin.getClass().getProtectionDomain().getCodeSource().getLocation().getPath());
171201

172202
long millis = System.currentTimeMillis();

src/de/buddelbubi/commands/PluginManagerReloadCommand.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import cn.nukkit.command.Command;
66
import cn.nukkit.command.CommandSender;
7+
import de.buddelbubi.PluginManagerInstance;
78
import de.buddelbubi.utils.PluginManagerAPI;
89

910
public class PluginManagerReloadCommand extends Command {
@@ -20,7 +21,12 @@ public boolean execute(CommandSender arg0, String arg1, String[] args) {
2021

2122
if(args.length == 0) {
2223

23-
PluginManagerAPI.reloadServer();
24+
try {
25+
PluginManagerAPI.reloadServer();
26+
} catch (Exception e) {
27+
Server.getInstance().broadcastMessage(PluginManagerInstance.prefix + "Casual reload failed! Now trying outside a new task.");
28+
Server.getInstance().reload();
29+
}
2430

2531
} else {
2632
Server.getInstance().dispatchCommand(arg0, "pluginmanager reload " + args[0]);

src/de/buddelbubi/listeners/UIListener.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ public void on(PlayerFormRespondedEvent e) {
7878
}
7979
if(pl.getPrefix() != null) content += "§ePrefix: §8" + pl.getPrefix() + "\n";
8080
if(pl.getWebsite() != null) content += "§eWebsite: §8" + pl.getWebsite() + "\n";
81+
File file = new File(plugin.getClass().getProtectionDomain().getCodeSource().getLocation().getPath());
82+
content += "§eFile Name: §8" + file.getName() + "\n";
8183
if(pl.getDepend() != null) {
8284
String depend = "§eDepending Plugins: §8\n";
8385
int length = pl.getDepend().size();

src/de/buddelbubi/utils/WorkArounds.java

Lines changed: 56 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ public class WorkArounds {
1717

1818

1919

20-
@SuppressWarnings("unused")
2120
private static Object getPrivateField(Object object, String field)throws SecurityException,
2221
NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
2322
Class<?> clazz = object.getClass();
@@ -70,51 +69,55 @@ public static void unregisterPlugin(Plugin plugin) {
7069
HashMap<String, String> cmdds = new HashMap<>();
7170

7271
for(Command c : Server.getInstance().getCommandMap().getCommands().values()) {
73-
if(cmdds.containsKey(c.getClass().getName())) {
74-
cmdds.put(c.getClass().getName(),cmdds.get(c.getClass().getName()) + ">>>" + c.getName());
75-
} else cmdds.put(c.getClass().getName(), c.getName());
72+
try {
73+
if(cmdds.containsKey(c.getClass().getName())) {
74+
cmdds.put(c.getClass().getName(),cmdds.get(c.getClass().getName()) + ">>>" + c.getName());
75+
} else cmdds.put(c.getClass().getName(), c.getName());
76+
} catch (Exception e) {
77+
e.printStackTrace();
78+
}
7679
}
7780

7881
Object files = getPrivateField(Server.getInstance().getPluginManager(), "fileAssociations");
7982
@SuppressWarnings("unchecked")
8083
HashMap<String, PluginLoader> fileAssociations = (HashMap<String, PluginLoader>) files;
8184
for(PluginLoader p : fileAssociations.values()) {
8285

83-
Object map2 = getPrivateField(p, "classLoaders");
84-
@SuppressWarnings("unchecked")
85-
HashMap<String, PluginClassLoader> classes = (HashMap<String, PluginClassLoader>) map2;
86-
87-
Object map4 = getPrivateField(p, "classes");
88-
@SuppressWarnings({ "unchecked", "rawtypes" })
89-
HashMap<String, Class> packs = (HashMap<String, Class>) map4;
90-
91-
// for(String s : packs.keySet()) System.out.println("1 " + s);
92-
93-
94-
PluginClassLoader loader = classes.get(plugin.getName());
95-
Object map3 = getPrivateField(loader, "classes");
96-
@SuppressWarnings({ "unchecked", "rawtypes" })
97-
HashMap<String, Class> classess = (HashMap<String, Class>) map3;
98-
for(Class<?> s : classess.values()) {
99-
100-
packs.remove(s.getName());
101-
102-
if(cmdds.containsKey(s.getName())) for(String ss : cmdds.get(s.getName()).split(">>>")) if(!commands.contains(knownCommands.get(ss))) commands.add(knownCommands.get(ss));
103-
104-
}
105-
106-
for(Command c : commands) unregisterCommand(c);
107-
108-
classess.clear();
109-
110-
classes.remove(plugin.getName());
86+
try {
87+
Object map2 = getPrivateField(p, "classLoaders");
88+
@SuppressWarnings("unchecked")
89+
HashMap<String, PluginClassLoader> classes = (HashMap<String, PluginClassLoader>) map2;
90+
91+
Object map4 = getPrivateField(p, "classes");
92+
@SuppressWarnings({ "unchecked", "rawtypes" })
93+
HashMap<String, Class> packs = (HashMap<String, Class>) map4;
94+
95+
// for(String s : packs.keySet()) System.out.println("1 " + s);
96+
97+
98+
PluginClassLoader loader = classes.get(plugin.getName());
99+
Object map3 = getPrivateField(loader, "classes");
100+
@SuppressWarnings({ "unchecked", "rawtypes" })
101+
HashMap<String, Class> classess = (HashMap<String, Class>) map3;
102+
for(Class<?> s : classess.values()) {
103+
104+
packs.remove(s.getName());
105+
106+
if(cmdds.containsKey(s.getName())) for(String ss : cmdds.get(s.getName()).split(">>>")) if(!commands.contains(knownCommands.get(ss))) commands.add(knownCommands.get(ss));
107+
108+
}
109+
110+
for(Command c : commands) unregisterCommand(c);
111+
112+
classess.clear();
113+
114+
classes.remove(plugin.getName());
115+
} catch (Exception e) {
116+
e.printStackTrace();
117+
}
111118

112119
}
113-
114-
115-
116-
117-
120+
118121
} catch (Exception e) {
119122
e.printStackTrace();
120123
}
@@ -133,10 +136,13 @@ public static List<Command> findCommands(Plugin plugin) {
133136
HashMap<String, String> cmdds = new HashMap<>();
134137

135138
for(Command c : Server.getInstance().getCommandMap().getCommands().values()) {
136-
137-
if(cmdds.containsKey(c.getClass().getName())) {
138-
cmdds.put(c.getClass().getName(),cmdds.get(c.getClass().getName()) + ">>>" + c.getName());
139-
} else cmdds.put(c.getClass().getName(), c.getName());
139+
try {
140+
if(cmdds.containsKey(c.getClass().getName())) {
141+
cmdds.put(c.getClass().getName(),cmdds.get(c.getClass().getName()) + ">>>" + c.getName());
142+
} else cmdds.put(c.getClass().getName(), c.getName());
143+
} catch (Exception e) {
144+
e.printStackTrace();
145+
}
140146
}
141147

142148

@@ -145,6 +151,7 @@ public static List<Command> findCommands(Plugin plugin) {
145151
HashMap<String, PluginLoader> fileAssociations = (HashMap<String, PluginLoader>) files;
146152
for(PluginLoader p : fileAssociations.values()) {
147153

154+
try {
148155
Object map2 = getPrivateField(p, "classLoaders");
149156
@SuppressWarnings("unchecked")
150157
HashMap<String, PluginClassLoader> classes = (HashMap<String, PluginClassLoader>) map2;
@@ -155,8 +162,15 @@ public static List<Command> findCommands(Plugin plugin) {
155162
@SuppressWarnings({ "unchecked", "rawtypes" })
156163
HashMap<String, Class> classess = (HashMap<String, Class>) map3;
157164
for(Class<?> s : classess.values()) {
158-
if(cmdds.containsKey(s.getName())) for(String ss : cmdds.get(s.getName()).split(">>>")) if(!commands.contains(knownCommands.get(ss))) commands.add(knownCommands.get(ss));
165+
try {
166+
if(cmdds.containsKey(s.getName())) for(String ss : cmdds.get(s.getName()).split(">>>")) if(!commands.contains(knownCommands.get(ss))) commands.add(knownCommands.get(ss));
167+
} catch (Exception e) {
168+
e.printStackTrace();
169+
}
159170
}
171+
} catch (Exception e) {
172+
e.printStackTrace();
173+
}
160174

161175
}
162176

0 commit comments

Comments
 (0)