2017-01-30 21:22:36 +01:00
|
|
|
package net.ME1312.SubServers.Host.API;
|
|
|
|
|
|
|
|
import net.ME1312.SubServers.Host.Library.Config.YAMLSection;
|
|
|
|
import net.ME1312.SubServers.Host.Library.Config.YAMLValue;
|
|
|
|
import net.ME1312.SubServers.Host.Library.ExtraDataHandler;
|
|
|
|
import net.ME1312.SubServers.Host.Library.Log.Logger;
|
|
|
|
import net.ME1312.SubServers.Host.Library.Util;
|
|
|
|
import net.ME1312.SubServers.Host.Library.Version.Version;
|
2017-02-05 23:03:17 +01:00
|
|
|
import net.ME1312.SubServers.Host.SubServers;
|
2017-01-30 21:22:36 +01:00
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.net.URL;
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SubPlugin Info Class
|
|
|
|
*
|
|
|
|
* @see SubPlugin
|
|
|
|
*/
|
2017-01-31 01:33:30 +01:00
|
|
|
public class SubPluginInfo implements ExtraDataHandler {
|
2017-02-08 01:39:18 +01:00
|
|
|
private SubServers host;
|
|
|
|
private Object plugin;
|
2017-01-30 21:22:36 +01:00
|
|
|
private String name;
|
|
|
|
private Version version;
|
|
|
|
private List<String> authors;
|
2017-02-05 23:03:17 +01:00
|
|
|
private String desc;
|
|
|
|
private URL website;
|
|
|
|
private List<String> loadBefore;
|
|
|
|
private List<String> depend;
|
|
|
|
private List<String> softDepend;
|
2017-01-30 21:22:36 +01:00
|
|
|
|
2017-02-08 01:39:18 +01:00
|
|
|
private Logger logger = null;
|
2017-01-30 21:22:36 +01:00
|
|
|
private boolean enabled = false;
|
|
|
|
private YAMLSection extra = new YAMLSection();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a SubPlugin Description
|
|
|
|
*
|
2017-02-08 01:39:18 +01:00
|
|
|
* @param host SubServers.Host
|
|
|
|
* @param plugin Plugin
|
2017-01-30 21:22:36 +01:00
|
|
|
* @param name Plugin Name
|
|
|
|
* @param version Plugin Version
|
|
|
|
* @param authors Authors List
|
|
|
|
* @param description Plugin Description
|
|
|
|
* @param website Authors' Website
|
2017-02-08 01:39:18 +01:00
|
|
|
* @param loadBefore Load Before Plugins List
|
2017-01-30 21:22:36 +01:00
|
|
|
* @param dependencies Dependencies List
|
2017-02-05 23:03:17 +01:00
|
|
|
* @param softDependencies Soft Dependencies List
|
2017-01-30 21:22:36 +01:00
|
|
|
*/
|
2017-02-08 01:39:18 +01:00
|
|
|
public SubPluginInfo(SubServers host, Object plugin, String name, Version version, List<String> authors, String description, URL website, List<String> loadBefore, List<String> dependencies, List<String> softDependencies) {
|
|
|
|
if (Util.isNull(host, plugin, name, version, authors)) throw new NullPointerException();
|
2017-02-05 23:03:17 +01:00
|
|
|
name = name.replaceAll("#|<|\\$|\\+|%|>|!|`|&|\\*|'|\\||\\{|\\?|\"|=|}|/|\\\\|\\s|@|\\.|\\n", "_");
|
|
|
|
if (name.length() == 0) throw new StringIndexOutOfBoundsException("Cannot use an empty name");
|
|
|
|
if (version.toString().length() == 0) throw new StringIndexOutOfBoundsException("Cannot use an empty version");
|
|
|
|
if (authors.size() == 0) throw new ArrayIndexOutOfBoundsException("Cannot use an empty authors list");
|
|
|
|
if (description != null && description.length() == 0) throw new StringIndexOutOfBoundsException("Cannot use an empty description");
|
2017-02-08 01:39:18 +01:00
|
|
|
this.host = host;
|
2017-01-30 21:22:36 +01:00
|
|
|
this.plugin = plugin;
|
|
|
|
this.name = name;
|
|
|
|
this.version = version;
|
2017-02-05 23:03:17 +01:00
|
|
|
this.authors = authors;
|
2017-01-30 21:22:36 +01:00
|
|
|
this.desc = description;
|
|
|
|
this.website = website;
|
2017-02-05 23:03:17 +01:00
|
|
|
this.loadBefore = (loadBefore == null)?Collections.emptyList():loadBefore;
|
2017-01-30 21:22:36 +01:00
|
|
|
this.depend = (dependencies == null)?Collections.emptyList():dependencies;
|
|
|
|
this.softDepend = (softDependencies == null)?Collections.emptyList():softDependencies;
|
|
|
|
}
|
|
|
|
|
2017-02-08 01:39:18 +01:00
|
|
|
/**
|
|
|
|
* Get Plugin Object
|
|
|
|
*
|
|
|
|
* @return Plugin Object
|
|
|
|
*/
|
2017-01-30 21:22:36 +01:00
|
|
|
public Object get() {
|
2017-02-08 01:39:18 +01:00
|
|
|
return plugin;
|
2017-01-30 21:22:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get Plugin's Name
|
|
|
|
*
|
|
|
|
* @return Plugin Name
|
|
|
|
*/
|
|
|
|
public String getName() {
|
|
|
|
return this.name;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get Plugin's Version
|
|
|
|
*
|
|
|
|
* @return Plugin Version
|
|
|
|
*/
|
|
|
|
public Version getVersion() {
|
|
|
|
return this.version;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get Authors List
|
|
|
|
*
|
|
|
|
* @return Authors List
|
|
|
|
*/
|
|
|
|
public List<String> getAuthors() {
|
|
|
|
return this.authors;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get Plugin Description
|
|
|
|
*
|
|
|
|
* @return Plugin Description
|
|
|
|
*/
|
|
|
|
public String getDescription() {
|
|
|
|
return this.desc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get Authors' Website
|
|
|
|
*
|
|
|
|
* @return Authors' Website
|
|
|
|
*/
|
|
|
|
public URL getWebsite() {
|
|
|
|
return this.website;
|
|
|
|
}
|
|
|
|
|
2017-02-05 23:03:17 +01:00
|
|
|
/**
|
|
|
|
* Gets the Load Before Plugins List
|
|
|
|
*
|
|
|
|
* @return Load Before Plugins List
|
|
|
|
*/
|
|
|
|
public List<String> getLoadBefore() {
|
|
|
|
return this.loadBefore;
|
|
|
|
}
|
|
|
|
|
2017-01-30 21:22:36 +01:00
|
|
|
/**
|
|
|
|
* Gets the Dependencies List
|
|
|
|
*
|
|
|
|
* @return Dependencies List
|
|
|
|
*/
|
|
|
|
public List<String> getDependancies() {
|
|
|
|
return this.depend;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the Soft Dependencies List
|
|
|
|
*
|
|
|
|
* @return Soft Dependencies List
|
|
|
|
*/
|
|
|
|
public List<String> getSoftDependancies() {
|
|
|
|
return this.softDepend;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the Plugin's Enabled Status
|
|
|
|
*
|
|
|
|
* @return Enabled Status
|
|
|
|
*/
|
|
|
|
public boolean isEnabled() {
|
|
|
|
return enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-02-08 01:39:18 +01:00
|
|
|
* Sets if the Plugin is Enabled
|
2017-01-30 21:22:36 +01:00
|
|
|
*
|
2017-02-08 01:39:18 +01:00
|
|
|
* @param value Value
|
2017-01-30 21:22:36 +01:00
|
|
|
*/
|
|
|
|
public void setEnabled(boolean value) {
|
|
|
|
enabled = value;
|
|
|
|
}
|
|
|
|
|
2017-02-08 01:39:18 +01:00
|
|
|
/**
|
|
|
|
* Replace this Plugin's Logger with a custom one
|
|
|
|
*
|
|
|
|
* @param value Value
|
|
|
|
*/
|
|
|
|
public void setLogger(Logger value) {
|
|
|
|
logger = value;
|
|
|
|
}
|
|
|
|
|
2017-01-30 21:22:36 +01:00
|
|
|
/**
|
|
|
|
* Gets the default Logger for this Plugin
|
|
|
|
*
|
|
|
|
* @return Logger
|
|
|
|
*/
|
|
|
|
public Logger getLogger() {
|
2017-02-08 01:39:18 +01:00
|
|
|
if (logger == null) logger = new Logger(name);
|
2017-01-30 21:22:36 +01:00
|
|
|
return logger;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets this Plugin's data folder
|
|
|
|
*
|
|
|
|
* @return Data Folder
|
|
|
|
*/
|
|
|
|
public File getDataFolder() {
|
2017-02-08 01:39:18 +01:00
|
|
|
File dir = new File(host.api.getRuntimeDirectory(), "Plugins" + File.separator + name);
|
|
|
|
if (!dir.exists()) dir.mkdirs();
|
2017-01-30 21:22:36 +01:00
|
|
|
return dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void addExtra(String handle, Object value) {
|
|
|
|
extra.set(handle, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean hasExtra(String handle) {
|
|
|
|
return extra.getKeys().contains(handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public YAMLValue getExtra(String handle) {
|
|
|
|
return extra.get(handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public YAMLSection getExtra() {
|
|
|
|
return extra.clone();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void removeExtra(String handle) {
|
|
|
|
extra.remove(handle);
|
|
|
|
}
|
|
|
|
}
|