Core/src/main/java/eu/univento/core/Core.java

144 lines
4.5 KiB
Java
Raw Normal View History

2016-04-13 05:52:53 +02:00
package eu.univento.core;
2016-04-29 12:54:03 +02:00
import eu.univento.core.antihack.AntiHack;
2016-04-13 05:52:53 +02:00
import eu.univento.core.api.Blackscreen;
import eu.univento.core.api.Config;
import eu.univento.core.api.database.MongoDB;
import eu.univento.core.api.database.MySQL;
import eu.univento.core.api.events.MoveEventFilter;
import eu.univento.core.api.player.CustomPlayer;
import eu.univento.core.api.server.ServerSettings;
import eu.univento.core.commands.*;
import eu.univento.core.listeners.*;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* main class
* @author joethei
* @version 1.0
*/
public class Core extends JavaPlugin{
//TODO: rewrite time critical database functions from MySQL to MongoDB
/**
* plugin instance
*/
2016-04-29 12:54:03 +02:00
private static Core instance;
2016-04-13 05:52:53 +02:00
/**
* @return plugin instance
*/
public static Core getInstance() {
return instance;
}
/**
* mysql stuff
*/
private static MySQL sql = new MySQL(getInstance(), Config.readString("MySQL.Host"), Config.readString("MySQL.Port"), Config.readString("MySQL.DB"), Config.readString("MySQL.User"), Config.readString("MySQL.Pass"));
/**
* @return sql
*/
public static MySQL returnSQL() {
return sql;
}
private static MongoDB mongoDB;
public static MongoDB getMongoDB() {
return mongoDB;
}
/**
* logging and stuff
*/
private static Logger log = Bukkit.getLogger();
public static ArrayList<CustomPlayer> getOnlinePlayers() {
ArrayList<CustomPlayer> list = new ArrayList<>();
for(Player players : Bukkit.getOnlinePlayers()) {
CustomPlayer p = CustomPlayer.getPlayer(players);
list.add(p);
}
return list;
}
/**
* @param level Log level
* @param string String
*/
public static void log(Level level, String string) {
if(ServerSettings.isDebug()) {
log.log(level, "[univento Core] " + string);
}
}
@Override
public void onEnable() {
ServerSettings.setDebug(true);
try {
Config.writeDefault();
} catch (ClassNotFoundException | SQLException | IOException e) {
e.printStackTrace();
}
instance = this;
log(Level.INFO, "activated debug mode");
PluginManager pm = Bukkit.getPluginManager();
pm.registerEvents(new Commands(), this);
pm.registerEvents(new JoinQuit(), this);
pm.registerEvents(new Chat(), this);
pm.registerEvents(new Events(), this);
pm.registerEvents(new MoveEventFilter(getServer()), this);
if(ServerSettings.isGame()) {
new Fix(this, "fix", "fix");
new Stats(this, "stats", "statistics");
new Nick(this, "nick", "nick");
}
2016-04-29 12:54:03 +02:00
AntiHack.registerListeners();
2016-04-13 05:52:53 +02:00
new RunAs(this, "RunAs", "runas");
new SystemInfo(this, "SystemInfo", "systeminfo");
new Vanish(this, "vanish", "vanish");
new GameMode(this, "gamemode" , "gamemode", "gm");
new SetRank(this, "setrank" , "setrank", "sr");
new GlobalMute(this, "globalmute", "globalmute");
new TS(this, "ts", "ts");
new Ban(this, "ban", "ban");
new ChatClear(this, "chatclear", "chatclear", "cc");
log(Level.INFO, "registered all commands");
PluginMessenger pluginMessenger = new PluginMessenger();
2016-04-13 05:52:53 +02:00
Bukkit.getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
Bukkit.getMessenger().registerOutgoingPluginChannel(this, "LABYMOD");
Bukkit.getMessenger().registerIncomingPluginChannel(this, "WDL|INIT", pluginMessenger);
Bukkit.getMessenger().registerOutgoingPluginChannel(this, "WDL|CONTROL");
Bukkit.getMessenger().registerIncomingPluginChannel(this, "PERMISSIONSREPL", pluginMessenger);
2016-04-13 05:52:53 +02:00
Blackscreen.setupUtil(getInstance());
mongoDB = new MongoDB(Config.readString("MongoDB.Host"), Config.readInt("MongoDB.Port"), Config.readString("MongoDB.User"), Config.readString("MongoDB.Password"), Config.readString("MongoDB.Database"));
2016-04-13 05:52:53 +02:00
log(Level.INFO, "Plugin ver. " + getDescription().getVersion() + " started");
}
@Override
public void onDisable() {
mongoDB.getClient().close();
Bukkit.getMessenger().unregisterOutgoingPluginChannel(this, "BungeeCord");
Bukkit.getMessenger().unregisterOutgoingPluginChannel(this, "LABYMOD");
Bukkit.getMessenger().unregisterIncomingPluginChannel(this, "WDL_INIT");
Bukkit.getMessenger().unregisterOutgoingPluginChannel(this, "WDL|CONTROL");
2016-04-13 05:52:53 +02:00
log(Level.INFO, "Plugin stoped");
}
}