mirror of
https://github.com/sekwah41/Advanced-Portals.git
synced 2024-12-27 19:37:44 +01:00
fix subchannel/bungee issues
This commit is contained in:
parent
a6555b171c
commit
0015a3bcb7
@ -18,7 +18,9 @@ public class AdvancedPortalsPlugin extends JavaPlugin {
|
|||||||
public CraftBukkit compat = null;
|
public CraftBukkit compat = null;
|
||||||
private Settings settings;
|
private Settings settings;
|
||||||
|
|
||||||
public HashMap<OfflinePlayer, String> PlayerDestiMap = new HashMap<>();
|
public String channelName = "mc:advancedportals";
|
||||||
|
|
||||||
|
// public HashMap<OfflinePlayer, String> PlayerDestiMap = new HashMap<>();
|
||||||
|
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
|
|
||||||
@ -110,6 +112,9 @@ public class AdvancedPortalsPlugin extends JavaPlugin {
|
|||||||
private void setupBungee() {
|
private void setupBungee() {
|
||||||
this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
|
this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
|
||||||
this.getServer().getMessenger().registerIncomingPluginChannel(this, "BungeeCord", new BungeeListener(this));
|
this.getServer().getMessenger().registerIncomingPluginChannel(this, "BungeeCord", new BungeeListener(this));
|
||||||
|
|
||||||
|
this.getServer().getMessenger().registerOutgoingPluginChannel(this, channelName);
|
||||||
|
this.getServer().getMessenger().registerIncomingPluginChannel(this, channelName, new PluginMessageReceiver(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -19,27 +19,11 @@ public class BungeeListener implements PluginMessageListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPluginMessageReceived(String channel, Player player, byte[] message) {
|
public void onPluginMessageReceived(String channel, Player player, byte[] message) {
|
||||||
if (!channel.equals("AdvancedPortals")) {
|
if (!channel.equals("BungeeCord")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ByteArrayDataInput in = ByteStreams.newDataInput(message);
|
|
||||||
String subchannel = in.readUTF();
|
|
||||||
|
|
||||||
plugin.getLogger().fine(subchannel);
|
// some codes
|
||||||
|
|
||||||
if (subchannel.equals("BungeePortal")) {
|
|
||||||
String targetPlayerUUID = in.readUTF();
|
|
||||||
String targetDestination = in.readUTF();
|
|
||||||
|
|
||||||
OfflinePlayer msgPlayer = plugin.getServer().getOfflinePlayer(UUID.fromString(targetPlayerUUID));
|
|
||||||
|
|
||||||
plugin.PlayerDestiMap.put(msgPlayer, targetDestination);
|
|
||||||
|
|
||||||
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () ->
|
|
||||||
plugin.PlayerDestiMap.remove(msgPlayer),
|
|
||||||
20L*10
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -66,11 +66,11 @@ public class Listeners implements Listener {
|
|||||||
public void onJoinEvent(PlayerJoinEvent event) {
|
public void onJoinEvent(PlayerJoinEvent event) {
|
||||||
Portal.cooldown.put(event.getPlayer().getName(), System.currentTimeMillis());
|
Portal.cooldown.put(event.getPlayer().getName(), System.currentTimeMillis());
|
||||||
|
|
||||||
if (plugin.PlayerDestiMap.containsKey(event.getPlayer())) {
|
/* if (plugin.PlayerDestiMap.containsKey(event.getPlayer())) {
|
||||||
String desti = plugin.PlayerDestiMap.get(event.getPlayer());
|
String desti = plugin.PlayerDestiMap.get(event.getPlayer());
|
||||||
|
|
||||||
Destination.warp(event.getPlayer(), desti);
|
Destination.warp(event.getPlayer(), desti);
|
||||||
}
|
} */
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
@ -0,0 +1,69 @@
|
|||||||
|
package com.sekwah.advancedportals.bukkit.listeners;
|
||||||
|
|
||||||
|
import com.google.common.io.ByteArrayDataInput;
|
||||||
|
import com.google.common.io.ByteStreams;
|
||||||
|
import com.sekwah.advancedportals.bukkit.AdvancedPortalsPlugin;
|
||||||
|
import com.sekwah.advancedportals.bukkit.destinations.Destination;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.messaging.PluginMessageListener;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class PluginMessageReceiver implements PluginMessageListener {
|
||||||
|
|
||||||
|
private AdvancedPortalsPlugin plugin;
|
||||||
|
|
||||||
|
public PluginMessageReceiver(AdvancedPortalsPlugin plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPluginMessageReceived(String channel, Player player, byte[] message) {
|
||||||
|
// plugin.getLogger().info(""+channel.equals(plugin.channelName));
|
||||||
|
|
||||||
|
if (!channel.equals(plugin.channelName)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ByteArrayDataInput in = ByteStreams.newDataInput(message);
|
||||||
|
String subchannel = in.readUTF();
|
||||||
|
|
||||||
|
// plugin.getLogger().info("bukkit plugin received: " + subchannel);
|
||||||
|
|
||||||
|
if (subchannel.equals("BungeePortal")) {
|
||||||
|
String targetPlayerUUID = in.readUTF();
|
||||||
|
String targetDestination = in.readUTF();
|
||||||
|
|
||||||
|
OfflinePlayer msgPlayer = plugin.getServer().getOfflinePlayer(UUID.fromString(targetPlayerUUID));
|
||||||
|
|
||||||
|
Destination.warp(msgPlayer.getPlayer(), targetDestination);
|
||||||
|
|
||||||
|
/* plugin.PlayerDestiMap.put(msgPlayer, targetDestination);
|
||||||
|
|
||||||
|
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, () ->
|
||||||
|
plugin.PlayerDestiMap.remove(msgPlayer),
|
||||||
|
20L*10
|
||||||
|
); */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Example forward packet.
|
||||||
|
*
|
||||||
|
* Construct like the forge packets.
|
||||||
|
*
|
||||||
|
* out.writeUTF("Forward"); // So BungeeCord knows to forward it
|
||||||
|
out.writeUTF("ALL");
|
||||||
|
out.writeUTF("MyChannel"); // The channel name to check if this your data
|
||||||
|
|
||||||
|
ByteArrayOutputStream msgbytes = new ByteArrayOutputStream();
|
||||||
|
DataOutputStream msgout = new DataOutputStream(msgbytes);
|
||||||
|
msgout.writeUTF("Some kind of data here"); // You can do anything you want with msgout
|
||||||
|
msgout.writeShort(123);
|
||||||
|
|
||||||
|
out.writeShort(msgbytes.toByteArray().length);
|
||||||
|
out.write(msgbytes.toByteArray());
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
}
|
@ -414,7 +414,7 @@ public class Portal {
|
|||||||
outForList.writeUTF(player.getUniqueId().toString());
|
outForList.writeUTF(player.getUniqueId().toString());
|
||||||
outForList.writeUTF(portal.getDestiation());
|
outForList.writeUTF(portal.getDestiation());
|
||||||
|
|
||||||
player.sendPluginMessage(plugin, "AdvancedPortals", outForList.toByteArray());
|
player.sendPluginMessage(plugin, plugin.channelName, outForList.toByteArray());
|
||||||
|
|
||||||
ByteArrayDataOutput outForSend = ByteStreams.newDataOutput();
|
ByteArrayDataOutput outForSend = ByteStreams.newDataOutput();
|
||||||
outForSend.writeUTF("Connect");
|
outForSend.writeUTF("Connect");
|
||||||
|
@ -1,13 +1,28 @@
|
|||||||
package com.sekwah.advancedportals.bungee;
|
package com.sekwah.advancedportals.bungee;
|
||||||
|
|
||||||
|
import com.sekwah.advancedportals.bungee.listener.EventListener;
|
||||||
|
import com.sekwah.advancedportals.bungee.listener.PluginMessageReceiver;
|
||||||
import net.md_5.bungee.api.plugin.Plugin;
|
import net.md_5.bungee.api.plugin.Plugin;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
public class AdvancedPortalsPlugin extends Plugin {
|
public class AdvancedPortalsPlugin extends Plugin {
|
||||||
|
|
||||||
|
public String channelName = "mc:advancedportals";
|
||||||
|
|
||||||
|
public HashMap<String, String[]> PlayerDestiMap = new HashMap<>();
|
||||||
|
// key: UUID (string)
|
||||||
|
// value: [0] targetServer, [1] targetDestination
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
getProxy().registerChannel("AdvancedPortals");
|
getProxy().registerChannel(channelName);
|
||||||
|
|
||||||
|
getProxy().getPluginManager().registerListener(this, new PluginMessageReceiver(this));
|
||||||
|
getProxy().getPluginManager().registerListener(this, new EventListener(this));
|
||||||
|
|
||||||
getLogger().info("\u00A7aAdvanced portals have been successfully enabled!");
|
getLogger().info("\u00A7aAdvanced portals have been successfully enabled!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
|
@ -0,0 +1,36 @@
|
|||||||
|
package com.sekwah.advancedportals.bungee.listener;
|
||||||
|
|
||||||
|
import com.google.common.io.ByteArrayDataOutput;
|
||||||
|
import com.google.common.io.ByteStreams;
|
||||||
|
import com.sekwah.advancedportals.bungee.AdvancedPortalsPlugin;
|
||||||
|
import net.md_5.bungee.api.event.ServerSwitchEvent;
|
||||||
|
import net.md_5.bungee.api.plugin.Listener;
|
||||||
|
import net.md_5.bungee.event.EventHandler;
|
||||||
|
|
||||||
|
public class EventListener implements Listener {
|
||||||
|
private AdvancedPortalsPlugin plugin;
|
||||||
|
|
||||||
|
public EventListener(AdvancedPortalsPlugin plugin) { this.plugin = plugin; }
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerSwitchServer(ServerSwitchEvent event) {
|
||||||
|
String uuid = event.getPlayer().getUniqueId().toString();
|
||||||
|
|
||||||
|
if (plugin.PlayerDestiMap.containsKey(uuid)) {
|
||||||
|
String[] val = plugin.PlayerDestiMap.get(uuid);
|
||||||
|
// key: UUID (string)
|
||||||
|
// value: [0] targetServer, [1] targetDestination
|
||||||
|
|
||||||
|
if (event.getPlayer().getServer().getInfo().getName().equalsIgnoreCase(val[0])) {
|
||||||
|
|
||||||
|
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||||
|
|
||||||
|
out.writeUTF("BungeePortal");
|
||||||
|
out.writeUTF(uuid);
|
||||||
|
out.writeUTF(val[1]);
|
||||||
|
|
||||||
|
event.getPlayer().getServer().getInfo().sendData(plugin.channelName, out.toByteArray());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,43 +1,41 @@
|
|||||||
package com.sekwah.advancedportals.bungee.listener;
|
package com.sekwah.advancedportals.bungee.listener;
|
||||||
|
|
||||||
import com.google.common.io.ByteArrayDataInput;
|
import com.google.common.io.ByteArrayDataInput;
|
||||||
import com.google.common.io.ByteArrayDataOutput;
|
|
||||||
import com.google.common.io.ByteStreams;
|
import com.google.common.io.ByteStreams;
|
||||||
import com.sekwah.advancedportals.bungee.AdvancedPortalsPlugin;
|
import com.sekwah.advancedportals.bungee.AdvancedPortalsPlugin;
|
||||||
import net.md_5.bungee.api.config.ServerInfo;
|
|
||||||
import net.md_5.bungee.api.event.PluginMessageEvent;
|
import net.md_5.bungee.api.event.PluginMessageEvent;
|
||||||
import net.md_5.bungee.api.plugin.Listener;
|
import net.md_5.bungee.api.plugin.Listener;
|
||||||
import net.md_5.bungee.event.EventHandler;
|
import net.md_5.bungee.event.EventHandler;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class PluginMessageReceiver implements Listener {
|
public class PluginMessageReceiver implements Listener {
|
||||||
private AdvancedPortalsPlugin plugin;
|
private AdvancedPortalsPlugin plugin;
|
||||||
|
|
||||||
public PluginMessageReceiver (AdvancedPortalsPlugin plugin) {
|
public PluginMessageReceiver(AdvancedPortalsPlugin plugin) { this.plugin = plugin; }
|
||||||
this.plugin = plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onMessageReceived(PluginMessageEvent event) {
|
public void onMessageReceived(PluginMessageEvent event) {
|
||||||
if(!event.getTag().equalsIgnoreCase("AdvancedPortals")) return;
|
if(!event.getTag().equalsIgnoreCase(plugin.channelName)) return;
|
||||||
|
|
||||||
ByteArrayDataInput in = ByteStreams.newDataInput(event.getData());
|
ByteArrayDataInput in = ByteStreams.newDataInput(event.getData());
|
||||||
String subChannel = in.readUTF();
|
String subChannel = in.readUTF();
|
||||||
|
|
||||||
|
plugin.getProxy().getLogger().info("bungee plugin received: " + subChannel);
|
||||||
|
|
||||||
if (subChannel.equalsIgnoreCase("PortalEnter")) {
|
if (subChannel.equalsIgnoreCase("PortalEnter")) {
|
||||||
String targetServer = in.readUTF();
|
String targetServer = in.readUTF();
|
||||||
String targetPlayerUUID = in.readUTF();
|
String targetPlayerUUID = in.readUTF();
|
||||||
String targetDestination = in.readUTF();
|
String targetDestination = in.readUTF();
|
||||||
|
|
||||||
ServerInfo server = plugin.getProxy().getServerInfo(targetServer);
|
// plugin.getProxy().getLogger().info(targetServer + " " + targetPlayerUUID + " " + targetDestination);
|
||||||
|
|
||||||
if (server != null) {
|
plugin.PlayerDestiMap.put(targetPlayerUUID, new String[]{targetServer, targetDestination});
|
||||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
|
||||||
out.writeUTF("BungeePortal");
|
|
||||||
out.writeUTF(targetPlayerUUID);
|
|
||||||
out.writeUTF(targetDestination);
|
|
||||||
|
|
||||||
server.sendData("AdvancedPortals", out.toByteArray());
|
plugin.getProxy().getScheduler().schedule(plugin, () -> {
|
||||||
}
|
if (plugin.PlayerDestiMap.containsKey(targetPlayerUUID)) {
|
||||||
|
plugin.PlayerDestiMap.remove(targetPlayerUUID);
|
||||||
|
}
|
||||||
|
}, 20, TimeUnit.SECONDS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user