Skip to content

Commit b023255

Browse files
committed
Merge branch 'develop'
2 parents 1b414bf + 5ea1723 commit b023255

20 files changed

+1344
-176
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@ hs_err_pid*
3030
/.project
3131
/bin/
3232
/.settings/
33+
/.DS_Store

.travis.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ sudo: false
33
addons:
44
sonarcloud:
55
organization: "bentobox-world"
6-
token:
7-
secure: $SONAR_TOKEN
6+
87
jdk:
98
- openjdk8
109
- openjdk11

pom.xml

+3-3
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@
4545
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
4646
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
4747
<java.version>1.8</java.version>
48-
<powermock.version>1.7.4</powermock.version>
48+
<powermock.version>2.0.2</powermock.version>
4949
<!-- More visible way how to change dependency versions -->
50-
<spigot.version>1.14.4-R0.1-SNAPSHOT</spigot.version>
50+
<spigot.version>1.13.2-R0.1-SNAPSHOT</spigot.version>
5151
<bentobox.version>1.7.0</bentobox.version>
5252
<!-- Revision variable removes warning about dynamic version -->
5353
<revision>${build.version}-SNAPSHOT</revision>
5454
<!-- This allows to change between versions and snapshots. -->
55-
<build.version>1.7.1</build.version>
55+
<build.version>1.7.3</build.version>
5656
<build.number>-LOCAL</build.number>
5757
</properties>
5858

src/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/.DS_Store

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

+36-26
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
package world.bentobox.islandfly;
22

3+
import java.util.List;
4+
35
import org.bukkit.entity.Player;
6+
47
import world.bentobox.bentobox.api.commands.CompositeCommand;
58
import world.bentobox.bentobox.api.user.User;
69
import world.bentobox.bentobox.database.objects.Island;
7-
import world.bentobox.bentobox.managers.IslandsManager;
810
import world.bentobox.bentobox.util.Util;
911

10-
import java.util.List;
11-
import java.util.Optional;
12-
1312

1413
/**
1514
* This command allows to enable and disable fly mode.
@@ -31,37 +30,48 @@ public void setup() {
3130
this.setDescription("islandfly.command.description");
3231
}
3332

33+
@Override
34+
public boolean canExecute(User user, String label, List<String> args) {
35+
36+
// Checks world from corresponding gamemode command with the world player is executing in
37+
if (this.getWorld() != Util.getWorld(user.getWorld())) {
38+
user.sendMessage("islandfly.wrong-world");
39+
return false;
40+
}
41+
42+
Island island = getIslands().getIslandAt(user.getLocation()).orElse(null);
43+
44+
if (island == null) return false;
45+
46+
// Gets the island at User's location
47+
48+
// Enable fly if island is a spawn and user has permission for it
49+
if (island.isSpawn() && user.hasPermission(this.getPermissionPrefix() + "island.flyspawn")) {
50+
return true;
51+
}
52+
53+
if (!island.isAllowed(user, IslandFlyAddon.ISLAND_FLY_PROTECTION) && !user.hasPermission(this.getPermissionPrefix() + "island.flybypass")) {
54+
55+
user.sendMessage("islandfly.command.not-allowed-fly");
56+
return false;
57+
}
58+
59+
60+
return true;
61+
}
3462

3563
@Override
3664
public boolean execute(User user, String label, List<String> args) {
37-
38-
// Checks world from corresponding gamemode command with the world player is executing in
39-
if (this.getWorld() != Util.getWorld(user.getWorld())) {
40-
user.sendMessage("islandfly.wrong-world");
41-
return true;
42-
}
43-
44-
// Allow this command only on island
45-
final IslandsManager islands = this.getIslands();
46-
islands.userIsOnIsland(user.getWorld(), user);
47-
final Optional<Island> island = islands.getIslandAt(user.getLocation());
48-
49-
if (!user.hasPermission(this.getPermissionPrefix() + "island.flybypass")
50-
&& (!island.isPresent() || !island.get().getMembers().containsKey(user.getUniqueId()))) {
51-
user.sendMessage("islandfly.command.only-on-island");
52-
return true;
53-
}
54-
5565
final Player player = user.getPlayer();
56-
57-
if (user.getPlayer().getAllowFlight()) {
58-
66+
67+
if (player.getAllowFlight()) {
68+
5969
// Disable fly and notify player
6070
player.setFlying(false);
6171
player.setAllowFlight(false);
6272
user.sendMessage("islandfly.disable-fly");
6373
} else {
64-
74+
6575
// Enable fly and notify player
6676
player.setAllowFlight(true);
6777
user.sendMessage("islandfly.enable-fly");

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

+26-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
package world.bentobox.islandfly;
22

3+
import org.bukkit.Material;
4+
35
import world.bentobox.bentobox.api.addons.Addon;
46
import world.bentobox.bentobox.api.configuration.Config;
7+
import world.bentobox.bentobox.api.flags.Flag;
8+
import world.bentobox.bentobox.managers.RanksManager;
59
import world.bentobox.islandfly.config.Settings;
610
import world.bentobox.islandfly.listeners.FlyDeathListener;
11+
import world.bentobox.islandfly.listeners.FlyFlagListener;
712
import world.bentobox.islandfly.listeners.FlyListener;
13+
import world.bentobox.islandfly.listeners.FlyLoginListener;
814
import world.bentobox.islandfly.listeners.FlyLogoutListener;
915

1016

@@ -17,6 +23,17 @@ public class IslandFlyAddon extends Addon {
1723
*/
1824
private Settings settings;
1925

