120 lines
3.1 KiB
Java
120 lines
3.1 KiB
Java
package xyz.etztech.mixtape;
|
|
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.configuration.file.FileConfiguration;
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
|
import xyz.etztech.mixtape.commands.CommandAlias;
|
|
import xyz.etztech.mixtape.commands.CommandMixtape;
|
|
import xyz.etztech.mixtape.listeners.CommandPreprocessListener;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.LinkedHashMap;
|
|
import java.util.List;
|
|
import java.util.logging.Logger;
|
|
|
|
public final class Mixtape extends JavaPlugin {
|
|
|
|
private Logger log = Logger.getLogger( "Minecraft" );
|
|
|
|
private static Mixtape instance;
|
|
private static FileConfiguration config;
|
|
private static Database database;
|
|
|
|
private static int loops;
|
|
private static int limit;
|
|
|
|
private static boolean global;
|
|
|
|
@Override
|
|
public void onEnable() {
|
|
// Plugin startup logic
|
|
instance = this;
|
|
saveDefaultConfig();
|
|
reloadConfig();
|
|
database = new Database(this);
|
|
|
|
new CommandMixtape(this);
|
|
new CommandAlias(this, Database.AliasType.CHAT);
|
|
new CommandAlias(this, Database.AliasType.COMMAND);
|
|
|
|
new CommandPreprocessListener(this);
|
|
}
|
|
|
|
@Override
|
|
public void onDisable() {
|
|
// Plugin shutdown logic
|
|
}
|
|
|
|
@Override
|
|
public void reloadConfig() {
|
|
super.reloadConfig();
|
|
config = Bukkit.getPluginManager().getPlugin("Mixtape").getConfig();
|
|
loops = config.getInt("loop", 5);
|
|
limit = config.getInt("limit", -1);
|
|
validate();
|
|
}
|
|
|
|
|
|
public void log(String message) {
|
|
log.info( "[Mixtape]: " + message );
|
|
}
|
|
|
|
public static Mixtape getInstance() {
|
|
return instance;
|
|
}
|
|
|
|
public static Database getDatabase() {
|
|
return database;
|
|
}
|
|
|
|
|
|
public static boolean getGlobal() {
|
|
return global;
|
|
}
|
|
|
|
public static void setGlobal(boolean bool) {
|
|
global = bool;
|
|
}
|
|
|
|
public static int getLoops() {
|
|
return loops;
|
|
}
|
|
|
|
public static int getLimit() {
|
|
return limit;
|
|
}
|
|
|
|
private void validate() {
|
|
List<String> errors = new ArrayList<>();
|
|
try {
|
|
List<?> aliases = getConfig().getList("aliases");
|
|
for (int i = 0; i < aliases.size(); i++) {
|
|
try {
|
|
LinkedHashMap<String, String> alias = (LinkedHashMap<String, String>) aliases.get(i);
|
|
if (!alias.containsKey("alias")) {
|
|
errors.add("Could not load alias #" + (i+1) + "'s alias");
|
|
}
|
|
if (!alias.containsKey("command")) {
|
|
errors.add("Could not load alias #" + (i+1) + "'s command");
|
|
}
|
|
} catch (Exception ex) {
|
|
errors.add("Could not load alias #" + (i+1));
|
|
}
|
|
}
|
|
} catch (Exception ex) {
|
|
errors.add("Could not load config. Is it up-to-date?");
|
|
}
|
|
for (String message : errors) {
|
|
log(message);
|
|
}
|
|
if (errors.size() > 0) {
|
|
log("Disabling global aliases...");
|
|
}
|
|
Mixtape.setGlobal(errors.size() == 0);
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|