SteamWar/BungeeCore
Archiviert
13
2

Refactoring WarkingUser & changing UserNames

Dieser Commit ist enthalten in:
Travis CI 2019-06-14 10:42:16 +02:00
Ursprung 4f17f4d3d2
Commit fe98bb72f4
3 geänderte Dateien mit 10 neuen und 27 gelöschten Zeilen

Datei anzeigen

@ -41,7 +41,7 @@ public class PlayerListener implements Listener {
} }
List<BannedUserIPs> ips = BannedUserIPs.get(event.getConnection().getAddress().getAddress().getHostAddress()); List<BannedUserIPs> ips = BannedUserIPs.get(event.getConnection().getAddress().getAddress().getHostAddress());
if(ips.size() > 0){ if(!ips.isEmpty()){
StringBuilder potentialBan = new StringBuilder(); StringBuilder potentialBan = new StringBuilder();
potentialBan.append(BungeeCore.ChatPrefix); potentialBan.append(BungeeCore.ChatPrefix);
potentialBan.append("§cMögliche Bannumgehung durch §r"); potentialBan.append("§cMögliche Bannumgehung durch §r");
@ -72,7 +72,7 @@ public class PlayerListener implements Listener {
@EventHandler @EventHandler
public void onPostLogin(PostLoginEvent event) { public void onPostLogin(PostLoginEvent event) {
ProxiedPlayer player = event.getPlayer(); ProxiedPlayer player = event.getPlayer();
WarkingUser user = new WarkingUser(player); WarkingUser user = WarkingUser.get(player.getUniqueId());
player.removeGroups("Admin", "team"); player.removeGroups("Admin", "team");
switch(user.getUserGroup()){ switch(user.getUserGroup()){
case "Admin": case "Admin":

Datei anzeigen

@ -27,7 +27,7 @@ public class WebpwCommand extends Command {
return; return;
} }
sql.setWebpw(new WarkingUser(player), args[0]); sql.setWebpw(WarkingUser.get(player.getUniqueId()), args[0]);
player.sendMessage(BungeeCore.ChatPrefix + "Webpasswort gesetzt!"); player.sendMessage(BungeeCore.ChatPrefix + "Webpasswort gesetzt!");
} }
} }

Datei anzeigen

@ -1,7 +1,6 @@
package de.steamwar.bungeecore.sql; package de.steamwar.bungeecore.sql;
import net.md_5.bungee.api.connection.PendingConnection; import net.md_5.bungee.api.connection.PendingConnection;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
@ -24,7 +23,7 @@ public class WarkingUser {
public static Timestamp PermaBan = Timestamp.from(Instant.ofEpochSecond(946684800)); public static Timestamp PermaBan = Timestamp.from(Instant.ofEpochSecond(946684800));
public WarkingUser(int id){ public WarkingUser(int id){
init(sql.select("SELECT * FROM UserData WHERE id = '" + id + "'")); init(sql.select("SELECT * FROM UserData WHERE id = " + id));
} }
public WarkingUser(UUID UUID){ public WarkingUser(UUID UUID){
@ -41,6 +40,10 @@ public class WarkingUser {
if(dbplayer.next()){ if(dbplayer.next()){
dbplayer.beforeFirst(); dbplayer.beforeFirst();
init(dbplayer); init(dbplayer);
if(!dbplayer.getString("UserName").equals(connection.getName())){
UserName = connection.getName();
sql.update("UPDATE UserData SET UserName = '" + UserName + "' WHERE id = " + id);
}
}else{ }else{
UUID = connection.getUniqueId(); UUID = connection.getUniqueId();
UserName = connection.getName(); UserName = connection.getName();
@ -55,26 +58,6 @@ public class WarkingUser {
} }
} }
public WarkingUser(ProxiedPlayer player){
ResultSet dbplayer = sql.select("SELECT * FROM UserData WHERE UUID = '" + player.getUniqueId().toString() + "'");
try {
if(dbplayer.next()){
dbplayer.beforeFirst();
init(dbplayer);
}else{
UUID = player.getUniqueId();
UserName = player.getName();
UserGroup = "Member";
sql.update("INSERT INTO UserData (UUID, UserName, UserGroup) VALUES ('" + getUUID().toString() + "', '" + getUserName() + "', '" + getUserGroup() + "')");
dbplayer = sql.select("SELECT * FROM UserData WHERE UUID = '" + getUUID().toString() + "'");
init(dbplayer);
}
} catch (SQLException e) {
e.printStackTrace();
}
}
public static WarkingUser get(String userName){ public static WarkingUser get(String userName){
userName = sql.disarmString(userName); userName = sql.disarmString(userName);
for(WarkingUser user : allUsers) for(WarkingUser user : allUsers)
@ -136,13 +119,13 @@ public class WarkingUser {
sql.update("INSERT INTO BannedUserIPs\n" + sql.update("INSERT INTO BannedUserIPs\n" +
" (UserID, Timestamp, IP)\n" + " (UserID, Timestamp, IP)\n" +
"VALUES\n" + "VALUES\n" +
" (" + getId() + ", NOW(), '" + ip + "')\n" + " (" + id + ", NOW(), '" + ip + "')\n" +
"ON DUPLICATE KEY UPDATE\n" + "ON DUPLICATE KEY UPDATE\n" +
" Timestamp=NOW()"); " Timestamp=NOW()");
} }
public void banPlayer(String ip, Timestamp time, String banReason){ public void banPlayer(String ip, Timestamp time, String banReason){
sql.update("UPDATE UserData SET BanTime = '" + time.toString() + "', BanReason = '" + banReason + "' WHERE UUID = '" + getUUID().toString() + "'"); sql.update("UPDATE UserData SET BanTime = '" + time.toString() + "', BanReason = '" + banReason + "' WHERE id = " + id);
if(ip != null) if(ip != null)
updateBanIP(ip); updateBanIP(ip);
} }