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;
|
2016-07-09 13:14:19 +02:00
|
|
|
import eu.univento.core.api.database.DatabaseManager;
|
2016-04-13 05:52:53 +02:00
|
|
|
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;
|
2016-06-25 15:42:06 +02:00
|
|
|
import eu.univento.core.api.server.NetworkData;
|
2016-04-13 05:52:53 +02:00
|
|
|
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
|
|
|
|
*/
|
2016-07-09 13:14:19 +02:00
|
|
|
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"));
|
2016-04-13 05:52:53 +02:00
|
|
|
/**
|
|
|
|
* @return sql
|
|
|
|
*/
|
2016-07-09 13:14:19 +02:00
|
|
|
public static MySQL getMySQL() {
|
2016-04-13 05:52:53 +02:00
|
|
|
return sql;
|
|
|
|
}
|
|
|
|
|
2016-07-09 13:14:19 +02:00
|
|
|
/*
|
|
|
|
private static AsyncMySQL asyncMySQL = new AsyncMySQL(getInstance(), Config.readString("MySQL.Host"), Config.readString("MySQL.Port"), Config.readString("MySQL.DB"), Config.readString("MySQL.User"), Config.readString("MySQL.Pass"));
|
|
|
|
public static AsyncMySQL getAsyncMySQL() {
|
|
|
|
return asyncMySQL;
|
|
|
|
}
|
|
|
|
*/
|
2016-04-13 05:52:53 +02:00
|
|
|
private static MongoDB mongoDB;
|
|
|
|
public static MongoDB getMongoDB() {
|
|
|
|
return mongoDB;
|
|
|
|
}
|
|
|
|
|
2016-07-09 13:14:19 +02:00
|
|
|
/*
|
|
|
|
private static AsyncMongoDB asyncMongoDB;
|
|
|
|
public static AsyncMongoDB getAsyncMongoDB() {
|
|
|
|
return asyncMongoDB;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
private static DatabaseManager databaseManager;
|
|
|
|
public static DatabaseManager getDatabaseManager() {
|
|
|
|
return databaseManager;
|
|
|
|
}
|
|
|
|
|
2016-04-13 05:52:53 +02:00
|
|
|
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 Nick(this, "nick", "nick");
|
2016-04-26 15:05:18 +02:00
|
|
|
}
|
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 ChatClear(this, "chatclear", "chatclear", "cc");
|
|
|
|
|
|
|
|
log(Level.INFO, "registered all commands");
|
2016-05-08 10:45:34 +02:00
|
|
|
|
|
|
|
PluginMessenger pluginMessenger = new PluginMessenger();
|
2016-06-25 15:42:06 +02:00
|
|
|
NetworkData networkData = new NetworkData();
|
|
|
|
Bukkit.getMessenger().registerOutgoingPluginChannel(this, "5zig_Set");
|
|
|
|
Bukkit.getMessenger().registerIncomingPluginChannel(this, "5zig_Set", pluginMessenger);
|
2016-04-13 05:52:53 +02:00
|
|
|
Bukkit.getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
|
2016-06-25 15:42:06 +02:00
|
|
|
Bukkit.getMessenger().registerIncomingPluginChannel(this, "BungeeCord", networkData);
|
2016-04-26 15:05:18 +02:00
|
|
|
Bukkit.getMessenger().registerOutgoingPluginChannel(this, "LABYMOD");
|
2016-05-08 10:45:34 +02:00
|
|
|
Bukkit.getMessenger().registerIncomingPluginChannel(this, "WDL|INIT", pluginMessenger);
|
|
|
|
Bukkit.getMessenger().registerOutgoingPluginChannel(this, "WDL|CONTROL");
|
2016-06-25 15:42:06 +02:00
|
|
|
Bukkit.getMessenger().registerIncomingPluginChannel(this, "WDL|REQUEST", pluginMessenger);
|
2016-05-08 10:45:34 +02:00
|
|
|
Bukkit.getMessenger().registerIncomingPluginChannel(this, "PERMISSIONSREPL", pluginMessenger);
|
2016-06-25 15:42:06 +02:00
|
|
|
Bukkit.getMessenger().registerOutgoingPluginChannel(this, "schematica");
|
2016-04-13 05:52:53 +02:00
|
|
|
|
|
|
|
Blackscreen.setupUtil(getInstance());
|
2016-07-09 13:14:19 +02:00
|
|
|
databaseManager = new DatabaseManager(getInstance());
|
2016-04-26 15:05:18 +02:00
|
|
|
mongoDB = new MongoDB(Config.readString("MongoDB.Host"), Config.readInt("MongoDB.Port"), Config.readString("MongoDB.User"), Config.readString("MongoDB.Password"), Config.readString("MongoDB.Database"));
|
2016-07-09 13:14:19 +02:00
|
|
|
//asyncMongoDB = new AsyncMongoDB(Config.readString("MongoDB.Host"), Config.readInt("MongoDB.Port"), Config.readString("MongoDB.User"), Config.readString("MongoDB.Password"), Config.readString("MongoDB.Database"));
|
2016-06-25 15:42:06 +02:00
|
|
|
log(Level.INFO, "\n" +
|
|
|
|
"\n" +
|
|
|
|
" \n" +
|
|
|
|
" \n" +
|
|
|
|
" \n" +
|
|
|
|
" \n" +
|
|
|
|
" \n" +
|
|
|
|
" \n" +
|
|
|
|
" \n" +
|
|
|
|
" \n" +
|
|
|
|
" _ _ _ \n" +
|
|
|
|
" | | | | (_) \n" +
|
|
|
|
" ___ ___ _ ____ _____ _ __ ___| |_ __ _ _ __| |_ _ _ __ __ _ \n" +
|
|
|
|
"/ __|/ _ \\ '__\\ \\ / / _ \\ '__| / __| __/ _` | '__| __| | '_ \\ / _` |\n" +
|
|
|
|
"\\__ \\ __/ | \\ V / __/ | \\__ \\ || (_| | | | |_| | | | | (_| |\n" +
|
|
|
|
"|___/\\___|_| \\_/ \\___|_| |___/\\__\\__,_|_| \\__|_|_| |_|\\__, |\n" +
|
|
|
|
" __/ |\n" +
|
|
|
|
" |___/ \n" +
|
|
|
|
" \n" +
|
|
|
|
" \n" +
|
|
|
|
" \n" +
|
|
|
|
" \n" +
|
|
|
|
" \n" +
|
|
|
|
" \n" +
|
|
|
|
" \n" +
|
|
|
|
" \n" +
|
|
|
|
"\n");
|
|
|
|
Bukkit.getScheduler().scheduleSyncDelayedTask(this, () -> log(Level.INFO, "\n" +
|
|
|
|
"\n" +
|
|
|
|
"\n" +
|
|
|
|
" _ _ \n" +
|
|
|
|
" | (_) \n" +
|
|
|
|
" ___ ___ _ ____ _____ _ __ ___ _ __ | |_ _ __ ___ \n" +
|
|
|
|
"/ __|/ _ \\ '__\\ \\ / / _ \\ '__| / _ \\| '_ \\| | | '_ \\ / _ \\\n" +
|
|
|
|
"\\__ \\ __/ | \\ V / __/ | | (_) | | | | | | | | | __/\n" +
|
|
|
|
"|___/\\___|_| \\_/ \\___|_| \\___/|_| |_|_|_|_| |_|\\___|\n" +
|
|
|
|
" \n" +
|
|
|
|
" \n" +
|
|
|
|
"\n"), 0L);
|
2016-04-13 05:52:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDisable() {
|
2016-04-26 15:05:18 +02:00
|
|
|
mongoDB.getClient().close();
|
2016-07-09 13:14:19 +02:00
|
|
|
databaseManager.closeConnections();
|
2016-05-08 10:45:34 +02:00
|
|
|
Bukkit.getMessenger().unregisterOutgoingPluginChannel(this, "BungeeCord");
|
2016-06-25 15:42:06 +02:00
|
|
|
Bukkit.getMessenger().unregisterIncomingPluginChannel(this, "BungeeCord");
|
2016-05-08 10:45:34 +02:00
|
|
|
Bukkit.getMessenger().unregisterOutgoingPluginChannel(this, "LABYMOD");
|
|
|
|
Bukkit.getMessenger().unregisterIncomingPluginChannel(this, "WDL_INIT");
|
|
|
|
Bukkit.getMessenger().unregisterOutgoingPluginChannel(this, "WDL|CONTROL");
|
|
|
|
|
2016-06-25 15:42:06 +02:00
|
|
|
log(Level.INFO, "\n" +
|
|
|
|
"\n" +
|
|
|
|
" \n" +
|
|
|
|
" \n" +
|
|
|
|
" \n" +
|
|
|
|
" \n" +
|
|
|
|
" \n" +
|
|
|
|
" \n" +
|
|
|
|
" \n" +
|
|
|
|
" \n" +
|
|
|
|
" _ _ _ \n" +
|
|
|
|
" | | | | | | \n" +
|
|
|
|
" ___ ___ _ ____ _____ _ __ ___| |__ _ _| |_ __| | _____ ___ __ \n" +
|
|
|
|
"/ __|/ _ \\ '__\\ \\ / / _ \\ '__| / __| '_ \\| | | | __/ _` |/ _ \\ \\ /\\ / / '_ \\ \n" +
|
|
|
|
"\\__ \\ __/ | \\ V / __/ | \\__ \\ | | | |_| | || (_| | (_) \\ V V /| | | |\n" +
|
|
|
|
"|___/\\___|_| \\_/ \\___|_| |___/_| |_|\\__,_|\\__\\__,_|\\___/ \\_/\\_/ |_| |_|\n" +
|
|
|
|
" \n" +
|
|
|
|
" \n" +
|
|
|
|
" \n" +
|
|
|
|
" \n" +
|
|
|
|
" \n" +
|
|
|
|
" \n" +
|
|
|
|
" \n" +
|
|
|
|
" \n" +
|
|
|
|
" \n" +
|
|
|
|
" \n" +
|
|
|
|
"\nd");
|
2016-04-13 05:52:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|