Skip to content

Commit

Permalink
Switch from FLAG to the RANKED COMMAND.
Browse files Browse the repository at this point in the history
Remove VISIT_CONFIG_PERMISSION flag and switch to RANKED COMMAND feature that is underutilized currently in BentoBox core.
Using RANKED COMMAND makes more sense than separate flag.
  • Loading branch information
BONNe committed Feb 3, 2022
1 parent 3c01559 commit 00cc417
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 45 deletions.
19 changes: 0 additions & 19 deletions src/main/java/world/bentobox/visit/VisitAddon.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
import world.bentobox.bentobox.api.addons.Addon;
import world.bentobox.bentobox.api.configuration.Config;
import world.bentobox.bentobox.api.flags.Flag;
import world.bentobox.bentobox.api.flags.clicklisteners.CycleClick;
import world.bentobox.bentobox.hooks.VaultHook;
import world.bentobox.bentobox.managers.RanksManager;
import world.bentobox.visit.commands.admin.VisitAdminCommand;
import world.bentobox.visit.commands.player.VisitPlayerCommand;
import world.bentobox.visit.configs.Settings;
Expand Down Expand Up @@ -56,15 +54,6 @@ public void onLoad()

// Save existing panels.
this.saveResource("panels/main_panel.yml", false);

// Set up flag with correct default rank permission.
VISIT_CONFIG_PERMISSION = new Flag.Builder("VISIT_CONFIG_PERMISSION", Material.PUMPKIN).
type(Flag.Type.PROTECTION).
defaultRank(this.settings.getDefaultConfigPermission()).
clickHandler(new CycleClick("VISIT_CONFIG_PERMISSION",
RanksManager.MEMBER_RANK,
RanksManager.OWNER_RANK)).
build();
}


Expand Down Expand Up @@ -109,7 +98,6 @@ public void onEnable()
{
// Now we add GameModes to our Flags
ALLOW_VISITS_FLAG.addGameModeAddon(gameModeAddon);
VISIT_CONFIG_PERMISSION.addGameModeAddon(gameModeAddon);

// Each GameMode could have Player Command and Admin Command and we could
// want to integrate our Visit Command into these commands.
Expand All @@ -136,7 +124,6 @@ public void onEnable()

ALLOW_VISITS_FLAG.setDefaultSetting(this.settings.isDefaultVisitingEnabled());
this.registerFlag(ALLOW_VISITS_FLAG);
this.registerFlag(VISIT_CONFIG_PERMISSION);

INSTANCE = this;
}
Expand Down Expand Up @@ -325,12 +312,6 @@ public static VisitAddon getInstance()
*/
private static VisitAddon INSTANCE;

/**
* This flag allows to change who have access to modify island visitor config option. Owner can change it from
* member rank till owner rank. Default value is set to subowner.
*/
public static Flag VISIT_CONFIG_PERMISSION;

/**
* Settings flags allows to modifying parameters of the island.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@
package world.bentobox.visit.commands.player;


import org.bukkit.Location;
import org.bukkit.event.entity.ItemSpawnEvent;
import java.util.List;
import java.util.Optional;

import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
Expand Down Expand Up @@ -59,6 +55,8 @@ public void setup()
this.setDescription(Constants.PLAYER_COMMANDS + "configure.description");

this.setOnlyPlayer(true);
this.setConfigurableRankCommand();
this.setDefaultCommandRank(this.<VisitAddon>getAddon().getSettings().getDefaultConfigPermission());
}


Expand All @@ -85,7 +83,7 @@ public boolean canExecute(User user, String label, List<String> args)
return false;
}

return island.isAllowed(user, VisitAddon.VISIT_CONFIG_PERMISSION);
return true;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@
import java.util.List;

import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.visit.VisitAddon;
import world.bentobox.visit.panels.player.ConfigurePanel;
import world.bentobox.visit.utils.Constants;
import world.bentobox.visit.utils.Utils;

Expand Down Expand Up @@ -58,6 +56,8 @@ public void setup()
this.setDescription(Constants.PLAYER_COMMANDS + "set-location.description");

this.setOnlyPlayer(true);
this.setConfigurableRankCommand();
this.setDefaultCommandRank(this.<VisitAddon>getAddon().getSettings().getDefaultConfigPermission());
}


Expand All @@ -84,16 +84,7 @@ public boolean canExecute(User user, String label, List<String> args)
user.sendMessage("general.errors.no-island");
return false;
}
else if (!island.isAllowed(user, VisitAddon.VISIT_CONFIG_PERMISSION))
{
// No permission to edit.
Utils.sendMessage(user, user.getTranslation("general.errors.insufficient-rank",
TextVariables.RANK,
user.getTranslation(this.getPlugin().getRanksManager().
getRank(VisitAddon.VISIT_CONFIG_PERMISSION.getDefaultRank()))));
return false;
}
else if (user.getLocation() == null || !World.Environment.NORMAL.equals(user.getWorld().getEnvironment()))
else if (!World.Environment.NORMAL.equals(user.getWorld().getEnvironment()))
{
// User must be in overworld.
Utils.sendMessage(user, user.getTranslation(Constants.ERRORS + "not-in-overworld"));
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/addon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ main: world.bentobox.visit.VisitAddon
# Version of your addon. Can use maven variables.
version: ${version}
# API version allows to specify minimal BentoBox version for your addon.
api-version: ${bentobox.version}
api-version: 1.20.0
# Allow to send metric about this addon usage.
metrics: true
# GitHub version check. Will work only for GitHub.
Expand Down
9 changes: 1 addition & 8 deletions src/main/resources/locales/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -333,11 +333,4 @@ protection:
&a Toggle if island can be
&a visited by anyone.
hint: "&c Visits are disabled in this island"
icon: PUMPKIN_PIE
VISIT_CONFIG_PERMISSION:
name: "Manage visitor config"
description: |-
&a Allows to switch who
&a can edit island visitor
&a configuration.
icon: PUMPKIN
icon: PUMPKIN_PIE

0 comments on commit 00cc417

Please sign in to comment.