Mineplex2018-withcommit/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/ore/OreHider.java

90 lines
1.7 KiB
Java
Raw Normal View History

2013-08-27 17:14:08 +02:00
package nautilus.game.arcade.ore;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.explosion.ExplosionEvent;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.event.block.BlockBreakEvent;
public class OreHider
{
private NautHashMap<Location, Material> _hidden = new NautHashMap<Location, Material>();
private boolean _visible = false;
public void AddOre(Location loc, Material type)
{
boolean visible = false;
for (Block block : UtilBlock.getSurrounding(loc.getBlock(), false))
2013-08-27 17:14:08 +02:00
{
if (!block.getType().isOccluding())
{
visible = true;
break;
}
}
if (visible)
{
loc.getBlock().setType(type);
}
else
{
_hidden.put(loc.getBlock().getLocation(), type);
}
}
public void BlockBreak(BlockBreakEvent event)
{
for (Block block : UtilBlock.getSurrounding(event.getBlock(), false))
2013-08-27 17:14:08 +02:00
{
if (_hidden.containsKey(block.getLocation()))
{
block.setType(_hidden.remove(block.getLocation()));
}
}
}
public void Explosion(ExplosionEvent event)
{
for (Block cur : event.GetBlocks())
{
for (Block block : UtilBlock.getSurrounding(cur, false))
2013-08-27 17:14:08 +02:00
{
if (_hidden.containsKey(block.getLocation()))
{
block.setType(_hidden.remove(block.getLocation()));
}
}
}
}
public void ToggleVisibility()
{
if (!_visible)
{
for (Location loc : _hidden.keySet())
{
loc.getBlock().setType(_hidden.get(loc));
}
}
else
{
for (Location loc : _hidden.keySet())
{
loc.getBlock().setType(Material.STONE);
}
}
_visible = !_visible;
}
public NautHashMap<Location, Material> GetHiddenOre()
{
return _hidden;
}
}