From c1b3ab6dbbf14c2deecfdb753eeb1ed68fba8306 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 11 Dec 2021 13:43:16 +0100 Subject: [PATCH] Fix SWCommandUtils SteamwarUser --- .../de/steamwar/command/SWCommandUtils.java | 8 +------ .../src/de/steamwar/sql/SteamwarUser.java | 24 ------------------- SpigotCore_Main/testsrc/.gitkeep | 0 3 files changed, 1 insertion(+), 31 deletions(-) delete mode 100644 SpigotCore_Main/testsrc/.gitkeep diff --git a/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java b/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java index cdcd346..7438ac1 100644 --- a/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java +++ b/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java @@ -60,13 +60,7 @@ public class SWCommandUtils { if (s.equals("a") || s.equals("adventure") || s.equals("2")) return GameMode.ADVENTURE; return null; }, 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 -> { - if (s.length() < 1) { - return Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList()); - } - List steamwarUsers = SteamwarUser.getByPrefix(s); - return steamwarUsers.stream().map(SteamwarUser::getUserName).limit(40).collect(Collectors.toList()); - })); + MAPPER_FUNCTIONS.put(SteamwarUser.class.getTypeName(), createMapper(SteamwarUser::get, s -> Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList()))); MAPPER_FUNCTIONS.put(SchematicNode.class.getTypeName(), new TypeMapper() { @Override public SchematicNode map(CommandSender commandSender, String[] previousArguments, String s) { diff --git a/SpigotCore_Main/src/de/steamwar/sql/SteamwarUser.java b/SpigotCore_Main/src/de/steamwar/sql/SteamwarUser.java index 9188cb7..bbad8d7 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/SteamwarUser.java +++ b/SpigotCore_Main/src/de/steamwar/sql/SteamwarUser.java @@ -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 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 startWithName = new SQL.Statement("SELECT * FROM UserData WHERE lower(UserName) LIKE ?"); private static final Map byUUID = new HashMap<>(); private static final Map byName = new HashMap<>(); private static final Map byId = new HashMap<>(); - private static final Map> byPrefix = new HashMap<>(); static{ Bukkit.getScheduler().runTaskTimer(Core.getInstance(), () -> { byId.clear(); byName.clear(); byUUID.clear(); - byPrefix.clear(); }, 72000, 72000); } @@ -97,27 +94,6 @@ public class SteamwarUser { return bedrock; } - public static List getByPrefix(String userName){ - if (userName.isEmpty()) { - return new ArrayList<>(); - } - List users = byPrefix.get(userName.toLowerCase().substring(0, 1)); - if (users == null) { - users = startWithName.select(rs -> { - List 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){ SteamwarUser user = byName.get(userName.toLowerCase()); if(user == null) diff --git a/SpigotCore_Main/testsrc/.gitkeep b/SpigotCore_Main/testsrc/.gitkeep deleted file mode 100644 index e69de29..0000000