public Map<String, ICommand> cmds = new HashMap<String, ICommand>();
@Override
public void onEnable() {
setumMap("Example.i.ICommand");
}
public void setumMap(String interfaceName) {
try {
String url = this.getClass().getProtectionDomain().getCodeSource().getLocation().toURI().getPath();
JarFile jar = new JarFile(url);
Enumeration<? extends JarEntry> ens = jar.entries();
while (ens.hasMoreElements()) {
ZipEntry en = ens.nextElement();
if (en.getName().endsWith(".class")) {
Class<?> cl = Class.forName(en.getName().replace("/", ".").replace(".class", ""));
for (Class<?> in : cl.getInterfaces()) {
if (in.getName().equals(interfaceName)) {
ICommand ic = (ICommand) cl.getConstructor(this.getClass()).newInstance(this);
cmds.put(ic.getName(), ic);
}
}
}
}
jar.close();
} catch (Exception e) {}
}
public interface ICommand {
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args);
public String getName();
}
public class CMDReload implements ICommand {
private Main plugin;
public CMDReload(Main plugin) {
this.plugin = plugin;
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (sender.hasPermission("example.reload")) {
for (CustomConfig cfg : this.plugin.cfgs.getConfigs().values()) {
cfg.reloadCfg();
}
sender.sendMessage("Example reloaded");
Player p = (Player) sender;
p.spawnParticle(Particle.LAVA, p.getLocation(), 5);
return true;
}
return false;
}
@Override
public String getName() {
return "reload";
}
}