mirror of
https://github.com/sekwah41/Advanced-Portals.git
synced 2024-11-29 05:55:19 +01:00
Finished Velocity Support
This commit is contained in:
parent
1796945896
commit
d06f150358
@ -1,6 +1,5 @@
|
|||||||
package com.sekwah.advancedportals.bungee.listener;
|
package com.sekwah.advancedportals.bungee.listener;
|
||||||
|
|
||||||
import com.google.common.base.Charsets;
|
|
||||||
import com.google.common.io.ByteArrayDataInput;
|
import com.google.common.io.ByteArrayDataInput;
|
||||||
import com.google.common.io.ByteStreams;
|
import com.google.common.io.ByteStreams;
|
||||||
import com.sekwah.advancedportals.bungee.AdvancedPortalsPlugin;
|
import com.sekwah.advancedportals.bungee.AdvancedPortalsPlugin;
|
||||||
|
@ -1,16 +1,26 @@
|
|||||||
package com.sekwah.advancedportals.velocity;
|
package com.sekwah.advancedportals.velocity;
|
||||||
|
|
||||||
|
import com.google.common.io.ByteArrayDataInput;
|
||||||
|
import com.google.common.io.ByteArrayDataOutput;
|
||||||
|
import com.google.common.io.ByteStreams;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.sekwah.advancedportals.bungee.BungeeMessages;
|
import com.sekwah.advancedportals.bungee.BungeeMessages;
|
||||||
import com.velocitypowered.api.event.Subscribe;
|
import com.velocitypowered.api.event.Subscribe;
|
||||||
import com.velocitypowered.api.event.connection.PluginMessageEvent;
|
import com.velocitypowered.api.event.connection.PluginMessageEvent;
|
||||||
|
import com.velocitypowered.api.event.player.ServerConnectedEvent;
|
||||||
|
import com.velocitypowered.api.event.player.ServerPostConnectEvent;
|
||||||
|
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
||||||
import com.velocitypowered.api.plugin.Plugin;
|
import com.velocitypowered.api.plugin.Plugin;
|
||||||
import com.velocitypowered.api.proxy.ProxyServer;
|
import com.velocitypowered.api.proxy.ProxyServer;
|
||||||
import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier;
|
import com.velocitypowered.api.proxy.ServerConnection;
|
||||||
|
import com.velocitypowered.api.proxy.messages.LegacyChannelIdentifier;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* While there may be a better way to do this for now we are keeping the behavior so it also works with Bungee's horrible API.
|
||||||
|
*/
|
||||||
@Plugin(id = "advancedportals", name = "Advanced Portals",
|
@Plugin(id = "advancedportals", name = "Advanced Portals",
|
||||||
url = "https://www.spigotmc.org/resources/advanced-portals.14356/",
|
url = "https://www.spigotmc.org/resources/advanced-portals.14356/",
|
||||||
version = "0.5.12")
|
version = "0.5.12")
|
||||||
@ -20,6 +30,7 @@ public class AdvancedPortalsPlugin {
|
|||||||
|
|
||||||
private final Logger logger;
|
private final Logger logger;
|
||||||
private ProxyServer proxy;
|
private ProxyServer proxy;
|
||||||
|
private LegacyChannelIdentifier AP_CHANNEL;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public AdvancedPortalsPlugin(ProxyServer proxy, Logger logger) {
|
public AdvancedPortalsPlugin(ProxyServer proxy, Logger logger) {
|
||||||
@ -27,17 +38,82 @@ public class AdvancedPortalsPlugin {
|
|||||||
this.proxy = proxy;
|
this.proxy = proxy;
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
|
|
||||||
String[] splitChannel = BungeeMessages.CHANNEL_NAME.split(":");
|
|
||||||
proxy.getChannelRegistrar().register(MinecraftChannelIdentifier.create(splitChannel[0], splitChannel[1]));
|
|
||||||
|
|
||||||
logger.info("\u00A7aAdvanced portals have been successfully enabled!");
|
logger.info("\u00A7aAdvanced portals have been successfully enabled!");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onProxyInitialize(ProxyInitializeEvent event) {
|
||||||
|
|
||||||
|
String[] splitChannel = BungeeMessages.CHANNEL_NAME.split(":");
|
||||||
|
AP_CHANNEL = new LegacyChannelIdentifier(BungeeMessages.CHANNEL_NAME);
|
||||||
|
|
||||||
|
proxy.getChannelRegistrar().register(AP_CHANNEL);
|
||||||
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onPluginMessage(PluginMessageEvent event) {
|
public void onPluginMessage(PluginMessageEvent event) {
|
||||||
System.out.println("THING HERE");
|
if(event.getIdentifier().equals(AP_CHANNEL)) {
|
||||||
|
if(event.getSource() instanceof ServerConnection) {
|
||||||
|
|
||||||
|
ByteArrayDataInput in = ByteStreams.newDataInput(event.getData());
|
||||||
|
|
||||||
|
String subChannel = in.readUTF();
|
||||||
|
|
||||||
|
System.out.printf("SubChannel: %s%n", subChannel);
|
||||||
|
if (subChannel.equalsIgnoreCase(BungeeMessages.ENTER_PORTAL)) {
|
||||||
|
String targetServer = in.readUTF();
|
||||||
|
String targetDestination = in.readUTF();
|
||||||
|
String targetUUID = in.readUTF();
|
||||||
|
|
||||||
|
PlayerDestiMap.put(targetUUID, new String[]{targetServer, targetDestination, targetUUID});
|
||||||
|
|
||||||
|
proxy.getScheduler().buildTask(this, () -> PlayerDestiMap.remove(targetUUID))
|
||||||
|
.delay(10, TimeUnit.SECONDS).schedule();
|
||||||
|
}
|
||||||
|
else if (subChannel.equalsIgnoreCase(BungeeMessages.BUNGEE_COMMAND)) {
|
||||||
|
String command = in.readUTF();
|
||||||
|
ServerConnection connection = (ServerConnection) event.getSource();
|
||||||
|
if(connection.getPlayer() != null) {
|
||||||
|
proxy.getCommandManager().executeAsync(connection.getPlayer(), command);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// So that client packets don't make it through to the servers, always trigger on this channel.
|
||||||
|
event.setResult(PluginMessageEvent.ForwardResult.handled());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void postJoinEvent(ServerPostConnectEvent event) {
|
||||||
|
String uuid = event.getPlayer().getUniqueId().toString();
|
||||||
|
|
||||||
|
String[] val = PlayerDestiMap.get(uuid);
|
||||||
|
|
||||||
|
System.out.println("POSTJOIN");
|
||||||
System.out.println(event);
|
System.out.println(event);
|
||||||
|
|
||||||
|
if (val != null) {
|
||||||
|
// key: UUID (string)
|
||||||
|
// value: [0] targetServer, [1] targetDestination, [2] onlineUUID
|
||||||
|
|
||||||
|
event.getPlayer().getCurrentServer().ifPresent(serverConnection -> {
|
||||||
|
System.out.println("EXIST");
|
||||||
|
|
||||||
|
if (serverConnection.getServerInfo().getName().equalsIgnoreCase(val[0])) {
|
||||||
|
|
||||||
|
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||||
|
|
||||||
|
out.writeUTF(BungeeMessages.SERVER_DESTI);
|
||||||
|
out.writeUTF(val[1]);
|
||||||
|
out.writeUTF(val[2]);
|
||||||
|
|
||||||
|
System.out.println(serverConnection.sendPluginMessage(AP_CHANNEL, out.toByteArray()));
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user