diff --git a/src/main/java/net/knarcraft/stargate/listener/BungeeCordListener.java b/src/main/java/net/knarcraft/stargate/listener/BungeeCordListener.java index 2a7d2e1..fba579d 100644 --- a/src/main/java/net/knarcraft/stargate/listener/BungeeCordListener.java +++ b/src/main/java/net/knarcraft/stargate/listener/BungeeCordListener.java @@ -9,8 +9,8 @@ import org.jetbrains.annotations.NotNull; * This listener teleports a user if a valid message is received from BungeeCord * *
Specifically, if a string starts with SGBungee encoded to be readable by readUTF followed by - * PlayerName#@#DestinationPortal is received on the BungeeCord channel, this listener will teleport the player to the - * destination portal.
+ * [PlayerUUID]delimiter[DestinationPortal] is received on the BungeeCord channel, this listener will teleport the + * player to the destination portal. */ public class BungeeCordListener implements PluginMessageListener { @@ -24,7 +24,7 @@ public class BungeeCordListener implements PluginMessageListener { @Override public void onPluginMessageReceived(@NotNull String channel, @NotNull Player unused, byte[] message) { //Ignore plugin messages if some other plugin message is received - if (!channel.equals("BungeeCord")) { + if (!channel.equals(BungeeHelper.getBungeeChannel())) { return; } diff --git a/src/main/java/net/knarcraft/stargate/listener/PlayerEventListener.java b/src/main/java/net/knarcraft/stargate/listener/PlayerEventListener.java index d63ad65..4ba8599 100644 --- a/src/main/java/net/knarcraft/stargate/listener/PlayerEventListener.java +++ b/src/main/java/net/knarcraft/stargate/listener/PlayerEventListener.java @@ -48,7 +48,7 @@ public class PlayerEventListener implements Listener { Player player = event.getPlayer(); //Check if the player is waiting to be teleported to a stargate - String destination = BungeeHelper.removeFromQueue(player.getName()); + String destination = BungeeHelper.removeFromQueue(player.getUniqueId()); if (destination == null) { return; } diff --git a/src/main/java/net/knarcraft/stargate/portal/PortalCreator.java b/src/main/java/net/knarcraft/stargate/portal/PortalCreator.java index cd5ecba..0714e2a 100644 --- a/src/main/java/net/knarcraft/stargate/portal/PortalCreator.java +++ b/src/main/java/net/knarcraft/stargate/portal/PortalCreator.java @@ -110,7 +110,7 @@ public class PortalCreator { //Check if the player can create portals on this network. If not, create a personal portal if (!portalOptions.get(PortalOption.BUNGEE) && !PermissionHelper.canCreateNetworkGate(player, network)) { Stargate.debug("createPortal", "Player doesn't have create permissions on network. Trying personal"); - if (PermissionHelper.canCreatePersonalGate(player)) { + if (PermissionHelper.canCreatePersonalPortal(player)) { network = player.getName(); if (network.length() > 11) { network = network.substring(0, 11); @@ -127,7 +127,7 @@ public class PortalCreator { //Check if the player can create this gate layout String gateName = gate.getFilename(); gateName = gateName.substring(0, gateName.indexOf('.')); - if (!deny && !PermissionHelper.canCreateGate(player, gateName)) { + if (!deny && !PermissionHelper.canCreatePortal(player, gateName)) { Stargate.debug("createPortal", "Player does not have access to gate layout"); deny = true; denyMessage = Stargate.getString("createGateDeny"); diff --git a/src/main/java/net/knarcraft/stargate/utility/BungeeHelper.java b/src/main/java/net/knarcraft/stargate/utility/BungeeHelper.java index e0040a8..18577e8 100644 --- a/src/main/java/net/knarcraft/stargate/utility/BungeeHelper.java +++ b/src/main/java/net/knarcraft/stargate/utility/BungeeHelper.java @@ -13,6 +13,7 @@ import java.io.DataOutputStream; import java.io.IOException; import java.util.HashMap; import java.util.Map; +import java.util.UUID; /** * This class contains helpful functions to help with sending and receiving BungeeCord plugin messages @@ -22,12 +23,21 @@ public final class BungeeHelper { private final static String bungeeSubChannel = "SGBungee"; private final static String bungeeChannel = "BungeeCord"; private final static String teleportMessageDelimiter = "#@#"; - private final static MapThe bungee plugin channel
+ */ + public static String getBungeeChannel() { + return bungeeChannel; + } + /** * Removes a player from the queue of players teleporting through BungeeCord * @@ -35,38 +45,43 @@ public final class BungeeHelper { * server, it'll be added to this queue. Once the player joins this server, the player should be removed from the * queue and teleported to the destination. * - * @param playerNameThe name of the player to remove
+ * @param playerUUIDThe UUID of the player to remove
* @returnThe name of the destination portal the player should be teleported to
*/ - public static String removeFromQueue(String playerName) { - return bungeeQueue.remove(playerName.toLowerCase()); + public static String removeFromQueue(UUID playerUUID) { + return bungeeQueue.remove(playerUUID); } /** * Sends a plugin message to BungeeCord allowing the target server to catch it * - * @param playerThe player teleporting
+ * @param playerThe teleporting player
* @param entrancePortalThe portal the player is teleporting from
* @returnTrue if the message was successfully sent
*/ public static boolean sendTeleportationMessage(Player player, Portal entrancePortal) { try { - // Build the message, format isThe player to teleport
- * @param entrancePortalThe bungee portal the player teleports from
- * @returnTrue if able to send the plugin message
+ * @param entrancePortalThe bungee portal the player is teleporting from
+ * @returnTrue if the plugin message was sent successfully
*/ public static boolean changeServer(Player player, Portal entrancePortal) { try { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); DataOutputStream dataOutputStream = new DataOutputStream(byteArrayOutputStream); + + //Send a connect-message to connect the player to the server defined in the entrance portal's network line dataOutputStream.writeUTF("Connect"); dataOutputStream.writeUTF(entrancePortal.getNetwork()); + //Send the plugin message player.sendPluginMessage(Stargate.stargate, bungeeChannel, byteArrayOutputStream.toByteArray()); - byteArrayOutputStream.reset(); } catch (IOException ex) { Stargate.getConsoleLogger().severe(Stargate.getString("prefix") + "Error sending BungeeCord connect packet"); @@ -102,7 +119,7 @@ public final class BungeeHelper { * Reads a plugin message byte array to a string if it's sent from another stargate plugin * * @param messageThe byte array to read
- * @returnThe message contained in the byte array or null on failure
+ * @returnThe message contained in the byte array, or null on failure
*/ public static String readPluginMessage(byte[] message) { // Get data from message @@ -114,8 +131,12 @@ public final class BungeeHelper { if (!subChannel.equals(bungeeSubChannel)) { return null; } + + //Get the length of the contained message short dataLength = dataInputStream.readShort(); + //Prepare a byte array for the sent message data = new byte[dataLength]; + //Read the message to the prepared array dataInputStream.readFully(data); } catch (IOException ex) { Stargate.getConsoleLogger().severe(Stargate.getString("prefix") + @@ -123,29 +144,27 @@ public final class BungeeHelper { ex.printStackTrace(); return null; } - - // Data should be player name, and destination gate name return new String(data); } /** * Handles the receival of a teleport message * - * @param receivedMessageThe received message
+ * @param receivedMessageThe received teleport message
*/ public static void handleTeleportMessage(String receivedMessage) { + //Get the player id and destination from the message String[] messageParts = receivedMessage.split(teleportMessageDelimiter); - - String playerName = messageParts[0]; + UUID playerUUID = UUID.fromString(messageParts[0]); String destination = messageParts[1]; - // Check if the player is online, if so, teleport, otherwise, queue - Player player = Stargate.server.getPlayer(playerName); + //Check if the player is online, if so, teleport, otherwise, queue + Player player = Stargate.server.getPlayer(playerUUID); if (player == null) { - bungeeQueue.put(playerName.toLowerCase(), destination); + bungeeQueue.put(playerUUID, destination); } else { Portal destinationPortal = PortalHandler.getBungeePortal(destination); - // Specified an invalid gate. For now, we'll just let them connect at their current location + //If teleporting to an invalid portal, let the server decide where the player arrives if (destinationPortal == null) { Stargate.getConsoleLogger().info(Stargate.getString("prefix") + "Bungee gate " + destination + " does not exist"); diff --git a/src/main/java/net/knarcraft/stargate/utility/PermissionHelper.java b/src/main/java/net/knarcraft/stargate/utility/PermissionHelper.java index 0b86582..3592b56 100644 --- a/src/main/java/net/knarcraft/stargate/utility/PermissionHelper.java +++ b/src/main/java/net/knarcraft/stargate/utility/PermissionHelper.java @@ -59,7 +59,7 @@ public final class PermissionHelper { } //Check if the player can use the private gate - if (portal.getOptions().isPrivate() && !PermissionHelper.canPrivate(player, portal)) { + if (portal.getOptions().isPrivate() && !PermissionHelper.canUsePrivatePortal(player, portal)) { Stargate.getMessageSender().sendErrorMessage(player, Stargate.getString("denyMsg")); return; } @@ -121,15 +121,16 @@ public final class PermissionHelper { * *This is the same as player.hasPermission(), but this function allows for printing permission debugging info.
* - * @param playerThe player to check
- * @param permThe permission to check
+ * @param playerThe player to check
+ * @param permissionThe permission to check
* @returnTrue if the player has the permission
*/ - public static boolean hasPermission(Player player, String perm) { + public static boolean hasPermission(Player player, String permission) { if (Stargate.getStargateConfig().isPermissionDebuggingEnabled()) { - Stargate.debug("hasPerm::SuperPerm(" + player.getName() + ")", perm + " => " + player.hasPermission(perm)); + Stargate.debug("hasPerm::SuperPerm(" + player.getName() + ")", permission + " => " + + player.hasPermission(permission)); } - return player.hasPermission(perm); + return player.hasPermission(permission); } /** @@ -264,7 +265,7 @@ public final class PermissionHelper { * @param portalThe private portal used
* @returnTrue if the player is allowed to use the portal
*/ - public static boolean canPrivate(Player player, Portal portal) { + public static boolean canUsePrivatePortal(Player player, Portal portal) { //Check if the player is the owner of the gate if (portal.isOwner(player)) { return true; @@ -308,7 +309,6 @@ public final class PermissionHelper { } //Check for this specific network return hasPermission(player, "stargate.create.network." + network); - } /** @@ -317,7 +317,7 @@ public final class PermissionHelper { * @param playerThe player trying to create the new gate
* @returnTrue if the player is allowed
*/ - public static boolean canCreatePersonalGate(Player player) { + public static boolean canCreatePersonalPortal(Player player) { //Check for general create if (hasPermission(player, "stargate.create")) { return true; @@ -333,7 +333,7 @@ public final class PermissionHelper { * @param gateThe gate type of the new portal
* @returnTrue if the player is allowed to create a portal with the given gate layout
*/ - public static boolean canCreateGate(Player player, String gate) { + public static boolean canCreatePortal(Player player, String gate) { //Check for general create if (hasPermission(player, "stargate.create")) { return true;