mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-18 18:23:06 +00:00
v
This commit is contained in:
parent
4ae5b49764
commit
d67cce4184
@ -30,12 +30,9 @@ import org.bukkit.command.Command;
|
|||||||
import org.bukkit.command.*;
|
import org.bukkit.command.*;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.event.Event;
|
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.permissions.PermissionDefault;
|
import org.bukkit.permissions.PermissionDefault;
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
import org.bukkit.plugin.RegisteredListener;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -43,11 +40,9 @@ import java.io.IOException;
|
|||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
import java.net.URLClassLoader;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.SortedSet;
|
|
||||||
|
|
||||||
@SuppressWarnings("EmptyMethod")
|
@SuppressWarnings("EmptyMethod")
|
||||||
public abstract class VolmitPlugin extends JavaPlugin implements Listener {
|
public abstract class VolmitPlugin extends JavaPlugin implements Listener {
|
||||||
@ -55,9 +50,6 @@ public abstract class VolmitPlugin extends JavaPlugin implements Listener {
|
|||||||
private KMap<KList<String>, VirtualCommand> commands;
|
private KMap<KList<String>, VirtualCommand> commands;
|
||||||
private KList<MortarCommand> commandCache;
|
private KList<MortarCommand> commandCache;
|
||||||
private KList<MortarPermission> permissionCache;
|
private KList<MortarPermission> permissionCache;
|
||||||
private KMap<String, IController> controllers;
|
|
||||||
private KList<IController> cachedControllers;
|
|
||||||
private KMap<Class<? extends IController>, IController> cachedClassControllers;
|
|
||||||
|
|
||||||
public File getJarFile() {
|
public File getJarFile() {
|
||||||
return getFile();
|
return getFile();
|
||||||
@ -83,15 +75,12 @@ public abstract class VolmitPlugin extends JavaPlugin implements Listener {
|
|||||||
registerInstance();
|
registerInstance();
|
||||||
registerPermissions();
|
registerPermissions();
|
||||||
registerCommands();
|
registerCommands();
|
||||||
registerControllers();
|
|
||||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, this::tickControllers, 0, 0);
|
|
||||||
J.a(this::outputInfo);
|
J.a(this::outputInfo);
|
||||||
registerListener(this);
|
registerListener(this);
|
||||||
start();
|
start();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void unregisterAll() {
|
public void unregisterAll() {
|
||||||
stopControllers();
|
|
||||||
unregisterListeners();
|
unregisterListeners();
|
||||||
unregisterCommands();
|
unregisterCommands();
|
||||||
unregisterPermissions();
|
unregisterPermissions();
|
||||||
@ -260,16 +249,6 @@ public abstract class VolmitPlugin extends JavaPlugin implements Listener {
|
|||||||
unregisterAll();
|
unregisterAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void tickControllers() {
|
|
||||||
if (bad) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (IController i : getControllers()) {
|
|
||||||
tickController(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void tickController(IController i) {
|
private void tickController(IController i) {
|
||||||
if (bad) {
|
if (bad) {
|
||||||
return;
|
return;
|
||||||
@ -291,62 +270,6 @@ public abstract class VolmitPlugin extends JavaPlugin implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public KList<IController> getControllers() {
|
|
||||||
if (bad) {
|
|
||||||
return new KList<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
return cachedControllers;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void registerControllers() {
|
|
||||||
if (bad) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
controllers = new KMap<>();
|
|
||||||
cachedClassControllers = new KMap<>();
|
|
||||||
|
|
||||||
for (Field i : getClass().getDeclaredFields()) {
|
|
||||||
if (i.isAnnotationPresent(Control.class)) {
|
|
||||||
try {
|
|
||||||
i.setAccessible(true);
|
|
||||||
IController pc = (IController) i.getType().getConstructor().newInstance();
|
|
||||||
registerController(pc);
|
|
||||||
i.set(this, pc);
|
|
||||||
v("Registered " + pc.getName() + " (" + i.getName() + ")");
|
|
||||||
} catch (IllegalArgumentException | IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
|
|
||||||
w("Failed to register controller (field " + i.getName() + ")");
|
|
||||||
e.printStackTrace();
|
|
||||||
Iris.reportError(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cachedControllers = controllers.v();
|
|
||||||
}
|
|
||||||
|
|
||||||
public IController getController(Class<? extends IController> c) {
|
|
||||||
return cachedClassControllers.get(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void registerController(IController pc) {
|
|
||||||
if (bad) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
controllers.put(pc.getName(), pc);
|
|
||||||
cachedClassControllers.put(pc.getClass(), pc);
|
|
||||||
registerListener(pc);
|
|
||||||
|
|
||||||
try {
|
|
||||||
pc.start();
|
|
||||||
v("Started " + pc.getName());
|
|
||||||
} catch (Throwable e) {
|
|
||||||
w("Failed to start controller " + pc.getName());
|
|
||||||
e.printStackTrace();
|
|
||||||
Iris.reportError(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void registerInstance() {
|
private void registerInstance() {
|
||||||
if (bad) {
|
if (bad) {
|
||||||
return;
|
return;
|
||||||
@ -569,23 +492,6 @@ public abstract class VolmitPlugin extends JavaPlugin implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void stopControllers() {
|
|
||||||
if (bad) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (IController i : controllers.v()) {
|
|
||||||
try {
|
|
||||||
unregisterListener(i);
|
|
||||||
i.stop();
|
|
||||||
v("Stopped " + i.getName());
|
|
||||||
} catch (Throwable e) {
|
|
||||||
Iris.reportError(e);
|
|
||||||
w("Failed to stop controller " + i.getName());
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public File getDataFile(String... strings) {
|
public File getDataFile(String... strings) {
|
||||||
File f = new File(getDataFolder(), new KList<>(strings).toString(File.separator));
|
File f = new File(getDataFolder(), new KList<>(strings).toString(File.separator));
|
||||||
f.getParentFile().mkdirs();
|
f.getParentFile().mkdirs();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user