Implement a flag that rules all flags. (#1927)

Add new Protection Flag: CHANGE_SETTINGS. This flag allows set which rank can change island settings. By default, it is set to OWNER rank and minimal value is MEMBER rank.

Fixes #1493
This commit is contained in:
BONNe 2022-01-29 04:45:50 +02:00 committed by GitHub
parent 90ebe103c4
commit 09ab327551
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 114 additions and 55 deletions

View File

@ -4,6 +4,8 @@ import org.bukkit.Bukkit;
import org.bukkit.Sound;
import org.bukkit.event.inventory.ClickType;
import java.util.Objects;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.addons.GameModeAddon;
import world.bentobox.bentobox.api.events.flags.FlagProtectionChangeEvent;
@ -13,6 +15,7 @@ import world.bentobox.bentobox.api.panels.PanelItem;
import world.bentobox.bentobox.api.panels.TabbedPanel;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.lists.Flags;
import world.bentobox.bentobox.managers.RanksManager;
import world.bentobox.bentobox.panels.settings.SettingsTab;
import world.bentobox.bentobox.util.Util;
@ -75,7 +78,7 @@ public class CycleClick implements PanelItem.ClickHandler {
// Left clicking increases the rank required
// Right clicking decreases the rank required
// Shift Left Click toggles player visibility
if (island != null && (user.isOp() || user.getUniqueId().equals(island.getOwner()) || user.hasPermission(prefix + "admin.settings"))) {
if (island != null && (user.isOp() || island.isAllowed(user, Flags.CHANGE_SETTINGS) || user.hasPermission(prefix + "admin.settings"))) {
changeOccurred = true;
RanksManager rm = plugin.getRanksManager();
plugin.getFlagsManager().getFlag(id).ifPresent(flag -> {
@ -124,8 +127,16 @@ public class CycleClick implements PanelItem.ClickHandler {
}
});
} else {
// Player is not the owner of the island.
user.sendMessage("general.errors.not-owner");
if (island == null) {
// Island is not targeted.
user.sendMessage("general.errors.not-on-island");
} else {
// Player is not the allowed to change settings.
user.sendMessage("general.errors.insufficient-rank",
TextVariables.RANK,
user.getTranslation(plugin.getRanksManager().getRank(Objects.requireNonNull(island).getRank(user))));
}
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_METAL_HIT, 1F, 1F);
}
return true;

View File

@ -4,6 +4,8 @@ import org.bukkit.Bukkit;
import org.bukkit.Sound;
import org.bukkit.event.inventory.ClickType;
import java.util.Objects;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.addons.GameModeAddon;
import world.bentobox.bentobox.api.events.flags.FlagSettingChangeEvent;
@ -13,6 +15,7 @@ import world.bentobox.bentobox.api.panels.PanelItem.ClickHandler;
import world.bentobox.bentobox.api.panels.TabbedPanel;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.lists.Flags;
import world.bentobox.bentobox.panels.settings.SettingsTab;
import world.bentobox.bentobox.util.Util;
@ -51,21 +54,30 @@ public class IslandToggleClick implements ClickHandler {
}
// Get the island for this tab
Island island = st.getIsland();
if (island != null && (user.isOp() || user.getUniqueId().equals(island.getOwner()) || user.hasPermission(prefix + "admin.settings"))) {
plugin.getFlagsManager().getFlag(id).ifPresent(flag -> {
if (click.equals(ClickType.SHIFT_LEFT) && user.isOp()) {
if (!plugin.getIWM().getHiddenFlags(user.getWorld()).contains(flag.getID())) {
if (island != null && (user.isOp() || island.isAllowed(user, Flags.CHANGE_SETTINGS) || user.hasPermission(prefix + "admin.settings")))
{
plugin.getFlagsManager().getFlag(id).ifPresent(flag ->
{
if (click.equals(ClickType.SHIFT_LEFT) && user.isOp())
{
if (!plugin.getIWM().getHiddenFlags(user.getWorld()).contains(flag.getID()))
{
plugin.getIWM().getHiddenFlags(user.getWorld()).add(flag.getID());
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_GLASS_BREAK, 1F, 1F);
} else {
}
else
{
plugin.getIWM().getHiddenFlags(user.getWorld()).remove(flag.getID());
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_NOTE_BLOCK_CHIME, 1F, 1F);
}
// Save changes
plugin.getIWM().getAddon(user.getWorld()).ifPresent(GameModeAddon::saveWorldSettings);
} else {
}
else
{
// Check cooldown
if (!user.isOp() && island.isCooldown(flag)) {
if (!user.isOp() && island.isCooldown(flag))
{
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_BEACON_DEACTIVATE, 1F, 1F);
user.notify("protection.panel.flag-item.setting-cooldown");
return;
@ -76,17 +88,32 @@ public class IslandToggleClick implements ClickHandler {
// Set cooldown
island.setCooldown(flag);
// Fire event
Bukkit.getPluginManager().callEvent(new FlagSettingChangeEvent(island, user.getUniqueId(), flag, island.isAllowed(flag)));
Bukkit.getPluginManager().callEvent(new FlagSettingChangeEvent(island,
user.getUniqueId(),
flag,
island.isAllowed(flag)));
if (flag.hasSubflags()) {
if (flag.hasSubflags())
{
// Fire events for all subflags as well
flag.getSubflags().forEach(subflag -> Bukkit.getPluginManager().callEvent(new FlagSettingChangeEvent(island, user.getUniqueId(), subflag, island.isAllowed(subflag))));
flag.getSubflags().forEach(subflag -> Bukkit.getPluginManager()
.callEvent(new FlagSettingChangeEvent(island,
user.getUniqueId(),
subflag,
island.isAllowed(subflag))));
}
}
});
} else {
// Player is not the owner of the island.
user.sendMessage("general.errors.not-owner");
if (island == null) {
user.sendMessage("general.errors.not-on-island");
} else {
// Player is not the allowed to change settings.
user.sendMessage("general.errors.insufficient-rank",
TextVariables.RANK,
user.getTranslation(plugin.getRanksManager().getRank(Objects.requireNonNull(island).getRank(user))));
}
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_METAL_HIT, 1F, 1F);
}
return true;

View File

@ -9,6 +9,7 @@ import world.bentobox.bentobox.api.panels.Panel;
import world.bentobox.bentobox.api.panels.PanelItem.ClickHandler;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.lists.Flags;
import world.bentobox.bentobox.managers.RanksManager;
/**
@ -36,7 +37,7 @@ public class CommandCycleClick implements ClickHandler {
// Get the user's island for the game world
World world = panel.getWorld().orElse(user.getWorld());
Island island = plugin.getIslands().getIsland(world, user.getUniqueId());
if (island != null && island.getOwner() != null && island.getOwner().equals(user.getUniqueId())) {
if (island != null && island.getOwner() != null && island.isAllowed(user, Flags.CHANGE_SETTINGS)) {
RanksManager rm = plugin.getRanksManager();
int currentRank = island.getRankCommand(command);
if (click.equals(ClickType.LEFT)) {

View File

@ -57,8 +57,11 @@ public class CommandRankClickListener implements ClickHandler {
// Get the user's island
Island island = plugin.getIslands().getIsland(panel.getWorld().orElse(user.getWorld()), user.getUniqueId());
if (island == null || island.getOwner() == null || !island.getOwner().equals(user.getUniqueId())) {
user.sendMessage("general.errors.not-owner");
if (island == null || island.getOwner() == null || !island.isAllowed(user, Flags.CHANGE_SETTINGS)) {
user.sendMessage("general.errors.insufficient-rank",
TextVariables.RANK,
user.getTranslation(plugin.getRanksManager().getRank(Objects.requireNonNull(island).getRank(user))));
user.getPlayer().playSound(user.getLocation(), Sound.BLOCK_METAL_HIT, 1F, 1F);
return true;
}

View File

@ -304,6 +304,16 @@ public final class Flags {
.clickHandler(new CycleClick("LOCK", RanksManager.VISITOR_RANK, RanksManager.MEMBER_RANK))
.mode(Flag.Mode.TOP_ROW).build();
/**
* This flag allows choosing which island members can change island settings values.
*
* @since 1.20.0
*/
public static final Flag CHANGE_SETTINGS = new Flag.Builder("CHANGE_SETTINGS", Material.CRAFTING_TABLE).defaultSetting(true)
.defaultRank(RanksManager.OWNER_RANK)
.clickHandler(new CycleClick("CHANGE_SETTINGS", RanksManager.MEMBER_RANK, RanksManager.OWNER_RANK))
.mode(Flag.Mode.TOP_ROW).build();
/*
* Settings flags (not protection flags)
*/

View File

@ -132,6 +132,7 @@ public class SettingsTab implements Tab, ClickHandler {
Map<Integer, PanelItem> icons = new HashMap<>();
// Add the lock icon - we want it to be displayed no matter the tab
if (island != null) {
icons.put(4, Flags.CHANGE_SETTINGS.toPanelItem(plugin, user, island, false));
icons.put(5, Flags.LOCK.toPanelItem(plugin, user, island, false));
}
// Add the mode icon

View File

@ -37,6 +37,7 @@ general:
wrong-world: "&c You are not in the right world to do that!"
you-must-wait: "&c You must wait [number]s before you can do that command again."
must-be-positive-number: "&c [number] is not a valid positive number."
not-on-island: "&c You are not on island!"
worlds:
overworld: "Overworld"
nether: "Nether"
@ -75,7 +76,7 @@ commands:
parameters: "<player> <resets>"
success: "&a Successfully removed &b [number] &a resets to &b [name], decreasing the total to &b [total]&a resets."
purge:
parameters: "[days]"
parameters: "[days]"
description: "purge islands abandoned for more than [days]"
days-one-or-more: "Must be at least 1 day or more"
purgable-islands: "&a Found &b [number] &a purgable islands."
@ -99,7 +100,7 @@ commands:
status:
description: "displays the status of the purge"
status: "&b [purged] &a islands purged out of &b [purgeable] &7(&b[percentage] %&7)&a."
team:
add:
parameters: "<owner> <player>"
@ -460,7 +461,7 @@ commands:
addons: "[prefix_bentobox]&6 Migrating addons"
class: "[prefix_bentobox]&6 Migrating [description]"
migrated: "[prefix_bentobox]&a Migrated"
confirmation:
confirm: "&c Type command again within &b [seconds]s&c to confirm."
previous-request-cancelled: "&6 Previous confirmation request cancelled."
@ -725,7 +726,7 @@ ranks:
banned: "Banned"
admin: "Admin"
mod: "Mod"
protection:
command-is-banned: "Command is banned for visitors"
flags:
@ -735,19 +736,19 @@ protection:
ANIMAL_SPAWNERS_SPAWN:
description: "Toggle animal spawning with spawners"
name: "Animal spawners"
ANVIL:
ANVIL:
description: "Toggle interaction"
name: "Anvils"
hint: "Anvil use disabled"
ARMOR_STAND:
ARMOR_STAND:
description: "Toggle interaction"
name: "Armor stands"
hint: "Armor stand use disabled"
BEACON:
BEACON:
description: "Toggle interaction"
name: "Beacons"
hint: "Beacon use disabled"
BED:
BED:
description: "Toggle interaction"
name: "Beds"
hint: "Bed use disabled"
@ -757,7 +758,7 @@ protection:
Toggle placing, breaking and
entering into boats.
hint: "No boat interaction allowed"
BREAK_BLOCKS:
BREAK_BLOCKS:
description: "Toggle breaking"
name: "Break blocks"
hint: "Block breaking disabled"
@ -773,19 +774,19 @@ protection:
Overrides the Break Blocks flag.
name: "Break hoppers"
hint: "Hoppers breaking disabled"
BREEDING:
BREEDING:
description: "Toggle breeding"
name: "Breed animals"
hint: "Animal breeding protected"
BREWING:
BREWING:
description: "Toggle interaction"
name: "Brewing stands"
hint: "Brewing disabled"
BUCKET:
BUCKET:
description: "Toggle interaction"
name: "Buckets"
hint: "Bucket use disabled"
BUTTON:
BUTTON:
description: "Toggle button use"
name: "Buttons"
hint: "Button use disabled"
@ -858,7 +859,7 @@ protection:
CHEST_DAMAGE:
description: "Toggle chest damage from explosions"
name: "Chest Damage"
CHORUS_FRUIT:
CHORUS_FRUIT:
description: "Toggle teleportation"
name: "Chorus fruits"
hint: "Chorus fruit teleporting disabled"
@ -875,13 +876,13 @@ protection:
&a to obtain dirt
name: "Coarse dirt tilling"
hint: "No coarse dirt tilling"
COLLECT_LAVA:
COLLECT_LAVA:
description: |-
&a Toggle collecting lava
&a (override Buckets)
name: "Collect lava"
hint: "No lava collection"
COLLECT_WATER:
COLLECT_WATER:
description: |-
&a Toggle collecting water
&a (override Buckets)
@ -890,7 +891,7 @@ protection:
COMMAND_RANKS:
name: "&e Command Ranks"
description: "&a Configure command ranks"
CRAFTING:
CRAFTING:
description: "Toggle use"
name: "Workbenches"
hint: "Workbench access disabled"
@ -906,11 +907,11 @@ protection:
&a by island visitor.
name: "Creeper griefing protection"
hint: "Creeper griefing disabled"
CROP_TRAMPLE:
CROP_TRAMPLE:
description: "Toggle crop trampling"
name: "Trample crops"
hint: "Crop trampling disabled"
DOOR:
DOOR:
description: "Toggle door usage"
name: "Use doors"
hint: "Door interaction disabled"
@ -926,7 +927,7 @@ protection:
description: "Prevent dye use"
name: "Dye use"
hint: "Dyeing disabled"
EGGS:
EGGS:
description: "Toggle egg throwing"
name: "Egg throwing"
hint: "Egg throwing disabled"
@ -938,22 +939,22 @@ protection:
description: "Toggle use/crafting"
name: "Ender Chests"
hint: "Ender chests are disabled in this world"
ENDERMAN_DEATH_DROP:
ENDERMAN_DEATH_DROP:
description: |-
&a Endermen will drop
&a any block they are
&a holding if killed.
name: "Enderman Death Drop"
ENDERMAN_GRIEFING:
ENDERMAN_GRIEFING:
description: |-
&a Endermen can remove
&a blocks from islands
name: "Enderman griefing"
ENDER_PEARL:
ENDER_PEARL:
description: "Toggle use"
name: "EnderPearls"
hint: "Enderpearl use disabled"
ENTER_EXIT_MESSAGES:
ENTER_EXIT_MESSAGES:
description: "Display entry and exit messages"
island: "[name]'s island"
name: "Enter/Exit messages"
@ -970,7 +971,7 @@ protection:
description: |-
&a Toggle whether fire can burn
&a blocks or not.
FIRE_EXTINGUISH:
FIRE_EXTINGUISH:
description: "Toggle extinguishing fires"
name: "Fire extinguish"
hint: "Extinguishing fire disabled"
@ -995,15 +996,15 @@ protection:
&a campfires using flint and steel
&a or fire charges.
hint: "Flint and steel and fire charges disabled"
FURNACE:
FURNACE:
description: "Toggle use"
name: "Furnace"
hint: "Furnace use disabled"
GATE:
GATE:
description: "Toggle use"
name: "Gates"
hint: "Gate use disabled"
GEO_LIMIT_MOBS:
GEO_LIMIT_MOBS:
description: |-
&a Remove mobs that go
&a outside protected
@ -1014,15 +1015,15 @@ protection:
&a Toggle hive harvesting.
name: "Hive harvesting"
hint: "Harvesting disabled"
HURT_ANIMALS:
HURT_ANIMALS:
description: "Toggle hurting"
name: "Hurt animals"
hint: "Animal hurting disabled"
HURT_MONSTERS:
HURT_MONSTERS:
description: "Toggle hurting"
name: "Hurt monsters"
hint: "Monster hurting disabled"
HURT_VILLAGERS:
HURT_VILLAGERS:
description: "Toggle hurting"
name: "Hurt villagers"
hint: "Villager hurting disabled"
@ -1037,7 +1038,7 @@ protection:
&a Mobs can damage
&a item frames
name: "Item Frame Damage"
INVINCIBLE_VISITORS:
INVINCIBLE_VISITORS:
description: |-
&a Configure invincible visitor
&a settings.
@ -1048,11 +1049,11 @@ protection:
&a Players respawn
&a on island
name: "Island respawn"
ITEM_DROP:
ITEM_DROP:
description: "Toggle dropping"
name: "Item drop"
hint: "Item dropping disabled"
ITEM_PICKUP:
ITEM_PICKUP:
description: "Toggle pickup"
name: "Item pickup"
hint: "Item pickup disabled"
@ -1063,7 +1064,7 @@ protection:
LEAF_DECAY:
name: "Leaf decay"
description: "Allow leaves to naturally decay"
LEASH:
LEASH:
description: "Toggle use"
name: "Leash use"
LECTERN:
@ -1079,7 +1080,7 @@ protection:
description: "Toggle use"
name: "Lever use"
hint: "Lever use disabled"
LIMIT_MOBS:
LIMIT_MOBS:
description: |-
&a Limit entities from
&a spawning in this game
@ -1100,9 +1101,14 @@ protection:
&c They will also not spread horizontally if
&c they are placed outside an island's
&c protection range.
LOCK:
LOCK:
description: "Toggle lock"
name: "Lock island"
CHANGE_SETTINGS:
name: "Change Settings"
description: |-
&a Allow to switch which member
&a role can change island settings.
MILKING:
description: "Toggle cow milking"
name: "Milking"