Skip to content

Commit

Permalink
Fix bugs from refactor
Browse files Browse the repository at this point in the history
- Networked portal not drawing
- Always on issues
- Invalid of portal
  • Loading branch information
Thorinwasher committed Mar 8, 2024
1 parent fb11564 commit c502aa2
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ public List<StargateComponent> getComponents() {

@Override
public String toString(){
return this.getClass().getName() + getComponents();
return this.getClass().getSimpleName() + getComponents();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,9 @@ public NetworkLineData(@NotNull Network network) {
public @NotNull String getText() {
return network.getName();
}

@Override
public String toString(){
return "NetworkLineData(" + getText() + ")";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,9 @@ public PortalLineData(@NotNull String portalName, SignLineType portalType){
public @NotNull String getText() {
return portalName;
}

@Override
public String toString(){
return "PortalLineData(" + getText() + ")";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,9 @@ public TextLineData(String text, HighlightingStyle highlightingStyle) {
public @Nullable HighlightingStyle getHighlightingStyle(){
return this.highlightingStyle;
}

@Override
public String toString(){
return "TextLineData(" + getText() + ")";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -128,7 +129,8 @@ public StargatePortal(Network network, String name, Set<PortalFlag> flags, Set<C
if (gate.getFormat().isIronDoorBlockable()) {
flags.add(PortalFlag.IRON_DOOR);
}

gate.getPortalPositions().stream().filter(portalPosition -> 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());
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand All @@ -595,6 +605,6 @@ public void redrawSigns() {

private void clearBehaviorFlags() {
List<PortalFlag> flagsToRemove = flags.stream().filter(PortalFlag::isBehaviorFlag).toList();
flags.removeAll(flagsToRemove);
flagsToRemove.forEach(flags::remove);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -41,7 +42,6 @@ public class NetworkedBehavior extends AbstractPortalBehavior {
private List<Portal> destinations;
private int selectedDestination = NO_DESTINATION_SELECTED;
private long previousDestinationSelectionTime;
private Portal destination;
private String loadedDestination;

public NetworkedBehavior(LanguageManager languageManager) {
Expand Down Expand Up @@ -115,7 +115,7 @@ private List<Portal> getDestinations(@Nullable Player player) {


@Override
public void onSignClick(PlayerInteractEvent event) {
public void onSignClick(@NotNull PlayerInteractEvent event) {
super.onSignClick(event);
if (event.getPlayer().isSneaking()) {
return;
Expand Down Expand Up @@ -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();
}
}

/**
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit c502aa2

Please sign in to comment.