This commit is contained in:
JaTiTV 2021-12-22 18:29:16 +01:00
parent 6b6ebbcd18
commit e0da2cd88d
5 changed files with 41 additions and 24 deletions

View File

@ -3,6 +3,8 @@ package de.jatitv.commandguiv2.Bungee;
import net.md_5.bungee.config.Configuration; import net.md_5.bungee.config.Configuration;
import net.md_5.bungee.config.ConfigurationProvider; import net.md_5.bungee.config.ConfigurationProvider;
import net.md_5.bungee.config.YamlConfiguration; import net.md_5.bungee.config.YamlConfiguration;
import net.t2code.lib.Bungee.Lib.messages.Bsend;
import net.t2code.lib.Util;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -26,17 +28,30 @@ public class BConfig {
e.printStackTrace(); e.printStackTrace();
} }
} }
Configuration configuration;
try { try {
Configuration configuration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(new File(BMain.plugin.getDataFolder(), "config.yml")); configuration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(new File(BMain.plugin.getDataFolder(), "config.yml"));
BMySQL.Enable = configuration.getBoolean("MySQL.Enable");
} catch (IOException e) {
Bsend.console(Util.Prefix + " Please replace the config: MySQL.Enable: [false,true]");
e.printStackTrace();
}
try {
configuration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(new File(BMain.plugin.getDataFolder(), "config.yml"));
BMySQL.ip = configuration.getString("MySQL.IP"); BMySQL.ip = configuration.getString("MySQL.IP");
BMySQL.port = configuration.getInt("MySQL.Port"); BMySQL.port = configuration.getInt("MySQL.Port");
BMySQL.database = configuration.getString("MySQL.Database"); BMySQL.database = configuration.getString("MySQL.Database");
BMySQL.user = configuration.getString("MySQL.User"); BMySQL.user = configuration.getString("MySQL.User");
BMySQL.password = configuration.getString("MySQL.Password"); BMySQL.password = configuration.getString("MySQL.Password");
BMySQL.SSL = configuration.getBoolean("MySQL.SSL"); BMySQL.SSL = configuration.getBoolean("MySQL.SSL");
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
} }

View File

@ -1,9 +1,6 @@
package de.jatitv.commandguiv2.Bungee; package de.jatitv.commandguiv2.Bungee;
import de.jatitv.commandguiv2.Spigot.system.config.config.SelectConfig;
import de.jatitv.commandguiv2.Spigot.system.database.MySQL;
import net.md_5.bungee.BungeeCord; import net.md_5.bungee.BungeeCord;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.event.PlayerDisconnectEvent; import net.md_5.bungee.api.event.PlayerDisconnectEvent;
import net.md_5.bungee.api.event.PluginMessageEvent; import net.md_5.bungee.api.event.PluginMessageEvent;
@ -13,7 +10,6 @@ import net.md_5.bungee.event.EventHandler;
import net.t2code.lib.Bungee.Lib.messages.Bsend; import net.t2code.lib.Bungee.Lib.messages.Bsend;
import java.io.*; import java.io.*;
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger; import java.util.logging.Logger;
public class BListener implements Listener { public class BListener implements Listener {
@ -25,8 +21,6 @@ public class BListener implements Listener {
String channel = stream.readUTF(); String channel = stream.readUTF();
String input = stream.readUTF(); String input = stream.readUTF();
ProxiedPlayer player = BungeeCord.getInstance().getPlayer(channel); ProxiedPlayer player = BungeeCord.getInstance().getPlayer(channel);
if (player != null) { if (player != null) {
BungeeCord.getInstance().getPluginManager().dispatchCommand(player, input); BungeeCord.getInstance().getPluginManager().dispatchCommand(player, input);
} }
@ -40,16 +34,21 @@ public class BListener implements Listener {
public void onJoin(PostLoginEvent e) { public void onJoin(PostLoginEvent e) {
ProxiedPlayer player = e.getPlayer(); ProxiedPlayer player = e.getPlayer();
sendToSpigotPlayer(player.getName(), true); sendToSpigotPlayer(player.getName(), true);
BMySQL.query("INSERT INTO `gui-bungeeplayer` (`UUID`, `Name`, `Online`) VALUES ('" + player.getUniqueId() + "', '" + player.getName() if (BMySQL.Enable) {
+ "', 'true') ON DUPLICATE KEY UPDATE `Name` = '" + player.getName() + "', `Online` = 'true';"); BMySQL.query("INSERT INTO `gui-bungeeplayer` (`UUID`, `Name`, `Online`) VALUES ('" + player.getUniqueId() + "', '" + player.getName()
+ "', 'true') ON DUPLICATE KEY UPDATE `Name` = '" + player.getName() + "', `Online` = 'true';");
}
} }
@EventHandler @EventHandler
public void onDisconnect(PlayerDisconnectEvent e) { public void onDisconnect(PlayerDisconnectEvent e) {
ProxiedPlayer player = e.getPlayer(); ProxiedPlayer player = e.getPlayer();
sendToSpigotPlayer(e.getPlayer().getName(), false); sendToSpigotPlayer(e.getPlayer().getName(), false);
BMySQL.query("INSERT INTO `gui-bungeeplayer` (`UUID`, `Name`, `Online`) VALUES ('" + player.getUniqueId() + "', '" + player.getName() if (BMySQL.Enable) {
+ "', 'true') ON DUPLICATE KEY UPDATE `Name` = '" + player.getName() + "', `Online` = 'false';"); BMySQL.query("INSERT INTO `gui-bungeeplayer` (`UUID`, `Name`, `Online`) VALUES ('" + player.getUniqueId() + "', '" + player.getName()
+ "', 'true') ON DUPLICATE KEY UPDATE `Name` = '" + player.getName() + "', `Online` = 'false';");
}
} }
public static void sendToSpigotPlayer(String name, Boolean join) { public static void sendToSpigotPlayer(String name, Boolean join) {

View File

@ -49,16 +49,19 @@ public final class BMain extends Plugin {
BListener.sendToSpigotDeleteAll(); BListener.sendToSpigotDeleteAll();
BMetrics metrics = new BMetrics(this, bstatsID); BMetrics metrics = new BMetrics(this, bstatsID);
BMySQL.main(); if (BMySQL.Enable){
BMySQL.query("CREATE TABLE IF NOT EXISTS `gui-bungeeplayer` (" + BMySQL.main();
" `UUID` VARCHAR(191) NOT NULL COLLATE 'utf8mb4_general_ci'," + BMySQL.query("CREATE TABLE IF NOT EXISTS `gui-bungeeplayer` (" +
" `Name` TINYTEXT NOT NULL COLLATE 'utf8mb4_general_ci'," + " `UUID` VARCHAR(191) NOT NULL COLLATE 'utf8mb4_general_ci'," +
" `Online` TINYTEXT NOT NULL COLLATE 'utf8mb4_general_ci'," + " `Name` TINYTEXT NOT NULL COLLATE 'utf8mb4_general_ci'," +
" UNIQUE INDEX `UUID` (`UUID`)" + " `Online` TINYTEXT NOT NULL COLLATE 'utf8mb4_general_ci'," +
")" + " UNIQUE INDEX `UUID` (`UUID`)" +
"COLLATE='utf8mb4_general_ci'" + ")" +
"ENGINE=InnoDB" + "COLLATE='utf8mb4_general_ci'" +
";"); "ENGINE=InnoDB" +
";");
}
Bsend.console(prefix + " §2Plugin loaded successfully." + " §7- §e" + (System.currentTimeMillis() - long_.longValue()) + "ms"); Bsend.console(prefix + " §2Plugin loaded successfully." + " §7- §e" + (System.currentTimeMillis() - long_.longValue()) + "ms");
Bsend.console(prefix + "§4=============================================================================="); Bsend.console(prefix + "§4==============================================================================");

View File

@ -12,6 +12,8 @@ import java.util.Calendar;
public class BMySQL { public class BMySQL {
private static Plugin plugin = BMain.plugin; private static Plugin plugin = BMain.plugin;
protected static Boolean Enable = false;
protected static String ip = "localhost"; protected static String ip = "localhost";
protected static Integer port = 3306; protected static Integer port = 3306;
protected static String database; protected static String database;

View File

@ -2,10 +2,8 @@ package de.jatitv.commandguiv2.Spigot.system;
import de.jatitv.commandguiv2.Spigot.Main; import de.jatitv.commandguiv2.Spigot.Main;
import net.t2code.lib.Spigot.Lib.messages.send; import net.t2code.lib.Spigot.Lib.messages.send;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.messaging.PluginMessageListener; import org.bukkit.plugin.messaging.PluginMessageListener;
import org.bukkit.scheduler.BukkitRunnable;
import java.io.*; import java.io.*;