SubServers-2/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/SubPlugin.java

70 lines
3.3 KiB
Java
Raw Normal View History

2016-12-20 00:31:01 +01:00
package net.ME1312.SubServers.Client.Bukkit;
import net.ME1312.SubServers.Client.Bukkit.Graphic.UIListener;
import net.ME1312.SubServers.Client.Bukkit.Library.Config.YAMLConfig;
import net.ME1312.SubServers.Client.Bukkit.Library.Config.YAMLSection;
import net.ME1312.SubServers.Client.Bukkit.Library.UniversalFile;
2016-12-27 17:03:19 +01:00
import net.ME1312.SubServers.Client.Bukkit.Library.Util;
2016-12-20 00:31:01 +01:00
import net.ME1312.SubServers.Client.Bukkit.Library.Version.Version;
import net.ME1312.SubServers.Client.Bukkit.Network.SubDataClient;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.*;
import java.net.InetAddress;
import java.nio.file.Files;
import java.util.Arrays;
public final class SubPlugin extends JavaPlugin {
public YAMLConfig pluginconf;
public YAMLSection lang = null;
public SubDataClient subdata = null;
public UIListener gui = null;
2016-12-24 05:55:17 +01:00
public Version version;
2017-01-08 03:30:03 +01:00
protected Version bversion = new Version(2);
2016-12-20 00:31:01 +01:00
//public final SubAPI api = new SubAPI(this);
@Override
public void onEnable() {
2016-12-24 05:55:17 +01:00
version = new Version(getDescription().getVersion());
2016-12-20 00:31:01 +01:00
try {
Bukkit.getLogger().info("SubServers > Loading SubServers v" + version.toString() + " Libraries... ");
getDataFolder().mkdirs();
if (!(new UniversalFile(getDataFolder(), "config.yml").exists())) {
2016-12-27 17:03:19 +01:00
Util.copyFromJar(SubPlugin.class.getClassLoader(), "config.yml", new UniversalFile(getDataFolder(), "config.yml").getPath());
2016-12-20 00:31:01 +01:00
Bukkit.getLogger().info("SubServers > Created ~/plugins/SubServers/config.yml");
2016-12-28 01:15:36 +01:00
} else if ((new Version((new YAMLConfig(new UniversalFile(getDataFolder(), "config.yml"))).get().getSection("Settings").getString("Version", "0")).compareTo(new Version("2.11.2a+"))) != 0) {
2016-12-20 00:31:01 +01:00
Files.move(new UniversalFile(getDataFolder(), "config.yml").toPath(), new UniversalFile(getDataFolder(), "config.old" + Math.round(Math.random() * 100000) + ".yml").toPath());
2016-12-27 17:03:19 +01:00
Util.copyFromJar(SubPlugin.class.getClassLoader(), "config.yml", new UniversalFile(getDataFolder(), "config.yml").getPath());
2016-12-20 00:31:01 +01:00
Bukkit.getLogger().info("SubServers > Updated ~/plugins/SubServers/config.yml");
}
pluginconf = new YAMLConfig(new UniversalFile(getDataFolder(), "config.yml"));
2017-01-01 20:34:46 +01:00
subdata = new SubDataClient(this, pluginconf.get().getSection("Settings").getSection("SubData").getString("Name", "undefined"),
2016-12-20 00:31:01 +01:00
InetAddress.getByName(pluginconf.get().getSection("Settings").getSection("SubData").getString("Address", "127.0.0.1:4391").split(":")[0]),
Integer.parseInt(pluginconf.get().getSection("Settings").getSection("SubData").getString("Address", "127.0.0.1:4391").split(":")[1]));
gui = new UIListener(this);
2017-01-01 20:34:46 +01:00
SubCommand cmd = new SubCommand(this);
getCommand("subservers").setExecutor(cmd);
getCommand("subserver").setExecutor(cmd);
getCommand("sub").setExecutor(cmd);
2016-12-20 00:31:01 +01:00
} catch (IOException e) {
setEnabled(false);
e.printStackTrace();
}
}
@Override
public void onDisable() {
2016-12-24 05:55:17 +01:00
if (subdata != null)
try {
subdata.destroy(false);
} catch (IOException e) {
e.printStackTrace();
}
2016-12-20 00:31:01 +01:00
}
}