mirror of
https://github.com/sekwah41/Advanced-Portals.git
synced 2024-11-22 10:36:17 +01:00
feat: bungee tags (#448)
This commit is contained in:
parent
7e981278b4
commit
a70e83b4d1
@ -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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -12,15 +12,6 @@ import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* The name of the destination or portal.
|
||||
*
|
||||
* <p>Most of the implementation of this tag is external, this is just to allow
|
||||
* for the tag to be used.
|
||||
*
|
||||
* <p>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;
|
||||
}
|
||||
|
||||
|
@ -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 =
|
||||
|
@ -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<String> triggerBlockList =
|
||||
Arrays.stream(Material.values())
|
||||
@ -67,6 +74,17 @@ public class SpigotServerContainer implements ServerContainer {
|
||||
.toArray(PlayerContainer[] ::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerOutgoingChannel(String channel) {
|
||||
server.getMessenger().registerOutgoingPluginChannel(AdvancedPortalsPlugin.getInstance(), channel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerIncomingChannel(String channel) {
|
||||
server.getMessenger().registerIncomingPluginChannel(AdvancedPortalsPlugin.getInstance(), channel,
|
||||
(s, player, bytes) -> coreListeners.incomingMessage(new SpigotPlayerContainer(player), s, bytes));
|
||||
}
|
||||
|
||||
// Check if it's a material compatible with making portals
|
||||
private boolean isAdvancedPortalBlock(Material material) {
|
||||
return switch (material) {
|
||||
|
Loading…
Reference in New Issue
Block a user