diff --git a/src/main/java/org/sgrewritten/stargate/api/network/portal/formatting/AbstractSignLine.java b/src/main/java/org/sgrewritten/stargate/api/network/portal/formatting/AbstractSignLine.java index eb5e4d6c..07e81154 100644 --- a/src/main/java/org/sgrewritten/stargate/api/network/portal/formatting/AbstractSignLine.java +++ b/src/main/java/org/sgrewritten/stargate/api/network/portal/formatting/AbstractSignLine.java @@ -17,6 +17,6 @@ public List getComponents() { @Override public String toString(){ - return this.getClass().getName() + getComponents(); + return this.getClass().getSimpleName() + getComponents(); } } diff --git a/src/main/java/org/sgrewritten/stargate/api/network/portal/formatting/data/NetworkLineData.java b/src/main/java/org/sgrewritten/stargate/api/network/portal/formatting/data/NetworkLineData.java index 8b099bc2..ce2bdf4f 100644 --- a/src/main/java/org/sgrewritten/stargate/api/network/portal/formatting/data/NetworkLineData.java +++ b/src/main/java/org/sgrewritten/stargate/api/network/portal/formatting/data/NetworkLineData.java @@ -27,4 +27,9 @@ public NetworkLineData(@NotNull Network network) { public @NotNull String getText() { return network.getName(); } + + @Override + public String toString(){ + return "NetworkLineData(" + getText() + ")"; + } } diff --git a/src/main/java/org/sgrewritten/stargate/api/network/portal/formatting/data/PortalLineData.java b/src/main/java/org/sgrewritten/stargate/api/network/portal/formatting/data/PortalLineData.java index 8b03f868..3a9288ff 100644 --- a/src/main/java/org/sgrewritten/stargate/api/network/portal/formatting/data/PortalLineData.java +++ b/src/main/java/org/sgrewritten/stargate/api/network/portal/formatting/data/PortalLineData.java @@ -37,4 +37,9 @@ public PortalLineData(@NotNull String portalName, SignLineType portalType){ public @NotNull String getText() { return portalName; } + + @Override + public String toString(){ + return "PortalLineData(" + getText() + ")"; + } } diff --git a/src/main/java/org/sgrewritten/stargate/api/network/portal/formatting/data/TextLineData.java b/src/main/java/org/sgrewritten/stargate/api/network/portal/formatting/data/TextLineData.java index 82330d24..42238be8 100644 --- a/src/main/java/org/sgrewritten/stargate/api/network/portal/formatting/data/TextLineData.java +++ b/src/main/java/org/sgrewritten/stargate/api/network/portal/formatting/data/TextLineData.java @@ -40,4 +40,9 @@ public TextLineData(String text, HighlightingStyle highlightingStyle) { public @Nullable HighlightingStyle getHighlightingStyle(){ return this.highlightingStyle; } + + @Override + public String toString(){ + return "TextLineData(" + getText() + ")"; + } } diff --git a/src/main/java/org/sgrewritten/stargate/network/portal/StargatePortal.java b/src/main/java/org/sgrewritten/stargate/network/portal/StargatePortal.java index 2e262566..99c41705 100644 --- a/src/main/java/org/sgrewritten/stargate/network/portal/StargatePortal.java +++ b/src/main/java/org/sgrewritten/stargate/network/portal/StargatePortal.java @@ -51,6 +51,7 @@ import org.sgrewritten.stargate.util.portal.PortalHelper; import java.util.ArrayList; +import java.util.Arrays; import java.util.EnumSet; import java.util.HashSet; import java.util.List; @@ -128,7 +129,8 @@ public StargatePortal(Network network, String name, Set flags, Set portalPosition.getPositionType() == PositionType.BUTTON) + .forEach(portalPosition -> gate.redrawPosition(portalPosition,null)); StringBuilder msg = new StringBuilder("Selected with flags "); for (PortalFlag flag : flags) { msg.append(flag.getCharacterRepresentation()); @@ -159,7 +161,7 @@ public void updateState() { this.behavior.update(); Portal currentDestination = getCurrentDestination(this.behavior.getDestination()); if (hasFlag(PortalFlag.ALWAYS_ON) && currentDestination != null) { - this.open(null); + this.open(currentDestination,null); } if (isOpen() && currentDestination == null) { close(true); @@ -398,10 +400,10 @@ public void run() { } } }.runNow(); - LineData[] lineData = behavior.getLines(); new StargateGlobalTask() { @Override public void run() { + LineData[] lineData = behavior.getLines(); getGate().redrawPosition(portalPosition, lineData); } }.runDelayed(2); @@ -469,10 +471,15 @@ public String getId() { } @Override - public void activate(Player player) { - this.activator = player.getUniqueId(); + public void activate(@Nullable Player player) { + if(player != null) { + this.activator = player.getUniqueId(); + } else { + this.activator = null; + } long activationTime = System.currentTimeMillis(); this.activatedTime = activationTime; + this.active = true; //Schedule for deactivation new StargateGlobalTask() { @@ -514,7 +521,6 @@ public void deactivate() { if (this.isDestroyed) { return; } - //Call the deactivate event to notify add-ons StargateDeactivatePortalEvent event = new StargateDeactivatePortalEvent(this); Bukkit.getPluginManager().callEvent(event); @@ -584,6 +590,10 @@ public void setBehavior(PortalBehavior portalBehavior) { flags.add(portalBehavior.getAttachedFlag()); this.behavior = Objects.requireNonNull(portalBehavior); this.behavior.assignPortal(this); + Portal destination = this.behavior.getDestination(); + if(hasFlag(PortalFlag.ALWAYS_ON) && destination != null){ + open(destination, null); + } } @Override @@ -595,6 +605,6 @@ public void redrawSigns() { private void clearBehaviorFlags() { List flagsToRemove = flags.stream().filter(PortalFlag::isBehaviorFlag).toList(); - flags.removeAll(flagsToRemove); + flagsToRemove.forEach(flags::remove); } } \ No newline at end of file diff --git a/src/main/java/org/sgrewritten/stargate/network/portal/behavior/FixedBehavior.java b/src/main/java/org/sgrewritten/stargate/network/portal/behavior/FixedBehavior.java index 644edce1..006a0f80 100644 --- a/src/main/java/org/sgrewritten/stargate/network/portal/behavior/FixedBehavior.java +++ b/src/main/java/org/sgrewritten/stargate/network/portal/behavior/FixedBehavior.java @@ -2,6 +2,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.sgrewritten.stargate.Stargate; import org.sgrewritten.stargate.api.formatting.LanguageManager; import org.sgrewritten.stargate.api.formatting.TranslatableMessage; import org.sgrewritten.stargate.api.network.portal.Portal; @@ -12,6 +13,9 @@ import org.sgrewritten.stargate.api.network.portal.formatting.data.PortalLineData; import org.sgrewritten.stargate.api.network.portal.formatting.data.TextLineData; +import java.util.Arrays; +import java.util.logging.Level; + public class FixedBehavior extends AbstractPortalBehavior{ private final String destinationName; private Portal destination; diff --git a/src/main/java/org/sgrewritten/stargate/network/portal/behavior/NetworkedBehavior.java b/src/main/java/org/sgrewritten/stargate/network/portal/behavior/NetworkedBehavior.java index 29513b52..274e2eca 100644 --- a/src/main/java/org/sgrewritten/stargate/network/portal/behavior/NetworkedBehavior.java +++ b/src/main/java/org/sgrewritten/stargate/network/portal/behavior/NetworkedBehavior.java @@ -32,6 +32,7 @@ import org.sgrewritten.stargate.util.MessageUtils; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.logging.Level; @@ -41,7 +42,6 @@ public class NetworkedBehavior extends AbstractPortalBehavior { private List destinations; private int selectedDestination = NO_DESTINATION_SELECTED; private long previousDestinationSelectionTime; - private Portal destination; private String loadedDestination; public NetworkedBehavior(LanguageManager languageManager) { @@ -115,7 +115,7 @@ private List getDestinations(@Nullable Player player) { @Override - public void onSignClick(PlayerInteractEvent event) { + public void onSignClick(@NotNull PlayerInteractEvent event) { super.onSignClick(event); if (event.getPlayer().isSneaking()) { return; @@ -144,9 +144,6 @@ public void onSignClick(PlayerInteractEvent event) { setSelectedDestination(selectNewDestination(event.getAction(), previouslyActivated)); portal.updateState(); - if (portal.hasFlag(PortalFlag.ALWAYS_ON)) { - this.destination = getDestination(); - } } /** @@ -227,7 +224,7 @@ private boolean hasActivatePermissions(Player player, StargatePermissionManager Bukkit.getPluginManager().callEvent(event); this.destinations = getPortals(event.getDestinations()); - this.destination = portal.getNetwork().getPortal(event.getDestination()); + // TODO: Modify the destination based on event outcome return true; }