From 822f8fb2b52f809df766da3ad6493d0c3d04e508 Mon Sep 17 00:00:00 2001
From: EpicKnarvik97 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.
The 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;