Skip to content

Commit

Permalink
Improve and clean up code in VisitAddon.
Browse files Browse the repository at this point in the history
- Clean up locales
- Implement new config options:
   - GUI filters,
   - GUI border block
   - Command overwriting
   - Default member group for VISIT_CONFIG_PERMISSION
- Rename EDIT_CONFIG_FLAG to VISIT_CONFIG_PERMISSION to make it less ambiguous.
- Clean up code.
  • Loading branch information
BONNe committed Jan 3, 2021
1 parent 183bbf9 commit 3c61b22
Show file tree
Hide file tree
Showing 16 changed files with 3,034 additions and 1,053 deletions.
20 changes: 12 additions & 8 deletions src/main/java/world/bentobox/visit/VisitAddon.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ public void onLoad()
this.logError("Visit settings could not load! Addon disabled.");
this.setState(State.DISABLED);
}

// Set up flag with correct default rank permission.
VISIT_CONFIG_PERMISSION = new Flag.Builder("VISIT_CONFIG_PERMISSION", Material.DIAMOND_PICKAXE).
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 @@ -96,7 +105,7 @@ public void onEnable()
{
// Now we add GameModes to our Flags
ALLOW_VISITS_FLAG.addGameModeAddon(gameModeAddon);
EDIT_CONFIG_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 @@ -123,7 +132,7 @@ public void onEnable()

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

INSTANCE = this;
}
Expand Down Expand Up @@ -286,10 +295,5 @@ public static VisitAddon getInstance()
* 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 final static Flag EDIT_CONFIG_FLAG =
new Flag.Builder("EDIT_CONFIG_FLAG", Material.PUMPKIN_PIE).
type(Flag.Type.PROTECTION).
defaultRank(RanksManager.SUB_OWNER_RANK).
clickHandler(new CycleClick("EDIT_CONFIG_FLAG", RanksManager.MEMBER_RANK, RanksManager.OWNER_RANK)).
build();
public static Flag VISIT_CONFIG_PERMISSION;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import world.bentobox.visit.VisitAddon;
import world.bentobox.visit.panels.admin.AdminPanel;
import world.bentobox.visit.panels.player.ConfigurePanel;
import world.bentobox.visit.utils.Constants;


/**
Expand All @@ -27,7 +28,10 @@ public class VisitAdminCommand extends CompositeCommand
*/
public VisitAdminCommand(VisitAddon addon, CompositeCommand parentCommand)
{
super(addon, parentCommand, "visit");
super(addon,
parentCommand,
addon.getSettings().getAdminMainCommand().split(" ")[0],
addon.getSettings().getAdminMainCommand().split(" "));
}


Expand All @@ -46,8 +50,8 @@ public VisitAdminCommand(VisitAddon addon, CompositeCommand parentCommand)
public void setup()
{
this.setPermission("admin.visit");
this.setParametersHelp("visit.commands.admin.main.parameters");
this.setDescription("visit.commands.admin.main.description");
this.setParametersHelp(Constants.ADMIN_COMMANDS + "main.parameters");
this.setDescription(Constants.ADMIN_COMMANDS + "main.description");

this.setOnlyPlayer(true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
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;


/**
Expand All @@ -23,7 +24,10 @@ public class VisitConfigureCommand extends CompositeCommand
*/
public VisitConfigureCommand(VisitAddon addon, CompositeCommand parentCommand)
{
super(addon, parentCommand, "configure");
super(addon,
parentCommand,
addon.getSettings().getPlayerConfigureCommand().split(" ")[0],
addon.getSettings().getPlayerConfigureCommand().split(" "));
}


Expand All @@ -42,8 +46,8 @@ public VisitConfigureCommand(VisitAddon addon, CompositeCommand parentCommand)
public void setup()
{
this.setPermission("configure");
this.setParametersHelp("visit.commands.player.configure.parameters");
this.setDescription("visit.commands.player.configure.description");
this.setParametersHelp(Constants.PLAYER_COMMANDS + "configure.parameters");
this.setDescription(Constants.PLAYER_COMMANDS + "configure.description");

this.setOnlyPlayer(true);
}
Expand Down Expand Up @@ -72,7 +76,7 @@ public boolean canExecute(User user, String label, List<String> args)
return false;
}

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


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import world.bentobox.bentobox.util.Util;
import world.bentobox.visit.VisitAddon;
import world.bentobox.visit.panels.player.VisitPanel;
import world.bentobox.visit.utils.Constants;


/**
Expand All @@ -28,7 +29,10 @@ public class VisitPlayerCommand extends DelayedTeleportCommand
*/
public VisitPlayerCommand(VisitAddon addon, CompositeCommand parentCommand)
{
super(addon, parentCommand, "visit");
super(addon,
parentCommand,
addon.getSettings().getPlayerMainCommand().split(" ")[0],
addon.getSettings().getPlayerMainCommand().split(" "));
}


Expand All @@ -47,8 +51,8 @@ public VisitPlayerCommand(VisitAddon addon, CompositeCommand parentCommand)
public void setup()
{
this.setPermission("visit");
this.setParametersHelp("visit.commands.player.main.parameters");
this.setDescription("visit.commands.player.main.description");
this.setParametersHelp(Constants.PLAYER_COMMANDS + "main.parameters");
this.setDescription(Constants.PLAYER_COMMANDS + "main.description");

new VisitConfigureCommand(this.getAddon(), this);

Expand Down

0 comments on commit 3c61b22

Please sign in to comment.