26+
/**
27+
* A flag to allow or disallow flight on island
28+
* based on player's rank
29+
*/
30+
public static final Flag ISLAND_FLY_PROTECTION =
31+
new Flag.Builder("ISLAND_FLY_PROTECTION", Material.ELYTRA)
32+
.type(Flag.Type.PROTECTION)
33+
.mode(Flag.Mode.ADVANCED)
34+
.defaultRank(RanksManager.MEMBER_RANK)
35+
.defaultSetting(true).build();
36+
2037
/**
2138
* Boolean that indicate if addon is hooked into any gamemode.
2239
*/
@@ -34,6 +51,7 @@ public void onLoad()
3451
// Save default config.yml
3552
this.saveDefaultConfig();
3653
// Load the plugin's config
54+
this.settings = new Config<>(this, Settings.class).loadConfigObject();
3755
this.loadSettings();
3856
}
3957

@@ -48,7 +66,7 @@ public void onReload()
4866

4967
if (this.hooked) {
5068
this.loadSettings();
51-
this.getLogger().info("IslandFly addon reloaded.");
69+
log("IslandFly addon reloaded.");
5270
}
5371
}
5472

@@ -68,6 +86,8 @@ public void onEnable() {
6886
new FlyToggleCommand(playerCommand);
6987
hooked = true;
7088
});
89+
90+
ISLAND_FLY_PROTECTION.addGameModeAddon(gameModeAddon);
7191
}
7292
});
7393

@@ -77,6 +97,11 @@ public void onEnable() {
7797
registerListener(new FlyListener(this));
7898
registerListener(new FlyDeathListener(this));
7999
registerListener(new FlyLogoutListener(this));
100+
registerListener(new FlyLoginListener(this));
101+
registerListener(new FlyFlagListener(this));
102+
103+
// Register a flag
104+
registerFlag(ISLAND_FLY_PROTECTION);
80105
}
81106
}
82107

@@ -94,7 +119,6 @@ public void onDisable() {
94119
* This method loads addon configuration settings in memory.
95120
*/
96121
private void loadSettings() {
97-
this.settings = new Config<>(this, Settings.class).loadConfigObject();
98122

99123
if (this.settings == null) {
100124
// Disable

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

+95-94
Original file line numberDiff line numberDiff line change
@@ -30,98 +30,99 @@
3030
@ConfigComment("This config file is dynamic and saved when the server is shutdown.")
3131
public class Settings implements ConfigObject
3232
{
33-
// ---------------------------------------------------------------------
34-
// Section: Getters and Setters
35-
// ---------------------------------------------------------------------
36-
37-
38-
/**
39-
* Method Settings#getFlyTimeout returns the flyTimeout of this object.
40-
*
41-
* @return the flyTimeout (type int) of this object.
42-
*/
43-
public int getFlyTimeout()
44-
{
45-
return flyTimeout;
46-
}
47-
48-
49-
/**
50-
* Method Settings#setFlyTimeout sets new value for the flyTimeout of this object.
51-
* @param flyTimeout new value for this object.
52-
*
53-
*/
54-
public void setFlyTimeout(int flyTimeout)
55-
{
56-
this.flyTimeout = flyTimeout;
57-
}
58-
59-
60-
/**
61-
* Method Settings#isFlyDisableOnLogout returns the flyDisableOnLogout of this object.
62-
*
63-
* @return the flyDisableOnLogout (type boolean) of this object.
64-
*/
65-
public boolean isFlyDisableOnLogout()
66-
{
67-
return flyDisableOnLogout;
68-
}
69-
70-
71-
/**
72-
* Method Settings#setFlyDisableOnLogout sets new value for the flyDisableOnLogout of this object.
73-
* @param flyDisableOnLogout new value for this object.
74-
*
75-
*/
76-
public void setFlyDisableOnLogout(boolean flyDisableOnLogout)
77-
{
78-
this.flyDisableOnLogout = flyDisableOnLogout;
79-
}
80-
81-
82-
/**
83-
* This method returns the disabledGameModes value.
84-
*
85-
* @return the value of disabledGameModes.
86-
*/
87-
public Set<String> getDisabledGameModes()
88-
{
89-
return disabledGameModes;
90-
}
91-
92-
93-
/**
94-
* This method sets the disabledGameModes value.
95-
*
96-
* @param disabledGameModes the disabledGameModes new value.
97-
*/
98-
public void setDisabledGameModes(Set<String> disabledGameModes)
99-
{
100-
this.disabledGameModes = disabledGameModes;
101-
}
102-
103-
104-
// ---------------------------------------------------------------------
105-
// Section: Variables
106-
// ---------------------------------------------------------------------
107-
108-
@ConfigComment("")
109-
@ConfigComment("This allows to define timeout in seconds on which fly mode will be disabled")
110-
@ConfigComment("when player leaves its island. Zero or negative number will result in immediate")
111-
@ConfigComment("fly mode disabling.")
112-
@ConfigEntry(path = "fly-timeout")
113-
private int flyTimeout = 5;
114-
115-
@ConfigComment("")
116-
@ConfigComment("This allows to change if players should lose their fly mode if they quit server.")
117-
@ConfigEntry(path = "logout-disable-fly")
118-
private boolean flyDisableOnLogout = false;
119-
120-
@ConfigComment("")
121-
@ConfigComment("This list stores GameModes in which islandFly addon should not work.")
122-
@ConfigComment("To disable addon it is necessary to write its name in new line that starts with -. Example:")
123-
@ConfigComment("disabled-gamemodes:")
124-
@ConfigComment(" - BSkyBlock")
125-
@ConfigEntry(path = "disabled-gamemodes")
126-
private Set<String> disabledGameModes = new HashSet<>();
33+
// ---------------------------------------------------------------------
34+
// Section: Getters and Setters
35+
// ---------------------------------------------------------------------
36+
37+
38+
/**
39+
* Method Settings#getFlyTimeout returns the flyTimeout of this object.
40+
*
41+
* @return the flyTimeout (type int) of this object.
42+
*/
43+
public int getFlyTimeout()
44+
{
45+
return flyTimeout;
46+
}
47+
48+
49+
/**
50+
* Method Settings#setFlyTimeout sets new value for the flyTimeout of this object.
51+
* @param flyTimeout new value for this object.
52+
*
53+
*/
54+
public void setFlyTimeout(int flyTimeout)
55+
{
56+
this.flyTimeout = flyTimeout;
57+
}
58+
59+
60+
/**
61+
* Method Settings#isFlyDisableOnLogout returns the flyDisableOnLogout of this object.
62+
*
63+
* @return the flyDisableOnLogout (type boolean) of this object.
64+
*/
65+
public boolean isFlyDisableOnLogout()
66+
{
67+
return flyDisableOnLogout;
68+
}
69+
70+
71+
/**
72+
* Method Settings#setFlyDisableOnLogout sets new value for the flyDisableOnLogout of this object.
73+
* @param flyDisableOnLogout new value for this object.
74+
*
75+
*/
76+
public void setFlyDisableOnLogout(boolean flyDisableOnLogout)
77+
{
78+
this.flyDisableOnLogout = flyDisableOnLogout;
79+
}
80+
81+
82+
/**
83+
* This method returns the disabledGameModes value.
84+
*
85+
* @return the value of disabledGameModes.
86+
*/
87+
public Set<String> getDisabledGameModes()
88+
{
89+
return disabledGameModes;
90+
}
91+
92+
93+
/**
94+
* This method sets the disabledGameModes value.
95+
*
96+
* @param disabledGameModes the disabledGameModes new value.
97+
*/
98+
public void setDisabledGameModes(Set<String> disabledGameModes)
99+
{
100+
this.disabledGameModes = disabledGameModes;
101+
}
102+
103+
104+
// ---------------------------------------------------------------------
105+
// Section: Variables
106+
// ---------------------------------------------------------------------
107+
108+
@ConfigComment("")
109+
@ConfigComment("This allows to define timeout in seconds on which fly mode will be disabled")
110+
@ConfigComment("when player leaves its island. Zero or negative number will result in immediate")
111+
@ConfigComment("fly mode disabling. Players with the bskyblock.island.flybypass permission (or similar)")
112+
@ConfigComment("can fly outside the island boundary.")
113+
@ConfigEntry(path = "fly-timeout")
114+
private int flyTimeout = 5;
115+
116+
@ConfigComment("")
117+
@ConfigComment("This allows to change if players should lose their fly mode if they quit server.")
118+
@ConfigEntry(path = "logout-disable-fly")
119+
private boolean flyDisableOnLogout = false;
120+
121+
@ConfigComment("")
122+
@ConfigComment("This list stores GameModes in which islandFly addon should not work.")
123+
@ConfigComment("To disable addon it is necessary to write its name in new line that starts with -. Example:")
124+
@ConfigComment("disabled-gamemodes:")
125+
@ConfigComment(" - BSkyBlock")
126+
@ConfigEntry(path = "disabled-gamemodes")
127+
private Set<String> disabledGameModes = new HashSet<>();
127128
}

0 commit comments

Comments
 (0)