Skip to content

Commit

Permalink
disabled enderpearls and chorus fruits + fix (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
emmanuelvlad committed May 17, 2022
1 parent 9a402e7 commit 73ea8f2
Showing 1 changed file with 37 additions and 5 deletions.
42 changes: 37 additions & 5 deletions src/main/java/world/bentobox/border/listeners/PlayerListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import org.bukkit.event.vehicle.VehicleExitEvent;
import org.bukkit.event.vehicle.VehicleMoveEvent;
import org.bukkit.util.RayTraceResult;
Expand All @@ -30,6 +31,7 @@
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.util.Util;
import world.bentobox.border.Border;
import world.bentobox.bentobox.api.flags.Flag;

/**
* @author tastybento
Expand Down Expand Up @@ -68,10 +70,40 @@ public void onPlayerRespawn(PlayerRespawnEvent e) {

@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onPlayerTeleport(PlayerTeleportEvent e) {
show.clearUser(User.getInstance(e.getPlayer()));
// Check if border is on and if from is inside island and to location is outside of
Bukkit.getScheduler().runTask(addon.getPlugin(), () -> addon.getIslands().getIslandAt(e.getPlayer().getLocation()).ifPresent(i ->
show.showBorder(e.getPlayer(), i)));
Player player = e.getPlayer();
Location to = e.getTo();

show.clearUser(User.getInstance(player));

if (!addon.inGameWorld(to.getWorld())) {
return;
}

TeleportCause cause = e.getCause();
boolean isBlacklistedCause = cause == TeleportCause.ENDER_PEARL || cause == TeleportCause.CHORUS_FRUIT;

addon.getIslands().getIslandAt(to).ifPresentOrElse(i -> {
Optional<Flag> boxedEnderPearlFlag = i.getPlugin().getFlagsManager().getFlag("ALLOW_MOVE_BOX");

if (isBlacklistedCause
&& (!i.getProtectionBoundingBox().contains(to.toVector())
|| !i.onIsland(player.getLocation()))) {
e.setCancelled(true);
}

if (boxedEnderPearlFlag.isPresent()
&& boxedEnderPearlFlag.get().isSetForWorld(to.getWorld())
&& cause == TeleportCause.ENDER_PEARL) {
e.setCancelled(false);
}

show.showBorder(player, i);
}, () -> {
if (isBlacklistedCause) {
e.setCancelled(true);
return;
}
});
}

@EventHandler(priority = EventPriority.NORMAL)
Expand Down Expand Up @@ -127,7 +159,7 @@ private boolean outsideCheck(Player player, Location from, Location to) {
if ((from.getWorld() != null && from.getWorld().equals(to.getWorld())
&& from.toVector().multiply(XZ).equals(to.toVector().multiply(XZ)))
|| !addon.inGameWorld(player.getWorld())
|| !addon.getIslands().getIslandAt(to).filter(i -> addon.getIslands().locationIsOnIsland(player, i.getCenter())).isPresent()
|| !addon.getIslands().getIslandAt(to).filter(i -> addon.getIslands().locationIsOnIsland(player, i.getProtectionCenter())).isPresent()
|| !user.getMetaData(BorderShower.BORDER_STATE_META_DATA).map(MetaDataValue::asBoolean).orElse(addon.getSettings().isShowByDefault())) {
return false;
}
Expand Down

0 comments on commit 73ea8f2

Please sign in to comment.