From 81e887607956150a7ffa5aeaf1f8c6697afc5ac4 Mon Sep 17 00:00:00 2001 From: Sekwah Date: Mon, 18 Dec 2023 02:03:03 +0000 Subject: [PATCH] fix: issues with tab menu capitalisation --- .../core/AdvancedPortalsCore.java | 2 + .../core/commands/CommandWithSubCommands.java | 6 +-- .../common/CreateTaggedSubCommand.java | 2 + .../connector/containers/ServerContainer.java | 3 ++ .../core/tags/activation/TriggerBlockTag.java | 50 +++++++++++++++++++ lang/src/main/resources/lang/en_GB.lang | 1 + .../container/SpigotServerContainer.java | 10 ++++ 7 files changed, 69 insertions(+), 5 deletions(-) create mode 100644 core/src/main/java/com/sekwah/advancedportals/core/tags/activation/TriggerBlockTag.java diff --git a/core/src/main/java/com/sekwah/advancedportals/core/AdvancedPortalsCore.java b/core/src/main/java/com/sekwah/advancedportals/core/AdvancedPortalsCore.java index 5fae4e18..307aa4ef 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/AdvancedPortalsCore.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/AdvancedPortalsCore.java @@ -15,6 +15,7 @@ import com.sekwah.advancedportals.core.services.DestinationServices; import com.sekwah.advancedportals.core.services.PortalServices; import com.sekwah.advancedportals.core.tags.activation.DestiTag; import com.sekwah.advancedportals.core.tags.activation.NameTag; +import com.sekwah.advancedportals.core.tags.activation.TriggerBlockTag; import com.sekwah.advancedportals.core.util.GameScheduler; import com.sekwah.advancedportals.core.util.InfoLogger; import com.sekwah.advancedportals.core.util.Lang; @@ -109,6 +110,7 @@ public class AdvancedPortalsCore { private void registerTags() { this.tagRegistry.registerTag(new NameTag()); this.tagRegistry.registerTag(new DestiTag()); + this.tagRegistry.registerTag(new TriggerBlockTag()); } /** diff --git a/core/src/main/java/com/sekwah/advancedportals/core/commands/CommandWithSubCommands.java b/core/src/main/java/com/sekwah/advancedportals/core/commands/CommandWithSubCommands.java index 6078dacb..dde1b814 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/commands/CommandWithSubCommands.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/commands/CommandWithSubCommands.java @@ -171,11 +171,7 @@ public class CommandWithSubCommands implements CommandTemplate { if(tabList == null) { return null; } - for(String arg : tabList.toArray(new String[0])) { - if(!arg.startsWith(lastArg.toLowerCase())) { - tabList.remove(arg); - } - } + tabList.removeIf(arg -> !arg.startsWith(lastArg)); return tabList; } } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/common/CreateTaggedSubCommand.java b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/common/CreateTaggedSubCommand.java index 010845e1..705826d3 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/common/CreateTaggedSubCommand.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/common/CreateTaggedSubCommand.java @@ -1,8 +1,10 @@ package com.sekwah.advancedportals.core.commands.subcommands.common; +import com.google.inject.Inject; import com.sekwah.advancedportals.core.commands.SubCommand; import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer; import com.sekwah.advancedportals.core.serializeddata.DataTag; +import com.sekwah.advancedportals.core.util.InfoLogger; import com.sekwah.advancedportals.core.util.TagReader; import com.sekwah.advancedportals.core.warphandler.Tag; diff --git a/core/src/main/java/com/sekwah/advancedportals/core/connector/containers/ServerContainer.java b/core/src/main/java/com/sekwah/advancedportals/core/connector/containers/ServerContainer.java index 6184e76d..027bce1a 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/connector/containers/ServerContainer.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/connector/containers/ServerContainer.java @@ -1,5 +1,6 @@ package com.sekwah.advancedportals.core.connector.containers; +import java.util.List; import java.util.UUID; public interface ServerContainer { @@ -10,6 +11,8 @@ public interface ServerContainer { PlayerContainer getPlayer(UUID name); + List getTriggerBlocks(); + PlayerContainer[] getPlayers(); } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/tags/activation/TriggerBlockTag.java b/core/src/main/java/com/sekwah/advancedportals/core/tags/activation/TriggerBlockTag.java new file mode 100644 index 00000000..634d6833 --- /dev/null +++ b/core/src/main/java/com/sekwah/advancedportals/core/tags/activation/TriggerBlockTag.java @@ -0,0 +1,50 @@ +package com.sekwah.advancedportals.core.tags.activation; + +import com.google.inject.Inject; +import com.sekwah.advancedportals.core.connector.containers.PlayerContainer; +import com.sekwah.advancedportals.core.connector.containers.ServerContainer; +import com.sekwah.advancedportals.core.registry.TagTarget; +import com.sekwah.advancedportals.core.services.DestinationServices; +import com.sekwah.advancedportals.core.util.Lang; +import com.sekwah.advancedportals.core.warphandler.ActivationData; +import com.sekwah.advancedportals.core.warphandler.Tag; + +import java.util.List; +import java.util.stream.Collectors; + +public class TriggerBlockTag implements Tag.AutoComplete { + + @Inject + private ServerContainer serverContainer; + + public static String TAG_NAME = "triggerblock"; + + private final TagType[] tagTypes = new TagType[]{ TagType.PORTAL }; + + @Override + public TagType[] getTagTypes() { + return tagTypes; + } + + @Override + public String getName() { + return TAG_NAME; + } + + @Override + public String[] getAliases() { + return null; + } + + @Override + public String description() { + return Lang.translate("tag.triggerblock.description"); + } + + @Override + public List autoComplete(String argData) { + return serverContainer.getTriggerBlocks().stream() + .filter(s -> s.startsWith(argData)) + .collect(Collectors.toList()); + } +} diff --git a/lang/src/main/resources/lang/en_GB.lang b/lang/src/main/resources/lang/en_GB.lang index 37ba69f7..47e99ad0 100644 --- a/lang/src/main/resources/lang/en_GB.lang +++ b/lang/src/main/resources/lang/en_GB.lang @@ -149,3 +149,4 @@ items.interact.right=Right Click tag.desti.description=Sets the destination of the portal tag.name.error.nospaces= The name cannot contain spaces. +tag.triggerblock.description=Sets the trigger block/s of the portal. Comma seperated or multi tag. diff --git a/spigot/src/main/java/com/sekwah/advancedportals/spigot/connector/container/SpigotServerContainer.java b/spigot/src/main/java/com/sekwah/advancedportals/spigot/connector/container/SpigotServerContainer.java index 32fac1ce..3426e199 100644 --- a/spigot/src/main/java/com/sekwah/advancedportals/spigot/connector/container/SpigotServerContainer.java +++ b/spigot/src/main/java/com/sekwah/advancedportals/spigot/connector/container/SpigotServerContainer.java @@ -3,13 +3,18 @@ package com.sekwah.advancedportals.spigot.connector.container; import com.sekwah.advancedportals.core.connector.containers.PlayerContainer; import com.sekwah.advancedportals.core.connector.containers.ServerContainer; import com.sekwah.advancedportals.core.connector.containers.WorldContainer; +import org.bukkit.Material; import org.bukkit.Server; +import java.util.Arrays; +import java.util.List; import java.util.UUID; public class SpigotServerContainer implements ServerContainer { private final Server server; + private final List triggerBlockList = Arrays.stream(Material.values()).filter(Material::isBlock).map(Enum::name) + .toList(); public SpigotServerContainer(Server server) { this.server = server; @@ -45,6 +50,11 @@ public class SpigotServerContainer implements ServerContainer { } } + @Override + public List getTriggerBlocks() { + return this.triggerBlockList; + } + @Override public PlayerContainer[] getPlayers() { return server.getOnlinePlayers().stream()