From c90597228af76f6da5e0941dcf286d8c1ba1fab6 Mon Sep 17 00:00:00 2001 From: Sekwah Date: Wed, 20 Dec 2023 05:58:20 +0000 Subject: [PATCH] feat: add default trigger block if unspecified --- .../portal/CreatePortalSubCommand.java | 12 +++++++++++- .../subcommands/portal/ShowPortalSubCommand.java | 16 ++++++++++------ .../core/portal/AdvancedPortal.java | 8 -------- .../core/repository/ConfigRepository.java | 4 ++-- .../repository/impl/ConfigRepositoryImpl.java | 13 +++++++++---- .../core/serializeddata/config/Config.java | 2 +- 6 files changed, 33 insertions(+), 22 deletions(-) diff --git a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/CreatePortalSubCommand.java b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/CreatePortalSubCommand.java index 599267c6..060e77e2 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/CreatePortalSubCommand.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/CreatePortalSubCommand.java @@ -5,11 +5,13 @@ import com.sekwah.advancedportals.core.commands.subcommands.common.CreateTaggedS import com.sekwah.advancedportals.core.connector.containers.CommandSenderContainer; import com.sekwah.advancedportals.core.connector.containers.PlayerContainer; import com.sekwah.advancedportals.core.registry.TagRegistry; +import com.sekwah.advancedportals.core.repository.ConfigRepository; import com.sekwah.advancedportals.core.serializeddata.DataTag; import com.sekwah.advancedportals.core.permissions.PortalPermissions; import com.sekwah.advancedportals.core.portal.AdvancedPortal; import com.sekwah.advancedportals.core.services.PortalServices; import com.sekwah.advancedportals.core.tags.activation.NameTag; +import com.sekwah.advancedportals.core.tags.activation.TriggerBlockTag; import com.sekwah.advancedportals.core.util.InfoLogger; import com.sekwah.advancedportals.core.util.Lang; import com.sekwah.advancedportals.core.util.TagReader; @@ -30,6 +32,9 @@ public class CreatePortalSubCommand extends CreateTaggedSubCommand { @Inject InfoLogger infoLogger; + @Inject + ConfigRepository config; + @Override public void onCommand(CommandSenderContainer sender, String[] args) { if(args.length > 1) { @@ -68,11 +73,16 @@ public class CreatePortalSubCommand extends CreateTaggedSubCommand { } sender.sendMessage(""); + var triggerBlockTag = portalTags.stream().filter(tag -> tag.NAME.equals(TriggerBlockTag.TAG_NAME)).findFirst().orElse(null); + + if(triggerBlockTag == null) { + portalTags.add(new DataTag(TriggerBlockTag.TAG_NAME, config.getDefaultTriggerBlock())); + } + AdvancedPortal portal = portalServices.createPortal(player, portalTags); if(portal != null) { sender.sendMessage(Lang.translate("messageprefix.positive") + Lang.translate("command.create.complete")); sender.sendMessage(Lang.translate("command.create.tags")); - //sender.sendMessage("\u00A7a" + " triggerBlock\u00A77:\u00A7e" + Arrays.toString(portal.getTriggerBlocks())); this.printTags(sender, portal.getArgs()); } else { sender.sendMessage(Lang.translate("messageprefix.negative") + Lang.translate("command.create.error")); diff --git a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/ShowPortalSubCommand.java b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/ShowPortalSubCommand.java index f07b0dd8..4f2a27ed 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/ShowPortalSubCommand.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/commands/subcommands/portal/ShowPortalSubCommand.java @@ -26,7 +26,9 @@ import java.util.function.Consumer; */ public class ShowPortalSubCommand implements SubCommand, SubCommand.SubCommandOnInit { - static final int SHOW_TICKS = 1300; + static final int SHOW_TICKS = 1010; + + boolean alternate_show_trigger = true; @Inject PortalTempDataServices tempDataServices; @@ -96,6 +98,7 @@ public class ShowPortalSubCommand implements SubCommand, SubCommand.SubCommandOn @Override public void registered() { gameScheduler.intervalTickEvent("show_portal", () -> { + alternate_show_trigger = !alternate_show_trigger; for(PlayerContainer player : serverContainer.getPlayers()) { var tempData = tempDataServices.getPlayerTempData(player); if(!tempData.isPortalVisible()) { @@ -131,7 +134,7 @@ public class ShowPortalSubCommand implements SubCommand, SubCommand.SubCommandOn else color = new Color(0, 0, 0, 0); } - debugVisuals(player, portal, OUTLINE_COLOR, 1000, TRIGGER_COLOR); + debugVisuals(player, portal, OUTLINE_COLOR, SHOW_TICKS, TRIGGER_COLOR); Debug.addMarker(player, midPoint, portal.getArgValues(NameTag.TAG_NAME)[0], color, SHOW_TICKS); } } @@ -171,14 +174,15 @@ public class ShowPortalSubCommand implements SubCommand, SubCommand.SubCommandOn for (int z = minZ; z <= maxZ; z++) { var pos = new BlockLocation(pos1.worldName, x, y, z); boolean isTrigger = portal != null && portal.isTriggerBlock(world.getBlock(pos)); + System.out.println(world.getBlock(pos)); boolean isOutline = (y == minY || y == maxY) && (x == minX || x == maxX || z == minZ || z == maxZ) || (z == minZ || z == maxZ) && (x == minX || x == maxX); - if (isTrigger && isOutline) { + if (isTrigger && isOutline && alternate_show_trigger) { Debug.addMarker(player, pos, "", TRIGGER_OUTLINE_COLOR, time); - } - else if(isTrigger) { - Debug.addMarker(player, pos, "", triggerColor, time); } else if (isOutline) { Debug.addMarker(player, pos, "", color, time); + } else if(isTrigger) { + if(alternate_show_trigger) + Debug.addMarker(player, pos, "", triggerColor, time); } } } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/portal/AdvancedPortal.java b/core/src/main/java/com/sekwah/advancedportals/core/portal/AdvancedPortal.java index 79784ebd..de78a67b 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/portal/AdvancedPortal.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/portal/AdvancedPortal.java @@ -163,12 +163,4 @@ public class AdvancedPortal implements TagTarget { } return false; } - - /*public void setTriggerBlocks(String[] triggerBlocks) { - this.triggerBlocks = triggerBlocks; - }*/ - - /*public String[] getTriggerBlocks() { - return triggerBlocks; - }*/ } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/repository/ConfigRepository.java b/core/src/main/java/com/sekwah/advancedportals/core/repository/ConfigRepository.java index 39b0c0fa..ad9a7f1e 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/repository/ConfigRepository.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/repository/ConfigRepository.java @@ -6,8 +6,6 @@ public interface ConfigRepository { boolean getUseOnlySpecialAxe(); - void setUseOnlySpecialAxe(boolean useOnlyServerMadeAxe); - String getTranslation(); String getSelectorMaterial(); @@ -18,5 +16,7 @@ public interface ConfigRepository { int getMaxTriggerVisualisationSize(); + String getDefaultTriggerBlock(); + } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/repository/impl/ConfigRepositoryImpl.java b/core/src/main/java/com/sekwah/advancedportals/core/repository/impl/ConfigRepositoryImpl.java index dba102df..ed5dcf8e 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/repository/impl/ConfigRepositoryImpl.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/repository/impl/ConfigRepositoryImpl.java @@ -27,22 +27,22 @@ public class ConfigRepositoryImpl implements ConfigRepository { return null; } + @Override public boolean getUseOnlySpecialAxe() { return this.config.useOnlySpecialAxe; } - public void setUseOnlySpecialAxe(boolean useOnlyServerMadeAxe) { - this.config.useOnlySpecialAxe = useOnlyServerMadeAxe; - } - + @Override public String getTranslation() { return this.config.translationFile; } + @Override public String getSelectorMaterial() { return this.config.selectorMaterial; } + @Override public int getVisibleRange() { return this.config.visibleRange; } @@ -52,6 +52,11 @@ public class ConfigRepositoryImpl implements ConfigRepository { return this.config.maxTriggerVisualisationSize; } + @Override + public String getDefaultTriggerBlock() { + return this.config.defaultTriggerBlock; + } + @Override public void loadConfig(DataStorage dataStorage) { this.config = dataStorage.loadJson(Config.class, "config.json"); diff --git a/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/config/Config.java b/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/config/Config.java index 0a1db003..d428e61b 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/config/Config.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/serializeddata/config/Config.java @@ -13,7 +13,7 @@ public class Config { public int portalProtectionRaduis = 5; - public String defaultTriggerBlock = "PORTAL"; + public String defaultTriggerBlock = "NETHER_PORTAL"; public boolean stopWaterFlow = true;