From 46b9239801acebc45bf1364506044213f35d25ce Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 15 Jan 2023 20:39:09 +0100 Subject: [PATCH] Remove deprecated code usage from CommandAPI Signed-off-by: yoyosource --- .../attributescopy/AttributeRemoveCommand.java | 5 +++-- .../features/region/RegionCommand.java | 9 +++++---- .../bausystem/features/region/TNTCommand.java | 5 +++-- .../features/region/TestblockCommand.java | 9 +++------ .../features/simulator/SimulatorCommand.java | 5 +++-- .../slaves/panzern/PanzernCommand.java | 9 +++++---- .../bausystem/features/team/SkinCommand.java | 13 +++++++------ .../features/tracer/TraceCommand.java | 18 +++++++----------- .../features/util/MaterialCommand.java | 5 +++-- .../bausystem/features/util/SkullCommand.java | 5 +++-- .../worldedit/ColorReplaceCommand.java | 5 +++-- .../features/worldedit/TypeReplaceCommand.java | 5 +++-- 12 files changed, 48 insertions(+), 45 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/AttributeRemoveCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/AttributeRemoveCommand.java index 0edd3b73..f9217497 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/AttributeRemoveCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/attributescopy/AttributeRemoveCommand.java @@ -20,6 +20,7 @@ package de.steamwar.bausystem.features.attributescopy; import de.steamwar.bausystem.BauSystem; +import de.steamwar.command.PreviousArguments; import de.steamwar.command.SWCommand; import de.steamwar.command.TypeMapper; import de.steamwar.linkage.Linked; @@ -87,7 +88,7 @@ public class AttributeRemoveCommand extends SWCommand { public TypeMapper attribute() { return new TypeMapper() { @Override - public Collection tabCompletes(CommandSender commandSender, String[] strings, String s) { + public Collection tabCompletes(CommandSender commandSender, PreviousArguments previousArguments, String s) { Player player = (Player) commandSender; ItemStack itemStack = player.getInventory().getItemInMainHand(); ItemMeta itemMeta = itemStack.getItemMeta(); @@ -104,7 +105,7 @@ public class AttributeRemoveCommand extends SWCommand { } @Override - public String map(CommandSender commandSender, String[] previousArguments, String s) { + public String map(CommandSender commandSender, PreviousArguments previousArguments, String s) { return s.replace('_', ' '); } }; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionCommand.java index 4bd0faf4..0288fbae 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionCommand.java @@ -27,6 +27,7 @@ import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.RegionUtils; import de.steamwar.bausystem.region.utils.RegionExtensionType; import de.steamwar.bausystem.region.utils.RegionType; +import de.steamwar.command.PreviousArguments; import de.steamwar.command.SWCommand; import de.steamwar.command.TypeMapper; import de.steamwar.command.TypeValidator; @@ -221,7 +222,7 @@ public class RegionCommand extends SWCommand { private TypeMapper regionTypeMapper() { return new TypeMapper() { @Override - public List tabCompletes(CommandSender commandSender, String[] strings, String s) { + public List tabCompletes(CommandSender commandSender, PreviousArguments previousArguments, String s) { Player p = (Player) commandSender; Region region = Region.getRegion(p.getLocation()); if (region.isGlobal()) { @@ -231,7 +232,7 @@ public class RegionCommand extends SWCommand { } @Override - public String map(CommandSender commandSender, String[] previousArguments, String s) { + public String map(CommandSender commandSender, PreviousArguments previousArguments, String s) { return s.replace('_', ' '); } }; @@ -241,7 +242,7 @@ public class RegionCommand extends SWCommand { private TypeMapper skinTypeMapper() { return new TypeMapper() { @Override - public List tabCompletes(CommandSender commandSender, String[] strings, String s) { + public List tabCompletes(CommandSender commandSender, PreviousArguments previousArguments, String s) { Player p = (Player) commandSender; Region region = Region.getRegion(p.getLocation()); if (region.isGlobal()) { @@ -251,7 +252,7 @@ public class RegionCommand extends SWCommand { } @Override - public String map(CommandSender commandSender, String[] previousArguments, String s) { + public String map(CommandSender commandSender, PreviousArguments previousArguments, String s) { return s.replace('_', ' '); } }; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTCommand.java index a7c11223..f8d6fd40 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TNTCommand.java @@ -26,6 +26,7 @@ import de.steamwar.bausystem.region.RegionUtils; import de.steamwar.bausystem.region.flags.Flag; import de.steamwar.bausystem.region.flags.flagvalues.TNTMode; import de.steamwar.bausystem.region.utils.RegionType; +import de.steamwar.command.PreviousArguments; import de.steamwar.command.SWCommand; import de.steamwar.command.TypeMapper; import de.steamwar.command.TypeValidator; @@ -91,7 +92,7 @@ public class TNTCommand extends SWCommand { return new TypeMapper() { @Override - public List tabCompletes(CommandSender sender, String[] strings, String s) { + public List tabCompletes(CommandSender sender, PreviousArguments previousArguments, String s) { Region region = Region.getRegion(((Player) sender).getLocation()); if (region.hasType(RegionType.TESTBLOCK) && region.hasType(RegionType.BUILD)) { return new ArrayList<>(tntModeMap.keySet()); @@ -101,7 +102,7 @@ public class TNTCommand extends SWCommand { } @Override - public TNTMode map(CommandSender sender, String[] previousArguments, String s) { + public TNTMode map(CommandSender sender, PreviousArguments previousArguments, String s) { Region region = Region.getRegion(((Player) sender).getLocation()); if (region.hasType(RegionType.TESTBLOCK) && region.hasType(RegionType.BUILD)) { return tntModeMap.getOrDefault(s, null); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java index 80a71346..a677e4df 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java @@ -25,10 +25,7 @@ import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.RegionUtils; import de.steamwar.bausystem.region.utils.RegionExtensionType; import de.steamwar.bausystem.region.utils.RegionType; -import de.steamwar.command.SWCommand; -import de.steamwar.command.SWCommandUtils; -import de.steamwar.command.TypeMapper; -import de.steamwar.command.TypeValidator; +import de.steamwar.command.*; import de.steamwar.linkage.Linked; import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SteamwarUser; @@ -129,14 +126,14 @@ public class TestblockCommand extends SWCommand { public TypeMapper nodeWithPublic() { return new TypeMapper() { @Override - public List tabCompletes(CommandSender commandSender, String[] strings, String s) { + public List tabCompletes(CommandSender commandSender, PreviousArguments previousArguments, String s) { List stringList = new ArrayList<>(SchematicNode.getNodeTabcomplete(SteamwarUser.get(((Player) commandSender).getUniqueId()), s)); stringList.addAll(SchematicNode.getNodeTabcomplete(SteamwarUser.get(0), s)); return stringList; } @Override - public SchematicNode map(CommandSender commandSender, String[] previousArguments, String s) { + public SchematicNode map(CommandSender commandSender, PreviousArguments previousArguments, String s) { SchematicNode node = SchematicNode.getNodeFromPath(SteamwarUser.get(((Player) commandSender).getUniqueId()), s); if(node == null) { node = SchematicNode.getNodeFromPath(SteamwarUser.get(0), s); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCommand.java index ae71cd6f..640d0360 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCommand.java @@ -24,6 +24,7 @@ import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.SWUtils; import de.steamwar.bausystem.features.simulator.gui.SimulatorSelectionGUI; import de.steamwar.bausystem.utils.ItemUtils; +import de.steamwar.command.PreviousArguments; import de.steamwar.command.SWCommand; import de.steamwar.command.TypeMapper; import de.steamwar.command.TypeValidator; @@ -114,7 +115,7 @@ public class SimulatorCommand extends SWCommand { public TypeMapper allSimulators() { return new TypeMapper() { @Override - public String map(CommandSender commandSender, String[] previousArguments, String s) { + public String map(CommandSender commandSender, PreviousArguments previousArguments, String s) { if (SimulatorStorage.getSimulatorNames().contains(s)) { return s; } else { @@ -123,7 +124,7 @@ public class SimulatorCommand extends SWCommand { } @Override - public Collection tabCompletes(CommandSender commandSender, String[] strings, String s) { + public Collection tabCompletes(CommandSender commandSender, PreviousArguments previousArguments, String s) { return SimulatorStorage.getSimulatorNames(); } }; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/panzern/PanzernCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/panzern/PanzernCommand.java index ed8ca2d5..3bb2379e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/panzern/PanzernCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/panzern/PanzernCommand.java @@ -24,6 +24,7 @@ import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.SWUtils; import de.steamwar.bausystem.shared.Pair; import de.steamwar.bausystem.utils.WorldEditUtils; +import de.steamwar.command.PreviousArguments; import de.steamwar.command.SWCommand; import de.steamwar.command.TypeMapper; import de.steamwar.command.TypeValidator; @@ -108,12 +109,12 @@ public class PanzernCommand extends SWCommand { } return new TypeMapper() { @Override - public List tabCompletes(CommandSender commandSender, String[] ignored, String s) { + public List tabCompletes(CommandSender commandSender, PreviousArguments previousArguments, String s) { return new ArrayList<>(strings); } @Override - public Material map(CommandSender commandSender, String[] previousArguments, String s) { + public Material map(CommandSender commandSender, PreviousArguments previousArguments, String s) { if (strings.contains(s.toLowerCase())) { return Material.valueOf(s.toUpperCase()); } @@ -135,12 +136,12 @@ public class PanzernCommand extends SWCommand { } return new TypeMapper() { @Override - public List tabCompletes(CommandSender commandSender, String[] ignored, String s) { + public List tabCompletes(CommandSender commandSender, PreviousArguments previousArguments, String s) { return new ArrayList<>(strings); } @Override - public Material map(CommandSender commandSender, String[] previousArguments, String s) { + public Material map(CommandSender commandSender, PreviousArguments previousArguments, String s) { if (strings.contains(s.toLowerCase())) { return Material.valueOf(s.toUpperCase()); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/team/SkinCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/team/SkinCommand.java index e5e56e24..ca88625f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/team/SkinCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/team/SkinCommand.java @@ -24,6 +24,7 @@ import de.steamwar.bausystem.features.team.boundary.BoundaryViewer; import de.steamwar.bausystem.region.Prototype; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.region.utils.RegionType; +import de.steamwar.command.PreviousArguments; import de.steamwar.command.SWCommand; import de.steamwar.command.TypeMapper; import de.steamwar.linkage.Linked; @@ -129,7 +130,7 @@ public class SkinCommand extends SWCommand { public static TypeMapper kurzelMapper() { return new TypeMapper() { @Override - public List tabCompletes(CommandSender commandSender, String[] strings, String s) { + public List tabCompletes(CommandSender commandSender, PreviousArguments previousArguments, String s) { List current = new ArrayList<>(); Prototype.getPrototypes().forEach(p -> { current.add(p.getName().toUpperCase().replace("_", "")); @@ -138,7 +139,7 @@ public class SkinCommand extends SWCommand { } @Override - public String map(CommandSender commandSender, String[] previousArguments, String s) { + public String map(CommandSender commandSender, PreviousArguments previousArguments, String s) { return s; } }; @@ -148,14 +149,14 @@ public class SkinCommand extends SWCommand { public static TypeMapper forceMapper() { return new TypeMapper() { @Override - public List tabCompletes(CommandSender commandSender, String[] strings, String s) { + public List tabCompletes(CommandSender commandSender, PreviousArguments previousArguments, String s) { List current = new ArrayList<>(); current.add("-f"); return current; } @Override - public String map(CommandSender commandSender, String[] previousArguments, String s) { + public String map(CommandSender commandSender, PreviousArguments previousArguments, String s) { if (s.equals("-f")) { return s; } @@ -171,7 +172,7 @@ public class SkinCommand extends SWCommand { public static TypeMapper creatorMapper() { return new TypeMapper() { @Override - public List tabCompletes(CommandSender commandSender, String[] strings, String s) { + public List tabCompletes(CommandSender commandSender, PreviousArguments previousArguments, String s) { List current = new ArrayList<>(); current.add("public"); Bukkit.getOnlinePlayers().forEach(player -> { @@ -181,7 +182,7 @@ public class SkinCommand extends SWCommand { } @Override - public String map(CommandSender commandSender, String[] previousArguments, String s) { + public String map(CommandSender commandSender, PreviousArguments previousArguments, String s) { Set current = new HashSet<>(); current.add("public"); Bukkit.getOnlinePlayers().forEach(player -> { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java index ced48fde..8f6b0017 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java @@ -29,6 +29,7 @@ import de.steamwar.bausystem.features.tracer.show.mode.RawEntityShowMode; import de.steamwar.bausystem.features.tracer.show.mode.TraceEntityShowMode; import de.steamwar.bausystem.region.Region; import de.steamwar.bausystem.shared.ShowMode; +import de.steamwar.command.PreviousArguments; import de.steamwar.command.SWCommand; import de.steamwar.command.TypeMapper; import de.steamwar.command.TypeValidator; @@ -228,22 +229,17 @@ public class TraceCommand extends SWCommand { return new TypeMapper() { @Override - public ShowModeParameterType map(CommandSender commandSender, String[] previousArguments, String s) { + public ShowModeParameterType map(CommandSender commandSender, PreviousArguments previousArguments, String s) { return showModeParameterTypesMap.get(s); } @Override - public List tabCompletes(CommandSender commandSender, String[] strings, String s) { + public List tabCompletes(CommandSender commandSender, PreviousArguments previousArguments, String s) { Set showModeParameterTypeSet = new HashSet<>(); - for (String previousArgument : strings) { - try { - ShowModeType showModeType = ShowModeType.valueOf(previousArgument.toUpperCase()); - showModeParameterTypeSet.addAll(Arrays.asList(showModeType.removedTypes)); - } catch (IllegalArgumentException ignored) { - // Ignored - } - showModeParameterTypeSet.add(showModeParameterTypesMap.get(previousArgument)); - } + Arrays.stream(previousArguments.mappedArgs).filter(ShowModeType.class::isInstance).map(ShowModeType.class::cast).forEach(showModeType -> { + showModeParameterTypeSet.addAll(Arrays.asList(showModeType.removedTypes)); + }); + Arrays.stream(previousArguments.userArgs).map(showModeParameterTypesMap::get).forEach(showModeParameterTypeSet::add); showModeParameterTypeSet.remove(null); Set removed = showModeParameterTypeSet.stream() diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/util/MaterialCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/util/MaterialCommand.java index afded503..e7efd6dd 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/util/MaterialCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/util/MaterialCommand.java @@ -21,6 +21,7 @@ package de.steamwar.bausystem.features.util; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.shared.EnumDisplay; +import de.steamwar.command.PreviousArguments; import de.steamwar.command.SWCommand; import de.steamwar.command.TypeMapper; import de.steamwar.inventory.SWAnvilInv; @@ -162,12 +163,12 @@ public class MaterialCommand extends SWCommand implements Listener { return new TypeMapper() { @Override - public String map(CommandSender commandSender, String[] previousArguments, String s) { + public String map(CommandSender commandSender, PreviousArguments previousArguments, String s) { return s; } @Override - public Collection tabCompletes(CommandSender commandSender, String[] strings, String s) { + public Collection tabCompletes(CommandSender commandSender, PreviousArguments previousArguments, String s) { List tabCompletes = new ArrayList<>(); tabCompletes.addAll(results); tabCompletes.add(s); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/util/SkullCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/util/SkullCommand.java index 8ff194a0..b8cce749 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/util/SkullCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/util/SkullCommand.java @@ -21,6 +21,7 @@ package de.steamwar.bausystem.features.util; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.SWUtils; +import de.steamwar.command.PreviousArguments; import de.steamwar.command.SWCommand; import de.steamwar.command.TypeMapper; import de.steamwar.inventory.SWItem; @@ -55,13 +56,13 @@ public class SkullCommand extends SWCommand { public TypeMapper typeMapper() { return new TypeMapper() { @Override - public String map(CommandSender commandSender, String[] previousArguments, String s) { + public String map(CommandSender commandSender, PreviousArguments previousArguments, String s) { if (s.endsWith("⍇")) return null; return s; } @Override - public List tabCompletes(CommandSender commandSender, String[] strings, String s) { + public List tabCompletes(CommandSender commandSender, PreviousArguments previousArguments, String s) { return Bukkit.getOnlinePlayers().stream().map(Player::getName).filter(s1 -> !s1.endsWith("⍇")).collect(Collectors.toList()); } }; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/ColorReplaceCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/ColorReplaceCommand.java index 00e0035c..13439c0e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/ColorReplaceCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/ColorReplaceCommand.java @@ -30,6 +30,7 @@ import de.steamwar.bausystem.features.worldedit.utils.SpecialReplace; import de.steamwar.bausystem.region.Color; import de.steamwar.bausystem.shared.Pair; import de.steamwar.bausystem.utils.WorldEditUtils; +import de.steamwar.command.PreviousArguments; import de.steamwar.command.SWCommand; import de.steamwar.command.TypeMapper; import de.steamwar.linkage.Linked; @@ -86,7 +87,7 @@ public class ColorReplaceCommand extends SWCommand { public TypeMapper> typeMapper() { return new TypeMapper>() { @Override - public Pair map(CommandSender commandSender, String[] previousArguments, String s) { + public Pair map(CommandSender commandSender, PreviousArguments previousArguments, String s) { if (s.contains("%")) { String[] split = s.split("%"); if (split.length != 2) { @@ -103,7 +104,7 @@ public class ColorReplaceCommand extends SWCommand { } @Override - public Collection tabCompletes(CommandSender commandSender, String[] strings, String s) { + public Collection tabCompletes(CommandSender commandSender, PreviousArguments previousArguments, String s) { if (s.matches("[0-9].*")) { if (s.contains("%")) { String sub = s.substring(0, s.indexOf("%") + 1); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/TypeReplaceCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/TypeReplaceCommand.java index 668a1b50..556a6a67 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/TypeReplaceCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/worldedit/TypeReplaceCommand.java @@ -29,6 +29,7 @@ import de.steamwar.bausystem.features.world.WorldEditListener; import de.steamwar.bausystem.features.worldedit.utils.SpecialReplace; import de.steamwar.bausystem.shared.Pair; import de.steamwar.bausystem.utils.WorldEditUtils; +import de.steamwar.command.PreviousArguments; import de.steamwar.command.SWCommand; import de.steamwar.command.TypeMapper; import de.steamwar.linkage.Linked; @@ -104,7 +105,7 @@ public class TypeReplaceCommand extends SWCommand { public TypeMapper> typeMapper() { return new TypeMapper>() { @Override - public Pair map(CommandSender commandSender, String[] previousArguments, String s) { + public Pair map(CommandSender commandSender, PreviousArguments previousArguments, String s) { if (s.contains("%")) { String[] split = s.split("%"); if (split.length != 2) { @@ -121,7 +122,7 @@ public class TypeReplaceCommand extends SWCommand { } @Override - public Collection tabCompletes(CommandSender commandSender, String[] strings, String s) { + public Collection tabCompletes(CommandSender commandSender, PreviousArguments previousArguments, String s) { if (s.matches("[0-9].*")) { if (s.contains("%")) { String sub = s.substring(0, s.indexOf("%") + 1);