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

179 lines
6.2 KiB
Java
Raw Blame History

package eu.univento.core;
import java.io.IOException;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bukkit.Bukkit;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import eu.univento.core.api.Config;
import eu.univento.core.api.Messages;
import eu.univento.core.api.MySQL;
import eu.univento.core.api.Settings;
import eu.univento.core.api.player.CustomPlayer;
import eu.univento.core.api.player.Perms;
import eu.univento.core.commands.Ban;
import eu.univento.core.commands.Build;
import eu.univento.core.commands.Fix;
import eu.univento.core.commands.GameMode;
import eu.univento.core.commands.GlobalMute;
import eu.univento.core.commands.RunAs;
import eu.univento.core.commands.SetRank;
import eu.univento.core.commands.SystemInfo;
import eu.univento.core.commands.TS;
import eu.univento.core.commands.Vanish;
import eu.univento.core.commands.Youtuber;
import eu.univento.core.listeners.Blocks;
import eu.univento.core.listeners.Chat;
import eu.univento.core.listeners.Commands;
import eu.univento.core.listeners.JoinQuit;
/**
* main class
* @author joethei
* @version 1.0
*/
public class Core extends JavaPlugin{
/**
* plugin instance
*/
public static Core instance;
/**
* @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;
}
/**
* nick names of players
*/
public static HashMap<CustomPlayer, String> nicks = new HashMap<CustomPlayer, String>();
/**
* logging and stuff
*/
private static Logger log = Bukkit.getLogger();
/**
* @param level Log level
* @param string String
*/
public static void log(Level level, String string) {
log.log(level, "[" + Messages.CONSOLE_PREFIX + Core.getInstance().getDescription().getName() + "] " + string);
}
@Override
public void onEnable() {
Settings.setDebug(true);
Settings.setBuild(true);
try {
Config.writeDefault();
} catch (ClassNotFoundException | SQLException | IOException e) {
e.printStackTrace();
}
instance = this;
if(Settings.isDebug()) log(Level.INFO, "Debug Modus aktiviert");
Perms.initScoreboard();
PluginManager pm = Bukkit.getPluginManager();
pm.registerEvents(new Commands(), this);
pm.registerEvents(new JoinQuit(), this);
pm.registerEvents(new Chat(), this);
pm.registerEvents(new Blocks(), this);
if(Settings.isDebug()) log(Level.INFO, "Events registriert");
String[] fix = {""};
new Fix(this, "fix", "Fixe dich oder andere Spieler", fix);
String[] runas = {""};
new RunAs(this, "RunAs", "Sende einen Befehl als ein anderer Spieler", runas);
String[] systeminfo = {""};
new SystemInfo(this, "SystemInfo", "Gibt Infos <20>ber den Server aus", systeminfo);
String[] vanish = {""};
new Vanish(this, "vanish", "L<EFBFBD>sst dich verschwinden", vanish);
String[] gamemode = {"gm"};
new GameMode(this, "gamemode" , "Setzt deinen GameMode", gamemode);
String[] setrank = {"sr"};
new SetRank(this, "setrank" , "Setzt den Rang eines Spielers", setrank);
String[] globalmute = {"globalmute"};
new GlobalMute(this, "globalmute", "Muted den gesamten Server", globalmute);
String[] youtuber = {""};
new Youtuber(this, "youtuber", "setzt Spieler in den Youtuber Rang", youtuber);
String[] ts = {""};
new TS(this, "ts", "verifiziert Spieler auf dem TS", ts);
String[] ban = {""};
new Ban(this, "ban", "Bannt Spieler", ban);
if(Settings.isBuild()) {
String[] build = {"b"};
new Build(this, "build", "Setzt den Spieler in den Bau Modus", build);
if(Settings.isDebug()) log(Level.INFO, "Build Modus aktiviert");
}
if(Settings.isDebug()) log(Level.INFO, "Alle Befehle registriert");
try
{
MySQL tempSQL = sql;
tempSQL.openConnection();
tempSQL.getConnection().createStatement().execute("CREATE TABLE IF NOT EXISTS PlayerData(ID bigint PRIMARY KEY auto_increment, player_uuid varchar(50), FirstJoin TIMESTAMP default now(), Coins bigint, mute boolean, Rank varchar(15),TS_ID bigint, Friends varchar(2500), nick boolean);");
if(Settings.isDebug()) log(Level.INFO, "MySQL PlayerData ausgef<65>hrt");
tempSQL.getConnection().createStatement().execute("CREATE TABLE IF NOT EXISTS bans(ID bigint PRIMARY KEY auto_increment, player_uuid varchar(50), Reason varchar(50), who varchar(50));");
if(Settings.isDebug()) log(Level.INFO, "MySQL Bans erstellt");
tempSQL.getConnection().createStatement().execute("CREATE TABLE IF NOT EXISTS bugs(ID bigint PRIMARY KEY auto_increment, player_uuid varchar(50), time timestamp, msg varchar(250));");
if(Settings.isDebug()) log(Level.INFO, "MySQL Bugs erstellt");
tempSQL.getConnection().createStatement().execute("CREATE TABLE IF NOT EXISTS Friends(ID bigint PRIMARY KEY auto_increment, player_uuid VARCHAR(64), Friends VARCHAR(2500));");
if(Settings.isDebug()) log(Level.INFO, "MySQL Friends erstellt");
tempSQL.getConnection().createStatement().execute("CREATE TABLE IF NOT EXISTS Messages(ID bigint PRIMARY KEY auto_increment,Ident varchar(25), Message varchar(250));");
if(Settings.isDebug()) log(Level.INFO, "MySQL Messages erstellt");
tempSQL.closeConnection();
} catch (SQLException | ClassNotFoundException e) {
e.printStackTrace();
}
Bukkit.getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
try {
Messages.writeDefault();
Messages.readStrings();
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
}
log(Level.INFO, "Plugin ver. " + getDescription().getVersion() + " gestartet");
}
@Override
public void onDisable() {
Core.log(Level.INFO, "Plugin beendet");
}
}