Skip to content

Commit

Permalink
Merge pull request #121 from BentoBoxWorld/develop
Browse files Browse the repository at this point in the history
Release 1.13.0
  • Loading branch information
tastybento authored Sep 3, 2024
2 parents 8de7019 + e667c6b commit fcd002d
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 19 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@
<java.version>17</java.version>
<powermock.version>2.0.9</powermock.version>
<!-- More visible way how to change dependency versions -->
<spigot.version>1.20.4-R0.1-SNAPSHOT</spigot.version>
<bentobox.version>2.0.0-SNAPSHOT</bentobox.version>
<spigot.version>1.21.1-R0.1-SNAPSHOT</spigot.version>
<bentobox.version>2.5.0-SNAPSHOT</bentobox.version>
<!-- Level addon version -->
<level.version>2.9.0</level.version>
<!-- Revision variable removes warning about dynamic version -->
<revision>${build.version}-SNAPSHOT</revision>
<!-- This allows to change between versions and snapshots. -->
<build.version>1.12.0</build.version>
<build.version>1.13.0</build.version>
<build.number>-LOCAL</build.number>
<sonar.projectKey>BentoBoxWorld_Boxed</sonar.projectKey>
<sonar.organization>bentobox-world</sonar.organization>
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/world/bentobox/islandfly/FlyToggleCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,11 @@ public boolean execute(User user, String label, List<String> args) {
final Player player = user.getPlayer();

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
6 changes: 5 additions & 1 deletion src/main/java/world/bentobox/islandfly/IslandFlyPladdon.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@

public class IslandFlyPladdon extends Pladdon
{
Addon addon;
@Override
public Addon getAddon()
{
return new IslandFlyAddon();
if (addon == null) {
addon = new IslandFlyAddon();
}
return addon;
}
}
44 changes: 32 additions & 12 deletions src/main/java/world/bentobox/islandfly/listeners/FlyListener.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
package world.bentobox.islandfly.listeners;

import java.util.HashMap;
import java.util.Map;

import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerToggleFlightEvent;
import org.eclipse.jdt.annotation.NonNull;

import world.bentobox.bentobox.api.events.island.IslandEnterEvent;
import world.bentobox.bentobox.api.events.island.IslandExitEvent;
import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.metadata.MetaDataValue;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.islandfly.IslandFlyAddon;
Expand All @@ -19,25 +25,34 @@
*/
public class FlyListener implements Listener {

private static final @NonNull String ISLANDFLY = "IslandFly-";
/**
* Addon instance object.
*/
private final IslandFlyAddon islandFlyAddon;
private final IslandFlyAddon addon;


/**
* Default constructor.
* @param islandFlyAddon instance of IslandFlyAddon
*/
public FlyListener(final IslandFlyAddon islandFlyAddon) {
this.islandFlyAddon = islandFlyAddon;
this.addon = islandFlyAddon;
}

@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onToggleFlight(final PlayerToggleFlightEvent event) {
final User user = User.getInstance(event.getPlayer());
if (checkUser(user)) {
user.sendMessage("islandfly.not-allowed");
} else {
addon.getIslands().getIslandAt(user.getLocation())
.filter(i -> i.getMemberSet().contains(user.getUniqueId())).ifPresent(is -> {
Map<String, MetaDataValue> metaData = new HashMap<>();
metaData.put("IslandFly-" + is.getUniqueId(), new MetaDataValue(event.isFlying()));
user.setMetaData(metaData); // Record the fly state for this island
});

}
}

Expand All @@ -46,7 +61,7 @@ public void onToggleFlight(final PlayerToggleFlightEvent event) {
* @return true if fly was blocked
*/
private boolean checkUser(User user) {
String permPrefix = islandFlyAddon.getPlugin().getIWM().getPermissionPrefix(user.getWorld());
String permPrefix = addon.getPlugin().getIWM().getPermissionPrefix(user.getWorld());
// Ignore ops
if (user.isOp() || user.getPlayer().getGameMode().equals(GameMode.CREATIVE)
|| user.getPlayer().getGameMode().equals(GameMode.SPECTATOR)
Expand All @@ -57,8 +72,13 @@ private boolean checkUser(User user) {
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onEnterIsland(final IslandEnterEvent event) {
final User user = User.getInstance(event.getPlayerUUID());
user.getMetaData(ISLANDFLY + event.getIsland().getUniqueId())
.ifPresent(mdv -> {
user.getPlayer().setAllowFlight(true);
user.getPlayer().setFlying(mdv.asBoolean());
});
// Wait until after arriving at the island
Bukkit.getScheduler().runTask(this.islandFlyAddon.getPlugin(), () -> checkUser(user));
Bukkit.getScheduler().runTask(this.addon.getPlugin(), () -> checkUser(user));
}

/**
Expand All @@ -67,17 +87,16 @@ public void onEnterIsland(final IslandEnterEvent event) {
*/
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onExitIsland(final IslandExitEvent event) {

final User user = User.getInstance(event.getPlayerUUID());
String permPrefix = islandFlyAddon.getPlugin().getIWM().getPermissionPrefix(user.getWorld());
String permPrefix = addon.getPlugin().getIWM().getPermissionPrefix(user.getWorld());
// Ignore ops
if (user.isOp() || user.getPlayer().getGameMode().equals(GameMode.CREATIVE)
|| user.getPlayer().getGameMode().equals(GameMode.SPECTATOR)
|| user.hasPermission(permPrefix + "island.flybypass")
|| (!user.hasPermission(permPrefix + "island.fly")
&& !user.hasPermission(permPrefix + "island.flyspawn"))) return;
// Alert player fly will be disabled
final int flyTimeout = this.islandFlyAddon.getSettings().getFlyTimeout();
final int flyTimeout = this.addon.getSettings().getFlyTimeout();

// If timeout is 0 or less disable fly immediately
if (flyTimeout <= 0) {
Expand All @@ -90,7 +109,7 @@ public void onExitIsland(final IslandExitEvent event) {
user.sendMessage("islandfly.fly-outside-alert", TextVariables.NUMBER, String.valueOf(flyTimeout));
}

Bukkit.getScheduler().runTaskLater(this.islandFlyAddon.getPlugin(), () -> removeFly(user), 20L* flyTimeout);
Bukkit.getScheduler().runTaskLater(this.addon.getPlugin(), () -> removeFly(user), 20L * flyTimeout);
}


Expand All @@ -103,7 +122,7 @@ boolean removeFly(User user) {
// Verify player is still online
if (!user.isOnline()) return false;

Island island = islandFlyAddon.getIslands().getProtectedIslandAt(user.getLocation()).orElse(null);
Island island = addon.getIslands().getProtectedIslandAt(user.getLocation()).orElse(null);

if (island == null) {
disableFly(user);
Expand All @@ -112,7 +131,7 @@ boolean removeFly(User user) {

// Check if player is back on a spawn island
if (island.isSpawn()) {
if (this.islandFlyAddon.getPlugin().getIWM().getAddon(user.getWorld())
if (this.addon.getPlugin().getIWM().getAddon(user.getWorld())
.map(a -> !user.hasPermission(a.getPermissionPrefix() + "island.flyspawn")).orElse(false)) {

disableFly(user);
Expand All @@ -121,8 +140,9 @@ boolean removeFly(User user) {
return false;
}

if(islandFlyAddon.getSettings().getFlyMinLevel() > 1 && islandFlyAddon.getLevelAddon() != null) {
if (islandFlyAddon.getLevelAddon().getIslandLevel(island.getWorld(), island.getOwner()) < islandFlyAddon.getSettings().getFlyMinLevel()) {
if (addon.getSettings().getFlyMinLevel() > 1 && addon.getLevelAddon() != null) {
if (addon.getLevelAddon().getIslandLevel(island.getWorld(), island.getOwner()) < addon.getSettings()
.getFlyMinLevel()) {
disableFly(user);
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/addon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ permissions:
default: op
'[gamemode].island.fly':
description: Allows access to fly command.
default: true
default: false
'[gamemode].island.flybypass':
description: Allows to keep fly mode on player death.
default: op

0 comments on commit fcd002d

Please sign in to comment.