From 278d4f84d2798c7fbe3308990a56163caeed4834 Mon Sep 17 00:00:00 2001 From: Brianna Date: Wed, 27 May 2020 09:23:29 -0500 Subject: [PATCH] Added a perm check. --- skyblock.iml | 12 --------- .../songoda/skyblock/gui/GuiPermissions.java | 27 +++++++++++++++++++ 2 files changed, 27 insertions(+), 12 deletions(-) delete mode 100644 skyblock.iml diff --git a/skyblock.iml b/skyblock.iml deleted file mode 100644 index fa63d4bf..00000000 --- a/skyblock.iml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - SPIGOT - - - - - \ No newline at end of file diff --git a/src/main/java/com/songoda/skyblock/gui/GuiPermissions.java b/src/main/java/com/songoda/skyblock/gui/GuiPermissions.java index 5262fc9c..9925d0ee 100644 --- a/src/main/java/com/songoda/skyblock/gui/GuiPermissions.java +++ b/src/main/java/com/songoda/skyblock/gui/GuiPermissions.java @@ -15,6 +15,7 @@ import com.songoda.skyblock.permission.PermissionManager; import com.songoda.skyblock.permission.PermissionType; import com.songoda.skyblock.visit.Visit; import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.entity.Player; import java.io.File; import java.util.ArrayList; @@ -140,6 +141,13 @@ public class GuiPermissions extends Gui { if (permission == null) continue; setButton(i, permission.getItem(island, role), (event) -> { + if (!hasPermission(island, event.player, role)) { + plugin.getMessageManager().sendMessage(event.player, configLoad + .getString("Command.Island.Settings.Permission.Change.Message")); + CompatibleSound.BLOCK_ANVIL_LAND.play(event.player); + + return; + } IslandPermission islandPermission = island.getPermission(role, permission); islandPermission.setStatus(!islandPermission.getStatus()); paint(); @@ -147,6 +155,25 @@ public class GuiPermissions extends Gui { } } + private boolean hasPermission(Island island, Player player, IslandRole role) { + PermissionManager permissionManager = SkyBlock.getInstance().getPermissionManager(); + if (role == IslandRole.Visitor || role == IslandRole.Member || role == IslandRole.Coop + || role == IslandRole.Owner) { + String roleName = role.name(); + + if (role == IslandRole.Owner) { + roleName = "Island"; + } + + return !island.hasRole(IslandRole.Operator, player.getUniqueId()) + || permissionManager.hasPermission(island, roleName, IslandRole.Operator); + } else if (role == IslandRole.Operator) { + return island.hasRole(IslandRole.Owner, player.getUniqueId()); + } + + return true; + } + public PermissionType getType(IslandRole role) { switch (role) { default: