Skip to content

Commit

Permalink
Added possibility to prevent players from doing the fly command outsi…
Browse files Browse the repository at this point in the history
…de (#59)

of the island protection range.

Co-authored-by: tastybento <tastybento@users.noreply.github.com>
  • Loading branch information
PapiCapi and tastybento committed Jul 8, 2021
1 parent f1f7850 commit b568f9c
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 10 deletions.
16 changes: 15 additions & 1 deletion src/main/java/world/bentobox/islandfly/FlyToggleCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,24 @@
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.util.Util;
import world.bentobox.islandfly.config.Settings;


/**
* This command allows to enable and disable fly mode.
*/
public class FlyToggleCommand extends CompositeCommand {


private Settings settings;

/**
* Default constructor
* @param parent Instance of CompositeCommand
*/
public FlyToggleCommand(CompositeCommand parent) {
public FlyToggleCommand(CompositeCommand parent, IslandFlyAddon addon) {
super(parent, "fly");
this.settings = addon.getSettings();
}


Expand Down Expand Up @@ -55,6 +61,14 @@ public boolean canExecute(User user, String label, List<String> args) {
user.sendMessage("islandfly.command.not-allowed-fly");
return false;
}


if ( !this.settings.isAllowCommandOutsideProtectionRange() && !island.getProtectionBoundingBox().contains(user.getLocation().toVector())) {

user.sendMessage("islandfly.outside-protection-range");
return false;

}


return true;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/world/bentobox/islandfly/IslandFlyAddon.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void onEnable() {

gameModeAddon.getPlayerCommand().ifPresent(
playerCommand -> {
new FlyToggleCommand(playerCommand);
new FlyToggleCommand(playerCommand, this);
hooked = true;
});

Expand Down
29 changes: 29 additions & 0 deletions src/main/java/world/bentobox/islandfly/config/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,30 @@ public void setDisabledGameModes(Set<String> disabledGameModes)
{
this.disabledGameModes = disabledGameModes;
}




/**
* Method Settings#isFlyDisableOnLogout returns the flyDisableOnLogout of this object.
*
* @return the flyDisableOnLogout (type boolean) of this object.
*/
public boolean isAllowCommandOutsideProtectionRange()
{
return allowCommandOutsideProtectionRange;
}


/**
* Method Settings#setFlyDisableOnLogout sets new value for the flyDisableOnLogout of this object.
* @param flyDisableOnLogout new value for this object.
*
*/
public void setAllowCommandOutsideProtectionRange(boolean commandAllowed)
{
this.allowCommandOutsideProtectionRange = commandAllowed;
}


// ---------------------------------------------------------------------
Expand All @@ -125,4 +149,9 @@ public void setDisabledGameModes(Set<String> disabledGameModes)
@ConfigComment(" - BSkyBlock")
@ConfigEntry(path = "disabled-gamemodes")
private Set<String> disabledGameModes = new HashSet<>();

@ConfigComment("")
@ConfigComment("This allows the player to use the command outside the island protection range.")
@ConfigEntry(path = "allow-command-outside-protection-range")
private boolean allowCommandOutsideProtectionRange = false;
}
3 changes: 3 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ logout-disable-fly: false
# disabled-gamemodes:
# - BSkyBlock
disabled-gamemodes: []

#This allows the player to use the command outside the island protection range.
allow-command-outside-protection-range: false
1 change: 1 addition & 0 deletions src/main/resources/locales/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ islandfly:
enable-fly: "&a Your fly mode has been enabled."
cancel-disable: "&a You are back, huh! Fly fuel successfully refilled!"
wrong-world: "&c You are not in the right gamemode world"
outside-protection-range: "&c You are not allowed to do that outside your island protection range"
command:
description: "allows you to fly on your island"
not-allowed-fly: "&c You are not allowed to fly on this island"
Expand Down
11 changes: 5 additions & 6 deletions src/main/resources/locales/fr.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
---
islandfly:
fly-outside-alert: "&cVous êtes hors de votre île, vous ne pourrez plus voler dans
&e[number]&c secondes."
fly-turning-off-alert: "&c Vous n'êtes plus autorisé à voler ici. Désactivation
de fly en &e [number] &c secondes."
fly-turning-off-alert: "&c Vous n'êtes plus autorisé à voler ici. Désactivation du vol dans &e [number] &c secondes."
reallowed-fly: "&a Vous pouvez de nouveau voler"
outside-protection-range: "&c Tu ne peux pas faire ça en dehors de la zone de protection de ton île"
fly-outside-alert: "&cVous êtes hors de votre île, vous ne pourrez plus voler dans &e[number]&c secondes."
disable-fly: "&cVous ne pouvez plus voler."
reallowed-fly: "& a Votre mouche a été réaffectée"
enable-fly: "&aVous pouvez désormais voler."
cancel-disable: "&aVous êtes de retour sur votre île ! Vous pouvez continuer à voler."
wrong-world: "&cVous n'êtes pas dans le bon monde de mode de jeu."
Expand All @@ -17,4 +16,4 @@ protection:
flags:
ISLAND_FLY_PROTECTION:
description: "&a Toggle qui peut voler sur votre île"
name: "&a Prévention des mouches"
name: "&a Interdiction du vol"
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public void setUp() throws Exception {
Optional<Island> opIsland = Optional.of(island);
when(im.getIslandAt(any())).thenReturn(opIsland);

ftc = new FlyToggleCommand(ic);
ftc = new FlyToggleCommand(ic, addon);
}

/**
Expand Down Expand Up @@ -203,7 +203,7 @@ public void testCanExecuteFlagAllowed() {
/**
* Test method for {@link world.bentobox.islandfly.FlyToggleCommand#execute(world.bentobox.bentobox.api.user.User, java.lang.String, java.util.List)}.
*/
@Test
@Test //I don't know what to do here
public void testExecuteUserStringListOfStringAllowedFlight() {
when(p.getAllowFlight()).thenReturn(true);
ftc.execute(user, "fly", Collections.emptyList());
Expand Down

0 comments on commit b568f9c

Please sign in to comment.