94 lines
2.5 KiB
Java
94 lines
2.5 KiB
Java
package eu.univento.core.api.player;
|
|
|
|
import java.sql.ResultSet;
|
|
import java.sql.SQLException;
|
|
import java.util.ArrayList;
|
|
import java.util.Random;
|
|
import org.bukkit.entity.Player;
|
|
|
|
import eu.univento.core.Core;
|
|
import eu.univento.core.api.MySQL;
|
|
|
|
/**
|
|
* gets nick settings for players
|
|
* @author joethei
|
|
* @version 1.1
|
|
*/
|
|
public class NickName {
|
|
|
|
/**
|
|
*
|
|
* @param p remove nickname from player
|
|
*/
|
|
public static void remove(Player p) {
|
|
if (Core.nicks.containsKey(p))
|
|
Core.nicks.remove(p);
|
|
}
|
|
|
|
/**
|
|
* sets nick boolean
|
|
* @param p player
|
|
* @param nick boolean
|
|
* @throws ClassNotFoundException Class couldn't be found
|
|
* @throws SQLException SQL server not available or throwing error
|
|
*/
|
|
public static void setNick(Player p, boolean nick) throws SQLException, ClassNotFoundException {
|
|
MySQL sql = Core.returnSQL();
|
|
sql.openConnection();
|
|
String uuid = p.getUniqueId().toString();
|
|
if (nick)
|
|
sql.getConnection().createStatement().executeUpdate("UPDATE PlayerData SET nick = '1' WHERE player_uuid = '" + uuid + "';");
|
|
else
|
|
sql.getConnection().createStatement().executeUpdate("UPDATE PlayerData SET nick = '0' WHERE player_uuid = '" + uuid + "';");
|
|
sql.closeConnection();
|
|
}
|
|
|
|
/**
|
|
* gets if player is nicked
|
|
* @param p player
|
|
* @return true / false
|
|
* @throws ClassNotFoundException Class couldn't be found
|
|
* @throws SQLException SQL server not available or throwing error
|
|
*/
|
|
public static boolean isNicked(Player p) throws SQLException, ClassNotFoundException {
|
|
MySQL sql = Core.returnSQL();
|
|
sql.openConnection();
|
|
String uuid = p.getUniqueId().toString();
|
|
ResultSet rs = sql.getConnection().createStatement().executeQuery("SELECT nick FROM PlayerData WHERE player_uuid = '" + uuid + "';");
|
|
if (rs.next()) {
|
|
return rs.getInt("nick") == 1;
|
|
}
|
|
sql.closeConnection();
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* gets nickname of player
|
|
* @param p player
|
|
* @return String
|
|
*/
|
|
public static String getNick(Player p) {
|
|
if (Core.nicks.containsKey(p)) {
|
|
String nick = (String) Core.nicks.get(p);
|
|
return nick;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* gets random Nickname
|
|
* @return String
|
|
* @throws SQLException SQL server not available or throwing error
|
|
*/
|
|
public static String getNicks() throws SQLException {
|
|
ArrayList<String> names = new ArrayList<String>();
|
|
names.add("XXKevinXX");
|
|
names.add("xxGamelcrafterxx");
|
|
names.add("LiaaamDesigns");
|
|
|
|
Random r = new Random();
|
|
int i = r.nextInt(names.size());
|
|
|
|
return (String) names.get(i);
|
|
}
|
|
} |