Skip to content

Commit

Permalink
Add explicit bordertype command (#130)
Browse files Browse the repository at this point in the history
* Add explicit bordertype command

* Add perm to addon.yml and make it default to off

* Remove unused method.
  • Loading branch information
tastybento authored Jul 25, 2024
1 parent e00b2c9 commit aa8806a
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 23 deletions.
2 changes: 2 additions & 0 deletions src/main/java/world/bentobox/border/Border.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import world.bentobox.bentobox.api.configuration.Config;
import world.bentobox.bentobox.api.metadata.MetaDataValue;
import world.bentobox.bentobox.util.Util;
import world.bentobox.border.commands.BorderTypeCommand;
import world.bentobox.border.commands.IslandBorderCommand;
import world.bentobox.border.listeners.BorderShower;
import world.bentobox.border.listeners.PlayerListener;
Expand Down Expand Up @@ -52,6 +53,7 @@ public void onEnable() {

log("Border hooking into " + gameModeAddon.getDescription().getName());
gameModeAddon.getPlayerCommand().ifPresent(c -> new IslandBorderCommand(this, c, "border"));
gameModeAddon.getPlayerCommand().ifPresent(c -> new BorderTypeCommand(this, c, "bordertype"));
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@
*/
public final class BorderTypeCommand extends CompositeCommand {

public static final String BORDER_TYPE_COMMAND_PERM = "border.type";
private final Border addon;
private Island island;
private final List<String> availableTypes;

public BorderTypeCommand(Border addon, CompositeCommand parent) {
super(addon, parent, "type");
public BorderTypeCommand(Border addon, CompositeCommand parent, String commandLabel) {
super(addon, parent, commandLabel);
this.addon = addon;
this.availableTypes = addon.getAvailableBorderTypesView()
.stream()
Expand All @@ -35,7 +34,7 @@ public BorderTypeCommand(Border addon, CompositeCommand parent) {

@Override
public void setup() {
this.setPermission(BORDER_TYPE_COMMAND_PERM);
this.setPermission("border." + this.getLabel());
this.setDescription("border.set-type.description");
this.setOnlyPlayer(true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void setup() {
this.setOnlyPlayer(true);
setConfigurableRankCommand();

new BorderTypeCommand(this.getAddon(), this);
new BorderTypeCommand(this.getAddon(), this, "type");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import world.bentobox.bentobox.util.Util;
import world.bentobox.border.Border;
import world.bentobox.border.PerPlayerBorderProxy;
import world.bentobox.border.commands.BorderTypeCommand;
import world.bentobox.border.commands.IslandBorderCommand;

/**
Expand Down Expand Up @@ -75,16 +74,16 @@ protected void processEvent(PlayerJoinEvent e) {
// Get the game mode that this player is in
addon.getPlugin().getIWM().getAddon(e.getPlayer().getWorld()).map(gma -> gma.getPermissionPrefix()).filter(
permPrefix -> !e.getPlayer().hasPermission(permPrefix + IslandBorderCommand.BORDER_COMMAND_PERM))
.ifPresent(permPrefix -> {
// Restore barrier on/off to default
user.putMetaData(BorderShower.BORDER_STATE_META_DATA,
new MetaDataValue(addon.getSettings().isShowByDefault()));
if (!e.getPlayer().hasPermission(permPrefix + BorderTypeCommand.BORDER_TYPE_COMMAND_PERM)) {
.ifPresent(permPrefix -> {
// Restore barrier on/off to default
user.putMetaData(BorderShower.BORDER_STATE_META_DATA,
new MetaDataValue(addon.getSettings().isShowByDefault()));
if (!e.getPlayer().hasPermission(permPrefix + "border.type") && !e.getPlayer().hasPermission(permPrefix + "border.bordertype")) {
// Restore default barrier type to player
MetaDataValue metaDataValue = new MetaDataValue(addon.getSettings().getType().getId());
user.putMetaData(PerPlayerBorderProxy.BORDER_BORDERTYPE_META_DATA, metaDataValue);
}
});
});

// Show the border if required one tick after
Bukkit.getScheduler().runTask(addon.getPlugin(), () -> addon.getIslands().getIslandAt(e.getPlayer().getLocation()).ifPresent(i ->
Expand Down Expand Up @@ -215,7 +214,7 @@ private boolean outsideCheck(Player player, Location from, Location to) {
return addon.getIslands().getIslandAt(to).filter(i -> !i.onIsland(to)).isPresent();
}

/**
/**
* Runs a task while the player is mounting an entity and eject
* if the entity went outside the protection range
* @param event - event
Expand Down
5 changes: 4 additions & 1 deletion src/main/resources/addon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ permissions:
default: op
'[gamemode].border.type':
description: Player can use border type setting command
default: true
default: true
'[gamemode].bordertype':
description: Player can use bordertype command to change the border type
default: false
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.eclipse.jdt.annotation.Nullable;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -139,14 +138,7 @@ public void setUp() throws Exception {
when(addon.getSettings()).thenReturn(settings);


ic = new BorderTypeCommand(addon, ac);
}

/**
* @throws java.lang.Exception
*/
@After
public void tearDown() throws Exception {
ic = new BorderTypeCommand(addon, ac, "type");
}

/**
Expand Down

0 comments on commit aa8806a

Please sign in to comment.