Make undead chests not show the 'you are not permitted to use ender chest' messages.

This commit is contained in:
Ben 2016-04-10 16:52:54 +01:00
parent 313b59d1d6
commit b313bc5308
4 changed files with 94 additions and 4 deletions

View File

@ -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();

View File

@ -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)
{

View File

@ -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."));

View File

@ -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<Block> 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));
}
}