Update to be compatible with the latest build of BungeeCord
This commit is contained in:
parent
1c58184656
commit
7b00e6fefd
2
README
2
README
@ -215,6 +215,8 @@ Bukkit Issue: Stargate will randomly NPE when drawing a sign. Long-standing Bukk
|
|||||||
=============
|
=============
|
||||||
Changes
|
Changes
|
||||||
=============
|
=============
|
||||||
|
[Version 0.7.9.3]
|
||||||
|
- Update BungeeCord integration for b152+
|
||||||
[Version 0.7.9.2]
|
[Version 0.7.9.2]
|
||||||
- Remove my custom sign class. Stupid Bukkit team.
|
- Remove my custom sign class. Stupid Bukkit team.
|
||||||
- Will work with CB 1.4.5 builds, but now will break randomly due to Bukkit screwup
|
- Will work with CB 1.4.5 builds, but now will break randomly due to Bukkit screwup
|
||||||
|
@ -850,14 +850,14 @@ public class Portal {
|
|||||||
} else {
|
} else {
|
||||||
// Check if network exists in our network list
|
// Check if network exists in our network list
|
||||||
if (!lookupNamesNet.containsKey(getNetwork().toLowerCase())) {
|
if (!lookupNamesNet.containsKey(getNetwork().toLowerCase())) {
|
||||||
Stargate.debug("register", "Network not in lookupNamesNet, adding");
|
Stargate.debug("register", "Network " + getNetwork() + " not in lookupNamesNet, adding");
|
||||||
lookupNamesNet.put(getNetwork().toLowerCase(), new HashMap<String, Portal>());
|
lookupNamesNet.put(getNetwork().toLowerCase(), new HashMap<String, Portal>());
|
||||||
}
|
}
|
||||||
lookupNamesNet.get(getNetwork().toLowerCase()).put(getName().toLowerCase(), this);
|
lookupNamesNet.get(getNetwork().toLowerCase()).put(getName().toLowerCase(), this);
|
||||||
|
|
||||||
// Check if this network exists
|
// Check if this network exists
|
||||||
if (!allPortalsNet.containsKey(getNetwork().toLowerCase())) {
|
if (!allPortalsNet.containsKey(getNetwork().toLowerCase())) {
|
||||||
Stargate.debug("register", "Network not in allPortalsNet, adding");
|
Stargate.debug("register", "Network " + getNetwork() + " not in allPortalsNet, adding");
|
||||||
allPortalsNet.put(getNetwork().toLowerCase(), new ArrayList<String>());
|
allPortalsNet.put(getNetwork().toLowerCase(), new ArrayList<String>());
|
||||||
}
|
}
|
||||||
allPortalsNet.get(getNetwork().toLowerCase()).add(getName().toLowerCase());
|
allPortalsNet.get(getNetwork().toLowerCase()).add(getName().toLowerCase());
|
||||||
@ -1204,7 +1204,7 @@ public class Portal {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Portal getBungeeGate(String name) {
|
public static Portal getBungeeGate(String name) {
|
||||||
return bungeePortals.get(name);
|
return bungeePortals.get(name.toLowerCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void saveAllGates(World world) {
|
public static void saveAllGates(World world) {
|
||||||
|
@ -1,9 +1,13 @@
|
|||||||
package net.TheDgtl.Stargate;
|
package net.TheDgtl.Stargate;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.DataOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
@ -40,6 +44,7 @@ import org.bukkit.event.block.BlockPistonRetractEvent;
|
|||||||
import org.bukkit.event.block.SignChangeEvent;
|
import org.bukkit.event.block.SignChangeEvent;
|
||||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
import org.bukkit.event.player.PlayerMoveEvent;
|
import org.bukkit.event.player.PlayerMoveEvent;
|
||||||
import org.bukkit.event.player.PlayerPortalEvent;
|
import org.bukkit.event.player.PlayerPortalEvent;
|
||||||
import org.bukkit.event.server.PluginDisableEvent;
|
import org.bukkit.event.server.PluginDisableEvent;
|
||||||
@ -116,6 +121,9 @@ public class Stargate extends JavaPlugin {
|
|||||||
// Used for populating gate open/closed material.
|
// Used for populating gate open/closed material.
|
||||||
public static Queue<BloxPopulator> blockPopulatorQueue = new LinkedList<BloxPopulator>();
|
public static Queue<BloxPopulator> blockPopulatorQueue = new LinkedList<BloxPopulator>();
|
||||||
|
|
||||||
|
// HashMap of player names for Bungee support
|
||||||
|
public static Map<String, String> bungeeQueue = new HashMap<String, String>();
|
||||||
|
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
Portal.closeAllGates();
|
Portal.closeAllGates();
|
||||||
Portal.clearGates();
|
Portal.clearGates();
|
||||||
@ -150,8 +158,8 @@ public class Stargate extends JavaPlugin {
|
|||||||
|
|
||||||
// Enable the required channels for Bungee support
|
// Enable the required channels for Bungee support
|
||||||
if (enableBungee) {
|
if (enableBungee) {
|
||||||
Bukkit.getMessenger().registerOutgoingPluginChannel(this, "SGBungee");
|
Bukkit.getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
|
||||||
Bukkit.getMessenger().registerIncomingPluginChannel(this, "SGBungee", new pmListener());
|
Bukkit.getMessenger().registerIncomingPluginChannel(this, "BungeeCord", new pmListener());
|
||||||
}
|
}
|
||||||
|
|
||||||
// It is important to load languages here, as they are used during reloadGates()
|
// It is important to load languages here, as they are used during reloadGates()
|
||||||
@ -723,6 +731,21 @@ public class Stargate extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private class pListener implements Listener {
|
private class pListener implements Listener {
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
|
if (!enableBungee) return;
|
||||||
|
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
String destination = bungeeQueue.get(player.getName().toLowerCase());
|
||||||
|
if (destination == null) return;
|
||||||
|
|
||||||
|
Portal portal = Portal.getBungeeGate(destination);
|
||||||
|
if (portal == null) {
|
||||||
|
Stargate.debug("PlayerJoin", "Error fetching destination portal: " + destination);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
portal.teleport(player, portal, null);
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerPortal(PlayerPortalEvent event) {
|
public void onPlayerPortal(PlayerPortalEvent event) {
|
||||||
@ -820,19 +843,51 @@ public class Stargate extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Stargate.sendMessage(player, Stargate.getString("teleportMsg"), false);
|
Stargate.sendMessage(player, Stargate.getString("teleportMsg"), false);
|
||||||
if (portal.isBungee()) {
|
|
||||||
|
|
||||||
|
// BungeeCord Support
|
||||||
|
if (portal.isBungee()) {
|
||||||
if (!enableBungee) {
|
if (!enableBungee) {
|
||||||
player.sendMessage(Stargate.getString("bungeeDisabled"));
|
player.sendMessage(Stargate.getString("bungeeDisabled"));
|
||||||
portal.close(false);
|
portal.close(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Teleport the player back to this gate, for sanity's sake
|
||||||
portal.teleport(player, portal, event);
|
portal.teleport(player, portal, event);
|
||||||
|
|
||||||
// Teleport player via BungeeCord
|
// Send the SGBungee packet first, it will be queued by BC if required
|
||||||
String pMsg = portal.getNetwork() + "@#@" + portal.getDestinationName();
|
try {
|
||||||
player.sendPluginMessage(stargate, "SGBungee", pMsg.getBytes());
|
// Build the message, format is <player>#@#<destination>
|
||||||
|
String msg = event.getPlayer().getName() + "#@#" + portal.getDestinationName();
|
||||||
|
// Build the message data, sent over the SGBungee bungeecord channel
|
||||||
|
ByteArrayOutputStream bao = new ByteArrayOutputStream();
|
||||||
|
DataOutputStream msgData = new DataOutputStream(bao);
|
||||||
|
msgData.writeUTF("Forward");
|
||||||
|
msgData.writeUTF(portal.getNetwork()); // Server
|
||||||
|
msgData.writeUTF("SGBungee"); // Channel
|
||||||
|
msgData.writeShort(msg.length()); // Data Length
|
||||||
|
msgData.writeBytes(msg); // Data
|
||||||
|
player.sendPluginMessage(stargate, "BungeeCord", bao.toByteArray());
|
||||||
|
} catch (IOException ex) {
|
||||||
|
Stargate.log.severe("[Stargate] Error sending BungeeCord teleport packet");
|
||||||
|
ex.printStackTrace();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Connect player to new server
|
||||||
|
try {
|
||||||
|
ByteArrayOutputStream bao = new ByteArrayOutputStream();
|
||||||
|
DataOutputStream msgData = new DataOutputStream(bao);
|
||||||
|
msgData.writeUTF("Connect");
|
||||||
|
msgData.writeUTF(portal.getNetwork());
|
||||||
|
|
||||||
|
player.sendPluginMessage(stargate, "BungeeCord", bao.toByteArray());
|
||||||
|
bao.reset();
|
||||||
|
} catch(IOException ex) {
|
||||||
|
Stargate.log.severe("[Stargate] Error sending BungeeCord connect packet");
|
||||||
|
ex.printStackTrace();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Close portal if required (Should never be)
|
// Close portal if required (Should never be)
|
||||||
portal.close(false);
|
portal.close(false);
|
||||||
@ -1346,11 +1401,11 @@ public class Stargate extends JavaPlugin {
|
|||||||
// Enable the required channels for Bungee support
|
// Enable the required channels for Bungee support
|
||||||
if (oldEnableBungee != enableBungee) {
|
if (oldEnableBungee != enableBungee) {
|
||||||
if (enableBungee) {
|
if (enableBungee) {
|
||||||
Bukkit.getMessenger().registerOutgoingPluginChannel(this, "SGBungee");
|
Bukkit.getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
|
||||||
Bukkit.getMessenger().registerIncomingPluginChannel(this, "SGBungee", new pmListener());
|
Bukkit.getMessenger().registerIncomingPluginChannel(this, "BungeeCord", new pmListener());
|
||||||
} else {
|
} else {
|
||||||
Bukkit.getMessenger().unregisterIncomingPluginChannel(this, "SGBungee");
|
Bukkit.getMessenger().unregisterIncomingPluginChannel(this, "BungeeCord");
|
||||||
Bukkit.getMessenger().unregisterOutgoingPluginChannel(this, "SGBungee");
|
Bukkit.getMessenger().unregisterOutgoingPluginChannel(this, "BungeeCord");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,23 +1,57 @@
|
|||||||
package net.TheDgtl.Stargate;
|
package net.TheDgtl.Stargate;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.DataInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.messaging.PluginMessageListener;
|
import org.bukkit.plugin.messaging.PluginMessageListener;
|
||||||
|
|
||||||
public class pmListener implements PluginMessageListener {
|
public class pmListener implements PluginMessageListener {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPluginMessageReceived(String channel, Player player, byte[] message) {
|
public void onPluginMessageReceived(String channel, Player unused, byte[] message) {
|
||||||
if (!channel.equals("SGBungee") || !Stargate.enableBungee) return;
|
if (!Stargate.enableBungee || !channel.equals("BungeeCord")) return;
|
||||||
|
|
||||||
// Message should be destination gate name.
|
// Get data from message
|
||||||
Portal dest = Portal.getBungeeGate(new String(message));
|
String inChannel;
|
||||||
|
byte[] data;
|
||||||
// Specified an invalid gate. For now we'll just let them connect at their current location
|
try {
|
||||||
if (dest == null) {
|
DataInputStream in = new DataInputStream(new ByteArrayInputStream(message));
|
||||||
|
inChannel = in.readUTF();
|
||||||
|
short len = in.readShort();
|
||||||
|
data = new byte[len];
|
||||||
|
in.readFully(data);
|
||||||
|
} catch (IOException ex) {
|
||||||
|
Stargate.log.severe("[Stargate] Error receiving BungeeCord message");
|
||||||
|
ex.printStackTrace();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Teleport the player to their destination portal
|
// Verify that it's an SGBungee packet
|
||||||
|
if (!inChannel.equals("SGBungee")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Data should be player name, and destination gate name
|
||||||
|
String msg = new String(data);
|
||||||
|
String[] parts = msg.split("#@#");
|
||||||
|
|
||||||
|
String playerName = parts[0];
|
||||||
|
String destination = parts[1];
|
||||||
|
|
||||||
|
// Check if the player is online, if so, teleport, otherwise, queue
|
||||||
|
Player player = Stargate.server.getPlayer(playerName);
|
||||||
|
if (player == null) {
|
||||||
|
Stargate.bungeeQueue.put(playerName.toLowerCase(), destination);
|
||||||
|
} else {
|
||||||
|
Portal dest = Portal.getBungeeGate(destination);
|
||||||
|
// Specified an invalid gate. For now we'll just let them connect at their current location
|
||||||
|
if (dest == null) {
|
||||||
|
Stargate.log.info("[Stargate] Bungee gate " + destination + " does not exist");
|
||||||
|
return;
|
||||||
|
}
|
||||||
dest.teleport(player, dest, null);
|
dest.teleport(player, dest, null);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
name: Stargate
|
name: Stargate
|
||||||
main: net.TheDgtl.Stargate.Stargate
|
main: net.TheDgtl.Stargate.Stargate
|
||||||
version: 0.7.9.2
|
version: 0.7.9.3
|
||||||
description: Stargate mod for Bukkit
|
description: Stargate mod for Bukkit
|
||||||
author: Drakia
|
author: Drakia
|
||||||
website: http://www.thedgtl.net
|
website: http://www.thedgtl.net
|
||||||
|
Loading…
Reference in New Issue
Block a user