Archiviert
1
0

You can now ban and mute Users who never joined the server, HOOZAH

Dieser Commit ist enthalten in:
Zeanon 2021-04-26 20:24:56 +02:00
Ursprung 956339faf6
Commit c7402b34ee
5 geänderte Dateien mit 55 neuen und 6 gelöschten Zeilen

Datei anzeigen

@ -42,7 +42,7 @@ public class BanCommand extends BasicCommand {
return;
}
SteamwarUser target = user(sender, args[0]);
SteamwarUser target = unsafeUser(sender, args[0]);
if(target == null)
return;

Datei anzeigen

@ -53,10 +53,17 @@ abstract class BasicCommand extends Command implements TabExecutor {
return new ArrayList<>();
}
protected SteamwarUser user(CommandSender sender, String arg){
protected SteamwarUser existingUser(CommandSender sender, String arg){
SteamwarUser target = SteamwarUser.get(arg);
if(target == null)
Message.send("UNKNOWN_PLAYER", sender);
return target;
}
protected SteamwarUser unsafeUser(CommandSender sender, String arg){
SteamwarUser target = SteamwarUser.getOrCreateOfflinePlayer(arg);
if(target == null)
Message.send("UNKNOWN_PLAYER", sender);
return target;
}
}

Datei anzeigen

@ -38,7 +38,7 @@ public class MuteCommand extends BasicCommand {
return;
}
SteamwarUser target = user(sender, args[0]);
SteamwarUser target = unsafeUser(sender, args[0]);
if(target == null)
return;

Datei anzeigen

@ -39,7 +39,7 @@ public class UnbanCommand extends BasicCommand {
return;
}
SteamwarUser target = user(sender, args[0]);
SteamwarUser target = existingUser(sender, args[0]);
if(target == null)
return;

Datei anzeigen

@ -19,10 +19,15 @@
package de.steamwar.bungeecore.sql;
import com.google.gson.JsonParser;
import de.steamwar.bungeecore.BungeeCore;
import de.steamwar.bungeecore.Message;
import de.steamwar.bungeecore.commands.WebregisterCommand;
import de.steamwar.bungeecore.listeners.ConnectionListener;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Scanner;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.connection.PendingConnection;
@ -38,6 +43,7 @@ import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
public class SteamwarUser {
private final int id;
private final UUID uuid;
@ -51,6 +57,8 @@ public class SteamwarUser {
private static final Map<UUID, SteamwarUser> usersByUUID = new HashMap<>();
private static final Map<Integer, SteamwarUser> usersById = new HashMap<>();
private static final InetAddress LIXFEL_DE;
private static final String API_URL = "https://api.mojang.com/users/profiles/minecraft/";
private static final JsonParser jsonParser = new JsonParser();
static {
try {
@ -85,8 +93,7 @@ public class SteamwarUser {
user.userName = userName;
}
}else{
SQL.update("INSERT INTO UserData (UUID, UserName, UserGroup) VALUES (?, ?, 'Member')", connection.getUniqueId().toString(), connection.getName());
user = dbInit(SQL.select("SELECT * FROM UserData WHERE UUID = ?", connection.getUniqueId().toString()));
user = SteamwarUser.createUserInDatabase(connection.getUniqueId(), connection.getName());
if(user == null)
throw new SecurityException("user == null");
ConnectionListener.newPlayer(user.uuid);
@ -97,6 +104,25 @@ public class SteamwarUser {
return user;
}
public static SteamwarUser getOrCreateOfflinePlayer(String name){
SteamwarUser user = SteamwarUser.get(name);
if (user != null) {
return user;
}
UUID uuid = SteamwarUser.loadUUID(name);
if (uuid == null) {
return null;
}
return SteamwarUser.createUserInDatabase(uuid, name);
}
private static SteamwarUser createUserInDatabase(UUID uuid, String name) {
SQL.update("INSERT INTO UserData (UUID, UserName, UserGroup) VALUES (?, ?, 'Member')", uuid.toString(), name);
return dbInit(SQL.select("SELECT * FROM UserData WHERE UUID = ?", uuid.toString()));
}
public static SteamwarUser get(String userName){
userName = userName.toLowerCase();
if(usersByName.containsKey(userName))
@ -126,6 +152,22 @@ public class SteamwarUser {
usersByUUID.clear();
}
public static UUID loadUUID(String playerName) {
try {
final URL url = new URL(API_URL + playerName);
return getUniqueIdFromString(jsonParser.parse(new Scanner(url.openConnection().getInputStream()).nextLine()).getAsJsonObject().get("id").getAsString());
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
private static UUID getUniqueIdFromString(String uuid) {
return UUID.fromString(uuid.replaceFirst("(\\w{8})(\\w{4})(\\w{4})(\\w{4})(\\w{12})", "$1-$2-$3-$4-$5"));
}
public void setTeam(int team){
this.team = team;
SQL.update("Update UserData SET Team = ? WHERE id = ?", team, id);