Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Apr 6, 2020
2 parents 1b414bf + 5ea1723 commit b023255
Show file tree
Hide file tree
Showing 20 changed files with 1,344 additions and 176 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ hs_err_pid*
/.project
/bin/
/.settings/
/.DS_Store
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ sudo: false
addons:
sonarcloud:
organization: "bentobox-world"
token:
secure: $SONAR_TOKEN

jdk:
- openjdk8
- openjdk11
Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<powermock.version>1.7.4</powermock.version>
<powermock.version>2.0.2</powermock.version>
<!-- More visible way how to change dependency versions -->
<spigot.version>1.14.4-R0.1-SNAPSHOT</spigot.version>
<spigot.version>1.13.2-R0.1-SNAPSHOT</spigot.version>
<bentobox.version>1.7.0</bentobox.version>
<!-- Revision variable removes warning about dynamic version -->
<revision>${build.version}-SNAPSHOT</revision>
<!-- This allows to change between versions and snapshots. -->
<build.version>1.7.1</build.version>
<build.version>1.7.3</build.version>
<build.number>-LOCAL</build.number>
</properties>

Expand Down
1 change: 1 addition & 0 deletions src/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.DS_Store
62 changes: 36 additions & 26 deletions src/main/java/world/bentobox/islandfly/FlyToggleCommand.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package world.bentobox.islandfly;

import java.util.List;

import org.bukkit.entity.Player;

import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.managers.IslandsManager;
import world.bentobox.bentobox.util.Util;

import java.util.List;
import java.util.Optional;


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

@Override
public boolean canExecute(User user, String label, List<String> args) {

// Checks world from corresponding gamemode command with the world player is executing in
if (this.getWorld() != Util.getWorld(user.getWorld())) {
user.sendMessage("islandfly.wrong-world");
return false;
}

Island island = getIslands().getIslandAt(user.getLocation()).orElse(null);

if (island == null) return false;

// Gets the island at User's location

// Enable fly if island is a spawn and user has permission for it
if (island.isSpawn() && user.hasPermission(this.getPermissionPrefix() + "island.flyspawn")) {
return true;
}

if (!island.isAllowed(user, IslandFlyAddon.ISLAND_FLY_PROTECTION) && !user.hasPermission(this.getPermissionPrefix() + "island.flybypass")) {

user.sendMessage("islandfly.command.not-allowed-fly");
return false;
}


return true;
}

@Override
public boolean execute(User user, String label, List<String> args) {

// Checks world from corresponding gamemode command with the world player is executing in
if (this.getWorld() != Util.getWorld(user.getWorld())) {
user.sendMessage("islandfly.wrong-world");
return true;
}

// Allow this command only on island
final IslandsManager islands = this.getIslands();
islands.userIsOnIsland(user.getWorld(), user);
final Optional<Island> island = islands.getIslandAt(user.getLocation());

if (!user.hasPermission(this.getPermissionPrefix() + "island.flybypass")
&& (!island.isPresent() || !island.get().getMembers().containsKey(user.getUniqueId()))) {
user.sendMessage("islandfly.command.only-on-island");
return true;
}

final Player player = user.getPlayer();
if (user.getPlayer().getAllowFlight()) {

if (player.getAllowFlight()) {

// Disable fly and notify player
player.setFlying(false);
player.setAllowFlight(false);
user.sendMessage("islandfly.disable-fly");
} else {

// Enable fly and notify player
player.setAllowFlight(true);
user.sendMessage("islandfly.enable-fly");
Expand Down
28 changes: 26 additions & 2 deletions src/main/java/world/bentobox/islandfly/IslandFlyAddon.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
package world.bentobox.islandfly;

import org.bukkit.Material;

import world.bentobox.bentobox.api.addons.Addon;
import world.bentobox.bentobox.api.configuration.Config;
import world.bentobox.bentobox.api.flags.Flag;
import world.bentobox.bentobox.managers.RanksManager;
import world.bentobox.islandfly.config.Settings;
import world.bentobox.islandfly.listeners.FlyDeathListener;
import world.bentobox.islandfly.listeners.FlyFlagListener;
import world.bentobox.islandfly.listeners.FlyListener;
import world.bentobox.islandfly.listeners.FlyLoginListener;
import world.bentobox.islandfly.listeners.FlyLogoutListener;


Expand All @@ -17,6 +23,17 @@ public class IslandFlyAddon extends Addon {
*/
private Settings settings;

/**
* A flag to allow or disallow flight on island
* based on player's rank
*/
public static final Flag ISLAND_FLY_PROTECTION =
new Flag.Builder("ISLAND_FLY_PROTECTION", Material.ELYTRA)
.type(Flag.Type.PROTECTION)
.mode(Flag.Mode.ADVANCED)
.defaultRank(RanksManager.MEMBER_RANK)
.defaultSetting(true).build();

/**
* Boolean that indicate if addon is hooked into any gamemode.
*/
Expand All @@ -34,6 +51,7 @@ public void onLoad()
// Save default config.yml
this.saveDefaultConfig();
// Load the plugin's config
this.settings = new Config<>(this, Settings.class).loadConfigObject();
this.loadSettings();
}

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

if (this.hooked) {
this.loadSettings();
this.getLogger().info("IslandFly addon reloaded.");
log("IslandFly addon reloaded.");
}
}

Expand All @@ -68,6 +86,8 @@ public void onEnable() {
new FlyToggleCommand(playerCommand);
hooked = true;
});

ISLAND_FLY_PROTECTION.addGameModeAddon(gameModeAddon);
}
});

