SteamWar/SpigotCore
Archiviert
13
0

Fix SWCommandUtils SteamwarUser

Dieser Commit ist enthalten in:
yoyosource 2021-12-11 13:43:16 +01:00
Ursprung afa80082b3
Commit c1b3ab6dbb
3 geänderte Dateien mit 1 neuen und 31 gelöschten Zeilen

Datei anzeigen

@ -60,13 +60,7 @@ public class SWCommandUtils {
if (s.equals("a") || s.equals("adventure") || s.equals("2")) return GameMode.ADVENTURE; if (s.equals("a") || s.equals("adventure") || s.equals("2")) return GameMode.ADVENTURE;
return null; return null;
}, s -> Arrays.asList("s", "survival", "0", "c", "creative", "1", "sp", "spectator", "3", "a", "adventure", "2"))); }, s -> Arrays.asList("s", "survival", "0", "c", "creative", "1", "sp", "spectator", "3", "a", "adventure", "2")));
MAPPER_FUNCTIONS.put(SteamwarUser.class.getTypeName(), createMapper(SteamwarUser::get, s -> { MAPPER_FUNCTIONS.put(SteamwarUser.class.getTypeName(), createMapper(SteamwarUser::get, s -> Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList())));
if (s.length() < 1) {
return Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList());
}
List<SteamwarUser> steamwarUsers = SteamwarUser.getByPrefix(s);
return steamwarUsers.stream().map(SteamwarUser::getUserName).limit(40).collect(Collectors.toList());
}));
MAPPER_FUNCTIONS.put(SchematicNode.class.getTypeName(), new TypeMapper<SchematicNode>() { MAPPER_FUNCTIONS.put(SchematicNode.class.getTypeName(), new TypeMapper<SchematicNode>() {
@Override @Override
public SchematicNode map(CommandSender commandSender, String[] previousArguments, String s) { public SchematicNode map(CommandSender commandSender, String[] previousArguments, String s) {

Datei anzeigen

@ -33,19 +33,16 @@ public class SteamwarUser {
private static final SQL.Statement getId = new SQL.Statement("SELECT * FROM UserData WHERE id = ?"); private static final SQL.Statement getId = new SQL.Statement("SELECT * FROM UserData WHERE id = ?");
private static final SQL.Statement getUUID = new SQL.Statement("SELECT * FROM UserData WHERE UUID = ?"); private static final SQL.Statement getUUID = new SQL.Statement("SELECT * FROM UserData WHERE UUID = ?");
private static final SQL.Statement getName = new SQL.Statement("SELECT * FROM UserData WHERE lower(UserName) = ?"); private static final SQL.Statement getName = new SQL.Statement("SELECT * FROM UserData WHERE lower(UserName) = ?");
private static final SQL.Statement startWithName = new SQL.Statement("SELECT * FROM UserData WHERE lower(UserName) LIKE ?");
private static final Map<UUID, SteamwarUser> byUUID = new HashMap<>(); private static final Map<UUID, SteamwarUser> byUUID = new HashMap<>();
private static final Map<String, SteamwarUser> byName = new HashMap<>(); private static final Map<String, SteamwarUser> byName = new HashMap<>();
private static final Map<Integer, SteamwarUser> byId = new HashMap<>(); private static final Map<Integer, SteamwarUser> byId = new HashMap<>();
private static final Map<String, List<SteamwarUser>> byPrefix = new HashMap<>();
static{ static{
Bukkit.getScheduler().runTaskTimer(Core.getInstance(), () -> { Bukkit.getScheduler().runTaskTimer(Core.getInstance(), () -> {
byId.clear(); byId.clear();
byName.clear(); byName.clear();
byUUID.clear(); byUUID.clear();
byPrefix.clear();
}, 72000, 72000); }, 72000, 72000);
} }
@ -97,27 +94,6 @@ public class SteamwarUser {
return bedrock; return bedrock;
} }
public static List<SteamwarUser> getByPrefix(String userName){
if (userName.isEmpty()) {
return new ArrayList<>();
}
List<SteamwarUser> users = byPrefix.get(userName.toLowerCase().substring(0, 1));
if (users == null) {
users = startWithName.select(rs -> {
List<SteamwarUser> steamwarUsers = new ArrayList<>();
while (rs.next()) {
String name = rs.getString("UserName");
SteamwarUser user = byName.get(name.toLowerCase());
if (user == null) user = new SteamwarUser(rs);
steamwarUsers.add(user);
}
return steamwarUsers;
}, userName.toLowerCase() + "%");
byPrefix.put(userName.toLowerCase().substring(0, 1), users);
}
return users.stream().filter(user -> user.getUserName().toLowerCase().startsWith(userName.toLowerCase())).collect(Collectors.toList());
}
public static SteamwarUser get(String userName){ public static SteamwarUser get(String userName){
SteamwarUser user = byName.get(userName.toLowerCase()); SteamwarUser user = byName.get(userName.toLowerCase());
if(user == null) if(user == null)