diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilAlg.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilAlg.java index ebf5f7f8d..1945a0e1b 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilAlg.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilAlg.java @@ -216,6 +216,24 @@ public class UtilAlg return true; } + + public static boolean inBoundingBox(Location loc, Vector cornerA, Vector cornerB) + { + if (loc.getX() <= Math.min(cornerA.getX(), cornerB.getX())) return false; + if (loc.getX() >= Math.max(cornerA.getX(), cornerB.getX())) return false; + + if (cornerA.getY() != cornerB.getY()) + { + if (loc.getY() <= Math.min(cornerA.getY(), cornerB.getY())) return false; + if (loc.getY() >= Math.max(cornerA.getY(), cornerB.getY())) return false; + } + + if (loc.getZ() <= Math.min(cornerA.getZ(), cornerB.getZ())) return false; + if (loc.getZ() >= Math.max(cornerA.getZ(), cornerB.getZ())) return false; + + return true; + } + public static Vector cross(Vector a, Vector b) { double x = a.getY()*b.getZ() - a.getZ()*b.getY(); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventManager.java index 0edc6e6e7..a419b2d1c 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventManager.java @@ -77,6 +77,19 @@ public class WorldEventManager extends MiniPlugin implements ScoreboardElement } } + public boolean isInEvent(Location location) + { + for (WorldEvent event : _runningEvents) + { + if (event.isInBounds(location)) + { + return true; + } + } + + return false; + } + @EventHandler public void update(UpdateEvent event) { diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java index b7627fc19..a6dbb83d6 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/gameplay/Gameplay.java @@ -305,7 +305,7 @@ public class Gameplay extends MiniPlugin event.setCancelled(true); } - @EventHandler + @EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) public void disableEnderChest(PlayerInteractEvent event) { if (event.getAction() != Action.RIGHT_CLICK_BLOCK) @@ -318,6 +318,11 @@ public class Gameplay extends MiniPlugin return; } + if (_clansManager.getWorldEvent().isInEvent(event.getClickedBlock().getLocation())) + { + return; + } + if (event.getClickedBlock().getType().equals(Material.ENDER_CHEST)) { UtilPlayer.message(event.getPlayer(), F.main("Clans", "You are not permitted to use Ender Chests.")); diff --git a/Plugins/Mineplex.Minecraft.Game.Core/src/mineplex/minecraft/game/core/boss/WorldEvent.java b/Plugins/Mineplex.Minecraft.Game.Core/src/mineplex/minecraft/game/core/boss/WorldEvent.java index f1cd8424b..6f10d660c 100644 --- a/Plugins/Mineplex.Minecraft.Game.Core/src/mineplex/minecraft/game/core/boss/WorldEvent.java +++ b/Plugins/Mineplex.Minecraft.Game.Core/src/mineplex/minecraft/game/core/boss/WorldEvent.java @@ -5,8 +5,8 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Random; +import java.util.Set; -import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; @@ -15,6 +15,7 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.HandlerList; import org.bukkit.event.Listener; import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.util.Vector; import mineplex.core.blockrestore.BlockRestore; import mineplex.core.blockrestore.BlockRestoreMap; @@ -25,7 +26,7 @@ import mineplex.core.common.block.schematic.UtilSchematic; import mineplex.core.common.util.C; import mineplex.core.common.util.Callback; import mineplex.core.common.util.F; -import mineplex.core.common.util.UtilBlock; +import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilTextMiddle; @@ -65,6 +66,14 @@ public abstract class WorldEvent implements Listener, ScoreboardElement private boolean _isArcade; private double _difficulty = 1; + private double _minX; + private double _minY; + private double _minZ; + + private double _maxX; + private double _maxY; + private double _maxZ; + public WorldEvent(DisguiseManager disguiseManager, ProjectileManager projectileManager, DamageManager damageManager, BlockRestore blockRestore, ConditionManager conditionManager, String name, Location cornerLocation) { this(disguiseManager, projectileManager, damageManager, blockRestore, conditionManager, name, cornerLocation, null); @@ -328,7 +337,6 @@ public abstract class WorldEvent implements Listener, ScoreboardElement { onComplete.run(); } - } }); @@ -407,4 +415,50 @@ public abstract class WorldEvent implements Listener, ScoreboardElement } } + public boolean isInBounds(Location location) + { + if (_minX == 0) + { + // Calculate bounds + Set blocks = _blocks.getChangedBlocks(); + + for (Block block : blocks) + { + if (_minX > block.getX()) + { + _minX = block.getX(); + } + + if (_minY > block.getY()) + { + _minY = block.getY(); + } + + if (_minZ > block.getZ()) + { + _minZ = block.getZ(); + } + + if (_maxX < block.getX()) + { + _maxX = block.getX(); + } + + if (_maxY < block.getY()) + { + _maxY = block.getY(); + } + + if (_maxZ < block.getZ()) + { + _maxZ = block.getZ(); + } + } + + _maxY++; + } + + return UtilAlg.inBoundingBox(location, new Vector(_minX, _minY, _minZ), new Vector(_maxX, _maxY, _maxZ)); + } + }