Expand All @@ -77,6 +97,11 @@ public void onEnable() {
registerListener(new FlyListener(this));
registerListener(new FlyDeathListener(this));
registerListener(new FlyLogoutListener(this));
registerListener(new FlyLoginListener(this));
registerListener(new FlyFlagListener(this));

// Register a flag
registerFlag(ISLAND_FLY_PROTECTION);
}
}

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

if (this.settings == null) {
// Disable
Expand Down
189 changes: 95 additions & 94 deletions src/main/java/world/bentobox/islandfly/config/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,98 +30,99 @@
@ConfigComment("This config file is dynamic and saved when the server is shutdown.")
public class Settings implements ConfigObject
{
// ---------------------------------------------------------------------
// Section: Getters and Setters
// ---------------------------------------------------------------------


/**
* Method Settings#getFlyTimeout returns the flyTimeout of this object.
*
* @return the flyTimeout (type int) of this object.
*/
public int getFlyTimeout()
{
return flyTimeout;
}


/**
* Method Settings#setFlyTimeout sets new value for the flyTimeout of this object.
* @param flyTimeout new value for this object.
*
*/
public void setFlyTimeout(int flyTimeout)
{
this.flyTimeout = flyTimeout;
}


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


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


/**
* This method returns the disabledGameModes value.
*
* @return the value of disabledGameModes.
*/
public Set<String> getDisabledGameModes()
{
return disabledGameModes;
}


/**
* This method sets the disabledGameModes value.
*
* @param disabledGameModes the disabledGameModes new value.
*/
public void setDisabledGameModes(Set<String> disabledGameModes)
{
this.disabledGameModes = disabledGameModes;
}


// ---------------------------------------------------------------------
// Section: Variables
// ---------------------------------------------------------------------

@ConfigComment("")
@ConfigComment("This allows to define timeout in seconds on which fly mode will be disabled")
@ConfigComment("when player leaves its island. Zero or negative number will result in immediate")
@ConfigComment("fly mode disabling.")
@ConfigEntry(path = "fly-timeout")
private int flyTimeout = 5;

@ConfigComment("")
@ConfigComment("This allows to change if players should lose their fly mode if they quit server.")
@ConfigEntry(path = "logout-disable-fly")
private boolean flyDisableOnLogout = false;

@ConfigComment("")
@ConfigComment("This list stores GameModes in which islandFly addon should not work.")
@ConfigComment("To disable addon it is necessary to write its name in new line that starts with -. Example:")
@ConfigComment("disabled-gamemodes:")
@ConfigComment(" - BSkyBlock")
@ConfigEntry(path = "disabled-gamemodes")
private Set<String> disabledGameModes = new HashSet<>();
// ---------------------------------------------------------------------
// Section: Getters and Setters
// ---------------------------------------------------------------------


/**
* Method Settings#getFlyTimeout returns the flyTimeout of this object.
*
* @return the flyTimeout (type int) of this object.
*/
public int getFlyTimeout()
{
return flyTimeout;
}


/**
* Method Settings#setFlyTimeout sets new value for the flyTimeout of this object.
* @param flyTimeout new value for this object.
*
*/
public void setFlyTimeout(int flyTimeout)
{
this.flyTimeout = flyTimeout;
}


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


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


/**
* This method returns the disabledGameModes value.
*
* @return the value of disabledGameModes.
*/
public Set<String> getDisabledGameModes()
{
return disabledGameModes;
}


/**
* This method sets the disabledGameModes value.
*
* @param disabledGameModes the disabledGameModes new value.
*/
public void setDisabledGameModes(Set<String> disabledGameModes)
{
this.disabledGameModes = disabledGameModes;
}


// ---------------------------------------------------------------------
// Section: Variables
// ---------------------------------------------------------------------

@ConfigComment("")
@ConfigComment("This allows to define timeout in seconds on which fly mode will be disabled")
@ConfigComment("when player leaves its island. Zero or negative number will result in immediate")
@ConfigComment("fly mode disabling. Players with the bskyblock.island.flybypass permission (or similar)")
@ConfigComment("can fly outside the island boundary.")
@ConfigEntry(path = "fly-timeout")
private int flyTimeout = 5;

@ConfigComment("")
@ConfigComment("This allows to change if players should lose their fly mode if they quit server.")
@ConfigEntry(path = "logout-disable-fly")
private boolean flyDisableOnLogout = false;

@ConfigComment("")
@ConfigComment("This list stores GameModes in which islandFly addon should not work.")
@ConfigComment("To disable addon it is necessary to write its name in new line that starts with -. Example:")
@ConfigComment("disabled-gamemodes:")
@ConfigComment(" - BSkyBlock")
@ConfigEntry(path = "disabled-gamemodes")
private Set<String> disabledGameModes = new HashSet<>();
}
Loading

0 comments on commit b023255

Please sign in to comment.