diff --git a/src/main/java/world/bentobox/bentobox/api/flags/clicklisteners/CycleClick.java b/src/main/java/world/bentobox/bentobox/api/flags/clicklisteners/CycleClick.java index 4c6213c86..9df28464e 100644 --- a/src/main/java/world/bentobox/bentobox/api/flags/clicklisteners/CycleClick.java +++ b/src/main/java/world/bentobox/bentobox/api/flags/clicklisteners/CycleClick.java @@ -4,7 +4,6 @@ import org.bukkit.Sound; import org.bukkit.event.inventory.ClickType; import world.bentobox.bentobox.BentoBox; -import world.bentobox.bentobox.api.flags.Flag; import world.bentobox.bentobox.api.localization.TextVariables; import world.bentobox.bentobox.api.panels.Panel; import world.bentobox.bentobox.api.panels.PanelItem; @@ -72,25 +71,26 @@ public class CycleClick implements PanelItem.ClickHandler { if (island != null && user.getUniqueId().equals(island.getOwner())) { changeOccurred = true; RanksManager rm = plugin.getRanksManager(); - Flag flag = plugin.getFlagsManager().getFlag(id).orElse(null); - int currentRank = island.getFlag(flag); - if (click.equals(ClickType.LEFT)) { - if (currentRank >= maxRank) { - island.setFlag(flag, minRank); - } else { - island.setFlag(flag, rm.getRankUpValue(currentRank)); + plugin.getFlagsManager().getFlag(id).ifPresent(flag -> { + int currentRank = island.getFlag(flag); + if (click.equals(ClickType.LEFT)) { + if (currentRank >= maxRank) { + island.setFlag(flag, minRank); + } else { + island.setFlag(flag, rm.getRankUpValue(currentRank)); + } + user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_STONE_BUTTON_CLICK_ON, 1F, 1F); + } else if (click.equals(ClickType.RIGHT)) { + if (currentRank <= minRank) { + island.setFlag(flag, maxRank); + } else { + island.setFlag(flag, rm.getRankDownValue(currentRank)); + } + user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_STONE_BUTTON_CLICK_ON, 1F, 1F); } - user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_STONE_BUTTON_CLICK_ON, 1F, 1F); - } else if (click.equals(ClickType.RIGHT)) { - if (currentRank <= minRank) { - island.setFlag(flag, maxRank); - } else { - island.setFlag(flag, rm.getRankDownValue(currentRank)); - } - user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_STONE_BUTTON_CLICK_ON, 1F, 1F); - } - // Apply change to panel - panel.getInventory().setItem(slot, flag.toPanelItem(plugin, user).getItem()); + // Apply change to panel + panel.getInventory().setItem(slot, flag.toPanelItem(plugin, user).getItem()); + }); } else { user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_METAL_HIT, 1F, 1F); } diff --git a/src/main/java/world/bentobox/bentobox/api/flags/clicklisteners/IslandToggleClick.java b/src/main/java/world/bentobox/bentobox/api/flags/clicklisteners/IslandToggleClick.java index 3194600f9..e5f996903 100644 --- a/src/main/java/world/bentobox/bentobox/api/flags/clicklisteners/IslandToggleClick.java +++ b/src/main/java/world/bentobox/bentobox/api/flags/clicklisteners/IslandToggleClick.java @@ -4,7 +4,6 @@ import org.bukkit.Sound; import org.bukkit.event.inventory.ClickType; import world.bentobox.bentobox.BentoBox; -import world.bentobox.bentobox.api.flags.Flag; import world.bentobox.bentobox.api.localization.TextVariables; import world.bentobox.bentobox.api.panels.Panel; import world.bentobox.bentobox.api.panels.PanelItem.ClickHandler; @@ -45,12 +44,13 @@ public class IslandToggleClick implements ClickHandler { // Get the user's island Island island = plugin.getIslands().getIsland(user.getWorld(), user); if (island != null && user.getUniqueId().equals(island.getOwner())) { - Flag flag = plugin.getFlagsManager().getFlag(id).orElse(null); - // Toggle flag - island.toggleFlag(flag); - user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_STONE_BUTTON_CLICK_ON, 1F, 1F); - // Apply change to panel - panel.getInventory().setItem(slot, flag.toPanelItem(plugin, user).getItem()); + plugin.getFlagsManager().getFlag(id).ifPresent(flag -> { + // Toggle flag + island.toggleFlag(flag); + user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_STONE_BUTTON_CLICK_ON, 1F, 1F); + // Apply change to panel + panel.getInventory().setItem(slot, flag.toPanelItem(plugin, user).getItem()); + }); } else { user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_METAL_HIT, 1F, 1F); } diff --git a/src/main/java/world/bentobox/bentobox/api/flags/clicklisteners/WorldToggleClick.java b/src/main/java/world/bentobox/bentobox/api/flags/clicklisteners/WorldToggleClick.java index 1222eef54..88dbba168 100644 --- a/src/main/java/world/bentobox/bentobox/api/flags/clicklisteners/WorldToggleClick.java +++ b/src/main/java/world/bentobox/bentobox/api/flags/clicklisteners/WorldToggleClick.java @@ -4,7 +4,6 @@ import org.bukkit.Sound; import org.bukkit.event.inventory.ClickType; import world.bentobox.bentobox.BentoBox; -import world.bentobox.bentobox.api.flags.Flag; import world.bentobox.bentobox.api.localization.TextVariables; import world.bentobox.bentobox.api.panels.Panel; import world.bentobox.bentobox.api.panels.PanelItem.ClickHandler; @@ -42,12 +41,13 @@ public class WorldToggleClick implements ClickHandler { return true; } // Get flag - Flag flag = plugin.getFlagsManager().getFlag(id).orElse(null); - // Toggle flag - flag.setSetting(user.getWorld(), !flag.isSetForWorld(user.getWorld())); - user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_STONE_BUTTON_CLICK_ON, 1F, 1F); - // Apply change to panel - panel.getInventory().setItem(slot, flag.toPanelItem(plugin, user).getItem()); + plugin.getFlagsManager().getFlag(id).ifPresent(flag -> { + // Toggle flag + flag.setSetting(user.getWorld(), !flag.isSetForWorld(user.getWorld())); + user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_STONE_BUTTON_CLICK_ON, 1F, 1F); + // Apply change to panel + panel.getInventory().setItem(slot, flag.toPanelItem(plugin, user).getItem()); + }); return true; }