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.ConfigurationProvider;
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.IOException;
@ -26,17 +28,30 @@ public class BConfig {
e.printStackTrace();
}
}
Configuration configuration;
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.port = configuration.getInt("MySQL.Port");
BMySQL.database = configuration.getString("MySQL.Database");
BMySQL.user = configuration.getString("MySQL.User");
BMySQL.password = configuration.getString("MySQL.Password");
BMySQL.SSL = configuration.getBoolean("MySQL.SSL");
} catch (IOException e) {
e.printStackTrace();
}
}
}

View File

@ -1,9 +1,6 @@
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.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.PluginMessageEvent;
@ -13,7 +10,6 @@ import net.md_5.bungee.event.EventHandler;
import net.t2code.lib.Bungee.Lib.messages.Bsend;
import java.io.*;
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;
public class BListener implements Listener {
@ -25,8 +21,6 @@ public class BListener implements Listener {
String channel = stream.readUTF();
String input = stream.readUTF();
ProxiedPlayer player = BungeeCord.getInstance().getPlayer(channel);
if (player != null) {
BungeeCord.getInstance().getPluginManager().dispatchCommand(player, input);
}
@ -40,18 +34,23 @@ public class BListener implements Listener {
public void onJoin(PostLoginEvent e) {
ProxiedPlayer player = e.getPlayer();
sendToSpigotPlayer(player.getName(), true);
if (BMySQL.Enable) {
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
public void onDisconnect(PlayerDisconnectEvent e) {
ProxiedPlayer player = e.getPlayer();
sendToSpigotPlayer(e.getPlayer().getName(), false);
if (BMySQL.Enable) {
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) {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
DataOutputStream output = new DataOutputStream(stream);

View File

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

View File

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

View File

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