Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.util.UUID;
- import java.util.concurrent.TimeUnit;
- import Level.LevelCommand;
- import commands.BanCMD;
- import commands.PingCommand;
- import net.md_5.bungee.api.ProxyServer;
- import net.md_5.bungee.api.connection.ProxiedPlayer;
- import net.md_5.bungee.api.event.PlayerDisconnectEvent;
- import net.md_5.bungee.api.event.ServerConnectEvent;
- import net.md_5.bungee.api.plugin.Listener;
- import net.md_5.bungee.api.plugin.Plugin;
- import net.md_5.bungee.event.EventHandler;
- import onlinetime.OnlineCmd;
- import rank.Rank;
- import rank.RankCommand;
- import report.ReportCmd;
- import report.ReportReason;
- import teleporter.TeleportCmd;
- public class MySQL extends Plugin implements Listener{
- private static String HOST = "localhost";
- private static String PORT = "3306";
- private static String USER = "root";
- private static String PASSWORD = "hPThDW9nD8uQuJST";
- private static String DATABASE = "MC-Server";
- public static Connection con;
- public static String Prefix = "§b§l▋ §9§lCerekCraft §b➤ §7";
- public static String Fehler = "§c§l▋ §4§lFehler §c➤ §7";
- public static String noperm = Fehler + "Du hast keinen Zugriff auf diesen Befehl!";getPluginManager().registerListener(this, this);
- ProxyServer.getInstance().getPluginManager().registerListener(this, this);
- ProxyServer.getInstance().getPluginManager().registerCommand(this, new RankCommand("rank"));
- ProxyServer.getInstance().getPluginManager().registerCommand(this, new LevelCommand("level"));
- ProxyServer.getInstance().getPluginManager().registerCommand(this, new PingCommand("ping"));
- ProxyServer.getInstance().getPluginManager().registerCommand(this, new OnlineCmd("onlinetime"));
- ProxyServer.getInstance().getPluginManager().registerCommand(this, new TeleportCmd("gtp"));
- ProxyServer.getInstance().getPluginManager().registerCommand(this, new ReportCmd("report"));
- ProxyServer.getInstance().getPluginManager().registerCommand(this, new BanCMD("ban"));
- ProxyServer.getInstance().getPluginManager().registerListener(this, this);
- connect();
- start();
- startReport();
- Nick.start();
- reconnect();
- AddOnlineTime();
- }
- public void onDisable() {
- disconnect();
- }
- private void AddOnlineTime(){
- ProxyServer.getInstance().getScheduler().schedule(this, new Runnable() {
- @Override
- public void run() {
- for(ProxiedPlayer p : ProxyServer.getInstance().getPlayers()){
- setOnlineTime(p.getUniqueId(), getOnlineTime(p.getUniqueId()) + 1);
- LevelCommand.addXP(p.getUniqueId(), 25);
- }
- AddOnlineTime();
- }
- }, 1, TimeUnit.MINUTES);
- }
- private void reconnect(){
- ProxyServer.getInstance().getScheduler().schedule(this, new Runnable() {
- @Override
- public void run() {
- disconnect();
- connect();
- reconnect();
- }
- }, 5, TimeUnit.MINUTES);
- }
- @EventHandler
- public void onJoin(ServerConnectEvent e){
- if(!containsPlayer(e.getPlayer().getUniqueId())){
- update(e.getPlayer().getUniqueId(), e.getPlayer().getName(), Rank.Spieler.toString(), Rank.Spieler.toString(), 100, 1, 0, "UNKNOWN", 0, true);
- }else{
- setName(e.getPlayer().getUniqueId(), e.getPlayer().getName());
- setOnline(e.getPlayer().getUniqueId(), true);
- }
- if(!Nick.containsPlayer(e.getPlayer().getUniqueId())){
- Nick.update(e.getPlayer().getUniqueId(), false, false, "UNKNOWN", "UNKNOWN");
- }
- e.getPlayer().addGroups(getRank(e.getPlayer().getUniqueId()).toString());
- }
- @EventHandler
- public void onJeave(PlayerDisconnectEvent e){
- setOnline(e.getPlayer().getUniqueId(), false);
- }
- @SuppressWarnings("deprecation")
- public static void connect() {
- try {
- con = DriverManager.getConnection("jdbc:mysql://" + HOST + ":" + PORT + "/" + DATABASE, USER, PASSWORD);
- ProxyServer.getInstance().getConsole().sendMessage("�9MySQL �8| �7Erfolgreich mit der Datenbank �e" + DATABASE + " �7verbunden...");
- } catch (SQLException e) {
- ProxyServer.getInstance().getConsole().sendMessage("�9MySQL �8| �cKonnte nicht zu �4" + DATABASE + " �cverbinden...");
- }
- }
- @SuppressWarnings("deprecation")
- public static void disconnect() {
- if (isConnected()) {
- try {
- con.close();
- ProxyServer.getInstance().getConsole().sendMessage("�9MySQL �8| �7Erfolgreich von Datenbank �e" + DATABASE + " �7getrennt...");
- } catch (SQLException e) {
- ProxyServer.getInstance().getConsole().sendMessage("�9MySQL �8| �cKonnte nicht von �4" + DATABASE + " �ctrennen...");
- }
- }
- }
- private static void startReport(){
- try {
- PreparedStatement ps = MySQL.getConnection().prepareStatement("CREATE TABLE IF NOT EXISTS Reports (TargetUUID varchar(100) NOT NULL,"
- + " FromUUID varchar(100) NOT NULL,"
- + " Reason varchar(100) NOT NULL)");
- ps.execute();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public static void addReport(UUID From, UUID To, ReportReaso
- public static void update(String qry) {
- if (isConnected()) {
- try {
- con.createStatement().executeUpdate(qry);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public static ResultSet getResult(String qry) {
- if (isConnected()) {
- try {
- return con.createStatement().executeQuery(qry);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- return null;
- }
- n reason){
- try {
- PreparedStatement ps = MySQL.getConnection()
- .prepareStatement("INSERT INTO Reports (TargetUUID, Fromeason) VALUES (?, ?, ?)");
- ps.setString(1, To.toString());
- ps.setString(2, From.toString());
- ps.setString(3, reason.toString());
- ps.execute();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public static boolean isConnected() {
- return (con == null ? false : true);
- }
- public static Connection getConnection() {
- return con;
- }
- public static void start() {
- try {
- PreparedStatement ps = MySQL.getConnection().prepareStatement("CREATE TABLE IF NOT EXISTS Spieler (UUID varchar(100) NOT NULL,"
- + " Name varchar(100) NOT NULL,"
- + " Rang varchar(100) NOT NULL,"
- + " RangDisplay varchar(100) NOT NULL,"
- + " Coins int NOT NULL,"
- + " Level int NOT NULL,"
- + " XP int NOT NULL,"
- + " OnlineTime int NOT NULL,"
- + " Server varchar(100) NOT NULL,"
- + " Online boolean NOT NULL DEFAULT false)");
- ps.execute();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public static void setOnlineTime(UUID uuid, int name){
- if(containsPlayer(uuid)){
- try {
- PreparedStatement ps = MySQL.getConnection().prepareStatement("UPDATE Spieler SET OnlineTime = ? WHERE UUID = ?");
- ps.setInt(1, name);
- ps.setString(2, uuid.toString());
- ps.executeUpdate();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public static void setServer(UUID uuid, String name){
- if(containsPlayer(uuid)){
- try {
- PreparedStatement ps = MySQL.getConnection().prepareStatement("UPDATE Spieler SET Server = ? WHERE UUID = ?");
- ps.setString(1, name);
- ps.setString(2, uuid.toString());
- ps.executeUpdate();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public static UUID getUUID(String name){
- try {
- PreparedStatement ps = MySQL.getConnection().prepareStatement("SELECT UUID FROM Spieler WHERE Name = ?");
- ps.setString(1, name);
- ResultSet rs = ps.executeQuery();
- while(rs.next()){
- return UUID.fromString(rs.getString("UUID"));
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return null;
- }
- public static String getServer(UUID uuid){
- if(containsPlayer(uuid)){
- try {
- PreparedStatement ps = MySQL.getConnection().prepareStatement("SELECT Server FROM Spieler WHERE UUID = ?");
- ps.setString(1, uuid.toString());
- ResultSet rs = ps.executeQuery();
- while(rs.next()){
- return rs.getString("Server");
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- return null;
- }
- public static Integer getOnlineTime(UUID uuid){
- if(containsPlayer(uuid)){
- try {
- PreparedStatement ps = MySQL.getConnection().prepareStatement("SELECT OnlineTime FROM Spieler WHERE UUID = ?");
- ps.setString(1, uuid.toString());
- ResultSet rs = ps.executeQuery();
- while(rs.next()){
- return rs.getInt("OnlineTime");
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- return null;
- }
- public static boolean containsPlayer(UUID uuid) {
- try {
- PreparedStatement ps = MySQL.getConnection().prepareStatement("SELECT UUID FROM Spieler WHERE UUID = ?");
- ps.setString(1, uuid.toString());
- ResultSet rs = ps.executeQuery();
- return rs.next();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- return false;
- }
- public static String getName(UUID uuid){
- if(containsPlayer(uuid)){
- try {
- PreparedStatement ps = MySQL.getConnection().prepareStatement("SELECT Name FROM Spieler WHERE UUID = ?");
- ps.setString(1, uuid.toString());
- ResultSet rs = ps.executeQuery();
- while(rs.next()){
- return rs.getString("Name");
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- return null;
- }
- public static Rank getRank(UUID uuid){
- if(containsPlayer(uuid)){
- try {
- PreparedStatement ps = MySQL.getConnection().prepareStatement("SELECT Rang FROM Spieler WHERE UUID = ?");
- ps.setString(1, uuid.toString());
- ResultSet rs = ps.executeQuery();
- while(rs.next()){
- return Rank.valueOf(rs.getString("Rang"));
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- return null;
- }
- public static Rank getRankDisplay(UUID uuid){
- if(containsPlayer(uuid)){
- try {
- PreparedStatement ps = MySQL.getConnection().prepareStatement("SELECT RangDisplay FROM Spieler WHERE UUID = ?");
- ps.setString(1, uuid.toString());
- ResultSet rs = ps.executeQuery();
- while(rs.next()){
- return Rank.valueOf(rs.getString("RangDisplay"));
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- return null;
- }
- public static Integer getCoins(UUID uuid){
- if(containsPlayer(uuid)){
- try {
- PreparedStatement ps = MySQL.getConnection().prepareStatement("SELECT Coins FROM Spieler WHERE UUID = ?");
- ps.setString(1, uuid.toString());
- ResultSet rs = ps.executeQuery();
- while(rs.next()){
- return rs.getInt("Coins");
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- return 0;
- }
- public static Integer getLevel(UUID uuid){
- if(containsPlayer(uuid)){
- try {
- PreparedStatement ps = MySQL.getConnection().prepareStatement("SELECT Level FROM Spieler WHERE UUID = ?");
- ps.setString(1, uuid.toString());
- ResultSet rs = ps.executeQuery();
- while(rs.next()){
- return rs.getInt("Level");
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- return 0;
- }
- public static Integer getXP(UUID uuid){
- if(containsPlayer(uuid)){
- try {
- PreparedStatement ps = MySQL.getConnection().prepareStatement("SELECT XP FROM Spieler WHERE UUID = ?");
- ps.setString(1, uuid.toString());
- ResultSet rs = ps.executeQuery();
- while(rs.next()){
- return rs.getInt("XP");
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- return 0;
- }
- public static boolean isOnline(UUID uuid){
- if(containsPlayer(uuid)){
- try {
- PreparedStatement ps = MySQL.getConnection().prepareStatement("SELECT Online FROM Spieler WHERE UUID = ?");
- ps.setString(1, uuid.toString());
- ResultSet rs = ps.executeQuery();
- while(rs.next()){
- return rs.getBoolean("Online");
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- return false;
- }
- public static void setName(UUID uuid, String name){
- if(containsPlayer(uuid)){
- try {
- PreparedStatement ps = MySQL.getConnection().prepareStatement("UPDATE Spieler SET Name = ? WHERE UUID = ?");
- ps.setString(1, name);
- ps.setString(2, uuid.toString());
- ps.executeUpdate();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public static void setRank(UUID uuid, String rank){
- if(containsPlayer(uuid)){
- try {
- PreparedStatement ps = MySQL.getConnection().prepareStatement("UPDATE Spieler SET Rang = ? WHERE UUID = ?");
- ps.setString(1, rank);
- ps.setString(2, uuid.toString());
- ps.executeUpdate();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public static void setRankDisplay(UUID uuid, String rank){
- if(containsPlayer(uuid)){
- try {
- PreparedStatement ps = MySQL.getConnection().prepareStatement("UPDATE Spieler SET RangDisplay = ? WHERE UUID = ?");
- ps.setString(1, rank);
- ps.setString(2, uuid.toString());
- ps.executeUpdate();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public static void setCoins(UUID uuid, int coins){
- if(containsPlayer(uuid)){
- try {
- PreparedStatement ps = MySQL.getConnection().prepareStatement("UPDATE Spieler SET Coins = ? WHERE UUID = ?");
- ps.setInt(1, coins);
- ps.setString(2, uuid.toString());
- ps.executeUpdate();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public static void setLevel(UUID uuid, int level){
- if(containsPlayer(uuid)){
- try {
- PreparedStatement ps = MySQL.getConnection().prepareStatement("UPDATE Spieler SET Level = ? WHERE UUID = ?");
- ps.setInt(1, level);
- ps.setString(2, uuid.toString());
- ps.executeUpdate();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public static void setXP(UUID uuid, int XP){
- if(containsPlayer(uuid)){
- try {
- PreparedStatement ps = MySQL.getConnection().prepareStatement("UPDATE Spieler SET XP = ? WHERE UUID = ?");
- ps.setInt(1, XP);
- ps.setString(2, uuid.toString());
- ps.executeUpdate();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public static void setOnline(UUID uuid, boolean online){
- if(containsPlayer(uuid)){
- try {
- PreparedStatement ps = MySQL.getConnection().prepareStatement("UPDATE Spieler SET Online = ? WHERE UUID = ?");
- ps.setBoolean(1, online);
- ps.setString(2, uuid.toString());
- ps.executeUpdate();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public static void update(UUID uuid, String Name, String Rang, String RangDisplay, int Coins, int Level, int XP, String Server, int Time, boolean Online) {
- try {
- if (containsPlayer(uuid)) {
- PreparedStatement ps = MySQL.getConnection().prepareStatement("UPDATE Spieler SET Name = ? WHERE UUID = ?");
- ps.setString(1, Name);
- ps.setString(2, uuid.toString());
- ps.executeUpdate();
- PreparedStatement ps2 = MySQL.getConnection().prepareStatement("UPDATE Spieler SET Rang = ? WHERE UUID = ?");
- ps2.setString(1, Rang);
- ps2.setString(2, uuid.toString());
- ps2.executeUpdate();
- PreparedStatement ps9 = MySQL.getConnection().prepareStatement("UPDATE Spieler SET RangDisplay = ? WHERE UUID = ?");
- ps9.setString(1, RangDisplay);
- ps9.setString(2, uuid.toString());
- ps9.executeUpdate();
- PreparedStatement ps3 = MySQL.getConnection().prepareStatement("UPDATE Spieler SET Coins = ? WHERE UUID = ?");
- ps3.setInt(1, Coins);
- ps3.setString(2, uuid.toString());
- ps3.executeUpdate();
- PreparedStatement ps4 = MySQL.getConnection().prepareStatement("UPDATE Spieler SET Level = ? WHERE UUID = ?");
- ps4.setInt(1, Level);
- ps4.setString(2, uuid.toString());
- ps4.executeUpdate();
- PreparedStatement ps5 = MySQL.getConnection().prepareStatement("UPDATE Spieler SET XP = ? WHERE UUID = ?");
- ps5.setInt(1, XP);
- ps5.setString(2, uuid.toString());
- ps5.executeUpdate();
- PreparedStatement ps8 = MySQL.getConnection().prepareStatement("UPDATE Spieler SET Server = ? WHERE UUID = ?");
- ps8.setString(1, Server);
- ps8.setString(2, uuid.toString());
- ps8.executeUpdate();
- PreparedStatement ps11 = MySQL.getConnection().prepareStatement("UPDATE Spieler SET OnlineTime = ? WHERE UUID = ?");
- ps11.setInt(1, Time);
- ps11.setString(2, uuid.toString());
- ps11.executeUpdate();
- PreparedStatement ps10 = MySQL.getConnection().prepareStatement("UPDATE Spieler SET Online = ? WHERE UUID = ?");
- ps10.setBoolean(1, Online);
- ps10.setString(2, uuid.toString());
- ps10.executeUpdate();
- } else {
- PreparedStatement ps = MySQL.getConnection()
- .prepareStatement("INSERT INTO Spieler (UUID, Name, Rang, RangDisplay, Coins, Level, XP, OnlineTime, Server, Online) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
- ps.setString(1, uuid.toString());
- ps.setString(2, Name);
- ps.setString(3, Rang);
- ps.setString(4, RangDisplay);
- ps.setInt(5, Coins);
- ps.setInt(6, Level);
- ps.setInt(7, XP);
- ps.setInt(8, Time);
- ps.setString(9, Server);
- ps.setBoolean(10, Online);
- ps.execute();
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement