Skip to content

Commit b568f9c

Browse files
PapiCapitastybento
andauthored
Added possibility to prevent players from doing the fly command outside (#59)
of the island protection range. Co-authored-by: tastybento <[email protected]>
1 parent f1f7850 commit b568f9c

File tree

7 files changed

+56
-10
lines changed

7 files changed

+56
-10
lines changed

src/main/java/world/bentobox/islandfly/FlyToggleCommand.java

+15-1
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,24 @@
88
import world.bentobox.bentobox.api.user.User;
99
import world.bentobox.bentobox.database.objects.Island;
1010
import world.bentobox.bentobox.util.Util;
11+
import world.bentobox.islandfly.config.Settings;
1112

1213

1314
/**
1415
* This command allows to enable and disable fly mode.
1516
*/
1617
public class FlyToggleCommand extends CompositeCommand {
18+
19+
20+
private Settings settings;
21+
1722
/**
1823
* Default constructor
1924
* @param parent Instance of CompositeCommand
2025
*/
21-
public FlyToggleCommand(CompositeCommand parent) {
26+
public FlyToggleCommand(CompositeCommand parent, IslandFlyAddon addon) {
2227
super(parent, "fly");
28+
this.settings = addon.getSettings();
2329
}
2430

2531

@@ -55,6 +61,14 @@ public boolean canExecute(User user, String label, List<String> args) {
5561
user.sendMessage("islandfly.command.not-allowed-fly");
5662
return false;
5763
}
64+
65+
66+
if ( !this.settings.isAllowCommandOutsideProtectionRange() && !island.getProtectionBoundingBox().contains(user.getLocation().toVector())) {
67+
68+
user.sendMessage("islandfly.outside-protection-range");
69+
return false;
70+
71+
}
5872

5973

6074
return true;

src/main/java/world/bentobox/islandfly/IslandFlyAddon.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public void onEnable() {
8484

8585
gameModeAddon.getPlayerCommand().ifPresent(
8686
playerCommand -> {
87-
new FlyToggleCommand(playerCommand);
87+
new FlyToggleCommand(playerCommand, this);
8888
hooked = true;
8989
});
9090

src/main/java/world/bentobox/islandfly/config/Settings.java

+29
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,30 @@ public void setDisabledGameModes(Set<String> disabledGameModes)
9999
{
100100
this.disabledGameModes = disabledGameModes;
101101
}
102+
103+
104+
105+
106+
/**
107+
* Method Settings#isFlyDisableOnLogout returns the flyDisableOnLogout of this object.
108+
*
109+
* @return the flyDisableOnLogout (type boolean) of this object.
110+
*/
111+
public boolean isAllowCommandOutsideProtectionRange()
112+
{
113+
return allowCommandOutsideProtectionRange;
114+
}
115+
116+
117+
/**
118+
* Method Settings#setFlyDisableOnLogout sets new value for the flyDisableOnLogout of this object.
119+
* @param flyDisableOnLogout new value for this object.
120+
*
121+
*/
122+
public void setAllowCommandOutsideProtectionRange(boolean commandAllowed)
123+
{
124+
this.allowCommandOutsideProtectionRange = commandAllowed;
125+
}
102126

103127

104128
// ---------------------------------------------------------------------
@@ -125,4 +149,9 @@ public void setDisabledGameModes(Set<String> disabledGameModes)
125149
@ConfigComment(" - BSkyBlock")
126150
@ConfigEntry(path = "disabled-gamemodes")
127151
private Set<String> disabledGameModes = new HashSet<>();
152+
153+
@ConfigComment("")
154+
@ConfigComment("This allows the player to use the command outside the island protection range.")
155+
@ConfigEntry(path = "allow-command-outside-protection-range")
156+
private boolean allowCommandOutsideProtectionRange = false;
128157
}

src/main/resources/config.yml

+3
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,6 @@ logout-disable-fly: false
1515
# disabled-gamemodes:
1616
# - BSkyBlock
1717
disabled-gamemodes: []
18+
19+
#This allows the player to use the command outside the island protection range.
20+
allow-command-outside-protection-range: false

src/main/resources/locales/en-US.yml

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ islandfly:
66
enable-fly: "&a Your fly mode has been enabled."
77
cancel-disable: "&a You are back, huh! Fly fuel successfully refilled!"
88
wrong-world: "&c You are not in the right gamemode world"
9+
outside-protection-range: "&c You are not allowed to do that outside your island protection range"
910
command:
1011
description: "allows you to fly on your island"
1112
not-allowed-fly: "&c You are not allowed to fly on this island"

src/main/resources/locales/fr.yml

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
---
22
islandfly:
3-
fly-outside-alert: "&cVous êtes hors de votre île, vous ne pourrez plus voler dans
4-
&e[number]&c secondes."
5-
fly-turning-off-alert: "&c Vous n'êtes plus autorisé à voler ici. Désactivation
6-
de fly en &e [number] &c secondes."
3+
fly-turning-off-alert: "&c Vous n'êtes plus autorisé à voler ici. Désactivation du vol dans &e [number] &c secondes."
4+
reallowed-fly: "&a Vous pouvez de nouveau voler"
5+
outside-protection-range: "&c Tu ne peux pas faire ça en dehors de la zone de protection de ton île"
6+
fly-outside-alert: "&cVous êtes hors de votre île, vous ne pourrez plus voler dans &e[number]&c secondes."
77
disable-fly: "&cVous ne pouvez plus voler."
8-
reallowed-fly: "& a Votre mouche a été réaffectée"
98
enable-fly: "&aVous pouvez désormais voler."
109
cancel-disable: "&aVous êtes de retour sur votre île ! Vous pouvez continuer à voler."
1110
wrong-world: "&cVous n'êtes pas dans le bon monde de mode de jeu."
@@ -17,4 +16,4 @@ protection:
1716
flags:
1817
ISLAND_FLY_PROTECTION:
1918
description: "&a Toggle qui peut voler sur votre île"
20-
name: "&a Prévention des mouches"
19+
name: "&a Interdiction du vol"

src/test/java/world/bentobox/islandfly/FlyToggleCommandTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public void setUp() throws Exception {
112112
Optional<Island> opIsland = Optional.of(island);
113113
when(im.getIslandAt(any())).thenReturn(opIsland);
114114

115-
ftc = new FlyToggleCommand(ic);
115+
ftc = new FlyToggleCommand(ic, addon);
116116
}
117117

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

0 commit comments

Comments
 (0)