From 45c2a77186132ce45d71e313f37c93ef3d166256 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 10 Apr 2021 14:52:58 +0200 Subject: [PATCH 01/36] Add TypeMapper.map with CommandSender --- .../src/de/steamwar/command/SWCommandUtils.java | 8 ++++---- .../src/de/steamwar/command/SubCommand.java | 6 +++--- .../src/de/steamwar/command/TypeMapper.java | 10 +++++++++- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java b/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java index da927ad..0d09c7f 100644 --- a/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java +++ b/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java @@ -100,7 +100,7 @@ public class SWCommandUtils { } } - static Object[] generateArgumentArray(TypeMapper[] parameters, String[] args, Class varArgType, String[] subCommand) throws CommandParseException { + static Object[] generateArgumentArray(CommandSender commandSender, TypeMapper[] parameters, String[] args, Class varArgType, String[] subCommand) throws CommandParseException { Object[] arguments = new Object[parameters.length + 1]; int index = 0; while (index < subCommand.length) { @@ -115,7 +115,7 @@ public class SWCommandUtils { arguments[arguments.length - 1] = varArgument; } else { for (int i = 0; i < parameters.length - (varArgType != null ? 1 : 0); i++) { - arguments[i + 1] = parameters[i].map(Arrays.copyOf(args, index), args[index]); + arguments[i + 1] = parameters[i].map(commandSender, Arrays.copyOf(args, index), args[index]); index++; if (arguments[i + 1] == null) { throw new CommandParseException(); @@ -128,7 +128,7 @@ public class SWCommandUtils { arguments[arguments.length - 1] = varArgument; for (int i = 0; i < length; i++) { - Object value = parameters[parameters.length - 1].map(Arrays.copyOf(args, index), args[index]); + Object value = parameters[parameters.length - 1].map(commandSender, Arrays.copyOf(args, index), args[index]); if (value == null) { throw new CommandParseException(); } @@ -156,7 +156,7 @@ public class SWCommandUtils { public static TypeMapper createMapper(Function mapper, BiFunction> tabCompleter) { return new TypeMapper() { @Override - public T map(String[] previous, String s) { + public T map(CommandSender commandSender, String[] previousArguments, String s) { return mapper.apply(s); } diff --git a/SpigotCore_Main/src/de/steamwar/command/SubCommand.java b/SpigotCore_Main/src/de/steamwar/command/SubCommand.java index 343cbd0..b7a414b 100644 --- a/SpigotCore_Main/src/de/steamwar/command/SubCommand.java +++ b/SpigotCore_Main/src/de/steamwar/command/SubCommand.java @@ -88,7 +88,7 @@ class SubCommand { return false; } try { - Object[] objects = SWCommandUtils.generateArgumentArray(arguments, args, varArgType, subCommand); + Object[] objects = SWCommandUtils.generateArgumentArray(commandSender, arguments, args, varArgType, subCommand); objects[0] = commandSenderFunction.apply(commandSender); method.setAccessible(true); method.invoke(swCommand, objects); @@ -116,7 +116,7 @@ class SubCommand { String s = argsList.remove(0); if (argsList.isEmpty()) return argument.tabCompletes(commandSender, Arrays.copyOf(args, args.length - 1), s); try { - if (argument.map(Arrays.copyOf(args, index), s) == null) { + if (argument.map(commandSender, Arrays.copyOf(args, index), s) == null) { return null; } } catch (Exception e) { @@ -129,7 +129,7 @@ class SubCommand { String s = argsList.remove(0); if (argsList.isEmpty()) return arguments[arguments.length - 1].tabCompletes(commandSender, Arrays.copyOf(args, args.length - 1), s); try { - if (arguments[arguments.length - 1].map(Arrays.copyOf(args, index), s) == null) { + if (arguments[arguments.length - 1].map(commandSender, Arrays.copyOf(args, index), s) == null) { return null; } } catch (Exception e) { diff --git a/SpigotCore_Main/src/de/steamwar/command/TypeMapper.java b/SpigotCore_Main/src/de/steamwar/command/TypeMapper.java index 27b04f7..c0c160c 100644 --- a/SpigotCore_Main/src/de/steamwar/command/TypeMapper.java +++ b/SpigotCore_Main/src/de/steamwar/command/TypeMapper.java @@ -24,7 +24,15 @@ import org.bukkit.command.CommandSender; import java.util.List; public interface TypeMapper { - T map(String[] previousArguments, String s); + default T map(CommandSender commandSender, String[] previousArguments, String s) { + return map(previousArguments, s); + } + + // For backwards compatibility, can be removed later on + @Deprecated(since = "Use the other map Function without calling super!") + default T map(String[] previousArguments, String s) { + throw new SecurityException(); + } List tabCompletes(CommandSender commandSender, String[] previousArguments, String s); } From 2f61d2836bd3256df19da0e15483e5531a68b3b8 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 10 Apr 2021 17:33:20 +0200 Subject: [PATCH 02/36] Make SWCommand.register and SWCommand.unregister public --- SpigotCore_Main/src/de/steamwar/command/SWCommand.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/command/SWCommand.java b/SpigotCore_Main/src/de/steamwar/command/SWCommand.java index 72cda65..ae31780 100644 --- a/SpigotCore_Main/src/de/steamwar/command/SWCommand.java +++ b/SpigotCore_Main/src/de/steamwar/command/SWCommand.java @@ -186,7 +186,7 @@ public abstract class SWCommand { }); } - protected void unregister() { + public void unregister() { SWCommandUtils.knownCommandMap.remove(command.getName()); for (String alias : command.getAliases()) { SWCommandUtils.knownCommandMap.remove(alias); @@ -194,7 +194,7 @@ public abstract class SWCommand { command.unregister(SWCommandUtils.commandMap); } - protected void register() { + public void register() { SWCommandUtils.commandMap.register("steamwar", this.command); } From e1c24293bdc95947a6e4196a468f58b37cd508ed Mon Sep 17 00:00:00 2001 From: zOnlyKroks Date: Sun, 11 Apr 2021 15:54:58 +0200 Subject: [PATCH 03/36] Multiple Team Leaders --- SpigotCore_Main/src/de/steamwar/sql/Team.java | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/sql/Team.java b/SpigotCore_Main/src/de/steamwar/sql/Team.java index 7504476..7841b23 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/Team.java +++ b/SpigotCore_Main/src/de/steamwar/sql/Team.java @@ -28,21 +28,19 @@ public class Team { private final int teamId; private final String teamKuerzel; private final String teamName; - private final int teamLeader; private final String teamColor; - private static final Team pub = new Team(0, "PUB", "Öffentlich", 0, "8"); + private static final Team pub = new Team(0, "PUB", "Öffentlich", "8"); - private Team(int teamId, String teamKuerzel, String teamName, int teamLeader, String teamColor){ + private Team(int teamId, String teamKuerzel, String teamName, String teamColor){ this.teamId = teamId; this.teamKuerzel = teamKuerzel; this.teamName = teamName; - this.teamLeader = teamLeader; this.teamColor = teamColor; } private Team(ResultSet rs) throws SQLException { - this(rs.getInt("TeamID"), rs.getString("TeamKuerzel"), rs.getString("TeamName"), rs.getInt("TeamLeader"), rs.getString("TeamColor")); + this(rs.getInt("TeamID"), rs.getString("TeamKuerzel"), rs.getString("TeamName"), rs.getString("TeamColor")); } public static Team get(int id){ @@ -70,10 +68,6 @@ public class Team { return teamName; } - public int getTeamLeader() { - return teamLeader; - } - public String getTeamColor() { return teamColor; } From a7e5f502623a470e20c72f2930455d1c796dabc2 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 16 Apr 2021 17:03:07 +0200 Subject: [PATCH 04/36] Fix CCE in SubCommand.invoke --- SpigotCore_Main/src/de/steamwar/command/SubCommand.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/SpigotCore_Main/src/de/steamwar/command/SubCommand.java b/SpigotCore_Main/src/de/steamwar/command/SubCommand.java index b7a414b..86cfdc7 100644 --- a/SpigotCore_Main/src/de/steamwar/command/SubCommand.java +++ b/SpigotCore_Main/src/de/steamwar/command/SubCommand.java @@ -26,6 +26,7 @@ import java.lang.reflect.Method; import java.lang.reflect.Parameter; import java.util.*; import java.util.function.Function; +import java.util.function.Predicate; class SubCommand { @@ -33,6 +34,7 @@ class SubCommand { private Method method; String[] subCommand; TypeMapper[] arguments; + private Predicate commandSenderPredicate; private Function commandSenderFunction; Class varArgType = null; @@ -45,6 +47,7 @@ class SubCommand { this.method = method; Parameter[] parameters = method.getParameters(); + commandSenderPredicate = sender -> parameters[0].getType().isAssignableFrom(sender.getClass()); commandSenderFunction = sender -> parameters[0].getType().cast(sender); this.subCommand = subCommand; @@ -88,6 +91,9 @@ class SubCommand { return false; } try { + if (!commandSenderPredicate.test(commandSender)) { + return false; + } Object[] objects = SWCommandUtils.generateArgumentArray(commandSender, arguments, args, varArgType, subCommand); objects[0] = commandSenderFunction.apply(commandSender); method.setAccessible(true); From d830eb6f47e89e4fbc8dfcd2388e769e53f03828 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Thu, 29 Apr 2021 02:03:23 +0200 Subject: [PATCH 05/36] Little Skull Patch --- SpigotCore_14/src/de/steamwar/inventory/SWItem_14.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/SpigotCore_14/src/de/steamwar/inventory/SWItem_14.java b/SpigotCore_14/src/de/steamwar/inventory/SWItem_14.java index adf1b9c..d31f937 100644 --- a/SpigotCore_14/src/de/steamwar/inventory/SWItem_14.java +++ b/SpigotCore_14/src/de/steamwar/inventory/SWItem_14.java @@ -19,7 +19,9 @@ package de.steamwar.inventory; +import org.bukkit.Bukkit; import org.bukkit.Material; +import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.SkullMeta; @@ -269,7 +271,12 @@ class SWItem_14 { ItemStack head = new ItemStack(Material.PLAYER_HEAD, 1); SkullMeta headmeta = (SkullMeta) head.getItemMeta(); assert headmeta != null; - headmeta.setOwner(player); + Player p = Bukkit.getPlayer(player); + if (p != null) { + headmeta.setOwningPlayer(p); + } else { + headmeta.setOwner(player); + } headmeta.setDisplayName(player); head.setItemMeta(headmeta); return head; From 24f605daf2713ae4e685960e5003a349553922c1 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Thu, 29 Apr 2021 02:04:37 +0200 Subject: [PATCH 06/36] Minor Fix --- SpigotCore_14/src/de/steamwar/inventory/SWItem_14.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SpigotCore_14/src/de/steamwar/inventory/SWItem_14.java b/SpigotCore_14/src/de/steamwar/inventory/SWItem_14.java index d31f937..08b3fee 100644 --- a/SpigotCore_14/src/de/steamwar/inventory/SWItem_14.java +++ b/SpigotCore_14/src/de/steamwar/inventory/SWItem_14.java @@ -271,7 +271,7 @@ class SWItem_14 { ItemStack head = new ItemStack(Material.PLAYER_HEAD, 1); SkullMeta headmeta = (SkullMeta) head.getItemMeta(); assert headmeta != null; - Player p = Bukkit.getPlayer(player); + Player p = Bukkit.getPlayerExact(player); if (p != null) { headmeta.setOwningPlayer(p); } else { From 319fcdfae056b0d4b05b0fb893c26e91d27b9429 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 29 Apr 2021 11:55:39 +0200 Subject: [PATCH 07/36] Add BauweltMemberConfig --- .../de/steamwar/sql/BauweltMemberConfig.java | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 SpigotCore_Main/src/de/steamwar/sql/BauweltMemberConfig.java diff --git a/SpigotCore_Main/src/de/steamwar/sql/BauweltMemberConfig.java b/SpigotCore_Main/src/de/steamwar/sql/BauweltMemberConfig.java new file mode 100644 index 0000000..b915d78 --- /dev/null +++ b/SpigotCore_Main/src/de/steamwar/sql/BauweltMemberConfig.java @@ -0,0 +1,78 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.sql; + +import org.bukkit.entity.Player; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.UUID; + +public final class BauweltMemberConfig { + + private BauweltMemberConfig() { + throw new IllegalStateException("Utility Class"); + } + + public static String getPlayerConfig(Player player) { + return getPlayerConfig(player.getUniqueId()); + } + + public static String getPlayerConfig(UUID uuid) { + return getPlayerConfig(SteamwarUser.get(uuid).getId()); + } + + public static String getPlayerConfig(int id) { + ResultSet config = SQL.select("SELECT * FROM MemberConfig WHERE UserID = ?", id); + try { + if (config == null || !config.next()) { + return null; + } + return config.getString("BauConfig"); + } catch (SQLException e) { + return null; + } + } + + public static void updatePlayerConfig(Player player, String config) { + updatePlayerConfig(player.getUniqueId(), config); + } + + public static void updatePlayerConfig(UUID uuid, String config) { + updatePlayerConfig(SteamwarUser.get(uuid).getId(), config); + } + + public static void updatePlayerConfig(int id, String config) { + SQL.update("INSERT INTO MemberConfig (UserID, BauConfig) VALUES (?, ?) ON DUPLICATE KEY UPDATE BauConfig = VALUES(BauConfig)", id, config); + } + + public static void removePlayerConfig(Player player) { + removePlayerConfig(player.getUniqueId()); + } + + public static void removePlayerConfig(UUID uuid) { + removePlayerConfig(SteamwarUser.get(uuid).getId()); + } + + public static void removePlayerConfig(int id) { + updatePlayerConfig(id, null); + } + +} From 6c2d9d067f07330ac702ab3fcadf465d0de1645a Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Thu, 29 Apr 2021 12:02:12 +0200 Subject: [PATCH 08/36] Even more Cache --- SpigotCore_14/src/de/steamwar/inventory/SWItem_14.java | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/SpigotCore_14/src/de/steamwar/inventory/SWItem_14.java b/SpigotCore_14/src/de/steamwar/inventory/SWItem_14.java index 08b3fee..623dd20 100644 --- a/SpigotCore_14/src/de/steamwar/inventory/SWItem_14.java +++ b/SpigotCore_14/src/de/steamwar/inventory/SWItem_14.java @@ -21,7 +21,6 @@ package de.steamwar.inventory; import org.bukkit.Bukkit; import org.bukkit.Material; -import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.SkullMeta; @@ -271,12 +270,7 @@ class SWItem_14 { ItemStack head = new ItemStack(Material.PLAYER_HEAD, 1); SkullMeta headmeta = (SkullMeta) head.getItemMeta(); assert headmeta != null; - Player p = Bukkit.getPlayerExact(player); - if (p != null) { - headmeta.setOwningPlayer(p); - } else { - headmeta.setOwner(player); - } + headmeta.setOwningPlayer(Bukkit.getOfflinePlayer(player)); headmeta.setDisplayName(player); head.setItemMeta(headmeta); return head; From f4e77fb6fc0ff2d9187668f8912b5c863a0f14c7 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Thu, 29 Apr 2021 12:28:55 +0200 Subject: [PATCH 09/36] Speedy UUID Lookup --- .../steamwar/authlib/AuthlibInjector_15.java | 33 ++++++++++ .../de/steamwar/authlib/AuthlibInjector.java | 46 ++++++++++++++ .../SteamwarGameProfileRepository.java | 61 +++++++++++++++++++ .../src/de/steamwar/core/Core.java | 2 + 4 files changed, 142 insertions(+) create mode 100644 SpigotCore_15/src/de/steamwar/authlib/AuthlibInjector_15.java create mode 100644 SpigotCore_Main/src/de/steamwar/authlib/AuthlibInjector.java create mode 100644 SpigotCore_Main/src/de/steamwar/authlib/SteamwarGameProfileRepository.java diff --git a/SpigotCore_15/src/de/steamwar/authlib/AuthlibInjector_15.java b/SpigotCore_15/src/de/steamwar/authlib/AuthlibInjector_15.java new file mode 100644 index 0000000..9864a31 --- /dev/null +++ b/SpigotCore_15/src/de/steamwar/authlib/AuthlibInjector_15.java @@ -0,0 +1,33 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.authlib; + +import net.minecraft.server.v1_15_R1.MinecraftServer; + +public class AuthlibInjector_15 { + + static Class getMinecraftClass() { + return MinecraftServer.class; + } + + static Object getMinecraftServerInstance() { + return MinecraftServer.getServer(); + } +} diff --git a/SpigotCore_Main/src/de/steamwar/authlib/AuthlibInjector.java b/SpigotCore_Main/src/de/steamwar/authlib/AuthlibInjector.java new file mode 100644 index 0000000..b96f71c --- /dev/null +++ b/SpigotCore_Main/src/de/steamwar/authlib/AuthlibInjector.java @@ -0,0 +1,46 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.authlib; + +import com.mojang.authlib.yggdrasil.YggdrasilGameProfileRepository; +import de.steamwar.core.Core; +import de.steamwar.core.VersionedCallable; + +import java.lang.reflect.Field; + +public class AuthlibInjector { + + public static void inject() { + if(Core.getVersion() < 15) { + return; + } + try { + Class minecraftServerClass = VersionedCallable.call(new VersionedCallable<>(() -> AuthlibInjector_15.getMinecraftClass(), 15)); + Field repo = minecraftServerClass.getDeclaredField("gameProfileRepository"); + repo.setAccessible(true); + Object instance = VersionedCallable.call(new VersionedCallable<>(() -> AuthlibInjector_15.getMinecraftServerInstance(), 15)); + repo.set(instance, new SteamwarGameProfileRepository((YggdrasilGameProfileRepository) repo.get(instance))); + } catch (NoSuchFieldException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + } +} diff --git a/SpigotCore_Main/src/de/steamwar/authlib/SteamwarGameProfileRepository.java b/SpigotCore_Main/src/de/steamwar/authlib/SteamwarGameProfileRepository.java new file mode 100644 index 0000000..20bcc9c --- /dev/null +++ b/SpigotCore_Main/src/de/steamwar/authlib/SteamwarGameProfileRepository.java @@ -0,0 +1,61 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.authlib; + +import com.mojang.authlib.Agent; +import com.mojang.authlib.GameProfile; +import com.mojang.authlib.GameProfileRepository; +import com.mojang.authlib.ProfileLookupCallback; +import com.mojang.authlib.yggdrasil.YggdrasilGameProfileRepository; +import de.steamwar.sql.SteamwarUser; + +import java.util.ArrayList; +import java.util.List; + +public class SteamwarGameProfileRepository implements GameProfileRepository { + + private final YggdrasilGameProfileRepository fallback; + + public SteamwarGameProfileRepository(YggdrasilGameProfileRepository repository) { + fallback = repository; + } + + @Override + public void findProfilesByNames(String[] strings, Agent agent, ProfileLookupCallback profileLookupCallback) { + System.out.println("Call!!"); + if(agent == Agent.SCROLLS) { + fallback.findProfilesByNames(strings, agent, profileLookupCallback); + } else { + List unknownNames = new ArrayList<>(); + for (String name:strings) { + SteamwarUser user = SteamwarUser.get(name); + if(user == null) { + unknownNames.add(name); + continue; + } + + profileLookupCallback.onProfileLookupSucceeded(new GameProfile(user.getUUID(), user.getUserName())); + } + if(!unknownNames.isEmpty()) { + fallback.findProfilesByNames(unknownNames.toArray(new String[0]), agent, profileLookupCallback); + } + } + } +} diff --git a/SpigotCore_Main/src/de/steamwar/core/Core.java b/SpigotCore_Main/src/de/steamwar/core/Core.java index d9c59df..62f8849 100644 --- a/SpigotCore_Main/src/de/steamwar/core/Core.java +++ b/SpigotCore_Main/src/de/steamwar/core/Core.java @@ -19,6 +19,7 @@ package de.steamwar.core; +import de.steamwar.authlib.AuthlibInjector; import de.steamwar.comms.BungeeReceiver; import de.steamwar.core.events.ChattingEvent; import de.steamwar.core.events.ChunkListener; @@ -64,6 +65,7 @@ public class Core extends JavaPlugin{ ErrorLogger.init(); getServer().getMessenger().registerIncomingPluginChannel(this, "sw:bridge", new BungeeReceiver()); getServer().getMessenger().registerOutgoingPluginChannel(this, "sw:bridge"); + AuthlibInjector.inject(); } @Override From c41a7d40404efe0d7b587ae42ad6082c8f5da00f Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Thu, 29 Apr 2021 12:30:09 +0200 Subject: [PATCH 10/36] Remove Debug Message --- .../src/de/steamwar/authlib/SteamwarGameProfileRepository.java | 1 - 1 file changed, 1 deletion(-) diff --git a/SpigotCore_Main/src/de/steamwar/authlib/SteamwarGameProfileRepository.java b/SpigotCore_Main/src/de/steamwar/authlib/SteamwarGameProfileRepository.java index 20bcc9c..3a4ebae 100644 --- a/SpigotCore_Main/src/de/steamwar/authlib/SteamwarGameProfileRepository.java +++ b/SpigotCore_Main/src/de/steamwar/authlib/SteamwarGameProfileRepository.java @@ -39,7 +39,6 @@ public class SteamwarGameProfileRepository implements GameProfileRepository { @Override public void findProfilesByNames(String[] strings, Agent agent, ProfileLookupCallback profileLookupCallback) { - System.out.println("Call!!"); if(agent == Agent.SCROLLS) { fallback.findProfilesByNames(strings, agent, profileLookupCallback); } else { From 1c3318d5fdb60f021cb8349069999d6d4db720a0 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Thu, 29 Apr 2021 20:16:38 +0200 Subject: [PATCH 11/36] Fix Version --- SpigotCore_Main/src/de/steamwar/authlib/AuthlibInjector.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/SpigotCore_Main/src/de/steamwar/authlib/AuthlibInjector.java b/SpigotCore_Main/src/de/steamwar/authlib/AuthlibInjector.java index b96f71c..dcb6ea2 100644 --- a/SpigotCore_Main/src/de/steamwar/authlib/AuthlibInjector.java +++ b/SpigotCore_Main/src/de/steamwar/authlib/AuthlibInjector.java @@ -28,9 +28,10 @@ import java.lang.reflect.Field; public class AuthlibInjector { public static void inject() { - if(Core.getVersion() < 15) { + if(Core.getVersion() != 15) { return; } + try { Class minecraftServerClass = VersionedCallable.call(new VersionedCallable<>(() -> AuthlibInjector_15.getMinecraftClass(), 15)); Field repo = minecraftServerClass.getDeclaredField("gameProfileRepository"); From 76cdbda4e7259516af99153b6691d18262ed886c Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Thu, 29 Apr 2021 20:17:10 +0200 Subject: [PATCH 12/36] Fix Version --- SpigotCore_Main/src/de/steamwar/authlib/AuthlibInjector.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SpigotCore_Main/src/de/steamwar/authlib/AuthlibInjector.java b/SpigotCore_Main/src/de/steamwar/authlib/AuthlibInjector.java index dcb6ea2..f12bd3d 100644 --- a/SpigotCore_Main/src/de/steamwar/authlib/AuthlibInjector.java +++ b/SpigotCore_Main/src/de/steamwar/authlib/AuthlibInjector.java @@ -28,7 +28,7 @@ import java.lang.reflect.Field; public class AuthlibInjector { public static void inject() { - if(Core.getVersion() != 15) { + if (Core.getVersion() != 15) { return; } From ad05babe45205b26d568933825fd1e16559b4f5c Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 30 Apr 2021 14:57:58 +0200 Subject: [PATCH 13/36] Fix BauweltMemberConfig --- SpigotCore_Main/src/de/steamwar/sql/BauweltMemberConfig.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/sql/BauweltMemberConfig.java b/SpigotCore_Main/src/de/steamwar/sql/BauweltMemberConfig.java index b915d78..3315e48 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/BauweltMemberConfig.java +++ b/SpigotCore_Main/src/de/steamwar/sql/BauweltMemberConfig.java @@ -28,7 +28,7 @@ import java.util.UUID; public final class BauweltMemberConfig { private BauweltMemberConfig() { - throw new IllegalStateException("Utility Class"); + } public static String getPlayerConfig(Player player) { @@ -47,7 +47,7 @@ public final class BauweltMemberConfig { } return config.getString("BauConfig"); } catch (SQLException e) { - return null; + throw new SecurityException(); } } From d239f2cbaa6933885aebf093804f52a8a895f654 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 30 Apr 2021 17:48:02 +0200 Subject: [PATCH 14/36] Fix BauweltMemberConfig --- SpigotCore_Main/src/de/steamwar/sql/BauweltMemberConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SpigotCore_Main/src/de/steamwar/sql/BauweltMemberConfig.java b/SpigotCore_Main/src/de/steamwar/sql/BauweltMemberConfig.java index 3315e48..691cd9e 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/BauweltMemberConfig.java +++ b/SpigotCore_Main/src/de/steamwar/sql/BauweltMemberConfig.java @@ -42,7 +42,7 @@ public final class BauweltMemberConfig { public static String getPlayerConfig(int id) { ResultSet config = SQL.select("SELECT * FROM MemberConfig WHERE UserID = ?", id); try { - if (config == null || !config.next()) { + if (!config.next()) { return null; } return config.getString("BauConfig"); From c62c2990c08b09eb12e30b8e3c0c22b59b1da884 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 30 Apr 2021 17:56:08 +0200 Subject: [PATCH 15/36] Add UserConfig --- .../de/steamwar/sql/BauweltMemberConfig.java | 78 ------------------ .../src/de/steamwar/sql/UserConfig.java | 82 +++++++++++++++++++ 2 files changed, 82 insertions(+), 78 deletions(-) delete mode 100644 SpigotCore_Main/src/de/steamwar/sql/BauweltMemberConfig.java create mode 100644 SpigotCore_Main/src/de/steamwar/sql/UserConfig.java diff --git a/SpigotCore_Main/src/de/steamwar/sql/BauweltMemberConfig.java b/SpigotCore_Main/src/de/steamwar/sql/BauweltMemberConfig.java deleted file mode 100644 index 691cd9e..0000000 --- a/SpigotCore_Main/src/de/steamwar/sql/BauweltMemberConfig.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2020 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.sql; - -import org.bukkit.entity.Player; - -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.UUID; - -public final class BauweltMemberConfig { - - private BauweltMemberConfig() { - - } - - public static String getPlayerConfig(Player player) { - return getPlayerConfig(player.getUniqueId()); - } - - public static String getPlayerConfig(UUID uuid) { - return getPlayerConfig(SteamwarUser.get(uuid).getId()); - } - - public static String getPlayerConfig(int id) { - ResultSet config = SQL.select("SELECT * FROM MemberConfig WHERE UserID = ?", id); - try { - if (!config.next()) { - return null; - } - return config.getString("BauConfig"); - } catch (SQLException e) { - throw new SecurityException(); - } - } - - public static void updatePlayerConfig(Player player, String config) { - updatePlayerConfig(player.getUniqueId(), config); - } - - public static void updatePlayerConfig(UUID uuid, String config) { - updatePlayerConfig(SteamwarUser.get(uuid).getId(), config); - } - - public static void updatePlayerConfig(int id, String config) { - SQL.update("INSERT INTO MemberConfig (UserID, BauConfig) VALUES (?, ?) ON DUPLICATE KEY UPDATE BauConfig = VALUES(BauConfig)", id, config); - } - - public static void removePlayerConfig(Player player) { - removePlayerConfig(player.getUniqueId()); - } - - public static void removePlayerConfig(UUID uuid) { - removePlayerConfig(SteamwarUser.get(uuid).getId()); - } - - public static void removePlayerConfig(int id) { - updatePlayerConfig(id, null); - } - -} diff --git a/SpigotCore_Main/src/de/steamwar/sql/UserConfig.java b/SpigotCore_Main/src/de/steamwar/sql/UserConfig.java new file mode 100644 index 0000000..df199ed --- /dev/null +++ b/SpigotCore_Main/src/de/steamwar/sql/UserConfig.java @@ -0,0 +1,82 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.sql; + +import org.bukkit.entity.Player; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.UUID; + +public class UserConfig { + + private UserConfig() { + + } + + public static String getConfig(Player player, String configType) { + return getConfig(player.getUniqueId(), configType); + } + + public static String getConfig(UUID player, String configType) { + return getConfig(SteamwarUser.get(player).getId(), configType); + } + + public static String getConfig(int player, String configType) { + ResultSet config = SQL.select("SELECT * FROM UserConfig WHERE User = ? AND Config = ?", player, configType); + try { + if (!config.next()) { + return null; + } + return config.getString("Value"); + } catch (SQLException e) { + throw new SecurityException(); + } + } + + public static void updatePlayerConfig(Player player, String configType, String config) { + updatePlayerConfig(player.getUniqueId(), configType, config); + } + + public static void updatePlayerConfig(UUID uuid, String configType, String config) { + updatePlayerConfig(SteamwarUser.get(uuid).getId(), configType, config); + } + + public static void updatePlayerConfig(int id, String configType, String config) { + if (config == null) { + removePlayerConfig(id, configType); + return; + } + SQL.update("INSERT INTO UserConfig (User, Config, Value) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE Value = VALUES(Value)", id, configType, config); + } + + public static void removePlayerConfig(Player player, String configType) { + removePlayerConfig(player.getUniqueId(), configType); + } + + public static void removePlayerConfig(UUID uuid, String configType) { + removePlayerConfig(SteamwarUser.get(uuid).getId(), configType); + } + + public static void removePlayerConfig(int id, String configType) { + SQL.update("DELETE FROM UserConfig WHERE User = ? AND Config = ?", id, configType); + } + +} From 8142224f6757bbe9aae927df9a32562e473c1ca3 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 3 May 2021 18:01:00 +0200 Subject: [PATCH 16/36] Add SWCommand.Register.Registeres --- .../src/de/steamwar/command/SWCommand.java | 15 ++++++++++++--- .../src/de/steamwar/command/SWCommandUtils.java | 4 ++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/command/SWCommand.java b/SpigotCore_Main/src/de/steamwar/command/SWCommand.java index ae31780..60bda46 100644 --- a/SpigotCore_Main/src/de/steamwar/command/SWCommand.java +++ b/SpigotCore_Main/src/de/steamwar/command/SWCommand.java @@ -153,8 +153,8 @@ public abstract class SWCommand { } private void add(Class annotation, Method method, IntPredicate parameterTester, boolean firstParameter, Class returnType, BiConsumer consumer) { - T anno = SWCommandUtils.getAnnotation(method, annotation); - if (anno == null) { + T[] anno = SWCommandUtils.getAnnotation(method, annotation); + if (anno == null || anno.length == 0) { return; } @@ -171,7 +171,9 @@ public abstract class SWCommand { Bukkit.getLogger().log(Level.WARNING, "The method '" + method.toString() + "' is lacking the desired return type '" + returnType.getTypeName() + "'"); return; } - consumer.accept(anno, parameters); + for (T a : anno) { + consumer.accept(a, parameters); + } } private void addMapper(Class annotation, Method method, IntPredicate parameterTester, boolean firstParameter, Class returnType, BiConsumer> consumer) { @@ -200,10 +202,17 @@ public abstract class SWCommand { @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.METHOD}) + @Repeatable(Register.Registeres.class) protected @interface Register { String[] value() default {}; boolean help() default false; + + @Retention(RetentionPolicy.RUNTIME) + @Target({ElementType.METHOD}) + @interface Registeres { + Register[] value(); + } } @Retention(RetentionPolicy.RUNTIME) diff --git a/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java b/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java index 0d09c7f..e6e281c 100644 --- a/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java +++ b/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java @@ -188,8 +188,8 @@ public class SWCommandUtils { }; } - static T getAnnotation(Method method, Class annotation) { + static T[] getAnnotation(Method method, Class annotation) { if (method.getAnnotations().length != 1) return null; - return method.getAnnotation(annotation); + return method.getDeclaredAnnotationsByType(annotation); } } From 9dad22742e26c4be501fe07cf8a11838d8a7e2bf Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 5 May 2021 07:58:23 +0200 Subject: [PATCH 17/36] Fix SWCommand registering on new instance Add SWCommandUtils long mapper --- SpigotCore_Main/src/de/steamwar/command/SWCommand.java | 1 + SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java | 1 + 2 files changed, 2 insertions(+) diff --git a/SpigotCore_Main/src/de/steamwar/command/SWCommand.java b/SpigotCore_Main/src/de/steamwar/command/SWCommand.java index 60bda46..44865c9 100644 --- a/SpigotCore_Main/src/de/steamwar/command/SWCommand.java +++ b/SpigotCore_Main/src/de/steamwar/command/SWCommand.java @@ -77,6 +77,7 @@ public abstract class SWCommand { return strings; } }; + unregister(); register(); for (Method method : getClass().getDeclaredMethods()) { diff --git a/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java b/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java index e6e281c..ed36ad8 100644 --- a/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java +++ b/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java @@ -61,6 +61,7 @@ public class SWCommandUtils { addMapper(float.class, Float.class, createMapper(numberMapper(Float::parseFloat), numberCompleter(Float::parseFloat))); addMapper(double.class, Double.class, createMapper(numberMapper(Double::parseDouble), numberCompleter(Double::parseDouble))); addMapper(int.class, Integer.class, createMapper(numberMapper(Integer::parseInt), numberCompleter(Integer::parseInt))); + addMapper(long.class, Long.class, createMapper(numberMapper(Long::parseLong), numberCompleter(Long::parseLong))); MAPPER_FUNCTIONS.put(String.class.getTypeName(), createMapper(s -> s, Collections::singletonList)); MAPPER_FUNCTIONS.put(Player.class.getTypeName(), createMapper(Bukkit::getPlayer, s -> Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList()))); MAPPER_FUNCTIONS.put(GameMode.class.getTypeName(), createMapper(s -> { From 84ce642bc66c886f71066d957c820695dd8dba13 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 5 May 2021 08:25:00 +0200 Subject: [PATCH 18/36] Simplify CommandParseException as it is a code-flow Exception --- .../steamwar/command/CommandParseException.java | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/command/CommandParseException.java b/SpigotCore_Main/src/de/steamwar/command/CommandParseException.java index b47cace..21e68bb 100644 --- a/SpigotCore_Main/src/de/steamwar/command/CommandParseException.java +++ b/SpigotCore_Main/src/de/steamwar/command/CommandParseException.java @@ -23,20 +23,4 @@ public class CommandParseException extends Exception { public CommandParseException() { } - - public CommandParseException(String message) { - super(message); - } - - public CommandParseException(String message, Throwable cause) { - super(message, cause); - } - - public CommandParseException(Throwable cause) { - super(cause); - } - - public CommandParseException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { - super(message, cause, enableSuppression, writableStackTrace); - } } From d48175234ad70e76b9c78ca130a5193f75af73de Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 5 May 2021 08:45:15 +0200 Subject: [PATCH 19/36] Simplify SubCommand and SWCommand --- .../src/de/steamwar/command/SWCommand.java | 2 +- .../src/de/steamwar/command/SubCommand.java | 24 +++++++++---------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/command/SWCommand.java b/SpigotCore_Main/src/de/steamwar/command/SWCommand.java index 44865c9..d20237b 100644 --- a/SpigotCore_Main/src/de/steamwar/command/SWCommand.java +++ b/SpigotCore_Main/src/de/steamwar/command/SWCommand.java @@ -109,7 +109,7 @@ public abstract class SWCommand { Bukkit.getLogger().log(Level.WARNING, "The method '" + method.toString() + "' is lacking the varArgs parameters of type '" + String.class.getTypeName() + "' as last Argument"); return; } - commandHelpSet.add(new SubCommand(this, method, anno.value())); + commandHelpSet.add(new SubCommand(this, method, anno.value(), new HashMap<>())); }); } for (Method method : getClass().getDeclaredMethods()) { diff --git a/SpigotCore_Main/src/de/steamwar/command/SubCommand.java b/SpigotCore_Main/src/de/steamwar/command/SubCommand.java index 86cfdc7..ef75877 100644 --- a/SpigotCore_Main/src/de/steamwar/command/SubCommand.java +++ b/SpigotCore_Main/src/de/steamwar/command/SubCommand.java @@ -28,6 +28,8 @@ import java.util.*; import java.util.function.Function; import java.util.function.Predicate; +import static de.steamwar.command.SWCommandUtils.*; + class SubCommand { private SWCommand swCommand; @@ -38,10 +40,6 @@ class SubCommand { private Function commandSenderFunction; Class varArgType = null; - public SubCommand(SWCommand swCommand, Method method, String[] subCommand) { - this(swCommand, method, subCommand, new HashMap<>()); - } - public SubCommand(SWCommand swCommand, Method method, String[] subCommand, Map> localTypeMapper) { this.swCommand = swCommand; this.method = method; @@ -61,13 +59,13 @@ class SubCommand { } SWCommand.Mapper mapper = parameter.getAnnotation(SWCommand.Mapper.class); - if (clazz.isEnum() && mapper == null && !SWCommandUtils.MAPPER_FUNCTIONS.containsKey(clazz.getTypeName()) && !localTypeMapper.containsKey(clazz.getTypeName())) { + if (clazz.isEnum() && mapper == null && !MAPPER_FUNCTIONS.containsKey(clazz.getTypeName()) && !localTypeMapper.containsKey(clazz.getTypeName())) { Class> enumClass = (Class>) clazz; List tabCompletes = new ArrayList<>(); for (Enum enumConstant : enumClass.getEnumConstants()) { tabCompletes.add(enumConstant.name().toLowerCase()); } - arguments[i - 1] = SWCommandUtils.createMapper(s -> SWCommandUtils.ENUM_MAPPER.apply(enumClass, s), s -> tabCompletes); + arguments[i - 1] = SWCommandUtils.createMapper(s -> ENUM_MAPPER.apply(enumClass, s), s -> tabCompletes); continue; } @@ -75,11 +73,9 @@ class SubCommand { if (mapper != null) { name = mapper.value(); } - if (localTypeMapper.containsKey(name)) { - arguments[i - 1] = localTypeMapper.getOrDefault(name, SWCommandUtils.ERROR_FUNCTION); - } else { - arguments[i - 1] = SWCommandUtils.MAPPER_FUNCTIONS.getOrDefault(name, SWCommandUtils.ERROR_FUNCTION); - } + arguments[i - 1] = localTypeMapper.containsKey(name) + ? localTypeMapper.get(name) + : MAPPER_FUNCTIONS.getOrDefault(name, ERROR_FUNCTION); } } @@ -120,7 +116,8 @@ class SubCommand { } for (TypeMapper argument : arguments) { String s = argsList.remove(0); - if (argsList.isEmpty()) return argument.tabCompletes(commandSender, Arrays.copyOf(args, args.length - 1), s); + if (argsList.isEmpty()) + return argument.tabCompletes(commandSender, Arrays.copyOf(args, args.length - 1), s); try { if (argument.map(commandSender, Arrays.copyOf(args, index), s) == null) { return null; @@ -133,7 +130,8 @@ class SubCommand { if (varArgType != null && !argsList.isEmpty()) { while (!argsList.isEmpty()) { String s = argsList.remove(0); - if (argsList.isEmpty()) return arguments[arguments.length - 1].tabCompletes(commandSender, Arrays.copyOf(args, args.length - 1), s); + if (argsList.isEmpty()) + return arguments[arguments.length - 1].tabCompletes(commandSender, Arrays.copyOf(args, args.length - 1), s); try { if (arguments[arguments.length - 1].map(commandSender, Arrays.copyOf(args, index), s) == null) { return null; From 95fb899d1408459d7b8ae8b8e5fba84d1d0cf665 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 5 May 2021 08:47:01 +0200 Subject: [PATCH 20/36] Simplify SubCommand --- SpigotCore_Main/src/de/steamwar/command/SubCommand.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/command/SubCommand.java b/SpigotCore_Main/src/de/steamwar/command/SubCommand.java index ef75877..d53b4a6 100644 --- a/SpigotCore_Main/src/de/steamwar/command/SubCommand.java +++ b/SpigotCore_Main/src/de/steamwar/command/SubCommand.java @@ -116,8 +116,9 @@ class SubCommand { } for (TypeMapper argument : arguments) { String s = argsList.remove(0); - if (argsList.isEmpty()) + if (argsList.isEmpty()) { return argument.tabCompletes(commandSender, Arrays.copyOf(args, args.length - 1), s); + } try { if (argument.map(commandSender, Arrays.copyOf(args, index), s) == null) { return null; @@ -130,8 +131,9 @@ class SubCommand { if (varArgType != null && !argsList.isEmpty()) { while (!argsList.isEmpty()) { String s = argsList.remove(0); - if (argsList.isEmpty()) + if (argsList.isEmpty()) { return arguments[arguments.length - 1].tabCompletes(commandSender, Arrays.copyOf(args, args.length - 1), s); + } try { if (arguments[arguments.length - 1].map(commandSender, Arrays.copyOf(args, index), s) == null) { return null; From 2adab560c24b1f28e53b50db44a2769cf0b706bd Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 5 May 2021 08:54:24 +0200 Subject: [PATCH 21/36] Simplify SWCommandUtils --- .../de/steamwar/command/SWCommandUtils.java | 49 ++++++++++--------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java b/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java index ed36ad8..04b90fa 100644 --- a/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java +++ b/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java @@ -111,31 +111,34 @@ public class SWCommandUtils { index++; } - if (varArgType != null && index > args.length - 1) { - Object varArgument = Array.newInstance(varArgType, 0); - arguments[arguments.length - 1] = varArgument; - } else { - for (int i = 0; i < parameters.length - (varArgType != null ? 1 : 0); i++) { - arguments[i + 1] = parameters[i].map(commandSender, Arrays.copyOf(args, index), args[index]); - index++; - if (arguments[i + 1] == null) { + int length = 0; + if (varArgType != null) { + length = args.length - parameters.length - subCommand.length + 1; + arguments[arguments.length - 1] = Array.newInstance(varArgType, length); + + if (index > args.length - 1) { + return arguments; + } + } + + for (int i = 0; i < parameters.length - (varArgType != null ? 1 : 0); i++) { + arguments[i + 1] = parameters[i].map(commandSender, Arrays.copyOf(args, index), args[index]); + index++; + if (arguments[i + 1] == null) { + throw new CommandParseException(); + } + } + + if (varArgType != null) { + Object varArgument = arguments[args.length - 1]; + + for (int i = 0; i < length; i++) { + Object value = parameters[parameters.length - 1].map(commandSender, Arrays.copyOf(args, index), args[index]); + if (value == null) { throw new CommandParseException(); } - } - - if (varArgType != null) { - int length = args.length - parameters.length - subCommand.length + 1; - Object varArgument = Array.newInstance(varArgType, length); - arguments[arguments.length - 1] = varArgument; - - for (int i = 0; i < length; i++) { - Object value = parameters[parameters.length - 1].map(commandSender, Arrays.copyOf(args, index), args[index]); - if (value == null) { - throw new CommandParseException(); - } - Array.set(varArgument, i, value); - index++; - } + Array.set(varArgument, i, value); + index++; } } return arguments; From 96b7652324f229a0f64bcfdb2f082b631e2c97a8 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 5 May 2021 08:58:03 +0200 Subject: [PATCH 22/36] Speed up SWCommand registration --- SpigotCore_Main/src/de/steamwar/command/SWCommand.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/command/SWCommand.java b/SpigotCore_Main/src/de/steamwar/command/SWCommand.java index d20237b..e29b8e4 100644 --- a/SpigotCore_Main/src/de/steamwar/command/SWCommand.java +++ b/SpigotCore_Main/src/de/steamwar/command/SWCommand.java @@ -80,7 +80,8 @@ public abstract class SWCommand { unregister(); register(); - for (Method method : getClass().getDeclaredMethods()) { + Method[] methods = getClass().getDeclaredMethods(); + for (Method method : methods) { addMapper(Mapper.class, method, i -> i == 0, false, TypeMapper.class, (anno, typeMapper) -> { if (anno.local()) { localTypeMapper.put(anno.value(), typeMapper); @@ -112,7 +113,7 @@ public abstract class SWCommand { commandHelpSet.add(new SubCommand(this, method, anno.value(), new HashMap<>())); }); } - for (Method method : getClass().getDeclaredMethods()) { + for (Method method : methods) { add(Register.class, method, i -> i > 0, true, null, (anno, parameters) -> { if (anno.help()) { return; From a42188f7a03dc423892eae78b8c85df1cb773c77 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 5 May 2021 09:21:05 +0200 Subject: [PATCH 23/36] Streamify SWCommand --- .../src/de/steamwar/command/SWCommand.java | 80 +++++++------------ 1 file changed, 28 insertions(+), 52 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/command/SWCommand.java b/SpigotCore_Main/src/de/steamwar/command/SWCommand.java index e29b8e4..9c66a2c 100644 --- a/SpigotCore_Main/src/de/steamwar/command/SWCommand.java +++ b/SpigotCore_Main/src/de/steamwar/command/SWCommand.java @@ -30,12 +30,13 @@ import java.util.*; import java.util.function.BiConsumer; import java.util.function.IntPredicate; import java.util.logging.Level; +import java.util.stream.Collectors; public abstract class SWCommand { private final Command command; - private final List commandSet = new ArrayList<>(); - private final List commandHelpSet = new ArrayList<>(); + private final List commandList = new ArrayList<>(); + private final List commandHelpList = new ArrayList<>(); private final Map> localTypeMapper = new HashMap<>(); protected SWCommand(String command) { @@ -46,15 +47,13 @@ public abstract class SWCommand { this.command = new Command(command, "", "/" + command, Arrays.asList(aliases)) { @Override public boolean execute(CommandSender sender, String alias, String[] args) { - for (SubCommand subCommand : commandSet) { - if (subCommand.invoke(sender, args)) { - return false; - } + // if (commandList.stream().filter(s -> s.invoke(sender, args)).findFirst().isEmpty()) return false; + // if (commandHelpList.stream().filter(s -> s.invoke(sender, args)).findFirst().isEmpty()) return false; + for (SubCommand subCommand : commandList) { + if (subCommand.invoke(sender, args)) return false; } - for (SubCommand subCommand : commandHelpSet) { - if (subCommand.invoke(sender, args)) { - return false; - } + for (SubCommand subCommand : commandHelpList) { + if (subCommand.invoke(sender, args)) return false; } return false; } @@ -62,19 +61,15 @@ public abstract class SWCommand { @Override public List tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException { List strings = new ArrayList<>(); - for (SubCommand subCommand : commandSet) { + for (SubCommand subCommand : commandList) { List tabCompletes = subCommand.tabComplete(sender, args); - if (tabCompletes != null) { - strings.addAll(tabCompletes); - } + if (tabCompletes != null) strings.addAll(tabCompletes); } - strings = new ArrayList<>(strings); - for (int i = strings.size() - 1; i >= 0; i--) { - if (!strings.get(i).toLowerCase().startsWith(args[args.length - 1].toLowerCase())) { - strings.remove(i); - } - } - return strings; + return strings.stream() + .filter(s -> !s.isEmpty()) + .filter(s -> !s.isBlank()) + .filter(s -> s.toLowerCase().startsWith(args[args.length - 1].toLowerCase())) + .collect(Collectors.toList()); } }; unregister(); @@ -83,23 +78,13 @@ public abstract class SWCommand { Method[] methods = getClass().getDeclaredMethods(); for (Method method : methods) { addMapper(Mapper.class, method, i -> i == 0, false, TypeMapper.class, (anno, typeMapper) -> { - if (anno.local()) { - localTypeMapper.put(anno.value(), typeMapper); - } else { - SWCommandUtils.addMapper(anno.value(), typeMapper); - } + (anno.local() ? localTypeMapper : SWCommandUtils.MAPPER_FUNCTIONS).putIfAbsent(anno.value(), typeMapper); }); addMapper(ClassMapper.class, method, i -> i == 0, false, TypeMapper.class, (anno, typeMapper) -> { - if (anno.local()) { - localTypeMapper.put(anno.value().getTypeName(), typeMapper); - } else { - SWCommandUtils.addMapper(anno.value().getTypeName(), typeMapper); - } + (anno.local() ? localTypeMapper : SWCommandUtils.MAPPER_FUNCTIONS).putIfAbsent(anno.value().getTypeName(), typeMapper); }); add(Register.class, method, i -> i > 0, true, null, (anno, parameters) -> { - if (!anno.help()) { - return; - } + if (!anno.help()) return; if (parameters.length != 2) { Bukkit.getLogger().log(Level.WARNING, "The method '" + method.toString() + "' is lacking parameters or has too many"); } @@ -110,14 +95,12 @@ public abstract class SWCommand { Bukkit.getLogger().log(Level.WARNING, "The method '" + method.toString() + "' is lacking the varArgs parameters of type '" + String.class.getTypeName() + "' as last Argument"); return; } - commandHelpSet.add(new SubCommand(this, method, anno.value(), new HashMap<>())); + commandHelpList.add(new SubCommand(this, method, anno.value(), new HashMap<>())); }); } for (Method method : methods) { add(Register.class, method, i -> i > 0, true, null, (anno, parameters) -> { - if (anno.help()) { - return; - } + if (anno.help()) return; for (int i = 1; i < parameters.length; i++) { Parameter parameter = parameters[i]; Class clazz = parameter.getType(); @@ -137,10 +120,10 @@ public abstract class SWCommand { return; } } - commandSet.add(new SubCommand(this, method, anno.value(), localTypeMapper)); + commandList.add(new SubCommand(this, method, anno.value(), localTypeMapper)); }); - this.commandSet.sort((o1, o2) -> { + this.commandList.sort((o1, o2) -> { int compare = Integer.compare(-o1.subCommand.length, -o2.subCommand.length); if (compare != 0) { return compare; @@ -150,15 +133,13 @@ public abstract class SWCommand { return Integer.compare(i1, i2); } }); - commandHelpSet.sort(Comparator.comparingInt(o -> -o.subCommand.length)); + commandHelpList.sort(Comparator.comparingInt(o -> -o.subCommand.length)); } } private void add(Class annotation, Method method, IntPredicate parameterTester, boolean firstParameter, Class returnType, BiConsumer consumer) { T[] anno = SWCommandUtils.getAnnotation(method, annotation); - if (anno == null || anno.length == 0) { - return; - } + if (anno == null || anno.length == 0) return; Parameter[] parameters = method.getParameters(); if (!parameterTester.test(parameters.length)) { @@ -173,17 +154,14 @@ public abstract class SWCommand { Bukkit.getLogger().log(Level.WARNING, "The method '" + method.toString() + "' is lacking the desired return type '" + returnType.getTypeName() + "'"); return; } - for (T a : anno) { - consumer.accept(a, parameters); - } + Arrays.stream(anno).forEach(t -> consumer.accept(t, parameters)); } private void addMapper(Class annotation, Method method, IntPredicate parameterTester, boolean firstParameter, Class returnType, BiConsumer> consumer) { add(annotation, method, parameterTester, firstParameter, returnType, (anno, parameters) -> { try { method.setAccessible(true); - Object object = method.invoke(this); - consumer.accept(anno, (TypeMapper) object); + consumer.accept(anno, (TypeMapper) method.invoke(this)); } catch (Exception e) { throw new SecurityException(e.getMessage(), e); } @@ -192,9 +170,7 @@ public abstract class SWCommand { public void unregister() { SWCommandUtils.knownCommandMap.remove(command.getName()); - for (String alias : command.getAliases()) { - SWCommandUtils.knownCommandMap.remove(alias); - } + command.getAliases().forEach(SWCommandUtils.knownCommandMap::remove); command.unregister(SWCommandUtils.commandMap); } From 06fb4bbc1ae81f07c6f6456b687c3a87f0ae1448 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 5 May 2021 09:35:51 +0200 Subject: [PATCH 24/36] Streamify SWCommand --- SpigotCore_Main/src/de/steamwar/command/SWCommand.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/command/SWCommand.java b/SpigotCore_Main/src/de/steamwar/command/SWCommand.java index 9c66a2c..6ec6fb1 100644 --- a/SpigotCore_Main/src/de/steamwar/command/SWCommand.java +++ b/SpigotCore_Main/src/de/steamwar/command/SWCommand.java @@ -60,12 +60,10 @@ public abstract class SWCommand { @Override public List tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException { - List strings = new ArrayList<>(); - for (SubCommand subCommand : commandList) { - List tabCompletes = subCommand.tabComplete(sender, args); - if (tabCompletes != null) strings.addAll(tabCompletes); - } - return strings.stream() + return commandList.stream() + .map(s -> s.tabComplete(sender, args)) + .filter(Objects::nonNull) + .flatMap(Collection::stream) .filter(s -> !s.isEmpty()) .filter(s -> !s.isBlank()) .filter(s -> s.toLowerCase().startsWith(args[args.length - 1].toLowerCase())) From 259d6fef99b4e6c063aaada7ddd157d7969a9bf5 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 5 May 2021 09:56:30 +0200 Subject: [PATCH 25/36] Streamify SWCommand --- .../src/de/steamwar/command/SWCommand.java | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/command/SWCommand.java b/SpigotCore_Main/src/de/steamwar/command/SWCommand.java index 6ec6fb1..5e73a02 100644 --- a/SpigotCore_Main/src/de/steamwar/command/SWCommand.java +++ b/SpigotCore_Main/src/de/steamwar/command/SWCommand.java @@ -47,8 +47,8 @@ public abstract class SWCommand { this.command = new Command(command, "", "/" + command, Arrays.asList(aliases)) { @Override public boolean execute(CommandSender sender, String alias, String[] args) { - // if (commandList.stream().filter(s -> s.invoke(sender, args)).findFirst().isEmpty()) return false; - // if (commandHelpList.stream().filter(s -> s.invoke(sender, args)).findFirst().isEmpty()) return false; + // if (commandList.stream().filter(s -> s.invoke(sender, args)).findFirst().isPresent()) return false; + // if (commandHelpList.stream().filter(s -> s.invoke(sender, args)).findFirst().isPresent()) return false; for (SubCommand subCommand : commandList) { if (subCommand.invoke(sender, args)) return false; } @@ -109,10 +109,7 @@ public abstract class SWCommand { if (clazz.isEnum() && mapper == null && !SWCommandUtils.MAPPER_FUNCTIONS.containsKey(clazz.getTypeName())) { continue; } - String name = clazz.getTypeName(); - if (mapper != null) { - name = mapper.value(); - } + String name = mapper != null ? mapper.value() : clazz.getTypeName(); if (!SWCommandUtils.MAPPER_FUNCTIONS.containsKey(name) && !localTypeMapper.containsKey(name)) { Bukkit.getLogger().log(Level.WARNING, "The parameter '" + parameter.toString() + "' is using an unsupported Mapper of type '" + name + "'"); return; @@ -126,9 +123,8 @@ public abstract class SWCommand { if (compare != 0) { return compare; } else { - int i1 = o1.varArgType != null ? Integer.MAX_VALUE : o1.arguments.length; - int i2 = o2.varArgType != null ? Integer.MAX_VALUE : o2.arguments.length; - return Integer.compare(i1, i2); + return Integer.compare(o1.varArgType != null ? Integer.MAX_VALUE : o1.arguments.length, + o2.varArgType != null ? Integer.MAX_VALUE : o2.arguments.length); } }); commandHelpList.sort(Comparator.comparingInt(o -> -o.subCommand.length)); From ee9f9d40ceaebaeec9c97f310955d2ede28761fa Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 5 May 2021 09:58:08 +0200 Subject: [PATCH 26/36] Optimize SWCommand --- SpigotCore_Main/src/de/steamwar/command/SWCommand.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/SpigotCore_Main/src/de/steamwar/command/SWCommand.java b/SpigotCore_Main/src/de/steamwar/command/SWCommand.java index 5e73a02..20f1d5c 100644 --- a/SpigotCore_Main/src/de/steamwar/command/SWCommand.java +++ b/SpigotCore_Main/src/de/steamwar/command/SWCommand.java @@ -60,13 +60,14 @@ public abstract class SWCommand { @Override public List tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException { + String string = args[args.length - 1].toLowerCase(); return commandList.stream() .map(s -> s.tabComplete(sender, args)) .filter(Objects::nonNull) .flatMap(Collection::stream) .filter(s -> !s.isEmpty()) .filter(s -> !s.isBlank()) - .filter(s -> s.toLowerCase().startsWith(args[args.length - 1].toLowerCase())) + .filter(s -> s.toLowerCase().startsWith(string)) .collect(Collectors.toList()); } }; From 37d308346ef917c0e495a84a326d5a3d4b644ed7 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 5 May 2021 10:02:07 +0200 Subject: [PATCH 27/36] Optimize SWCommand --- SpigotCore_Main/src/de/steamwar/command/SWCommand.java | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/command/SWCommand.java b/SpigotCore_Main/src/de/steamwar/command/SWCommand.java index 20f1d5c..3b6245d 100644 --- a/SpigotCore_Main/src/de/steamwar/command/SWCommand.java +++ b/SpigotCore_Main/src/de/steamwar/command/SWCommand.java @@ -47,14 +47,8 @@ public abstract class SWCommand { this.command = new Command(command, "", "/" + command, Arrays.asList(aliases)) { @Override public boolean execute(CommandSender sender, String alias, String[] args) { - // if (commandList.stream().filter(s -> s.invoke(sender, args)).findFirst().isPresent()) return false; - // if (commandHelpList.stream().filter(s -> s.invoke(sender, args)).findFirst().isPresent()) return false; - for (SubCommand subCommand : commandList) { - if (subCommand.invoke(sender, args)) return false; - } - for (SubCommand subCommand : commandHelpList) { - if (subCommand.invoke(sender, args)) return false; - } + if (commandList.stream().anyMatch(s -> s.invoke(sender, args))) return false; + commandHelpList.stream().anyMatch(s -> s.invoke(sender, args)); return false; } From 218641b21dea2e30dbb5b7298be6f9a74ba16405 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 5 May 2021 10:11:02 +0200 Subject: [PATCH 28/36] Optimize SWCommandUtils.numberCompleter --- .../src/de/steamwar/command/SWCommandUtils.java | 11 +++-------- .../src/de/steamwar/command/SubCommand.java | 2 +- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java b/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java index 04b90fa..e4e6c29 100644 --- a/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java +++ b/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java @@ -182,14 +182,9 @@ public class SWCommandUtils { } private static Function> numberCompleter(Function mapper) { - return s -> { - try { - mapper.apply(s); - return Collections.singletonList(s); - } catch (Exception e) { - return Collections.emptyList(); - } - }; + return s -> numberMapper(mapper).apply(s) != null + ? Collections.singletonList(s) + : Collections.emptyList(); } static T[] getAnnotation(Method method, Class annotation) { diff --git a/SpigotCore_Main/src/de/steamwar/command/SubCommand.java b/SpigotCore_Main/src/de/steamwar/command/SubCommand.java index d53b4a6..15dad9a 100644 --- a/SpigotCore_Main/src/de/steamwar/command/SubCommand.java +++ b/SpigotCore_Main/src/de/steamwar/command/SubCommand.java @@ -40,7 +40,7 @@ class SubCommand { private Function commandSenderFunction; Class varArgType = null; - public SubCommand(SWCommand swCommand, Method method, String[] subCommand, Map> localTypeMapper) { + SubCommand(SWCommand swCommand, Method method, String[] subCommand, Map> localTypeMapper) { this.swCommand = swCommand; this.method = method; From a1125ae48f0dbc652b0baab8ee047c4d1675b5fc Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 5 May 2021 10:25:44 +0200 Subject: [PATCH 29/36] Optimize SWCommandUtils.numberCompleter --- .../de/steamwar/command/SWCommandUtils.java | 24 +++++-------------- 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java b/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java index e4e6c29..d4c0cc3 100644 --- a/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java +++ b/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java @@ -50,10 +50,7 @@ public class SWCommandUtils { static final BiFunction>, String, Enum> ENUM_MAPPER = (enumClass, s) -> { Enum[] enums = enumClass.getEnumConstants(); - for (Enum e : enums) { - if (e.name().equalsIgnoreCase(s)) return e; - } - return null; + return Arrays.stream(enums).filter(e -> e.name().equalsIgnoreCase(s)).findFirst().orElse(null); }; static { @@ -105,9 +102,7 @@ public class SWCommandUtils { Object[] arguments = new Object[parameters.length + 1]; int index = 0; while (index < subCommand.length) { - if (!args[index].equalsIgnoreCase(subCommand[index])) { - throw new CommandParseException(); - } + if (!args[index].equalsIgnoreCase(subCommand[index])) throw new CommandParseException(); index++; } @@ -116,17 +111,13 @@ public class SWCommandUtils { length = args.length - parameters.length - subCommand.length + 1; arguments[arguments.length - 1] = Array.newInstance(varArgType, length); - if (index > args.length - 1) { - return arguments; - } + if (index > args.length - 1) return arguments; } for (int i = 0; i < parameters.length - (varArgType != null ? 1 : 0); i++) { arguments[i + 1] = parameters[i].map(commandSender, Arrays.copyOf(args, index), args[index]); index++; - if (arguments[i + 1] == null) { - throw new CommandParseException(); - } + if (arguments[i + 1] == null) throw new CommandParseException(); } if (varArgType != null) { @@ -134,9 +125,7 @@ public class SWCommandUtils { for (int i = 0; i < length; i++) { Object value = parameters[parameters.length - 1].map(commandSender, Arrays.copyOf(args, index), args[index]); - if (value == null) { - throw new CommandParseException(); - } + if (value == null) throw new CommandParseException(); Array.set(varArgument, i, value); index++; } @@ -149,8 +138,7 @@ public class SWCommandUtils { } public static void addMapper(String name, TypeMapper mapper) { - if (MAPPER_FUNCTIONS.containsKey(name)) return; - MAPPER_FUNCTIONS.put(name, mapper); + MAPPER_FUNCTIONS.putIfAbsent(name, mapper); } public static TypeMapper createMapper(Function mapper, Function> tabCompleter) { From 2fb3f9a01b5d7683ff1ecd758ded43a9d4e483f1 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 5 May 2021 10:28:57 +0200 Subject: [PATCH 30/36] Optimize SWCommandUtils.numberCompleter --- SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java | 1 - 1 file changed, 1 deletion(-) diff --git a/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java b/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java index d4c0cc3..05f0e94 100644 --- a/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java +++ b/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java @@ -110,7 +110,6 @@ public class SWCommandUtils { if (varArgType != null) { length = args.length - parameters.length - subCommand.length + 1; arguments[arguments.length - 1] = Array.newInstance(varArgType, length); - if (index > args.length - 1) return arguments; } From c07d4fbe5585fb43f9dc1563a253ce3a0380e50c Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 5 May 2021 19:03:21 +0200 Subject: [PATCH 31/36] Add SWCommand.inject --- .../src/de/steamwar/command/SWCommand.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/SpigotCore_Main/src/de/steamwar/command/SWCommand.java b/SpigotCore_Main/src/de/steamwar/command/SWCommand.java index 3b6245d..6c94f7a 100644 --- a/SpigotCore_Main/src/de/steamwar/command/SWCommand.java +++ b/SpigotCore_Main/src/de/steamwar/command/SWCommand.java @@ -22,6 +22,8 @@ package de.steamwar.command; import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; +import org.bukkit.plugin.Plugin; +import org.bukkit.scheduler.BukkitRunnable; import java.lang.annotation.*; import java.lang.reflect.Method; @@ -60,7 +62,6 @@ public abstract class SWCommand { .filter(Objects::nonNull) .flatMap(Collection::stream) .filter(s -> !s.isEmpty()) - .filter(s -> !s.isBlank()) .filter(s -> s.toLowerCase().startsWith(string)) .collect(Collectors.toList()); } @@ -167,6 +168,16 @@ public abstract class SWCommand { SWCommandUtils.commandMap.register("steamwar", this.command); } + public void inject(Plugin plugin) { + new BukkitRunnable() { + @Override + public void run() { + SWCommand.this.unregister(); + SWCommand.this.register(); + } + }.runTask(plugin); + } + @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.METHOD}) @Repeatable(Register.Registeres.class) From 0158f24e3e2422405620351e3090da0fd80d6afc Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 5 May 2021 19:17:39 +0200 Subject: [PATCH 32/36] Fix SWCommandUtils --- SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java b/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java index 05f0e94..e6e0ee4 100644 --- a/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java +++ b/SpigotCore_Main/src/de/steamwar/command/SWCommandUtils.java @@ -120,7 +120,7 @@ public class SWCommandUtils { } if (varArgType != null) { - Object varArgument = arguments[args.length - 1]; + Object varArgument = arguments[arguments.length - 1]; for (int i = 0; i < length; i++) { Object value = parameters[parameters.length - 1].map(commandSender, Arrays.copyOf(args, index), args[index]); From 83cc566558051e3cb3569b9673076fa54cf92b27 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 7 May 2021 09:05:28 +0200 Subject: [PATCH 33/36] Update UserConfig --- .../src/de/steamwar/sql/UserConfig.java | 46 +++++++------------ 1 file changed, 16 insertions(+), 30 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/sql/UserConfig.java b/SpigotCore_Main/src/de/steamwar/sql/UserConfig.java index df199ed..50d8ad3 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/UserConfig.java +++ b/SpigotCore_Main/src/de/steamwar/sql/UserConfig.java @@ -19,8 +19,6 @@ package de.steamwar.sql; -import org.bukkit.entity.Player; - import java.sql.ResultSet; import java.sql.SQLException; import java.util.UUID; @@ -31,52 +29,40 @@ public class UserConfig { } - public static String getConfig(Player player, String configType) { - return getConfig(player.getUniqueId(), configType); + public static String getConfig(UUID player, String config) { + return getConfig(SteamwarUser.get(player).getId(), config); } - public static String getConfig(UUID player, String configType) { - return getConfig(SteamwarUser.get(player).getId(), configType); - } - - public static String getConfig(int player, String configType) { - ResultSet config = SQL.select("SELECT * FROM UserConfig WHERE User = ? AND Config = ?", player, configType); + public static String getConfig(int player, String config) { + ResultSet configResult = SQL.select("SELECT * FROM UserConfig WHERE User = ? AND Config = ?", player, config); try { - if (!config.next()) { + if (!configResult.next()) { return null; } - return config.getString("Value"); + return configResult.getString("Value"); } catch (SQLException e) { throw new SecurityException(); } } - public static void updatePlayerConfig(Player player, String configType, String config) { - updatePlayerConfig(player.getUniqueId(), configType, config); + public static void updatePlayerConfig(UUID uuid, String config, String value) { + updatePlayerConfig(SteamwarUser.get(uuid).getId(), config, value); } - public static void updatePlayerConfig(UUID uuid, String configType, String config) { - updatePlayerConfig(SteamwarUser.get(uuid).getId(), configType, config); - } - - public static void updatePlayerConfig(int id, String configType, String config) { - if (config == null) { - removePlayerConfig(id, configType); + public static void updatePlayerConfig(int id, String config, String value) { + if (value == null) { + removePlayerConfig(id, config); return; } - SQL.update("INSERT INTO UserConfig (User, Config, Value) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE Value = VALUES(Value)", id, configType, config); + SQL.update("INSERT INTO UserConfig (User, Config, Value) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE Value = VALUES(Value)", id, config, value); } - public static void removePlayerConfig(Player player, String configType) { - removePlayerConfig(player.getUniqueId(), configType); + public static void removePlayerConfig(UUID uuid, String config) { + removePlayerConfig(SteamwarUser.get(uuid).getId(), config); } - public static void removePlayerConfig(UUID uuid, String configType) { - removePlayerConfig(SteamwarUser.get(uuid).getId(), configType); - } - - public static void removePlayerConfig(int id, String configType) { - SQL.update("DELETE FROM UserConfig WHERE User = ? AND Config = ?", id, configType); + public static void removePlayerConfig(int id, String config) { + SQL.update("DELETE FROM UserConfig WHERE User = ? AND Config = ?", id, config); } } From 5d9b874d4e56f2845fdf928641a0b2bc760f12a5 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 7 May 2021 09:23:37 +0200 Subject: [PATCH 34/36] Remove SWCommand.inject --- SpigotCore_Main/src/de/steamwar/command/SWCommand.java | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/command/SWCommand.java b/SpigotCore_Main/src/de/steamwar/command/SWCommand.java index 6c94f7a..7167bc7 100644 --- a/SpigotCore_Main/src/de/steamwar/command/SWCommand.java +++ b/SpigotCore_Main/src/de/steamwar/command/SWCommand.java @@ -168,16 +168,6 @@ public abstract class SWCommand { SWCommandUtils.commandMap.register("steamwar", this.command); } - public void inject(Plugin plugin) { - new BukkitRunnable() { - @Override - public void run() { - SWCommand.this.unregister(); - SWCommand.this.register(); - } - }.runTask(plugin); - } - @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.METHOD}) @Repeatable(Register.Registeres.class) From 732ac93b3f84ae12568a107dbd826c0343ab475b Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 7 May 2021 09:43:22 +0200 Subject: [PATCH 35/36] Optimize imports in SWCommand --- SpigotCore_Main/src/de/steamwar/command/SWCommand.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/command/SWCommand.java b/SpigotCore_Main/src/de/steamwar/command/SWCommand.java index 7167bc7..ab72fc5 100644 --- a/SpigotCore_Main/src/de/steamwar/command/SWCommand.java +++ b/SpigotCore_Main/src/de/steamwar/command/SWCommand.java @@ -22,8 +22,6 @@ package de.steamwar.command; import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; -import org.bukkit.plugin.Plugin; -import org.bukkit.scheduler.BukkitRunnable; import java.lang.annotation.*; import java.lang.reflect.Method; From 38155f53457af1c7adb6cc90cbdb7f682a919e9a Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 12 May 2021 20:40:49 +0200 Subject: [PATCH 36/36] Fix UserConfig.getConfig --- SpigotCore_Main/src/de/steamwar/sql/UserConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SpigotCore_Main/src/de/steamwar/sql/UserConfig.java b/SpigotCore_Main/src/de/steamwar/sql/UserConfig.java index df199ed..65581b7 100644 --- a/SpigotCore_Main/src/de/steamwar/sql/UserConfig.java +++ b/SpigotCore_Main/src/de/steamwar/sql/UserConfig.java @@ -47,7 +47,7 @@ public class UserConfig { } return config.getString("Value"); } catch (SQLException e) { - throw new SecurityException(); + throw new SecurityException(e.getMessage(), e); } }