Untitled
unknown
plain_text
a year ago
1.1 kB
5
Indexable
package archivo.ar;
import org.bukkit.ChatColor;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import java.sql.Connection;
import java.util.UUID;
public class Evento implements Listener {
private Mysql mysql; // Cambia el tipo a Mysql
// Constructor que recibe Mysql
public Evento(Mysql mysql) {
this.mysql = mysql; // Inicializa la variable mysql
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
UUID uuid = event.getPlayer().getUniqueId();
String nombre = event.getPlayer().getName();
Connection connection = mysql.getConnection();
if (connection == null) {
event.getPlayer().sendMessage(ChatColor.RED + "Error: No se pudo conectar a la base de datos.");
return; // Sal de la función si no hay conexión
}
SQLPlayerData.crearJugador(connection, uuid, nombre);
event.getPlayer().sendMessage(ChatColor.GREEN + "¡Bienvenido al servidor! Tu UUID es: " + ChatColor.YELLOW + uuid);
}
}
Editor is loading...
Leave a Comment