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 dc62cf27..505bbb72 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/AdvancedPortalsCore.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/AdvancedPortalsCore.java @@ -117,12 +117,17 @@ public class AdvancedPortalsCore { this.registerCommands(); this.registerTags(); + this.registerChannels(); this.portalServices.loadPortals(); this.destinationServices.loadDestinations(); this.infoLogger.info(Lang.translate("logger.pluginenable")); } + private void registerChannels() { + this.serverContainer.registerOutgoingChannel(BungeeTag.PACKET_CHANNEL); + } + private void registerTags() { this.tagRegistry.registerTag(new NameTag()); this.tagRegistry.registerTag(new DestiTag()); @@ -132,6 +137,7 @@ public class AdvancedPortalsCore { this.tagRegistry.registerTag(new CommandTag()); this.tagRegistry.registerTag(new PortalEventTag()); this.tagRegistry.registerTag(new MessageTag()); + this.tagRegistry.registerTag(new BungeeTag()); } /** diff --git a/core/src/main/java/com/sekwah/advancedportals/core/CoreListeners.java b/core/src/main/java/com/sekwah/advancedportals/core/CoreListeners.java index 5bcfa3a6..fc38136f 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/CoreListeners.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/CoreListeners.java @@ -55,6 +55,10 @@ public class CoreListeners { this.playerDataServices.playerLeave(player); } + public void incomingMessage(PlayerContainer player, String channel, byte[] message) { + // TODO implement proxy handling + } + public void tick() { this.gameScheduler.tick(); } 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 3ff60a26..97aacbd0 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 @@ -15,6 +15,10 @@ public interface ServerContainer { PlayerContainer[] getPlayers(); + void registerOutgoingChannel(String channel); + + void registerIncomingChannel(String channel); + void dispatchCommand(UUID uuid, String command, CommandTag.CommandLevel commandLevel); } diff --git a/core/src/main/java/com/sekwah/advancedportals/core/tags/BungeeTag.java b/core/src/main/java/com/sekwah/advancedportals/core/tags/BungeeTag.java new file mode 100644 index 00000000..c50d7e0f --- /dev/null +++ b/core/src/main/java/com/sekwah/advancedportals/core/tags/BungeeTag.java @@ -0,0 +1,70 @@ +package com.sekwah.advancedportals.core.tags; + +import com.google.common.io.ByteArrayDataOutput; +import com.google.common.io.ByteStreams; +import com.google.inject.Inject; +import com.sekwah.advancedportals.core.connector.containers.PlayerContainer; +import com.sekwah.advancedportals.core.registry.TagTarget; +import com.sekwah.advancedportals.core.repository.ConfigRepository; +import com.sekwah.advancedportals.core.util.FriendlyDataOutput; +import com.sekwah.advancedportals.core.util.Lang; +import com.sekwah.advancedportals.core.warphandler.ActivationData; +import com.sekwah.advancedportals.core.warphandler.Tag; + +import java.util.Random; + +public class BungeeTag implements Tag.Activation { + + public static final String PACKET_CHANNEL = "BungeeCord"; + @Inject + ConfigRepository configRepository; + + public static String TAG_NAME = "bungee"; + + private final TagType[] tagTypes = + new TagType[] {TagType.PORTAL}; + + private final Random random = new Random(); + + @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.bungee.description"); + } + + @Override + public boolean preActivated(TagTarget target, PlayerContainer player, ActivationData activeData, String[] argData) { + return true; + } + + @Override + public void postActivated(TagTarget target, PlayerContainer player, ActivationData activationData, String[] argData) { + + } + + @Override + public boolean activated(TagTarget target, PlayerContainer player, ActivationData activeData, String[] argData) { + String selectedArg = argData[random.nextInt(argData.length)]; + + ByteArrayDataOutput outForSend = ByteStreams.newDataOutput(); + outForSend.writeUTF("Connect"); + outForSend.writeUTF(selectedArg); + player.sendPacket(BungeeTag.PACKET_CHANNEL, outForSend.toByteArray()); + activeData.setWarpStatus(ActivationData.WarpedStatus.WARPED); + return true; + } +} diff --git a/core/src/main/java/com/sekwah/advancedportals/core/tags/MessageTag.java b/core/src/main/java/com/sekwah/advancedportals/core/tags/MessageTag.java index 69114d03..5b38684b 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/tags/MessageTag.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/tags/MessageTag.java @@ -12,15 +12,6 @@ import javax.annotation.Nullable; import java.util.List; import java.util.Random; -/** - * The name of the destination or portal. - * - *
Most of the implementation of this tag is external, this is just to allow - * for the tag to be used. - * - *
Most tags shouldn't be like this unless they are to be paired with
- * another tag.
- */
public class MessageTag implements Tag.Activation {
@Inject
@@ -55,10 +46,6 @@ public class MessageTag implements Tag.Activation {
@Override
public boolean preActivated(TagTarget target, PlayerContainer player, ActivationData activeData, String[] argData) {
-
- String selectedArg = argData[random.nextInt(argData.length)];
- activeData.setMetadata(TAG_NAME, selectedArg);
- activeData.setWarpStatus(ActivationData.WarpedStatus.ACTIVATED);
return true;
}
@@ -77,7 +64,10 @@ public class MessageTag implements Tag.Activation {
}
@Override
- public boolean activated(TagTarget target, PlayerContainer player, ActivationData activationData, String[] argData) {
+ public boolean activated(TagTarget target, PlayerContainer player, ActivationData activeData, String[] argData) {
+ String selectedArg = argData[random.nextInt(argData.length)];
+ activeData.setMetadata(TAG_NAME, selectedArg);
+ activeData.setWarpStatus(ActivationData.WarpedStatus.ACTIVATED);
return true;
}
diff --git a/spigot/src/main/java/com/sekwah/advancedportals/spigot/commands/subcommands/portal/ImportPortalSubCommand.java b/spigot/src/main/java/com/sekwah/advancedportals/spigot/commands/subcommands/portal/ImportPortalSubCommand.java
index 66e8c484..4a81a402 100644
--- a/spigot/src/main/java/com/sekwah/advancedportals/spigot/commands/subcommands/portal/ImportPortalSubCommand.java
+++ b/spigot/src/main/java/com/sekwah/advancedportals/spigot/commands/subcommands/portal/ImportPortalSubCommand.java
@@ -68,14 +68,20 @@ public class ImportPortalSubCommand implements SubCommand {
if (triggerblock != null)
args.add(new DataTag("triggerblock", triggerblock.split(",")));
// It's called bungee as that's the implementation behind it
- var bungee = config.getString(portalName + ".bungee");
- if (bungee != null)
- args.add(new DataTag("bungee", bungee.split(",")));
var destination = config.getString(portalName + ".destination");
if (destination != null)
args.add(new DataTag("destination", destination.split(",")));
+ var bungee = config.getString(portalName + ".bungee");
+ if (bungee != null) {
+ if(destination == null) {
+ args.add(new DataTag("bungee", bungee.split(",")));
+ } else {
+ args.add(new DataTag("proxy", bungee.split(",")));
+ }
+ }
+
ConfigurationSection portalConfigSection =
config.getConfigurationSection(portalName);
ConfigurationSection portalArgsConf =
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 9c468242..da23403d 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
@@ -1,5 +1,7 @@
package com.sekwah.advancedportals.spigot.connector.container;
+import com.google.inject.Inject;
+import com.sekwah.advancedportals.core.CoreListeners;
import com.sekwah.advancedportals.core.connector.containers.PlayerContainer;
import com.sekwah.advancedportals.core.connector.containers.ServerContainer;
import com.sekwah.advancedportals.core.connector.containers.WorldContainer;
@@ -7,12 +9,17 @@ import com.sekwah.advancedportals.core.tags.CommandTag;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
+
+import com.sekwah.advancedportals.spigot.AdvancedPortalsPlugin;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import org.bukkit.permissions.PermissionAttachment;
+import org.bukkit.plugin.messaging.PluginMessageListener;
public class SpigotServerContainer implements ServerContainer {
+ @Inject
+ private CoreListeners coreListeners;
private final Server server;
private final List