mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-01-05 13:08:20 +07:00
Plugin config file creation
This commit is contained in:
parent
3fad378b69
commit
f71c3af2e1
@ -14,13 +14,12 @@ import io.anuke.mindustry.entities.*;
|
||||
import io.anuke.mindustry.entities.effect.*;
|
||||
import io.anuke.mindustry.entities.traits.*;
|
||||
import io.anuke.mindustry.entities.type.*;
|
||||
import io.anuke.mindustry.entities.type.Bullet;
|
||||
import io.anuke.mindustry.entities.type.EffectEntity;
|
||||
import io.anuke.mindustry.game.*;
|
||||
import io.anuke.mindustry.gen.*;
|
||||
import io.anuke.mindustry.input.*;
|
||||
import io.anuke.mindustry.maps.*;
|
||||
import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.mindustry.plugin.*;
|
||||
import io.anuke.mindustry.world.blocks.defense.ForceProjector.*;
|
||||
|
||||
import java.nio.charset.*;
|
||||
@ -141,6 +140,7 @@ public class Vars implements Loadable{
|
||||
public static DefaultWaves defaultWaves;
|
||||
public static LoopControl loops;
|
||||
public static Platform platform;
|
||||
public static Plugins plugins;
|
||||
|
||||
public static World world;
|
||||
public static Maps maps;
|
||||
|
@ -1,9 +1,16 @@
|
||||
package io.anuke.mindustry.plugin;
|
||||
|
||||
import io.anuke.arc.files.*;
|
||||
import io.anuke.arc.util.*;
|
||||
import io.anuke.mindustry.*;
|
||||
|
||||
public abstract class Plugin{
|
||||
|
||||
/** @return the config file for this plugin.*/
|
||||
public FileHandle getConfig(){
|
||||
return Vars.plugins.getConfig(this);
|
||||
}
|
||||
|
||||
/** Called after all plugins have been created and commands have been registered.*/
|
||||
public void init(){
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package io.anuke.mindustry.plugin;
|
||||
|
||||
import io.anuke.annotations.Annotations.*;
|
||||
import io.anuke.arc.collection.*;
|
||||
import io.anuke.arc.files.*;
|
||||
import io.anuke.arc.function.*;
|
||||
@ -12,6 +13,20 @@ import static io.anuke.mindustry.Vars.pluginDirectory;
|
||||
|
||||
public class Plugins{
|
||||
private Array<LoadedPlugin> loaded = new Array<>();
|
||||
private ObjectMap<Class<?>, PluginMeta> metas = new ObjectMap<>();
|
||||
|
||||
/** Returns a file named 'config.json' in a special folder for the specified plugin.
|
||||
* Call this in init(). */
|
||||
public FileHandle getConfig(Plugin plugin){
|
||||
PluginMeta load = metas.get(plugin.getClass());
|
||||
if(load == null) throw new IllegalArgumentException("Plugin is not loaded yet (or missing)!");
|
||||
return pluginDirectory.child(load.name).child("config.json");
|
||||
}
|
||||
|
||||
/** @return the loaded plugin found by class, or null if not found. */
|
||||
public @Nullable LoadedPlugin getPlugin(Class<? extends Plugin> type){
|
||||
return loaded.find(l -> l.plugin.getClass() == type);
|
||||
}
|
||||
|
||||
/** Loads all plugins from the folder, but does call any methods on them.*/
|
||||
public void load(){
|
||||
@ -51,6 +66,7 @@ public class Plugins{
|
||||
|
||||
URLClassLoader classLoader = new URLClassLoader(new URL[]{jar.file().toURI().toURL()}, ClassLoader.getSystemClassLoader());
|
||||
Class<?> main = classLoader.loadClass(meta.main);
|
||||
metas.put(main, meta);
|
||||
return new LoadedPlugin(jar, zip, (Plugin)main.newInstance(), meta);
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,3 @@
|
||||
org.gradle.daemon=true
|
||||
org.gradle.jvmargs=-Xms256m -Xmx1024m
|
||||
archash=63d0746402858e5bd112a2a04b0596f9eba9a975
|
||||
archash=173c53ecebbaa0ef86371e8ec9500357f0cf870a
|
||||
|
@ -41,7 +41,6 @@ public class ServerControl implements ApplicationListener{
|
||||
|
||||
private final CommandHandler handler = new CommandHandler("");
|
||||
private final FileHandle logFolder = Core.settings.getDataDirectory().child("logs/");
|
||||
private final io.anuke.mindustry.plugin.Plugins plugins = new Plugins();
|
||||
|
||||
private FileHandle currentLogFile;
|
||||
private boolean inExtraRound;
|
||||
@ -52,6 +51,8 @@ public class ServerControl implements ApplicationListener{
|
||||
private PrintWriter socketOutput;
|
||||
|
||||
public ServerControl(String[] args){
|
||||
plugins = new Plugins();
|
||||
|
||||
Core.settings.defaults(
|
||||
"shufflemode", "normal",
|
||||
"bans", "",
|
||||
|
Loading…
Reference in New Issue
Block a user