Refactor tpaccept world permission checks for clarity

When mdcfe in `world_nether` sends a `/tpa` to mdcfe3 in `world` and mdcfe3 accepts:
```
[13:57:02 INFO]: mdcfe3 issued server command: /tpaccept
[...]
[13:57:02 INFO]: [Essentials] checking if mdcfe3 has essentials.tpaccept - true
[...]
[13:57:02 INFO]: [Essentials] checking if mdcfe has essentials.tpa - true
[13:57:02 INFO]: [Essentials] checking if mdcfe has essentials.worlds.world - true
```

When mdcfe in `world` sends a `/tpahere` to mdcfe3 in `world_nether` and mdcfe3 accepts:
```
[14:02:36 INFO]: mdcfe3 issued server command: /tpaccept
[...]
[14:02:36 INFO]: [Essentials] checking if mdcfe3 has essentials.tpaccept - true
[...]
[14:02:36 INFO]: [Essentials] checking if mdcfe has essentials.tpahere - true
[14:02:36 INFO]: [Essentials] checking if mdcfe3 has essentials.worlds.world - true
```
This commit is contained in:
MD 2023-04-11 14:04:52 +01:00
parent f0cdada4a9
commit ff7569c77d

View File

@ -8,6 +8,7 @@ import net.essentialsx.api.v2.events.TeleportRequestResponseEvent;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import java.util.ArrayList;
@ -87,13 +88,16 @@ public class Commandtpaccept extends EssentialsCommand {
throw new Exception(tl("noPendingRequest"));
}
if (request.isHere() && ((!requester.isAuthorized("essentials.tpahere") && !requester.isAuthorized("essentials.tpaall")) || (user.getWorld() != requester.getWorld() && ess.getSettings().isWorldTeleportPermissions() && !user.isAuthorized("essentials.worlds." + requester.getWorld().getName())))) {
if (request.isHere()) {
final boolean isRequesterAuthorized = requester.isAuthorized("essentials.tpahere") || requester.isAuthorized("essentials.tpaall");
if (!isRequesterAuthorized || !canTeleportToWorld(user, requester.getWorld())) {
throw new Exception(tl("noPendingRequest"));
}
if (!request.isHere() && (!requester.isAuthorized("essentials.tpa") || (user.getWorld() != requester.getWorld() && ess.getSettings().isWorldTeleportPermissions() && !requester.isAuthorized("essentials.worlds." + user.getWorld().getName())))) {
} else {
if (!requester.isAuthorized("essentials.tpa") || !canTeleportToWorld(requester, user.getWorld())) {
throw new Exception(tl("noPendingRequest"));
}
}
final TeleportRequestResponseEvent event = new TeleportRequestResponseEvent(user, requester, request, true);
Bukkit.getPluginManager().callEvent(event);
@ -129,4 +133,8 @@ public class Commandtpaccept extends EssentialsCommand {
}
user.removeTpaRequest(request.getName());
}
private boolean canTeleportToWorld(final User user, final World destination) {
return user.getWorld() == destination || !ess.getSettings().isWorldTeleportPermissions() || user.isAuthorized("essentials.worlds." + destination.getName());
}
}