From 19018e46b8f6f1187dc95c5d0a97f19d7dedb311 Mon Sep 17 00:00:00 2001 From: EpicKnarvik97 Date: Sun, 12 Sep 2021 01:23:16 +0200 Subject: [PATCH] Fixes some bugs regarding bungee teleportation Fixes the server being teleported normally after it's teleported to another server Fixes a nullpointerexception --- .../java/net/knarcraft/stargate/Stargate.java | 33 ++++++++++++------- .../listener/PlayerEventListener.java | 7 ++-- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/src/main/java/net/knarcraft/stargate/Stargate.java b/src/main/java/net/knarcraft/stargate/Stargate.java index 00f2bd5..18790e9 100644 --- a/src/main/java/net/knarcraft/stargate/Stargate.java +++ b/src/main/java/net/knarcraft/stargate/Stargate.java @@ -217,21 +217,27 @@ public class Stargate extends JavaPlugin { return player.hasPermission(perm); } - /* + /** * Check a deep permission, this will check to see if the permissions is defined for this use - * If using Permissions it will return the same as hasPerm - * If using SuperPerms will return true if the node isn't defined - * Or the value of the node if it is + * + *

If using Permissions it will return the same as hasPerm. If using SuperPerms will return true if the node + * isn't defined, or the value of the node if it is

+ * + * @param player

The player to check

+ * @param permission

The permission to check

+ * @return

True if the player has the permission or it is not set

*/ - public static boolean hasPermDeep(Player player, String perm) { - if (!player.isPermissionSet(perm)) { - if (permDebug) - Stargate.debug("hasPermDeep::SuperPerm", perm + " => true"); + public static boolean hasPermDeep(Player player, String permission) { + if (!player.isPermissionSet(permission)) { + if (permDebug) { + Stargate.debug("hasPermDeep::SuperPerm", permission + " => true"); + } return true; } - if (permDebug) - Stargate.debug("hasPermDeep::SuperPerms", perm + " => " + player.hasPermission(perm)); - return player.hasPermission(perm); + if (permDebug) { + Stargate.debug("hasPermDeep::SuperPerms", permission + " => " + player.hasPermission(permission)); + } + return player.hasPermission(permission); } /* @@ -309,10 +315,13 @@ public class Stargate extends JavaPlugin { boolean deny = false; // Check if player has access to this server for Bungee gates if (entrancePortal.isBungee() && !Stargate.canAccessServer(player, entrancePortal.getNetwork())) { + Stargate.debug("cannotAccessPortal", "Cannot access server"); deny = true; } else if (!Stargate.canAccessNetwork(player, entrancePortal.getNetwork())) { + Stargate.debug("cannotAccessPortal", "Cannot access network"); deny = true; - } else if (!Stargate.canAccessWorld(player, destination.getWorld().getName())) { + } else if (!entrancePortal.isBungee() && !Stargate.canAccessWorld(player, destination.getWorld().getName())) { + Stargate.debug("cannotAccessPortal", "Cannot access world"); deny = true; } return Stargate.cannotAccessPortal(player, entrancePortal, deny); diff --git a/src/main/java/net/knarcraft/stargate/listener/PlayerEventListener.java b/src/main/java/net/knarcraft/stargate/listener/PlayerEventListener.java index 5fd5c4e..8da8abc 100644 --- a/src/main/java/net/knarcraft/stargate/listener/PlayerEventListener.java +++ b/src/main/java/net/knarcraft/stargate/listener/PlayerEventListener.java @@ -155,10 +155,8 @@ public class PlayerEventListener implements Listener { if (entrancePortal.isBungee()) { if (bungeeTeleport(player, entrancePortal, event)) { Stargate.sendMessage(player, Stargate.getString("teleportMsg"), false); - return true; - } else { - return false; } + return false; } return true; } @@ -328,15 +326,18 @@ public class PlayerEventListener implements Listener { //Send the SGBungee packet first, it will be queued by BC if required if (!BungeeHelper.sendTeleportationMessage(player, entrancePortal)) { + Stargate.debug("bungeeTeleport", "Unable to send teleportation message"); return false; } // Connect player to new server if (!BungeeHelper.changeServer(player, entrancePortal)) { + Stargate.debug("bungeeTeleport", "Unable to change server"); return false; } // Close portal if required (Should never be) + Stargate.debug("bungeeTeleport", "Teleported player to another server"); entrancePortal.close(false); return true; }