SteamWar/SpigotCore
Archiviert
13
0

Update SWCommandUtils SteamwarUser mapper
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
yoyosource 2021-12-09 17:27:27 +01:00
Ursprung cd90cba7d5
Commit 779199f058
2 geänderte Dateien mit 24 neuen und 13 gelöschten Zeilen

Datei anzeigen

@ -23,15 +23,11 @@ import de.steamwar.sql.SchematicNode;
import de.steamwar.sql.SteamwarUser;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.command.Command;
import org.bukkit.command.CommandMap;
import org.bukkit.command.CommandSender;
import org.bukkit.command.SimpleCommandMap;
import org.bukkit.entity.Player;
import java.lang.annotation.Annotation;
import java.lang.reflect.Array;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.*;
import java.util.function.BiFunction;
@ -76,7 +72,7 @@ public class SWCommandUtils {
if (s.length() < 1) {
return Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList());
}
List<SteamwarUser> steamwarUsers = SteamwarUser.startsWithName(s);
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>() {

Datei anzeigen

@ -26,6 +26,7 @@ import org.bukkit.entity.Player;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.*;
import java.util.stream.Collectors;
public class SteamwarUser {
@ -37,12 +38,14 @@ public class SteamwarUser {
private static final Map<UUID, SteamwarUser> byUUID = new HashMap<>();
private static final Map<String, SteamwarUser> byName = new HashMap<>();
private static final Map<Integer, SteamwarUser> byId = new HashMap<>();
private static final Map<String, List<SteamwarUser>> byPrefix = new HashMap<>();
static{
Bukkit.getScheduler().runTaskTimer(Core.getInstance(), () -> {
byId.clear();
byName.clear();
byUUID.clear();
byPrefix.clear();
}, 72000, 72000);
}
@ -94,15 +97,27 @@ public class SteamwarUser {
return bedrock;
}
public static List<SteamwarUser> startsWithName(String userName){
return startWithName.select(rs -> {
public static List<SteamwarUser> getByPrefix(String userName){
if (userName.length() < 2) {
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");
if (byName.containsKey(name)) {
steamwarUsers.add(byName.get(name));
} else {
steamwarUsers.add(new SteamwarUser(rs));
}
}
return steamwarUsers;
}, userName.toLowerCase() + "%");
}
return users.stream().filter(user -> user.getUserName().toLowerCase().startsWith(userName.toLowerCase())).collect(Collectors.toList());
}
public static SteamwarUser get(String userName){
SteamwarUser user = byName.get(userName.toLowerCase());