Mob destroying. Removed a debug change that only selected builds with mobs in them.

This commit is contained in:
Virizion 2016-01-21 20:13:32 -05:00
parent 69825893c9
commit 636da8f4fa
3 changed files with 89 additions and 10 deletions

View File

@ -69,6 +69,7 @@ import org.bukkit.event.block.BlockSpreadEvent;
import org.bukkit.event.block.LeavesDecayEvent;
import org.bukkit.event.entity.EntityChangeBlockEvent;
import org.bukkit.event.entity.EntityCombustEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.player.PlayerBucketEmptyEvent;
import org.bukkit.event.player.PlayerBucketFillEvent;
import org.bukkit.event.player.PlayerInteractEvent;
@ -431,13 +432,7 @@ public class SpeedBuilder extends SoloGame
return;
}
//_currentBuild = UtilAlg.Random(_buildData);;
do
{
_currentBuild = UtilAlg.Random(_buildData);
}
while (_currentBuild.Mobs.isEmpty());
_currentBuild = UtilAlg.Random(_buildData);;
HashSet<Location> usedBuildLocs = new HashSet<Location>();
@ -1011,6 +1006,29 @@ public class SpeedBuilder extends SoloGame
_buildRecreations.get(event.getPlayer()).addToDemolition(event.getClickedBlock());
}
@EventHandler
public void markMobForDemolition(EntityDamageByEntityEvent event)
{
if (!(event.getDamager() instanceof Player))
return;
Player player = (Player) event.getDamager();
if (_state != SpeedBuilderState.BUILDING)
return;
if (!_buildRecreations.containsKey(player))
return;
if (_perfectBuild.containsKey(player))
return;
if (!_buildRecreations.get(player).inBuildArea(event.getEntity().getLocation()))
return;
_buildRecreations.get(player).addToDemolition(event.getEntity());
}
@EventHandler
public void updateDemolitionBlocks(UpdateEvent event)
{

View File

@ -4,15 +4,19 @@ import java.util.ArrayList;
import mineplex.core.common.util.MapUtil;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilTime;
import mineplex.core.hologram.Hologram;
import org.bukkit.Effect;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Item;
import org.bukkit.inventory.ItemStack;
import org.bukkit.material.Bed;
@ -24,6 +28,7 @@ public class DemolitionData
public RecreationData Parent;
public NautHashMap<Block, BlockState> Blocks;
public ArrayList<Entity> Mobs;
public long Start;
@ -32,11 +37,12 @@ public class DemolitionData
private boolean _flickerAir = true;
private long _lastFlicker = System.currentTimeMillis();
public DemolitionData(RecreationData parent, ArrayList<Block> blocks)
public DemolitionData(RecreationData parent, ArrayList<Block> blocks, ArrayList<Entity> mobs)
{
Parent = parent;
Blocks = new NautHashMap<Block, BlockState>();
Mobs = mobs;
for (Block block : blocks)
{
@ -50,7 +56,14 @@ public class DemolitionData
public void spawnHologram()
{
_hologram = new Hologram(Parent.Game.Manager.getHologramManager(), Blocks.keySet().iterator().next().getLocation().add(0.5, 0.5, 0.5), "3");
Location loc = Parent.getMidpoint();
if (!Blocks.isEmpty())
loc = Blocks.keySet().iterator().next().getLocation().add(0.5, 0.5, 0.5);
else if (!Mobs.isEmpty())
loc = UtilAlg.Random(Mobs).getLocation().add(0, 1, 0);
_hologram = new Hologram(Parent.Game.Manager.getHologramManager(), loc, "3");
_hologram.start();
}
@ -83,6 +96,14 @@ public class DemolitionData
Blocks.get(block).update(true, false);
}
for (Entity entity : Mobs)
{
if (_flickerAir)
UtilEnt.ghost(entity, true, true);
else
UtilEnt.ghost(entity, true, false);
}
_flickerAir = !_flickerAir;
}
@ -98,6 +119,11 @@ public class DemolitionData
{
Blocks.get(block).update(true, false);
}
for (Entity entity : Mobs)
{
UtilEnt.ghost(entity, true, false);
}
Parent.BlocksForDemolition.remove(this);
}
@ -164,6 +190,19 @@ public class DemolitionData
MapUtil.QuickChangeBlockAt(block.getLocation(), Material.AIR);
}
for (Entity entity : Mobs)
{
ItemStack spawnEgg = new ItemStack(Material.MONSTER_EGG, 1, entity.getType().getTypeId());
Item item = entity.getWorld().dropItem(entity.getLocation().add(0, 1, 0), spawnEgg);
Parent.DroppedItems.put(item, System.currentTimeMillis());
entity.remove();
Parent.Mobs.remove(entity);
}
Parent.BlocksForDemolition.remove(this);
Parent.Game.checkPerfectBuild(Parent.Player);

View File

@ -355,6 +355,17 @@ public class RecreationData
return false;
}
public boolean isQueuedForDemolition(Entity entity)
{
for (DemolitionData demolition : BlocksForDemolition)
{
if (demolition.Mobs.contains(entity))
return true;
}
return false;
}
public void addToDemolition(Block block)
{
if (isQueuedForDemolition(block))
@ -390,7 +401,18 @@ public class RecreationData
blocks.add(block.getRelative(BlockFace.UP));
}
BlocksForDemolition.add(new DemolitionData(this, blocks));
BlocksForDemolition.add(new DemolitionData(this, blocks, new ArrayList<Entity>()));
}
public void addToDemolition(Entity entity)
{
if (isQueuedForDemolition(entity))
return;
ArrayList<Entity> mobs = new ArrayList<Entity>();
mobs.add(entity);
BlocksForDemolition.add(new DemolitionData(this, new ArrayList<Block>(), mobs));
}
}