From 32700d76772c3c1eee470e421b3ad59cbabba096 Mon Sep 17 00:00:00 2001 From: Thorinwasher Date: Mon, 10 Jun 2024 17:17:50 +0200 Subject: [PATCH] Fixes #372 --- .../portal/behavior/LegacyBungeeBehavior.java | 12 ++++++++++++ .../sgrewritten/stargate/database/SQLDatabase.java | 13 +++++-------- .../network/portal/LegacyVirtualPortal.java | 6 +++--- .../stargate/network/portal/StargatePortal.java | 12 ++++++------ 4 files changed, 26 insertions(+), 17 deletions(-) diff --git a/src/main/java/org/sgrewritten/stargate/api/network/portal/behavior/LegacyBungeeBehavior.java b/src/main/java/org/sgrewritten/stargate/api/network/portal/behavior/LegacyBungeeBehavior.java index e1a922a3..2f509704 100644 --- a/src/main/java/org/sgrewritten/stargate/api/network/portal/behavior/LegacyBungeeBehavior.java +++ b/src/main/java/org/sgrewritten/stargate/api/network/portal/behavior/LegacyBungeeBehavior.java @@ -6,6 +6,7 @@ import org.sgrewritten.stargate.api.formatting.LanguageManager; import org.sgrewritten.stargate.api.formatting.TranslatableMessage; import org.sgrewritten.stargate.api.network.portal.Portal; +import org.sgrewritten.stargate.api.network.portal.RealPortal; import org.sgrewritten.stargate.api.network.portal.flag.StargateFlag; import org.sgrewritten.stargate.api.network.portal.formatting.SignLineType; import org.sgrewritten.stargate.api.network.portal.formatting.data.LineData; @@ -14,6 +15,7 @@ import org.sgrewritten.stargate.exception.UnimplementedFlagException; import org.sgrewritten.stargate.exception.name.BungeeNameException; import org.sgrewritten.stargate.exception.name.InvalidNameException; +import org.sgrewritten.stargate.exception.name.NameConflictException; import org.sgrewritten.stargate.exception.name.NameLengthException; import org.sgrewritten.stargate.network.NetworkType; import org.sgrewritten.stargate.network.StargateNetwork; @@ -89,4 +91,14 @@ public void update() { public @NotNull StargateFlag getAttachedFlag() { return StargateFlag.LEGACY_INTERSERVER; } + + @Override + public void assignPortal(@NotNull RealPortal portal){ + super.assignPortal(portal); + try { + portal.setNetwork(fakeNetwork); + } catch (NameConflictException e) { + Stargate.log(e); + } + } } diff --git a/src/main/java/org/sgrewritten/stargate/database/SQLDatabase.java b/src/main/java/org/sgrewritten/stargate/database/SQLDatabase.java index 42b2320b..39595e35 100644 --- a/src/main/java/org/sgrewritten/stargate/database/SQLDatabase.java +++ b/src/main/java/org/sgrewritten/stargate/database/SQLDatabase.java @@ -9,18 +9,15 @@ import org.sgrewritten.stargate.api.network.NetworkManager; import org.sgrewritten.stargate.api.network.RegistryAPI; import org.sgrewritten.stargate.api.network.portal.Portal; -import org.sgrewritten.stargate.api.network.portal.flag.StargateFlag; import org.sgrewritten.stargate.api.network.portal.PortalPosition; import org.sgrewritten.stargate.api.network.portal.RealPortal; +import org.sgrewritten.stargate.api.network.portal.flag.PortalFlag; +import org.sgrewritten.stargate.api.network.portal.flag.StargateFlag; import org.sgrewritten.stargate.config.ConfigurationHelper; import org.sgrewritten.stargate.config.TableNameConfiguration; import org.sgrewritten.stargate.database.property.StoredPropertiesAPI; import org.sgrewritten.stargate.database.property.StoredProperty; -import org.sgrewritten.stargate.exception.InvalidStructureException; -import org.sgrewritten.stargate.exception.PortalLoadException; -import org.sgrewritten.stargate.exception.StargateInitializationException; -import org.sgrewritten.stargate.exception.TranslatableException; -import org.sgrewritten.stargate.exception.UnimplementedFlagException; +import org.sgrewritten.stargate.exception.*; import org.sgrewritten.stargate.exception.database.StorageReadException; import org.sgrewritten.stargate.exception.database.StorageWriteException; import org.sgrewritten.stargate.exception.name.InvalidNameException; @@ -30,8 +27,8 @@ import org.sgrewritten.stargate.network.NetworkType; import org.sgrewritten.stargate.network.StargateNetwork; import org.sgrewritten.stargate.network.StorageType; -import org.sgrewritten.stargate.network.portal.StargatePortal; import org.sgrewritten.stargate.network.portal.GlobalPortalId; +import org.sgrewritten.stargate.network.portal.StargatePortal; import org.sgrewritten.stargate.network.portal.VirtualPortal; import org.sgrewritten.stargate.network.portal.portaldata.PortalData; import org.sgrewritten.stargate.thread.task.StargateRegionTask; @@ -286,7 +283,7 @@ private void loadPortal(PortalData portalData, StargateAPI stargateAPI) throws S portalData.flags().add(StargateFlag.NETWORKED); } - final List portalPositions = getPortalPositions(portalData, network.getId()); + final List portalPositions = getPortalPositions(portalData, portalData.flags().contains(PortalFlag.LEGACY_INTERSERVER) ? portalData.networkName() : network.getId()); //Actually register the gate and its positions new StargateRegionTask(portalData.gateData().topLeft()) { diff --git a/src/main/java/org/sgrewritten/stargate/network/portal/LegacyVirtualPortal.java b/src/main/java/org/sgrewritten/stargate/network/portal/LegacyVirtualPortal.java index 33c99619..a1594b04 100644 --- a/src/main/java/org/sgrewritten/stargate/network/portal/LegacyVirtualPortal.java +++ b/src/main/java/org/sgrewritten/stargate/network/portal/LegacyVirtualPortal.java @@ -5,9 +5,8 @@ import org.bukkit.plugin.java.JavaPlugin; import org.sgrewritten.stargate.Stargate; import org.sgrewritten.stargate.api.network.Network; -import org.sgrewritten.stargate.api.network.portal.flag.PortalFlag; -import org.sgrewritten.stargate.api.network.portal.flag.StargateFlag; import org.sgrewritten.stargate.api.network.portal.RealPortal; +import org.sgrewritten.stargate.api.network.portal.flag.PortalFlag; import org.sgrewritten.stargate.property.PluginChannel; import org.sgrewritten.stargate.util.BungeeHelper; @@ -51,7 +50,7 @@ public void teleportHere(Entity target, RealPortal origin) { msgData.writeUTF(PluginChannel.LEGACY_BUNGEE.getChannel()); String msg = BungeeHelper.generateLegacyTeleportMessage(player.getName(), this); msgData.writeUTF(msg); - Stargate.log(Level.FINEST, bao.toString()); + Stargate.log(Level.FINEST, "Sending plugin message: " + bao); player.sendPluginMessage(plugin, PluginChannel.BUNGEE.getChannel(), bao.toByteArray()); } catch (IOException e) { Stargate.log(Level.WARNING, "[Stargate] Error sending BungeeCord teleport packet"); @@ -64,6 +63,7 @@ public void teleportHere(Entity target, RealPortal origin) { DataOutputStream msgData = new DataOutputStream(bao); msgData.writeUTF(PluginChannel.PLAYER_CONNECT.getChannel()); msgData.writeUTF(server); + Stargate.log(Level.FINEST, "Sending plugin message: " + bao); player.sendPluginMessage(plugin, PluginChannel.BUNGEE.getChannel(), bao.toByteArray()); } catch (IOException e) { Stargate.log(Level.WARNING, "[Stargate] Error sending BungeeCord connect packet"); 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 745070fa..00b79e06 100644 --- a/src/main/java/org/sgrewritten/stargate/network/portal/StargatePortal.java +++ b/src/main/java/org/sgrewritten/stargate/network/portal/StargatePortal.java @@ -52,7 +52,6 @@ import java.util.*; import java.util.logging.Level; -import java.util.logging.Logger; /** * An abstract implementation of a real portal @@ -202,7 +201,7 @@ public void close(boolean forceClose) { if (!isOpen() || (hasFlag(StargateFlag.ALWAYS_ON) && !forceClose)) { return; } - if(this.isDestroyed){ + if (this.isDestroyed) { getGate().close(); return; } @@ -238,7 +237,8 @@ public Network getNetwork() { @Override public void setNetwork(Network targetNetwork) throws NameConflictException { - if (targetNetwork.getPortal(this.name) != null) { + Portal conflictingPortal = targetNetwork.getPortal(this.name); + if (conflictingPortal != null && conflictingPortal != this) { throw new NameConflictException(String.format("Portal of name %s already exists in network %s", this.name, targetNetwork.getId()), false); } this.network = targetNetwork; @@ -305,7 +305,7 @@ public void doTeleport(@NotNull Entity target, @Nullable Portal destination) { @Override public void doTeleport(@NotNull Entity target) { - if(overriddenDestination != null){ + if (overriddenDestination != null) { this.doTeleport(target, overriddenDestination); return; } @@ -566,7 +566,7 @@ public PortalBehavior getBehavior() { @Override public void setBehavior(PortalBehavior portalBehavior) { - if(isDestroyed){ + if (isDestroyed) { return; } clearBehaviorFlags(); @@ -581,7 +581,7 @@ public void setBehavior(PortalBehavior portalBehavior) { @Override public void redrawSigns() { - if(isDestroyed || !savedToStorage){ + if (isDestroyed || !savedToStorage) { return; } LineData[] lineData = behavior.getLines();