Skip to content

Commit

Permalink
Prevents dragon eggs from teleporting outside of protection zone
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Mar 21, 2019
1 parent 05e5424 commit 68a52c7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockFromToEvent;
import org.bukkit.event.player.PlayerInteractEvent;

import world.bentobox.bentobox.api.flags.FlagListener;
Expand Down Expand Up @@ -276,4 +278,24 @@ private void checkClickedBlock(Event e, Player player, Location loc, Material ty
public void onBlockBreak(final BlockBreakEvent e) {
checkClickedBlock(e, e.getPlayer(), e.getBlock().getLocation(), e.getBlock().getType());
}

/**
* Prevents dragon eggs from flying out of an island's protected space
* @param e - event
*/
@EventHandler(priority = EventPriority.LOWEST)
public void onDragonEggTeleport(BlockFromToEvent e) {
Block from = e.getBlock();
if (!from.getType().equals(Material.DRAGON_EGG) || !getIWM().inWorld(from.getLocation())) {
return;
}
// If egg starts in a protected island...
getIslands().getProtectedIslandAt(from.getLocation()).ifPresent(fromIsland -> {
// Cancel if toIsland is not fromIsland or if there is no protected island there
// This protects against eggs dropping into adjacent islands, e.g. island distance and protection range are equal
e.setCancelled(getIslands().getProtectedIslandAt(e.getToBlock().getLocation()).map(toIsland -> {
return toIsland != fromIsland;
}).orElse(true));
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ public void onLiquidFlow(BlockFromToEvent e) {
e.setCancelled(true);
}
}

}

0 comments on commit 68a52c7

Please sign in to comment.