Iron Wizard: Commit progress

This commit is contained in:
libraryaddict 2015-08-14 20:49:17 +12:00
parent a1ea03f74b
commit 81f793d693
18 changed files with 3312 additions and 5 deletions

View File

@ -353,4 +353,40 @@ public class UtilAlg
return bestLoc;
}
public static Vector calculateVelocity(Vector from, Vector to, int heightGain)
{
// Gravity of a potion
double gravity = 0.115;
// Block locations
int endGain = to.getBlockY() - from.getBlockY();
double dx1 = to.getBlockX() - from.getBlockX();
double dz1 = to.getBlockZ() - from.getBlockZ();
double horizDist = Math.sqrt(dx1 * dx1 + dz1 * dz1);
// Height gain
int gain = heightGain;
double maxGain = gain > (endGain + gain) ? gain : (endGain + gain);
// Solve quadratic equation for velocity
double a = -horizDist * horizDist / (4 * maxGain);
double b = horizDist;
double c = -endGain;
double slope = -b / (2 * a) - Math.sqrt(b * b - 4 * a * c) / (2 * a);
// Vertical velocity
double vy = Math.sqrt(maxGain * gravity);
// Horizontal velocity
double vh = vy / slope;
// Calculate horizontal direction
int dx = to.getBlockX() - from.getBlockX();
int dz = to.getBlockZ() - from.getBlockZ();
double mag = Math.sqrt(dx * dx + dz * dz);
double dirx = dx / mag;
double dirz = dz / mag;
// Horizontal velocity components
double vx = vh * dirx;
double vz = vh * dirz;
return new Vector(vx, vy, vz);
}
}

View File

@ -12,6 +12,7 @@ import net.minecraft.server.v1_7_R4.Packet;
import net.minecraft.server.v1_7_R4.PlayerConnection;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftEntity;

View File

@ -30,6 +30,7 @@ import mineplex.core.creature.event.CreatureSpawnCustomEvent;
import mineplex.core.disguise.DisguiseManager;
import mineplex.core.donation.DonationManager;
import mineplex.core.energy.Energy;
import mineplex.core.explosion.Explosion;
import mineplex.core.movement.Movement;
import mineplex.core.npc.NpcManager;
import mineplex.core.packethandler.PacketHandler;
@ -102,6 +103,7 @@ public class ClansManager extends MiniClientPlugin<ClientClan> implements IRelat
private WorldEventManager _worldEvent;
private Chat _chat;
private ItemMapManager _itemMapManager;
private Explosion _explosion;
private int _inviteExpire = 2;
private int _nameMin = 3;
@ -151,6 +153,7 @@ public class ClansManager extends MiniClientPlugin<ClientClan> implements IRelat
_clanGame = new ClansGame(plugin, this);
_clanUtility = new ClansUtility(this);
_itemMapManager = new ItemMapManager(this, _worldEvent);
_explosion = new Explosion(plugin, blockRestore);
Energy energy = new Energy(plugin);
// TODO: Re-enable customtagfix with NCP update?
@ -217,6 +220,11 @@ public class ClansManager extends MiniClientPlugin<ClientClan> implements IRelat
return _itemMapManager;
}
public Explosion getExplosion()
{
return _explosion;
}
public int getInviteExpire()
{
return _inviteExpire;
@ -609,7 +617,7 @@ public class ClansManager extends MiniClientPlugin<ClientClan> implements IRelat
_worldEvent.onDisable();
}
@EventHandler
// @EventHandler
public void onJoin(PlayerLoginEvent event)
{
Rank rank = _clientManager.Get(event.getPlayer()).GetRank();

View File

@ -4,6 +4,7 @@ import org.bukkit.Location;
import mineplex.game.clans.clans.worldevent.event.WorldEvent;
import mineplex.game.clans.clans.worldevent.event.slimeking.SlimeBoss;
import mineplex.game.clans.clans.worldevent.event.golem.GolemBoss;
import mineplex.game.clans.clans.worldevent.event.kinghill.KingHill;
import mineplex.game.clans.clans.worldevent.event.undead.UndeadCamp;
@ -11,7 +12,8 @@ public enum WorldEventType
{
SLIME_KING("Slime King", SlimeBoss.class, 30),
KING_OF_THE_HILL("King of The Hill", KingHill.class, 30),
UNDEAD_CAMP("Undead Camp", UndeadCamp.class, 30);
UNDEAD_CAMP("Undead Camp", UndeadCamp.class, 30),
Golem("Iron Wizard", GolemBoss.class, 30);
private String _name;
private Class<? extends WorldEvent> _clazz;

View File

@ -145,6 +145,11 @@ public abstract class EventCreature<T extends LivingEntity> implements Listener
_entityClass = clazz;
}
public double getHealthPercent()
{
return getHealth() / getMaxHealth();
}
public Location getSpawnLocation()
{
return _spawnLocation;

View File

@ -0,0 +1,88 @@
package mineplex.game.clans.clans.worldevent.event.golem;
import java.io.File;
import java.io.IOException;
import mineplex.core.common.block.schematic.Schematic;
import mineplex.core.common.block.schematic.UtilSchematic;
import mineplex.game.clans.clans.worldevent.EventMap;
import mineplex.game.clans.clans.worldevent.WorldEventManager;
import mineplex.game.clans.clans.worldevent.creature.EventCreature;
import mineplex.game.clans.clans.worldevent.event.EventState;
import mineplex.game.clans.clans.worldevent.event.WorldEvent;
import mineplex.game.clans.clans.worldevent.event.slimeking.creature.SlimeCreature;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.util.Vector;
public class GolemBoss extends WorldEvent
{
public GolemBoss(WorldEventManager eventManager, Location corner)
{
super(eventManager, "Iron Wizard", corner);
Schematic schematic = null;
try
{
schematic = UtilSchematic.loadSchematic(new File("schematic/Golem.schematic"));
}
catch (IOException e)
{
e.printStackTrace();
setState(EventState.COMPLETE);
}
EventMap map = new EventMap(schematic, corner, 15, 15, 15, 15, 15, 15);
setMap(map, new Runnable()
{
@Override
public void run()
{
System.out.println("Runnable on complete");
}
});
}
@Override
protected void customStart()
{
Bukkit.broadcastMessage("Custom Start");
spawnGolem(getCenterLocation());
setState(EventState.LIVE);
announceStart();
}
/**
* Check if this slime boss has been defeated
*/
private void checkDeath()
{
if (getCreatures().size() == 0)
{
setState(EventState.COMPLETE);
Bukkit.broadcastMessage("FINISHED!");
}
}
@Override
public void removeCreature(EventCreature creature)
{
super.removeCreature(creature);
if (creature instanceof GolemCreature)
{
checkDeath();
}
}
private GolemCreature spawnGolem(Location location)
{
GolemCreature slimeCreature = new GolemCreature(this, location, 1500);
registerCreature(slimeCreature);
return slimeCreature;
}
}

View File

@ -0,0 +1,382 @@
package mineplex.game.clans.clans.worldevent.event.golem;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map.Entry;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.IronGolem;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.util.Vector;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTime;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.worldevent.creature.EventCreature;
import mineplex.game.clans.clans.worldevent.event.golem.abilities.*;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
public class GolemCreature extends EventCreature<IronGolem>
{
private GolemBoss _boss;
private GolemAbility _currentAbility;
private int _lastAbility;
private long _lastWalked;
private Location _standing;
private long _attackDelay = System.currentTimeMillis();
private long _reverseWalk;
private HashMap<Class, Class[]> _preferedCombos = new HashMap<Class, Class[]>();
private Class _lastAttack;
public GolemCreature(GolemBoss boss, Location location, double maxHealth)
{
super(boss, location, "Iron Wizard", true, maxHealth, IronGolem.class);
_boss = boss;
spawnEntity();
_preferedCombos.put(GolemEarthquake.class, new Class[]
{
GolemBlockHail.class, GolemRumble.class
});
_preferedCombos.put(GolemMeleeAttack.class, new Class[]
{
GolemEarthquake.class, GolemRumble.class
});
_preferedCombos.put(GolemCaveIn.class, new Class[]
{
GolemMeleeAttack.class
});
_preferedCombos.put(GolemBlockShot.class, new Class[]
{
GolemEarthquake.class
});
_preferedCombos.put(GolemRumble.class, new Class[]
{
GolemBlockShot.class
});
}
@Override
protected void spawnCustom()
{
UtilEnt.Vegetate(getEntity());
// EntityInsentient creature = (EntityInsentient) ((CraftEntity) getEntity()).getHandle();
// creature.Vegetated = false;
_standing = getEntity().getLocation();
}
@EventHandler
public void abilityTick(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
return;
if (!UtilTime.elapsed(_attackDelay, 5000))
{
_standing = getEntity().getLocation();
return;
}
if (_currentAbility == null || _currentAbility.hasFinished())
{
if (_currentAbility != null)
{
_lastAttack = _currentAbility.getClass();
_currentAbility.setFinished();
_lastAbility = 30;// _currentAbility.getCooldown();
HandlerList.unregisterAll(_currentAbility);
System.out.print("Unregistered golem ability " + _currentAbility.getClass().getSimpleName());
// Bukkit.broadcastMessage("Ability end");
_currentAbility = null;
}
else if (_lastAbility-- <= 0 && UtilBlock.solid(getEntity().getLocation().getBlock().getRelative(BlockFace.DOWN)))
{
HashMap<Class, Integer> weight = new HashMap<Class, Integer>();
HashMap<Player, Double> dist = new HashMap<Player, Double>();
for (Player player : UtilPlayer.getNearby(getEntity().getLocation(), 50))
{
if (player.hasLineOfSight(getEntity()))
{
dist.put(player, player.getLocation().distance(getEntity().getLocation()));
}
}
if (!dist.isEmpty())
{
{ // Melee
ArrayList<Player> players = getPlayers(dist, 3);
if (!players.isEmpty())
{
weight.put(GolemMeleeAttack.class, 3 + (players.size() * 5));
}
}
{ // Earthquake
ArrayList<Player> players = getPlayers(dist, 6);
if (!players.isEmpty())
{
weight.put(GolemEarthquake.class, players.size() * 2);
}
}
{ // Wall explode
ArrayList<Player> players = getPlayers(dist, 12);
for (Player player : players)
{
if (dist.get(player) > 4)
{
weight.put(GolemWallExplode.class, 4);
break;
}
}
}
{ // Rumble
ArrayList<Player> players = getPlayers(dist, 30);
if (!players.isEmpty())
{
weight.put(GolemRumble.class, (int) Math.min(5, dist.get(players.get(0))));
}
}
{ // Cave in
ArrayList<Player> players = getPlayers(dist, 30);
if (!players.isEmpty())
{
weight.put(GolemCaveIn.class, (int) Math.min(players.size() * 2, 7));
}
}
{// Block Hail
ArrayList<Player> players = getPlayers(dist, 30);
if (!players.isEmpty())
{
weight.put(GolemBlockHail.class, (int) Math.min(5, dist.get(players.get(0))));
}
}
if (_lastAttack != null && _preferedCombos.containsKey(_lastAttack))
{
weight.remove(_lastAttack);
for (Class c : _preferedCombos.get(_lastAttack))
{
if (weight.containsKey(c))
{
weight.put(c, weight.get(c) + 5);
}
}
}
if (!weight.isEmpty())
{
int i = 0;
for (Integer entry : weight.values())
{
i += entry;
}
for (int a = 0; a < 10; a++)
{
int luckyNumber = UtilMath.r(i);
for (Entry<Class, Integer> entry : weight.entrySet())
{
luckyNumber -= entry.getValue();
if (luckyNumber <= 0)
{
try
{
_currentAbility = (GolemAbility) entry.getKey().getConstructor(GolemCreature.class)
.newInstance(this);
if (_currentAbility.getTarget() == null)
{
_currentAbility = null;
}
else
{
break;
}
}
catch (Exception ex)
{
ex.printStackTrace();
}
break;
}
}
}
}
if (_currentAbility != null && _currentAbility.getTarget() != null)
{
Bukkit.getPluginManager().registerEvents(_currentAbility, _boss.getEventManager().getPlugin());
// Bukkit.broadcastMessage("Ability: " + _currentAbility.getClass().getSimpleName());
System.out.print("Golem boss is using " + _currentAbility.getClass().getSimpleName());
}
else
{
_currentAbility = null;
_lastAbility = 10;
}
}
_lastAttack = null;
}
}
if (_currentAbility != null)
{
_currentAbility.tick();
}
if (_currentAbility == null || _currentAbility.canMove())
{
Player target = null;
double dist = 0;
for (Player player : UtilServer.getPlayers())
{
if (!player.hasLineOfSight(getEntity()))
{
continue;
}
double d = player.getLocation().distance(getEntity().getLocation());
if (d > 1.5 && (d < 7 || d > 15) && (target == null || (d < 50 && dist > d)))
{
target = player;
dist = d;
}
}
Vector vec = null;
boolean reverse = target != null && dist < 8;
if (target != null)
{
vec = target.getLocation().subtract(getEntity().getLocation()).toVector();
vec.setY(getEntity().getLocation().getY());
double len = vec.length();
vec.setX(vec.getX() * (UtilMath.random.nextDouble() / 3D));
vec.setZ(vec.getZ() * (UtilMath.random.nextDouble() / 3D));
vec.multiply(len);
}
else if (UtilTime.elapsed(_lastWalked, 10000))
{
vec = new Vector(UtilMath.r(50) - 25, 0, UtilMath.r(50) - 25);
}
if (vec != null)
{
_lastWalked = System.currentTimeMillis();
if (reverse)
{
vec.multiply(-1);
}
if (!UtilAlg.HasSight(getEntity().getLocation(),
getEntity().getLocation().add(vec.clone().normalize().multiply(2))))
{
_reverseWalk = System.currentTimeMillis();
}
if (!UtilTime.elapsed(_reverseWalk, 4000))
{
vec.multiply(-1);
}
// if (vec.length() > 1)
{
UtilEnt.CreatureMoveFast(getEntity(), getEntity().getLocation().add(vec), 1.5F);
}
}
_standing = getEntity().getLocation();
}
else
{
Location l = getEntity().getLocation();
_standing.setYaw(l.getYaw());
_standing.setPitch(l.getPitch());
_standing.setY(l.getY());
getEntity().teleport(_standing);
}
}
private ArrayList<Player> getPlayers(HashMap<Player, Double> map, double maxDist)
{
ArrayList<Player> list = new ArrayList<Player>();
for (Player p : map.keySet())
{
if (map.get(p) < maxDist)
{
list.add(p);
}
}
return list;
}
@EventHandler
public void onGolemDamage(CustomDamageEvent event)
{
if (event.GetDamageeEntity().equals(getEntity()))
{
event.AddKnockback("Heavy Golem", 0.3);
}
}
@Override
public void dieCustom()
{
if (_currentAbility != null)
{
_currentAbility.setFinished();
HandlerList.unregisterAll(_currentAbility);
_currentAbility = null;
}
}
}

View File

@ -0,0 +1,86 @@
package mineplex.game.clans.clans.worldevent.event.golem.abilities;
import mineplex.core.common.util.UtilEnt;
import net.minecraft.server.v1_7_R4.DataWatcher;
import net.minecraft.server.v1_7_R4.Packet;
import net.minecraft.server.v1_7_R4.PacketPlayOutAttachEntity;
import net.minecraft.server.v1_7_R4.PacketPlayOutEntityDestroy;
import net.minecraft.server.v1_7_R4.PacketPlayOutSpawnEntity;
import net.minecraft.server.v1_7_R4.PacketPlayOutSpawnEntityLiving;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftEntity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.IronGolem;
public class BlockHailBlock
{
private int _block = UtilEnt.getNewEntityId();
private int _chicken = UtilEnt.getNewEntityId();
private Location _location;
private Material _mat;
public BlockHailBlock(Location loc, Material mat)
{
_location = loc;
_mat = mat;
}
public Packet getDestroyPacket()
{
return new PacketPlayOutEntityDestroy(new int[]
{
_chicken, _block
});
}
public Location getLocation()
{
return _location;
}
public Material getMaterial()
{
return _mat;
}
public Packet[] getSpawnPackets(IronGolem entity)
{
Packet[] packets = new Packet[3];
PacketPlayOutSpawnEntityLiving packet1 = new PacketPlayOutSpawnEntityLiving();
DataWatcher watcher = new DataWatcher(null);
watcher.a(0, (byte) 32);
watcher.a(1, 0);
packet1.a = _chicken;
packet1.b = EntityType.SILVERFISH.getTypeId();
packet1.c = (int) Math.floor(_location.getX() * 32);
packet1.d = (int) Math.floor(_location.getY() * 32);
packet1.e = (int) Math.floor(_location.getZ() * 32);
packet1.l = watcher;
packets[0] = packet1;
PacketPlayOutSpawnEntity packet2 = new PacketPlayOutSpawnEntity(((CraftEntity) entity).getHandle(), 70, _mat.getId());
packet2.a = _block;
packet2.b = (int) Math.floor(_location.getX() * 32);
packet2.c = (int) Math.floor(entity.getLocation().getY() * 32);
packet2.d = (int) Math.floor(_location.getZ() * 32);
packets[1] = packet2;
PacketPlayOutAttachEntity packet3 = new PacketPlayOutAttachEntity();
packet3.b = _block;
packet3.c = _chicken;
packets[2] = packet3;
return packets;
}
}

View File

@ -0,0 +1,98 @@
package mineplex.game.clans.clans.worldevent.event.golem.abilities;
import java.util.HashMap;
import java.util.UUID;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTime;
import mineplex.game.clans.clans.worldevent.event.golem.GolemCreature;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.IronGolem;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
public abstract class GolemAbility implements Listener
{
private GolemCreature _creature;
private HashMap<UUID, Long> _damaged = new HashMap<UUID, Long>();
public boolean canDamage(Entity player)
{
if (_damaged.containsKey(player.getUniqueId()))
{
if (!UtilTime.elapsed(_damaged.get(player.getUniqueId()), 400))
{
return false;
}
}
_damaged.put(player.getUniqueId(), System.currentTimeMillis());
return true;
}
public GolemAbility(GolemCreature creature)
{
_creature = creature;
}
public abstract boolean canMove();
public int getCooldown()
{
return 60;
}
public IronGolem getEntity()
{
return getGolem().getEntity();
}
public GolemCreature getGolem()
{
return _creature;
}
public Location getLocation()
{
return getEntity().getLocation();
}
public Player getTarget()
{
return getTarget(30);
}
public Player getTarget(double maxDistance)
{
Player target = null;
double dist = 0;
for (Player player : UtilServer.getPlayers())
{
if (!player.hasLineOfSight(getEntity()))
{
continue;
}
double d = player.getLocation().distance(getLocation());
if (d <= maxDistance && (target == null || dist > d))
{
target = player;
dist = d;
}
}
return target;
}
public abstract boolean hasFinished();
public abstract void setFinished();
public abstract void tick();
}

View File

@ -0,0 +1,430 @@
package mineplex.game.clans.clans.worldevent.event.golem.abilities;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilParticle.ParticleType;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilShapes;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.worldevent.event.golem.GolemCreature;
import net.minecraft.server.v1_7_R4.AxisAlignedBB;
import net.minecraft.server.v1_7_R4.EntityIronGolem;
import net.minecraft.server.v1_7_R4.MathHelper;
import net.minecraft.server.v1_7_R4.MovingObjectPosition;
import net.minecraft.server.v1_7_R4.Packet;
import net.minecraft.server.v1_7_R4.Vec3D;
import org.bukkit.Effect;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_7_R4.CraftWorld;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftIronGolem;
import org.bukkit.entity.Entity;
import org.bukkit.entity.FallingBlock;
import org.bukkit.entity.IronGolem;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.util.Vector;
/**
* Rumble is where the golem picks a target then starts playing a animation for a second where its obviously preparing to use it.
* Copy this from Wizards
*/
public class GolemBlockHail extends GolemAbility
{
private int _currentBlock;
private int _currentLevel;
private ArrayList<FallingBlock> _fallingBlocks = new ArrayList<FallingBlock>();
private HashMap<Integer, ArrayList<BlockHailBlock>> _floatingBlocks = new HashMap<Integer, ArrayList<BlockHailBlock>>();
private int _levelToReach;
private boolean _spawned;
private ArrayList<Location> _spawnLocs = new ArrayList<Location>();
private Player _target;
private Location _center;
private int _ticks;
public GolemBlockHail(GolemCreature creature)
{
super(creature);
_center = getLocation();
if (creature.getHealthPercent() > 0.75)
{
_levelToReach = 1;
}
else if (creature.getHealthPercent() > 0.5)
{
_levelToReach = 2;
}
else
{
_levelToReach = 3;
}
_target = getTarget();
}
@Override
public Player getTarget()
{
Player target = null;
double dist = 0;
for (Player player : UtilPlayer.getNearby(_center, 40))
{
if (!player.hasLineOfSight(getEntity()))
{
continue;
}
double d = player.getLocation().distance(_center);
if (target == null || dist > d)
{
target = player;
dist = d;
}
}
return target;
}
@Override
public boolean canMove()
{
return _spawned && _floatingBlocks.isEmpty();
}
@Override
public boolean hasFinished()
{
return _target == null || !_target.isValid() || ((_fallingBlocks.isEmpty() && _spawned) && _ticks >= 8 * 9)
|| _center.distance(_target.getLocation()) > 100;
}
@EventHandler
public void onUpdate(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
{
return;
}
Iterator<FallingBlock> fallingIterator = _fallingBlocks.iterator();
while (fallingIterator.hasNext())
{
FallingBlock cur = fallingIterator.next();
if (cur.isDead() || !cur.isValid() || cur.getTicksLived() > 400
|| !cur.getWorld().isChunkLoaded(cur.getLocation().getBlockX() >> 4, cur.getLocation().getBlockZ() >> 4))
{
fallingIterator.remove();
Block block = cur.getLocation().getBlock();
block.setTypeIdAndData(0, (byte) 0, true);
cur.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, cur.getBlockId());
// Expire
if (cur.getTicksLived() > 400
|| !cur.getWorld().isChunkLoaded(cur.getLocation().getBlockX() >> 4, cur.getLocation().getBlockZ() >> 4))
{
cur.remove();
continue;
}
cur.remove();
continue;
}
double distanceToEntity = 0.0D;
LivingEntity victim = null;
net.minecraft.server.v1_7_R4.Entity nmsEntity = ((CraftEntity) cur).getHandle();
Vec3D vec3d = Vec3D.a(nmsEntity.locX, nmsEntity.locY, nmsEntity.locZ);
Vec3D vec3d1 = Vec3D.a(nmsEntity.locX + nmsEntity.motX, nmsEntity.locY + nmsEntity.motY, nmsEntity.locZ
+ nmsEntity.motZ);
MovingObjectPosition finalObjectPosition = nmsEntity.world.rayTrace(vec3d, vec3d1, false, true, false);
vec3d = Vec3D.a(nmsEntity.locX, nmsEntity.locY, nmsEntity.locZ);
vec3d1 = Vec3D.a(nmsEntity.locX + nmsEntity.motX, nmsEntity.locY + nmsEntity.motY, nmsEntity.locZ + nmsEntity.motZ);
if (finalObjectPosition != null)
{
vec3d1 = Vec3D.a(finalObjectPosition.pos.a, finalObjectPosition.pos.b, finalObjectPosition.pos.c);
}
for (Object entity : ((CraftWorld) cur.getWorld()).getHandle().getEntities(
((CraftEntity) cur).getHandle(),
((CraftEntity) cur).getHandle().boundingBox.a(((CraftEntity) cur).getHandle().motX,
((CraftEntity) cur).getHandle().motY, ((CraftEntity) cur).getHandle().motZ).grow(2, 2, 2)))
{
Entity bukkitEntity = ((net.minecraft.server.v1_7_R4.Entity) entity).getBukkitEntity();
if (bukkitEntity instanceof LivingEntity)
{
LivingEntity ent = (LivingEntity) bukkitEntity;
// Avoid Self
if (ent.equals(getEntity()))
continue;
// Creative or Spec
if (ent instanceof Player)
if (((Player) ent).getGameMode() == GameMode.CREATIVE || UtilPlayer.isSpectator(ent))
continue;
// float f1 = (float)(nmsEntity.boundingBox.a() * 0.6f);
AxisAlignedBB axisalignedbb1 = ((CraftEntity) ent).getHandle().boundingBox.grow(1F, 1F, 1F);
MovingObjectPosition entityCollisionPosition = axisalignedbb1.a(vec3d, vec3d1);
if (entityCollisionPosition != null)
{
double d1 = vec3d.distanceSquared(entityCollisionPosition.pos);
if ((d1 < distanceToEntity) || (distanceToEntity == 0.0D))
{
victim = ent;
distanceToEntity = d1;
}
}
}
}
if (victim != null)
{
cur.getWorld().playEffect(victim.getEyeLocation().subtract(0, 0.5, 0), Effect.STEP_SOUND, cur.getBlockId());
if (canDamage(victim))
{
getGolem()
.getEvent()
.getDamageManager()
.NewDamageEvent((LivingEntity) victim, getEntity(), null, DamageCause.CONTACT, 6, true, true, false,
"Block Hail", "Block Hail");
}
if (victim instanceof Player)
{
getGolem().getEvent().getEventManager().getClans().getCondition().Factory()
.Slow("Block Hail", (LivingEntity) victim, getEntity(), 3, 2, false, false, false, false);
}
fallingIterator.remove();
cur.remove();
}
else if (finalObjectPosition != null)
{
Block block = cur.getWorld().getBlockAt(finalObjectPosition.b, finalObjectPosition.c, finalObjectPosition.d);
if (!UtilBlock.airFoliage(block) && !block.isLiquid())
{
nmsEntity.motX = ((float) (finalObjectPosition.pos.a - nmsEntity.locX));
nmsEntity.motY = ((float) (finalObjectPosition.pos.b - nmsEntity.locY));
nmsEntity.motZ = ((float) (finalObjectPosition.pos.c - nmsEntity.locZ));
float f2 = MathHelper.sqrt(nmsEntity.motX * nmsEntity.motX + nmsEntity.motY * nmsEntity.motY + nmsEntity.motZ
* nmsEntity.motZ);
nmsEntity.locX -= nmsEntity.motX / f2 * 0.0500000007450581D;
nmsEntity.locY -= nmsEntity.motY / f2 * 0.0500000007450581D;
nmsEntity.locZ -= nmsEntity.motZ / f2 * 0.0500000007450581D;
cur.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, cur.getBlockId());
fallingIterator.remove();
cur.remove();
}
}
else
{
UtilParticle.PlayParticle(ParticleType.BLOCK_DUST.getParticle(Material.STONE, 0), cur.getLocation()
.add(0, 0.5, 0), 0.3F, 0.3F, 0.3F, 0, 2, UtilParticle.ViewDist.NORMAL, UtilServer.getPlayers());
}
}
}
@Override
public void setFinished()
{
for (ArrayList<BlockHailBlock> floatingBlocks : _floatingBlocks.values())
{
for (BlockHailBlock falling : floatingBlocks)
{
Packet packet = falling.getDestroyPacket();
for (Player player : UtilServer.getPlayers())
{
UtilPlayer.sendPacket(player, packet);
}
}
}
}
@Override
public void tick()
{
if (!_spawned)
{
if (_currentBlock >= _spawnLocs.size())
{
if (_currentLevel + 1 <= _levelToReach)
{
_currentLevel++;
_currentBlock = 0;
_spawnLocs = UtilShapes.getDistancedCircle(_center.clone().add(0, 2.8 + (_currentLevel * 0.75), 0), 1.3,
1 + (_currentLevel * 1.3));
}
}
if (_currentBlock < _spawnLocs.size())
{
if (_ticks % 2 == 0)
{
IronGolem entity = getEntity();
Location loc = _spawnLocs.get(_currentBlock++);
ArrayList<BlockHailBlock> floatingBlocks = new ArrayList<BlockHailBlock>();
if (_floatingBlocks.containsKey(_currentLevel))
{
floatingBlocks = _floatingBlocks.get(_currentLevel);
}
else
{
_floatingBlocks.put(_currentLevel, floatingBlocks);
}
if (loc.getBlock().getType() == Material.AIR && UtilAlg.HasSight(entity.getLocation(), loc))
{
BlockHailBlock floating = new BlockHailBlock(loc, Material.STONE);
UtilEnt.CreatureLook(entity, _target);
floatingBlocks.add(floating);
Packet[] packets = floating.getSpawnPackets(entity);
for (Player player : UtilServer.getPlayers())
{
if (player.getLocation().distance(loc) < 100)
{
UtilPlayer.sendPacket(player, packets);
}
}
entity.getWorld().playSound(entity.getLocation(), Sound.DIG_GRASS, 3, 0.9F);
}
if (_floatingBlocks.size() % 2 == 0)
{
Collections.reverse(floatingBlocks);
}
}
}
else
{
_spawned = true;
_ticks = -20;
}
}
else if (_ticks > 0 && _ticks % 2 == 0 && !_floatingBlocks.isEmpty())
{
IronGolem entity = getEntity();
if (_ticks % 16 == 0)
{
_target = getTarget();
if (_target == null)
return;
}
EntityIronGolem golem = ((CraftIronGolem) entity).getHandle();
golem.world.broadcastEntityEffect(golem, (byte) 4);
UtilEnt.CreatureLook(entity, _target);
BlockHailBlock floatingBlock = null;
for (int i = 1; i <= _currentLevel; i++)
{
if (_floatingBlocks.containsKey(i))
{
floatingBlock = _floatingBlocks.get(i).remove(0);
if (_floatingBlocks.get(i).isEmpty())
{
_floatingBlocks.remove(i);
}
break;
}
}
Packet packet = floatingBlock.getDestroyPacket();
for (Player player : UtilServer.getPlayers())
{
UtilPlayer.sendPacket(player, packet);
}
Location loc = floatingBlock.getLocation();
FallingBlock b = loc.getWorld().spawnFallingBlock(loc, floatingBlock.getMaterial(), (byte) 0);
b.setDropItem(false);
Vector vec = UtilAlg.calculateVelocity(
loc.toVector(),
_target.getLocation()
.toVector()
.add(new Vector(UtilMath.r(6 + (_currentLevel * 2)) - (2 + _currentLevel), 0, UtilMath
.r(6 + (_currentLevel * 2)) - (2 + _currentLevel))), 6);
b.setVelocity(vec);
_fallingBlocks.add(b);
entity.getWorld().playSound(entity.getLocation(), Sound.IRONGOLEM_THROW, 3, 0.9F);
}
ArrayList<Location> points = new ArrayList<Location>();
for (int i = _currentLevel; i <= _currentLevel; i++)
{
points.addAll(UtilShapes.getDistancedCircle(_center.clone().add(0, 3.3 + (i * 0.75), 0), 0.3, 1 + (i * 1.3)));
}
for (int i = 0; i < points.size(); i++)
{
if (_spawned || i < _ticks)
{
Location loc = points.get(i);
UtilParticle.PlayParticle(
ParticleType.BLOCK_DUST.getParticle(_spawned && i < _ticks ? Material.STONE : Material.DIRT, 0), loc, 0,
0, 0, 0, 0, UtilParticle.ViewDist.LONG, UtilServer.getPlayers());
}
}
_ticks++;
}
}

View File

@ -0,0 +1,412 @@
package mineplex.game.clans.clans.worldevent.event.golem.abilities;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map.Entry;
import java.util.UUID;
import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilParticle.ParticleType;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTime;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.worldevent.event.golem.GolemCreature;
import net.minecraft.server.v1_7_R4.AxisAlignedBB;
import net.minecraft.server.v1_7_R4.EntityIronGolem;
import net.minecraft.server.v1_7_R4.MathHelper;
import net.minecraft.server.v1_7_R4.MovingObjectPosition;
import net.minecraft.server.v1_7_R4.PacketPlayOutEntityDestroy;
import net.minecraft.server.v1_7_R4.PacketPlayOutEntityVelocity;
import net.minecraft.server.v1_7_R4.PacketPlayOutSpawnEntity;
import net.minecraft.server.v1_7_R4.Vec3D;
import org.bukkit.Bukkit;
import org.bukkit.Effect;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.craftbukkit.v1_7_R4.CraftWorld;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftIronGolem;
import org.bukkit.entity.Entity;
import org.bukkit.entity.FallingBlock;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.util.Vector;
public class GolemBlockShot extends GolemAbility
{
private HashMap<Integer, Location> _blockLoc = new HashMap<Integer, Location>();
private HashMap<Integer, Material> _blockType = new HashMap<Integer, Material>();
private ArrayList<FallingBlock> _current = new ArrayList<FallingBlock>();
private HashMap<Integer, Long> _preshoot = new HashMap<Integer, Long>();
private Player _target;
private HashMap<Integer, Player> _targetBlock = new HashMap<Integer, Player>();
private HashMap<UUID, Integer> _shotAt = new HashMap<UUID, Integer>();
private int _thrown;
private int _tick;
private int _toThrow;
public GolemBlockShot(GolemCreature creature)
{
super(creature);
if (creature.getHealthPercent() > 0.75)
{
_toThrow = 3;
}
else if (creature.getHealthPercent() > 0.5)
{
_toThrow = 6;
}
else
{
_toThrow = 9;
}
_target = getTarget();
}
@Override
public boolean canMove()
{
return _current.isEmpty() && _thrown == _toThrow;
}
@Override
public Player getTarget()
{
Player target = null;
double dist = 0;
Location loc1 = getLocation();
Location loc2 = loc1.clone().add(loc1.getDirection().setY(0).normalize());
LinkedList<Player> players = UtilPlayer.getNearby(getLocation(), 40);
for (Player player : players)
{
if (_shotAt.containsKey(player.getUniqueId()) && _shotAt.get(player.getUniqueId()) >= 3)
{
continue;
}
double dist1 = player.getLocation().distance(loc1);
double dist2 = player.getLocation().distance(loc2);
double dist3 = dist1 - dist2;
if (dist3 < 0.6 || dist1 > 30 || (target != null && dist3 < dist))
{
continue;
}
if (!player.hasLineOfSight(getEntity()))
{
continue;
}
target = player;
dist = dist3;
}
return target;
}
@Override
public boolean hasFinished()
{
return _current.isEmpty() && _preshoot.isEmpty() && (_target == null || _thrown == _toThrow);
}
@EventHandler
public void onUpdate(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
{
return;
}
Iterator<FallingBlock> fallingIterator = _current.iterator();
while (fallingIterator.hasNext())
{
FallingBlock cur = fallingIterator.next();
if (cur.isDead() || !cur.isValid() || cur.getTicksLived() > 400
|| !cur.getWorld().isChunkLoaded(cur.getLocation().getBlockX() >> 4, cur.getLocation().getBlockZ() >> 4))
{
fallingIterator.remove();
Block block = cur.getLocation().getBlock();
block.setTypeIdAndData(0, (byte) 0, true);
cur.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, cur.getBlockId());
// Expire
if (cur.getTicksLived() > 400
|| !cur.getWorld().isChunkLoaded(cur.getLocation().getBlockX() >> 4, cur.getLocation().getBlockZ() >> 4))
{
cur.remove();
continue;
}
cur.remove();
continue;
}
double distanceToEntity = 0.0D;
LivingEntity victim = null;
net.minecraft.server.v1_7_R4.Entity nmsEntity = ((CraftEntity) cur).getHandle();
Vec3D vec3d = Vec3D.a(nmsEntity.locX, nmsEntity.locY, nmsEntity.locZ);
Vec3D vec3d1 = Vec3D.a(nmsEntity.locX + nmsEntity.motX, nmsEntity.locY + nmsEntity.motY, nmsEntity.locZ
+ nmsEntity.motZ);
MovingObjectPosition finalObjectPosition = nmsEntity.world.rayTrace(vec3d, vec3d1, false, true, false);
vec3d = Vec3D.a(nmsEntity.locX, nmsEntity.locY, nmsEntity.locZ);
vec3d1 = Vec3D.a(nmsEntity.locX + nmsEntity.motX, nmsEntity.locY + nmsEntity.motY, nmsEntity.locZ + nmsEntity.motZ);
if (finalObjectPosition != null)
{
vec3d1 = Vec3D.a(finalObjectPosition.pos.a, finalObjectPosition.pos.b, finalObjectPosition.pos.c);
}
for (Object entity : ((CraftWorld) cur.getWorld()).getHandle().getEntities(
((CraftEntity) cur).getHandle(),
((CraftEntity) cur).getHandle().boundingBox.a(((CraftEntity) cur).getHandle().motX,
((CraftEntity) cur).getHandle().motY, ((CraftEntity) cur).getHandle().motZ).grow(2, 2, 2)))
{
Entity bukkitEntity = ((net.minecraft.server.v1_7_R4.Entity) entity).getBukkitEntity();
if (bukkitEntity instanceof LivingEntity)
{
LivingEntity ent = (LivingEntity) bukkitEntity;
// Avoid Self
if (ent.equals(getEntity()))
continue;
// Creative or Spec
if (ent instanceof Player)
if (((Player) ent).getGameMode() == GameMode.CREATIVE || UtilPlayer.isSpectator(ent))
continue;
// float f1 = (float)(nmsEntity.boundingBox.a() * 0.6f);
AxisAlignedBB axisalignedbb1 = ((CraftEntity) ent).getHandle().boundingBox.grow(1F, 1F, 1F);
MovingObjectPosition entityCollisionPosition = axisalignedbb1.a(vec3d, vec3d1);
if (entityCollisionPosition != null)
{
double d1 = vec3d.distanceSquared(entityCollisionPosition.pos);
if ((d1 < distanceToEntity) || (distanceToEntity == 0.0D))
{
victim = ent;
distanceToEntity = d1;
}
}
}
}
if (victim != null)
{
cur.getWorld().playEffect(victim.getEyeLocation().subtract(0, 0.5, 0), Effect.STEP_SOUND, cur.getBlockId());
getGolem()
.getEvent()
.getDamageManager()
.NewDamageEvent((LivingEntity) victim, getEntity(), null, DamageCause.CONTACT, 6, true, true, false,
"Block Throw", "Block Throw");
cur.remove();
fallingIterator.remove();
Vector vec = UtilAlg.getTrajectory(cur, victim);
vec.setY(0).normalize();
UtilAction.velocity(victim, vec, 1.2, true, 0, 0.1, 1, true);
}
else if (finalObjectPosition != null)
{
Block block = cur.getWorld().getBlockAt(finalObjectPosition.b, finalObjectPosition.c, finalObjectPosition.d);
if (!UtilBlock.airFoliage(block) && !block.isLiquid())
{
nmsEntity.motX = ((float) (finalObjectPosition.pos.a - nmsEntity.locX));
nmsEntity.motY = ((float) (finalObjectPosition.pos.b - nmsEntity.locY));
nmsEntity.motZ = ((float) (finalObjectPosition.pos.c - nmsEntity.locZ));
float f2 = MathHelper.sqrt(nmsEntity.motX * nmsEntity.motX + nmsEntity.motY * nmsEntity.motY + nmsEntity.motZ
* nmsEntity.motZ);
nmsEntity.locX -= nmsEntity.motX / f2 * 0.0500000007450581D;
nmsEntity.locY -= nmsEntity.motY / f2 * 0.0500000007450581D;
nmsEntity.locZ -= nmsEntity.motZ / f2 * 0.0500000007450581D;
cur.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, cur.getBlockId());
cur.remove();
fallingIterator.remove();
}
}
else
{
UtilParticle.PlayParticle(ParticleType.BLOCK_DUST.getParticle(Material.STONE, 0), cur.getLocation()
.add(0, 0.5, 0), 0.3F, 0.3F, 0.3F, 0, 2, UtilParticle.ViewDist.NORMAL, UtilServer.getPlayers());
}
}
}
@Override
public void setFinished()
{
for (FallingBlock falling : _current)
{
falling.remove();
}
int[] ids = new int[_preshoot.size()];
int a = 0;
for (int id : _preshoot.keySet())
{
ids[a++] = id;
}
PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(ids);
for (Player player : Bukkit.getOnlinePlayers())
{
UtilPlayer.sendPacket(player, packet);
}
}
@Override
public void tick()
{
if (_target == null || _target.getLocation().distance(getLocation()) > 30 || !_target.hasLineOfSight(getEntity()))
{
_target = getTarget();
}
Entity entity = getEntity();
if (_tick++ % 16 == 0 && _target != null && _thrown < _toThrow)
{
_thrown++;
UtilEnt.CreatureLook(entity, _target);
EntityIronGolem golem = ((CraftIronGolem) entity).getHandle();
golem.world.broadcastEntityEffect(golem, (byte) 4);
entity.getWorld().playSound(entity.getLocation(), Sound.IRONGOLEM_THROW, 2, 1);
Location loc = entity.getLocation();
loc.setYaw(loc.getYaw() + (UtilMath.r(150) - 75));
loc.add(loc.getDirection().setY(0).normalize());
Block block = loc.getBlock();
if (block.getType() == Material.AIR)
{
block = block.getRelative(BlockFace.DOWN);
}
Material mat = block.getType();
if (!UtilBlock.solid(block))
{
mat = Material.STONE;
}
int id = UtilEnt.getNewEntityId();
_preshoot.put(id, System.currentTimeMillis());
_blockType.put(id, mat);
_blockLoc.put(id, loc.clone().add(0, 0.6, 0));
_targetBlock.put(id, _target);
PacketPlayOutSpawnEntity packet = new PacketPlayOutSpawnEntity(((CraftEntity) entity).getHandle(), 70, mat.getId());
packet.a = id;
packet.b = (int) Math.floor(loc.getX() * 32);
packet.c = (int) Math.floor(loc.getY() * 32);
packet.d = (int) Math.floor(loc.getZ() * 32);
packet.g = (int) ((0.45) * 8000);
PacketPlayOutEntityVelocity packet2 = new PacketPlayOutEntityVelocity(id, 0, 0.45D, 0);
for (Player player : UtilPlayer.getNearby(loc, 70))
{
UtilPlayer.sendPacket(player, packet, packet2);
}
_shotAt.put(_target.getUniqueId(), (_shotAt.containsKey(_target.getUniqueId()) ? _shotAt.get(_target.getUniqueId())
: 0) + 1);
_target = getTarget();
}
else
{
Iterator<Entry<Integer, Long>> itel = _preshoot.entrySet().iterator();
while (itel.hasNext())
{
Entry<Integer, Long> entry = itel.next();
if (UtilTime.elapsed(entry.getValue(), 900))
{
itel.remove();
int id = entry.getKey();
PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(new int[]
{
id
});
for (Player player : Bukkit.getOnlinePlayers())
{
UtilPlayer.sendPacket(player, packet);
}
Location loc = _blockLoc.get(id);
FallingBlock falling = loc.getWorld().spawnFallingBlock(loc, _blockType.get(id), (byte) 0);
falling.setDropItem(false);
_current.add(falling);
Player target = _targetBlock.get(id);
UtilEnt.CreatureLook(entity, target);
EntityIronGolem golem = ((CraftIronGolem) entity).getHandle();
golem.world.broadcastEntityEffect(golem, (byte) 4);
entity.getWorld().playSound(entity.getLocation(), Sound.IRONGOLEM_THROW, 2, 1.2F);
entity.getWorld().playEffect(falling.getLocation(), Effect.STEP_SOUND, falling.getBlockId());
Location l = falling.getLocation();
l.setY(entity.getLocation().getY());
Vector vector = UtilAlg.getTrajectory(l, target.getEyeLocation());
falling.setVelocity(vector.multiply(0.5 + (l.distance(target.getEyeLocation()) / 10)));
}
}
}
}
}

View File

@ -0,0 +1,316 @@
package mineplex.game.clans.clans.worldevent.event.golem.abilities;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilParticle.ParticleType;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilShapes;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.worldevent.event.golem.GolemCreature;
import net.minecraft.server.v1_7_R4.AxisAlignedBB;
import net.minecraft.server.v1_7_R4.MathHelper;
import net.minecraft.server.v1_7_R4.MovingObjectPosition;
import net.minecraft.server.v1_7_R4.Vec3D;
import org.bukkit.Effect;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_7_R4.CraftWorld;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftEntity;
import org.bukkit.entity.Entity;
import org.bukkit.entity.FallingBlock;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.util.Vector;
public class GolemCaveIn extends GolemAbility
{
private ArrayList<Block> _blocks = new ArrayList<Block>();
private ArrayList<FallingBlock> _fallingBlocks = new ArrayList<FallingBlock>();
private int _tick;
public GolemCaveIn(GolemCreature creature)
{
super(creature);
}
@Override
public boolean canMove()
{
return false;
}
@Override
public Player getTarget()
{
if (getTarget(3) == null)
{
return getTarget(40);
}
return null;
}
@Override
public boolean hasFinished()
{
return _tick > 60 && _fallingBlocks.isEmpty();
}
@EventHandler
public void onUpdate(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
{
return;
}
Iterator<FallingBlock> fallingIterator = _fallingBlocks.iterator();
while (fallingIterator.hasNext())
{
FallingBlock cur = fallingIterator.next();
if (cur.isDead() || !cur.isValid() || cur.getTicksLived() > 400
|| !cur.getWorld().isChunkLoaded(cur.getLocation().getBlockX() >> 4, cur.getLocation().getBlockZ() >> 4))
{
fallingIterator.remove();
Block block = cur.getLocation().getBlock();
block.setTypeIdAndData(0, (byte) 0, true);
cur.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, cur.getBlockId());
// Expire
if (cur.getTicksLived() > 400
|| !cur.getWorld().isChunkLoaded(cur.getLocation().getBlockX() >> 4, cur.getLocation().getBlockZ() >> 4))
{
cur.remove();
continue;
}
cur.remove();
continue;
}
double distanceToEntity = 0.0D;
LivingEntity victim = null;
net.minecraft.server.v1_7_R4.Entity nmsEntity = ((CraftEntity) cur).getHandle();
Vec3D vec3d = Vec3D.a(nmsEntity.locX, nmsEntity.locY, nmsEntity.locZ);
Vec3D vec3d1 = Vec3D.a(nmsEntity.locX + nmsEntity.motX, nmsEntity.locY + nmsEntity.motY, nmsEntity.locZ
+ nmsEntity.motZ);
MovingObjectPosition finalObjectPosition = nmsEntity.world.rayTrace(vec3d, vec3d1, false, true, false);
vec3d = Vec3D.a(nmsEntity.locX, nmsEntity.locY, nmsEntity.locZ);
vec3d1 = Vec3D.a(nmsEntity.locX + nmsEntity.motX, nmsEntity.locY + nmsEntity.motY, nmsEntity.locZ + nmsEntity.motZ);
if (finalObjectPosition != null)
{
vec3d1 = Vec3D.a(finalObjectPosition.pos.a, finalObjectPosition.pos.b, finalObjectPosition.pos.c);
}
for (Object entity : ((CraftWorld) cur.getWorld()).getHandle().getEntities(
((CraftEntity) cur).getHandle(),
((CraftEntity) cur).getHandle().boundingBox.a(((CraftEntity) cur).getHandle().motX,
((CraftEntity) cur).getHandle().motY, ((CraftEntity) cur).getHandle().motZ).grow(2, 2, 2)))
{
Entity bukkitEntity = ((net.minecraft.server.v1_7_R4.Entity) entity).getBukkitEntity();
if (bukkitEntity instanceof LivingEntity)
{
LivingEntity ent = (LivingEntity) bukkitEntity;
// Avoid Self
if (ent.equals(getEntity()))
continue;
// Creative or Spec
if (ent instanceof Player)
if (((Player) ent).getGameMode() == GameMode.CREATIVE || UtilPlayer.isSpectator(ent))
continue;
// float f1 = (float)(nmsEntity.boundingBox.a() * 0.6f);
AxisAlignedBB axisalignedbb1 = ((CraftEntity) ent).getHandle().boundingBox.grow(1F, 1F, 1F);
MovingObjectPosition entityCollisionPosition = axisalignedbb1.a(vec3d, vec3d1);
if (entityCollisionPosition != null)
{
double d1 = vec3d.distanceSquared(entityCollisionPosition.pos);
if ((d1 < distanceToEntity) || (distanceToEntity == 0.0D))
{
victim = ent;
distanceToEntity = d1;
}
}
}
}
if (victim != null)
{
cur.getWorld().playEffect(victim.getEyeLocation().subtract(0, 0.5, 0), Effect.STEP_SOUND, cur.getBlockId());
if (canDamage(victim))
{
getGolem()
.getEvent()
.getDamageManager()
.NewDamageEvent((LivingEntity) victim, getEntity(), null, DamageCause.CONTACT, 6, true, true, false,
"Cave In", "Cave In");
}
cur.remove();
fallingIterator.remove();
}
else if (finalObjectPosition != null)
{
Block block = cur.getWorld().getBlockAt(finalObjectPosition.b, finalObjectPosition.c, finalObjectPosition.d);
if (!UtilBlock.airFoliage(block) && !block.isLiquid())
{
nmsEntity.motX = ((float) (finalObjectPosition.pos.a - nmsEntity.locX));
nmsEntity.motY = ((float) (finalObjectPosition.pos.b - nmsEntity.locY));
nmsEntity.motZ = ((float) (finalObjectPosition.pos.c - nmsEntity.locZ));
float f2 = MathHelper.sqrt(nmsEntity.motX * nmsEntity.motX + nmsEntity.motY * nmsEntity.motY + nmsEntity.motZ
* nmsEntity.motZ);
nmsEntity.locX -= nmsEntity.motX / f2 * 0.0500000007450581D;
nmsEntity.locY -= nmsEntity.motY / f2 * 0.0500000007450581D;
nmsEntity.locZ -= nmsEntity.motZ / f2 * 0.0500000007450581D;
cur.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, cur.getBlockId());
cur.remove();
fallingIterator.remove();
}
}
else
{
UtilParticle.PlayParticle(ParticleType.BLOCK_DUST.getParticle(Material.STONE, 0), cur.getLocation()
.add(0, 0.5, 0), 0.3F, 0.3F, 0.3F, 0, 2, UtilParticle.ViewDist.NORMAL, UtilServer.getPlayers());
}
}
}
@Override
public void setFinished()
{
for (FallingBlock block : _fallingBlocks)
{
block.remove();
}
for (Block block : _blocks)
{
block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, block.getTypeId());
block.setType(Material.AIR);
}
}
@Override
public void tick()
{
if (_tick++ == 0)
{
Location l = getLocation();
ArrayList<Location> blocks = UtilShapes.getSphereBlocks(l, 3, 3, true);
for (Location loc : blocks)
{
if (loc.getBlockY() >= l.getBlockY())
{
Block b = loc.getBlock();
if (b.getType() == Material.AIR)
{
_blocks.add(b);
loc.setY(l.getY() - 1);
b.setType(loc.getBlock().getType());
b.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, loc.getBlock().getTypeId());
}
}
}
}
if (_tick < 200)
{
Location loc = getLocation();
loc.setY(loc.getY() + 8);
for (int i = 0; i < 30; i++)
{
loc.setY(loc.getY() + 1);
Block b = loc.getBlock();
if (UtilBlock.solid(b))
{
break;
}
}
if (!UtilBlock.solid(loc.getBlock()))
{
return;
}
LinkedList<Player> players = UtilPlayer.getNearby(getLocation(), 50);
for (int i = 0; i < players.size(); i++)
{
int dist = UtilMath.r(10);
if (dist < 3)
{
dist = 2;
}
else if (dist < 5)
{
dist = 5;
}
else
{
dist = 10;
}
Location l = players.get(UtilMath.r(players.size())).getLocation()
.add(UtilMath.r(dist * 2) - dist, 0, UtilMath.r(dist * 2) - dist);
l.setY(loc.getY());
Block b = l.getBlock();
l.subtract(0, 1, 0);
if (UtilBlock.solid(b))
{
if (l.getBlock().getType() == Material.AIR)
{
if (UtilAlg.HasSight(l, getLocation().add(0, 8, 0)))
{
FallingBlock block = b.getWorld().spawnFallingBlock(b.getLocation().add(0.5, -1, 0.5), b.getTypeId(),
b.getData());
block.setVelocity(new Vector(UtilMath.r(5) - 2.5D, 0, UtilMath.r(5) - 2.5D).multiply(0.1));
block.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, block.getBlockId());
block.setDropItem(false);
_fallingBlocks.add(block);
}
}
}
}
}
}
}

View File

@ -0,0 +1,161 @@
package mineplex.game.clans.clans.worldevent.event.golem.abilities;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.UUID;
import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilParticle.ParticleType;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilShapes;
import mineplex.game.clans.clans.worldevent.event.golem.GolemCreature;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.util.Vector;
public class GolemEarthquake extends GolemAbility
{
private Location _center;
private float _range;
private int _tick;
private ArrayList<UUID> _damaged = new ArrayList<UUID>();
public GolemEarthquake(GolemCreature creature)
{
super(creature);
_center = getLocation();
}
@Override
public boolean canMove()
{
return !UtilEnt.isGrounded(getEntity()) && _tick > 1;
}
@Override
public Player getTarget()
{
return getTarget(7);
}
@Override
public boolean hasFinished()
{
return _range > 15;
}
@Override
public void setFinished()
{
}
@Override
public void tick()
{
Entity entity = getEntity();
if (_tick == 0)
{
entity.getWorld().playSound(entity.getLocation(), Sound.IRONGOLEM_THROW, 4, 0);
entity.setVelocity(new Vector(0, 1, 0));
}
if (_tick > 10 && UtilEnt.isGrounded(entity))
{
_range += 0.7;
for (float range = _range - 2; range <= _range; range++)
{
if (range <= 0)
{
continue;
}
for (int x = -1; x <= 1; x++)
{
for (int z = -1; z <= 1; z++)
{
if ((x != 0) == (z != 0))
{
continue;
}
UtilParticle.PlayParticle(ParticleType.BLOCK_DUST.getParticle(Material.DIRT, 0),
_center.clone().add(x * range, 0.1, z * range), (x != 0) ? 0 : (range / 2), 0.1F, (z != 0) ? 0
: (range / 2), 0, (int) (range * 4), UtilParticle.ViewDist.NORMAL, UtilServer
.getPlayers());
}
}
}
_center.getWorld().playSound(_center, Sound.DIG_GRASS, 2, 0.8F);
HashSet<Player> toDamage = new HashSet<Player>();
Location cornerA = _center.clone().add(-_range, -1, -_range);
Location cornerB = _center.clone().add(_range, 1, _range);
Location cornerA1 = _center.clone().add(-(_range - 1.5), -1, -(_range - 1.5));
Location cornerB1 = _center.clone().add(_range - 1.5, 1, _range - 1.5);
for (Player player : Bukkit.getOnlinePlayers())
{
Location pLoc = player.getLocation();
if (_damaged.contains(player.getUniqueId()))
{
continue;
}
if (!UtilAlg.inBoundingBox(pLoc, cornerA, cornerB))
{
continue;
}
if (UtilAlg.inBoundingBox(pLoc, cornerA1, cornerB1))
{
continue;
}
toDamage.add(player);
}
for (Player player : toDamage)
{
_damaged.add(player.getUniqueId());
getGolem()
.getEvent()
.getDamageManager()
.NewDamageEvent((LivingEntity) player, getEntity(), null, DamageCause.CONTACT, 6, false, true, false,
"Earthquake", "Earthquake");
getGolem().getEvent().getEventManager().getClans().getCondition().Factory()
.Slow("Earthquake", (LivingEntity) player, getEntity(), 3, 1, false, false, false, false);
// Velocity
UtilAction.velocity(player, UtilAlg.getTrajectory2d(getLocation().toVector(), player.getLocation().toVector()),
1.8, true, 0, 0.5, 0.5, true);
// Condition
getGolem().getEvent().getEventManager().getClans().getCondition().Factory()
.Falling("Earthquake", player, getEntity(), 10, false, true);
}
}
_tick++;
}
}

View File

@ -0,0 +1,583 @@
package mineplex.game.clans.clans.worldevent.event.golem.abilities;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map.Entry;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilParticle.ParticleType;
import mineplex.core.common.util.UtilParticle.ViewDist;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.worldevent.event.golem.GolemCreature;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import mineplex.minecraft.game.core.explosion.CustomExplosion;
import net.minecraft.server.v1_7_R4.AxisAlignedBB;
import net.minecraft.server.v1_7_R4.DataWatcher;
import net.minecraft.server.v1_7_R4.EntityIronGolem;
import net.minecraft.server.v1_7_R4.MathHelper;
import net.minecraft.server.v1_7_R4.MovingObjectPosition;
import net.minecraft.server.v1_7_R4.Packet;
import net.minecraft.server.v1_7_R4.PacketPlayOutAttachEntity;
import net.minecraft.server.v1_7_R4.PacketPlayOutEntityDestroy;
import net.minecraft.server.v1_7_R4.PacketPlayOutRelEntityMove;
import net.minecraft.server.v1_7_R4.PacketPlayOutSpawnEntity;
import net.minecraft.server.v1_7_R4.PacketPlayOutSpawnEntityLiving;
import net.minecraft.server.v1_7_R4.Vec3D;
import org.bukkit.Bukkit;
import org.bukkit.Effect;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_7_R4.CraftWorld;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftIronGolem;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.FallingBlock;
import org.bukkit.entity.IronGolem;
import org.bukkit.entity.Item;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.util.Vector;
public class GolemExplosiveBlock extends GolemAbility
{
private HashMap<Integer, Vector> _blocksLocation = new HashMap<Integer, Vector>();
private Location _center;
private int _explosionsLeft;
private FallingBlock _fallingBlock;
private HashMap<Integer, Integer> _fallingBlocks = new HashMap<Integer, Integer>();
private ArrayList<Item> _items = new ArrayList<Item>();
private int _strength;
private Player _target;
private int _tick;
public GolemExplosiveBlock(GolemCreature creature, int strength)
{
super(creature);
_strength = strength;
_center = getLocation().add(0, 3, 0);
_target = getTarget();
if (_target != null)
{
UtilEnt.CreatureLook(getEntity(), _target);
}
}
@Override
public boolean canMove()
{
return _fallingBlock != null;
}
private int clamp(int value)
{
if (value < -127)
return -127;
if (value > 127)
return 127;
return value;
}
@Override
public Player getTarget()
{
HashMap<Player, Double> locs = new HashMap<Player, Double>();
for (Player player : UtilServer.getPlayers())
{
double dist = player.getLocation().distance(_center);
if (dist < 30)
{
double score = (dist > 10 ? 30 - dist : 10);
for (Player p : UtilServer.getPlayers())
{
if (player.getLocation().distance(p.getLocation()) < 4)
{
score += 7;
}
}
if (player.hasLineOfSight(getEntity()))
{
score += 10;
}
locs.put(player, score);
}
}
Player lowest = null;
for (Entry<Player, Double> entry : locs.entrySet())
{
if (lowest == null || locs.get(lowest) > locs.get(entry.getKey()))
{
lowest = entry.getKey();
}
}
return lowest;
}
@Override
public boolean hasFinished()
{
return _target == null || (_fallingBlock != null && !_fallingBlock.isValid() && _explosionsLeft == 0);
}
@EventHandler
public void onDamage(CustomDamageEvent event)
{
if (event.GetDamageeEntity().equals(getEntity()))
{
if (_tick >= 40 + (40 * _strength) && _tick <= 50 + (40 * _strength))
{
event.SetCancelled("Iron Wizard charging bomb");
}
event.SetKnockback(false);
}
}
public void onExplode(final Location loc)
{
for (int i = 0; i < _strength * 2; i++)
{
if (i == 0)
{
onSubExplode(loc);
}
else
{
_explosionsLeft++;
Bukkit.getScheduler().scheduleSyncDelayedTask(getGolem().getEvent().getEventManager().getPlugin(), new Runnable()
{
public void run()
{
onSubExplode(loc);
_explosionsLeft--;
}
}, 2 * i);
}
}
}
public void onSubExplode(Location loc)
{
for (int i = 0; i < 2; i++)
{
Location l = loc.clone().add(UtilMath.r(_strength * 4) - (_strength * 2), UtilMath.r(_strength * 2),
UtilMath.r(_strength * 4) - (_strength * 2));
CustomExplosion explosion = new CustomExplosion(getGolem().getEvent().getDamageManager(), getGolem().getEvent()
.getEventManager().getClans().getExplosion(), l, _strength * 0.8F, "Golem Explosive Block");
explosion.setPlayer(getEntity(), false);
explosion.setDamageBlocks(false);
explosion.explode();
UtilParticle.PlayParticle(ParticleType.LARGE_EXPLODE, l, _strength * 3, 1, _strength * 3, 0, _strength * 4,
ViewDist.LONG, UtilServer.getPlayers());
}
}
@EventHandler
public void onUpdate(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
{
return;
}
if (_fallingBlock == null)
{
return;
}
if (_fallingBlock.isDead()
|| !_fallingBlock.isValid()
|| _fallingBlock.getTicksLived() > 400
|| !_fallingBlock.getWorld().isChunkLoaded(_fallingBlock.getLocation().getBlockX() >> 4,
_fallingBlock.getLocation().getBlockZ() >> 4))
{
Block block = _fallingBlock.getLocation().getBlock();
block.setTypeIdAndData(0, (byte) 0, true);
_fallingBlock.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, _fallingBlock.getBlockId());
// Expire
if (_fallingBlock.getTicksLived() > 400
|| !_fallingBlock.getWorld().isChunkLoaded(_fallingBlock.getLocation().getBlockX() >> 4,
_fallingBlock.getLocation().getBlockZ() >> 4))
{
_fallingBlock.remove();
return;
}
_fallingBlock.remove();
return;
}
double distanceToEntity = 0.0D;
LivingEntity victim = null;
net.minecraft.server.v1_7_R4.Entity nmsEntity = ((CraftEntity) _fallingBlock).getHandle();
Vec3D vec3d = Vec3D.a(nmsEntity.locX, nmsEntity.locY, nmsEntity.locZ);
Vec3D vec3d1 = Vec3D.a(nmsEntity.locX + nmsEntity.motX, nmsEntity.locY + nmsEntity.motY, nmsEntity.locZ + nmsEntity.motZ);
MovingObjectPosition finalObjectPosition = nmsEntity.world.rayTrace(vec3d, vec3d1, false, true, false);
vec3d = Vec3D.a(nmsEntity.locX, nmsEntity.locY, nmsEntity.locZ);
vec3d1 = Vec3D.a(nmsEntity.locX + nmsEntity.motX, nmsEntity.locY + nmsEntity.motY, nmsEntity.locZ + nmsEntity.motZ);
if (finalObjectPosition != null)
{
vec3d1 = Vec3D.a(finalObjectPosition.pos.a, finalObjectPosition.pos.b, finalObjectPosition.pos.c);
}
for (Object entity : ((CraftWorld) _fallingBlock.getWorld()).getHandle().getEntities(
((CraftEntity) _fallingBlock).getHandle(),
((CraftEntity) _fallingBlock).getHandle().boundingBox.a(((CraftEntity) _fallingBlock).getHandle().motX,
((CraftEntity) _fallingBlock).getHandle().motY, ((CraftEntity) _fallingBlock).getHandle().motZ).grow(2,
2, 2)))
{
Entity bukkitEntity = ((net.minecraft.server.v1_7_R4.Entity) entity).getBukkitEntity();
if (bukkitEntity instanceof LivingEntity)
{
LivingEntity ent = (LivingEntity) bukkitEntity;
// Avoid Self
if (ent.equals(getEntity()))
continue;
// Creative or Spec
if (ent instanceof Player)
if (((Player) ent).getGameMode() == GameMode.CREATIVE || UtilPlayer.isSpectator(ent))
continue;
// float f1 = (float)(nmsEntity.boundingBox.a() * 0.6f);
AxisAlignedBB axisalignedbb1 = ((CraftEntity) ent).getHandle().boundingBox.grow(1F, 1F, 1F);
MovingObjectPosition entityCollisionPosition = axisalignedbb1.a(vec3d, vec3d1);
if (entityCollisionPosition != null)
{
double d1 = vec3d.distanceSquared(entityCollisionPosition.pos);
if ((d1 < distanceToEntity) || (distanceToEntity == 0.0D))
{
victim = ent;
distanceToEntity = d1;
}
}
}
}
if (victim != null)
{
onExplode(victim.getEyeLocation());
_fallingBlock.remove();
}
else if (finalObjectPosition != null)
{
Block block = _fallingBlock.getWorld()
.getBlockAt(finalObjectPosition.b, finalObjectPosition.c, finalObjectPosition.d);
if (!UtilBlock.airFoliage(block) && !block.isLiquid())
{
nmsEntity.motX = ((float) (finalObjectPosition.pos.a - nmsEntity.locX));
nmsEntity.motY = ((float) (finalObjectPosition.pos.b - nmsEntity.locY));
nmsEntity.motZ = ((float) (finalObjectPosition.pos.c - nmsEntity.locZ));
float f2 = MathHelper.sqrt(nmsEntity.motX * nmsEntity.motX + nmsEntity.motY * nmsEntity.motY + nmsEntity.motZ
* nmsEntity.motZ);
nmsEntity.locX -= nmsEntity.motX / f2 * 0.0500000007450581D;
nmsEntity.locY -= nmsEntity.motY / f2 * 0.0500000007450581D;
nmsEntity.locZ -= nmsEntity.motZ / f2 * 0.0500000007450581D;
onExplode(block.getLocation().add(0.5, 0.5, 0.5));
_fallingBlock.remove();
}
}
else
{
UtilParticle.PlayParticle(ParticleType.BLOCK_DUST.getParticle(Material.STONE, 0),
_fallingBlock.getLocation().add(0, 0.5, 0), 0.3F, 0.3F, 0.3F, 0, 2, UtilParticle.ViewDist.NORMAL,
UtilServer.getPlayers());
}
}
@Override
public void setFinished()
{
int[] ids = new int[_fallingBlocks.size() * 2];
int index = 0;
for (Entry<Integer, Integer> entry : _fallingBlocks.entrySet())
{
ids[index] = entry.getKey();
ids[index + 1] = entry.getValue();
index += 2;
}
PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(ids);
for (Player player : Bukkit.getOnlinePlayers())
{
UtilPlayer.sendPacket(player, packet);
}
for (Item item : _items)
{
item.remove();
}
if (_fallingBlock != null)
{
_fallingBlock.remove();
}
}
@Override
public void tick()
{
IronGolem entity = getEntity();
Iterator<Item> itel = _items.iterator();
while (itel.hasNext())
{
Item item = itel.next();
Vector vec = item.getVelocity();
Location loc = item.getLocation();
if (item.getTicksLived() > 100 || vec.getY() <= 0 || loc.distance(_center) > loc.add(vec).distance(_center)
|| UtilEnt.isGrounded(item))
{
itel.remove();
}
}
// This spawns a floating block
if (_tick >= 20 && _tick % 60 == 0 && _fallingBlocks.size() < _strength)
{
int id = UtilEnt.getNewEntityId();
int id2 = UtilEnt.getNewEntityId();
_fallingBlocks.put(id, id2);
_blocksLocation.put(id, _center.toVector());
Packet[] packets = new Packet[3];
PacketPlayOutSpawnEntityLiving packet1 = new PacketPlayOutSpawnEntityLiving();
DataWatcher watcher = new DataWatcher(null);
watcher.a(0, (byte) 32);
watcher.a(1, 0);
packet1.a = id;
packet1.b = EntityType.SILVERFISH.getTypeId();
packet1.c = (int) Math.floor(_center.getX() * 32);
packet1.d = (int) Math.floor((_center.getY() - 0.125) * 32);
packet1.e = (int) Math.floor(_center.getZ() * 32);
packet1.l = watcher;
packets[0] = packet1;
PacketPlayOutSpawnEntity packet2 = new PacketPlayOutSpawnEntity(((CraftEntity) entity).getHandle(), 70,
Material.DIRT.getId());
packet2.a = id2;
packet2.b = (int) Math.floor(_center.getX() * 32);
packet2.c = (int) Math.floor(_center.getY() * 32);
packet2.d = (int) Math.floor(_center.getZ() * 32);
packets[1] = packet2;
PacketPlayOutAttachEntity packet3 = new PacketPlayOutAttachEntity();
packet3.b = id2;
packet3.c = id;
packets[2] = packet3;
for (Player player : UtilServer.getPlayers())
{
if (player.getLocation().distance(_center) < 80)
{
UtilPlayer.sendPacket(player, packets);
}
}
}
// This spawns a item that flies above the golem's head and disappears
if (UtilMath.r(6) == 0 && _tick < 40 + (_strength * 40))
{
double angle = ((2 * Math.PI) / 30) * UtilMath.r(30);
double x = 5 * Math.cos(angle);
double z = 5 * Math.sin(angle);
Location loc = _center.clone().add(x, -3, z);
Material mat = null;
switch (UtilMath.r(3))
{
case 0:
mat = Material.DIRT;
break;
case 1:
mat = Material.STONE;
break;
case 2:
mat = Material.COBBLESTONE;
break;
default:
break;
}
Item item = loc.getWorld().dropItem(loc, new ItemBuilder(mat).setTitle(System.currentTimeMillis() + "").build());
item.setPickupDelay(999999);
Vector vec = UtilAlg.getTrajectory(_center, item.getLocation());
vec.normalize().multiply(5);
item.setVelocity(vec);
// TODO Fix velocity
_items.add(item);
}
// 10 being when items no longer fly in, 0 being when its shot.
int ticksTillFired = (60 + (40 * _strength)) - _tick;
if (ticksTillFired > 20)
{
int strength = (int) Math.floor(_tick / 20D);
int nine = 8 - strength;
if (_tick % nine == 0)
{
_center.getWorld().playSound(_center, Sound.DIG_GRASS, strength + 1, 1F);
}
}
else if (ticksTillFired < 0)
{
if (_tick % 3 == 0)
{
_center.getWorld().playSound(_fallingBlock.getLocation(), Sound.WOOD_CLICK, _strength + 1, 0.4F);
}
}
// The location the falling blocks need to stick by
Vector blockCenter = _center.toVector();
if (ticksTillFired >= 0 && ticksTillFired <= 20)
{
Vector vec = entity.getLocation().add(entity.getLocation().getDirection().setY(0).normalize().multiply(1.2))
.add(0, 1, 0).toVector();
blockCenter = UtilAlg.getTrajectory(_center.toVector(), blockCenter);
vec.multiply(ticksTillFired / 10D);
_center.getWorld().playSound(_center, Sound.DIG_SNOW, _strength + 1, 0);
}
else if (_fallingBlock != null)
{
blockCenter = _fallingBlock.getLocation().add(0, 0.5, 0).toVector();
}
// Move the fake floating blocks
for (Entry<Integer, Integer> entry : _fallingBlocks.entrySet())
{
int id = entry.getKey();
Vector vec = _blocksLocation.get(id);
int x = clamp((int) ((blockCenter.getX() - vec.getX()) * 32) + (UtilMath.r(8) - 4));
int y = clamp((int) ((blockCenter.getY() - vec.getY()) * 32) + (UtilMath.r(8) - 4));
int z = clamp((int) ((blockCenter.getZ() - vec.getZ()) * 32) + (UtilMath.r(8) - 4));
vec.add(new Vector(x, y, z));
PacketPlayOutRelEntityMove packet = new PacketPlayOutRelEntityMove();
packet.a = id;
packet.b = (byte) x;
packet.c = (byte) y;
packet.d = (byte) z;
for (Player player : UtilServer.getPlayers())
{
if (player.getLocation().distance(_center) < 70)
{
UtilPlayer.sendPacket(player, packet);
UtilParticle.PlayParticle(ParticleType.BLOCK_DUST.getParticle(Material.STONE, 0),
vec.toLocation(_center.getWorld()), 0.7F, 0.7F, 0.7F, 0, 11, ViewDist.NORMAL, player);
}
}
}
if (ticksTillFired == 0)
{
int id = _fallingBlocks.keySet().iterator().next();
PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(new int[]
{
id, _fallingBlocks.get(id)
});
for (Player player : Bukkit.getOnlinePlayers())
{
UtilPlayer.sendPacket(player, packet);
}
_fallingBlocks.remove(id);
_fallingBlock = _center.getWorld().spawnFallingBlock(_blocksLocation.get(id).toLocation(_center.getWorld()),
Material.STONE, (byte) 0);
Vector vec1 = _fallingBlock.getLocation().toVector();
Vector vec2 = _target.getLocation().toVector();
Vector vec = UtilAlg.calculateVelocity(vec1, vec2, (int) (vec1.distanceSquared(vec2) / 4));
_fallingBlock.setVelocity(vec);
EntityIronGolem golem = ((CraftIronGolem) entity).getHandle();
golem.world.broadcastEntityEffect(golem, (byte) 4);
}
_tick++;
}
}

View File

@ -0,0 +1,81 @@
package mineplex.game.clans.clans.worldevent.event.golem.abilities;
import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilPlayer;
import mineplex.game.clans.clans.worldevent.event.golem.GolemCreature;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.util.Vector;
public class GolemMeleeAttack extends GolemAbility
{
private boolean _attacked;
public GolemMeleeAttack(GolemCreature creature)
{
super(creature);
}
@Override
public boolean canMove()
{
return true;
}
@Override
public int getCooldown()
{
return 20;
}
@Override
public Player getTarget()
{
return getTarget(2);
}
@Override
public boolean hasFinished()
{
return _attacked;
}
@Override
public void setFinished()
{
}
@Override
public void tick()
{
_attacked = true;
for (Player target : UtilPlayer.getNearby(getLocation(), 2))
{
if (target.getVelocity().length() > 0.5)
{
continue;
}
UtilEnt.CreatureLook(getEntity(), target);
getGolem()
.getEvent()
.getDamageManager()
.NewDamageEvent(target, getEntity(), null, DamageCause.ENTITY_ATTACK, 6, false, true, false, "Golem Attack",
"Golem Attack");
Vector vec = getLocation().getDirection();
vec.setY(0).normalize().multiply(0.2);
vec.setY(1);
UtilAction.velocity(target, vec, 1.4, false, 0, 0, 2, false);
target.getWorld().playSound(target.getLocation(), Sound.IRONGOLEM_THROW, 3, 0.9F);
}
}
}

View File

@ -0,0 +1,215 @@
package mineplex.game.clans.clans.worldevent.event.golem.abilities;
import java.util.ArrayList;
import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilPlayer;
import mineplex.game.clans.clans.worldevent.event.golem.GolemCreature;
import net.minecraft.server.v1_7_R4.EntityIronGolem;
import org.bukkit.Effect;
import org.bukkit.Location;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftIronGolem;
import org.bukkit.entity.Damageable;
import org.bukkit.entity.Entity;
import org.bukkit.entity.IronGolem;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.util.Vector;
/**
* Rumble is where the golem picks a target then starts playing a animation for a second where its obviously preparing to use it.
* Copy this from Wizards
*/
public class GolemRumble extends GolemAbility
{
private Location _loc;
private Player _target;
private int _ticks;
private int _travelled;
private Vector _vec;
private int _width = 1;
public GolemRumble(GolemCreature creature)
{
super(creature);
_target = getTarget();
UtilEnt.CreatureLook(getEntity(), _target);
}
@Override
public boolean canMove()
{
return _ticks >= 20;
}
@Override
public boolean hasFinished()
{
return _target == null || !_target.isValid() || getLocation().distance(_target.getLocation()) > 100;
}
@Override
public void setFinished()
{
}
@Override
public void tick()
{
if (_ticks++ < 14)
{
IronGolem entity = getEntity();
EntityIronGolem golem = ((CraftIronGolem) entity).getHandle();
golem.world.broadcastEntityEffect(golem, (byte) 4);
if (_ticks % 2 == 0)
{
entity.getWorld().playSound(entity.getLocation(), Sound.IRONGOLEM_THROW, 3, 2F);
UtilEnt.CreatureLook(entity, _target);
}
}
else if (_ticks % 2 == 0)
{
int oldWidth = _width;
if ((_width <= 3 || _ticks % 4 == 0) && _width <= 5)
{
_width++;
}
Location newLoc;
boolean validBlock = false;
ArrayList<Block> current = new ArrayList<Block>();
if (_vec == null)
{
_vec = _target.getLocation().subtract(getLocation()).toVector().setY(0).normalize();// .multiply(0.5);
_loc = getLocation().subtract(0, 1, 0).getBlock().getLocation().add(0, 0.99, 0);
newLoc = _loc;
current.add(_loc.getBlock());
validBlock = true;
}
else
{ // Move rumble
newLoc = _loc.clone().add(_vec);
// Check if the rumble needs to go up or drop a block or two
for (int y : new int[]
{
0, 1, -1, -2
})
{
if (_loc.getBlockY() + y <= 0)
{
continue;
}
for (int a = 1; a <= 2; a++)
{
Block b = newLoc.clone().add(_vec.clone().multiply(a)).getBlock().getRelative(0, y, 0);
if (UtilBlock.solid(b) && !UtilBlock.solid(b.getRelative(0, 1, 0)))
{
validBlock = true;
newLoc.add(0, y, 0);
break;
}
}
if (validBlock)
{
break;
}
}
for (int width = -_width; width <= _width; width++)
{
if (Math.abs(width) <= oldWidth)
{
Block b = _loc.clone().add(UtilAlg.getRight(_vec).multiply(width)).getBlock();
if (!current.contains(b))
{
current.add(b);
}
}
if (validBlock)
{
Block b = newLoc.clone().add(UtilAlg.getRight(_vec).multiply(width)).getBlock();
if (!current.contains(b))
{
current.add(b);
b.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, b.getTypeId());
}
}
}
}
UtilEnt.CreatureLook(getEntity(), _loc);
for (Entity entity : getEntity().getWorld().getEntities())
{
if (entity instanceof Damageable && !UtilPlayer.isSpectator(entity) && entity != getEntity())
{
Block b = entity.getLocation().getBlock();
boolean canDamage = false;
for (int y = -1; y <= 0; y++)
{
if (current.contains(b.getRelative(0, y, 0)))
{
canDamage = true;
break;
}
}
if (!canDamage)
{
continue;
}
if (canDamage(entity))
{
getGolem()
.getEvent()
.getDamageManager()
.NewDamageEvent((LivingEntity) entity, getEntity(), null, DamageCause.CONTACT, 6, false, true,
false, "Rumble", "Rumble");
}
UtilAction.velocity(entity, _vec.clone(), 1.5, true, 0, 0.2, 1, true);
if (entity instanceof Player)
{
getGolem().getEvent().getEventManager().getClans().getCondition().Factory()
.Slow("Rumble", (LivingEntity) entity, getEntity(), 3, 1, false, false, false, false);
}
}
}
if (_travelled++ > 35 || !validBlock)
{
// TODO Explode?
_target = null;
}
_loc = newLoc;
}
}
}

View File

@ -0,0 +1,403 @@
package mineplex.game.clans.clans.worldevent.event.golem.abilities;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map.Entry;
import mineplex.core.common.util.UtilAction;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilParticle.ParticleType;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilShapes;
import mineplex.core.common.util.UtilTime;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.worldevent.event.golem.GolemCreature;
import net.minecraft.server.v1_7_R4.AxisAlignedBB;
import net.minecraft.server.v1_7_R4.MathHelper;
import net.minecraft.server.v1_7_R4.MovingObjectPosition;
import net.minecraft.server.v1_7_R4.Vec3D;
import org.bukkit.Effect;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.craftbukkit.v1_7_R4.CraftWorld;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftEntity;
import org.bukkit.entity.Entity;
import org.bukkit.entity.FallingBlock;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.util.Vector;
public class GolemWallExplode extends GolemAbility
{
private HashMap<BlockFace, ArrayList<Block>> _blockWalls = new HashMap<BlockFace, ArrayList<Block>>();
private ArrayList<String> _dontTarget = new ArrayList<String>();
private ArrayList<FallingBlock> _fallingBlocks = new ArrayList<FallingBlock>();
private int _maxTimes = UtilMath.r(2) + 1;
private int _tick;
private int _timesDone;
private HashMap<BlockFace, Long> _wallTimers = new HashMap<BlockFace, Long>();
public GolemWallExplode(GolemCreature creature)
{
super(creature);
}
@Override
public boolean canMove()
{
return true;
}
@Override
public int getCooldown()
{
return 20;
}
private float getMod(int div)
{
return UtilMath.random.nextFloat() / div;
}
@Override
public Player getTarget()
{
for (Player player : UtilPlayer.getNearby(getLocation(), 15))
{
if (_dontTarget.contains(player.getName()))
{
continue;
}
if (player.getLocation().distance(getLocation()) <= 4)
{
continue;
}
return player;
}
return null;
}
@Override
public boolean hasFinished()
{
return _wallTimers.isEmpty() && _fallingBlocks.isEmpty() && _timesDone >= _maxTimes;
}
@EventHandler
public void onUpdate(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
{
return;
}
Iterator<FallingBlock> fallingIterator = _fallingBlocks.iterator();
while (fallingIterator.hasNext())
{
FallingBlock cur = fallingIterator.next();
if (cur.isDead() || !cur.isValid() || cur.getTicksLived() > 400
|| !cur.getWorld().isChunkLoaded(cur.getLocation().getBlockX() >> 4, cur.getLocation().getBlockZ() >> 4))
{
fallingIterator.remove();
Block block = cur.getLocation().getBlock();
block.setTypeIdAndData(0, (byte) 0, true);
cur.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, cur.getBlockId());
// Expire
if (cur.getTicksLived() > 400
|| !cur.getWorld().isChunkLoaded(cur.getLocation().getBlockX() >> 4, cur.getLocation().getBlockZ() >> 4))
{
cur.remove();
continue;
}
cur.remove();
continue;
}
double distanceToEntity = 0.0D;
LivingEntity victim = null;
net.minecraft.server.v1_7_R4.Entity nmsEntity = ((CraftEntity) cur).getHandle();
Vec3D vec3d = Vec3D.a(nmsEntity.locX, nmsEntity.locY, nmsEntity.locZ);
Vec3D vec3d1 = Vec3D.a(nmsEntity.locX + nmsEntity.motX, nmsEntity.locY + nmsEntity.motY, nmsEntity.locZ
+ nmsEntity.motZ);
MovingObjectPosition finalObjectPosition = nmsEntity.world.rayTrace(vec3d, vec3d1, false, true, false);
vec3d = Vec3D.a(nmsEntity.locX, nmsEntity.locY, nmsEntity.locZ);
vec3d1 = Vec3D.a(nmsEntity.locX + nmsEntity.motX, nmsEntity.locY + nmsEntity.motY, nmsEntity.locZ + nmsEntity.motZ);
if (finalObjectPosition != null)
{
vec3d1 = Vec3D.a(finalObjectPosition.pos.a, finalObjectPosition.pos.b, finalObjectPosition.pos.c);
}
for (Object entity : ((CraftWorld) cur.getWorld()).getHandle().getEntities(
((CraftEntity) cur).getHandle(),
((CraftEntity) cur).getHandle().boundingBox.a(((CraftEntity) cur).getHandle().motX,
((CraftEntity) cur).getHandle().motY, ((CraftEntity) cur).getHandle().motZ).grow(2, 2, 2)))
{
Entity bukkitEntity = ((net.minecraft.server.v1_7_R4.Entity) entity).getBukkitEntity();
if (bukkitEntity instanceof LivingEntity)
{
LivingEntity ent = (LivingEntity) bukkitEntity;
// Avoid Self
if (ent.equals(getEntity()))
continue;
// Creative or Spec
if (ent instanceof Player)
if (((Player) ent).getGameMode() == GameMode.CREATIVE || UtilPlayer.isSpectator(ent))
continue;
// float f1 = (float)(nmsEntity.boundingBox.a() * 0.6f);
AxisAlignedBB axisalignedbb1 = ((CraftEntity) ent).getHandle().boundingBox.grow(1F, 1F, 1F);
MovingObjectPosition entityCollisionPosition = axisalignedbb1.a(vec3d, vec3d1);
if (entityCollisionPosition != null)
{
double d1 = vec3d.distanceSquared(entityCollisionPosition.pos);
if ((d1 < distanceToEntity) || (distanceToEntity == 0.0D))
{
victim = ent;
distanceToEntity = d1;
}
}
}
}
if (victim != null)
{
cur.getWorld().playEffect(victim.getEyeLocation().subtract(0, 0.5, 0), Effect.STEP_SOUND, cur.getBlockId());
if (canDamage(victim))
{
getGolem()
.getEvent()
.getDamageManager()
.NewDamageEvent((LivingEntity) victim, getEntity(), null, DamageCause.CONTACT, 6, true, true, false,
"Wall Explosion", "Wall Explosion");
}
cur.remove();
fallingIterator.remove();
Vector vec = cur.getVelocity();
UtilAction.velocity(victim, vec, 1.5, true, 0, 0.2, 1, true);
}
else if (finalObjectPosition != null)
{
Block block = cur.getWorld().getBlockAt(finalObjectPosition.b, finalObjectPosition.c, finalObjectPosition.d);
if (!UtilBlock.airFoliage(block) && !block.isLiquid())
{
nmsEntity.motX = ((float) (finalObjectPosition.pos.a - nmsEntity.locX));
nmsEntity.motY = ((float) (finalObjectPosition.pos.b - nmsEntity.locY));
nmsEntity.motZ = ((float) (finalObjectPosition.pos.c - nmsEntity.locZ));
float f2 = MathHelper.sqrt(nmsEntity.motX * nmsEntity.motX + nmsEntity.motY * nmsEntity.motY + nmsEntity.motZ
* nmsEntity.motZ);
nmsEntity.locX -= nmsEntity.motX / f2 * 0.0500000007450581D;
nmsEntity.locY -= nmsEntity.motY / f2 * 0.0500000007450581D;
nmsEntity.locZ -= nmsEntity.motZ / f2 * 0.0500000007450581D;
cur.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, cur.getBlockId());
cur.remove();
fallingIterator.remove();
}
}
else
{
UtilParticle.PlayParticle(ParticleType.BLOCK_DUST.getParticle(Material.STONE, 0), cur.getLocation()
.add(0, 0.5, 0), 0.3F, 0.3F, 0.3F, 0, 2, UtilParticle.ViewDist.NORMAL, UtilServer.getPlayers());
}
}
}
@Override
public void setFinished()
{
for (FallingBlock block : _fallingBlocks)
{
block.remove();
}
for (ArrayList<Block> list : _blockWalls.values())
{
for (Block b : list)
{
b.setType(Material.AIR);
}
}
}
@Override
public void tick()
{
if (_tick++ % 30 == 0 && _timesDone < _maxTimes)
{
_dontTarget.clear();
_timesDone++;
for (int i = 0; i < 10; i++)
{
Player target = getTarget();
if (target == null)
{
if (_dontTarget.isEmpty())
{
_timesDone = _maxTimes;
}
}
else
{
_dontTarget.add(target.getName());
UtilEnt.CreatureLook(getEntity(), target);
BlockFace face = UtilShapes.getFacing(getLocation().getYaw());
if (_wallTimers.containsKey(face))
{
continue;
}
ArrayList<Block> blocks = new ArrayList<Block>();
Location loc = getLocation().getBlock().getLocation().add(0.5, 0, 0.5);
int mul = (face.getModX() != 0 && face.getModZ() != 0) ? 2 : 3;
loc.add(face.getModX() * mul, 0, face.getModZ() * mul);
Block b = loc.getBlock();
BlockFace sideFace = UtilShapes.getSideBlockFaces(face, true)[0];
boolean invalid = false;
for (int mult = -2; mult <= 2; mult++)
{
Block block = b;
if (Math.abs(mult) < 2)
{
block = block.getRelative(face);
}
block = block.getRelative(sideFace, mult);
if (Math.abs(mult) == 2 && face.getModX() != 0 && face.getModZ() != 0)
{
block = block.getRelative(UtilShapes.getSideBlockFaces(face, false)[mult < 0 ? 0 : 1]);
}
if (!UtilAlg.HasSight(getLocation(), block.getLocation()))
{
invalid = true;
break;
}
Block under = block.getRelative(0, -1, 0);
if (!UtilBlock.solid(under))
{
continue;
}
for (int y = 0; y <= 1; y++)
{
block = block.getRelative(0, y, 0);
if (block.getType() != Material.AIR)
{
invalid = true;
break;
}
blocks.add(block);
}
if (invalid)
{
break;
}
}
if (invalid)
{
continue;
}
for (Block block : blocks)
{
block.setType(block.getWorld().getBlockAt(block.getX(), b.getY() - 1, block.getZ()).getType());
block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, block.getTypeId());
}
_blockWalls.put(face, blocks);
_wallTimers.put(face, System.currentTimeMillis());
break;
}
}
}
Iterator<Entry<BlockFace, ArrayList<Block>>> itel = _blockWalls.entrySet().iterator();
while (itel.hasNext())
{
Entry<BlockFace, ArrayList<Block>> entry = itel.next();
BlockFace face = entry.getKey();
if (UtilTime.elapsed(_wallTimers.get(face), 1000))
{
itel.remove();
_wallTimers.remove(face);
for (Block b : entry.getValue())
{
FallingBlock block = getEntity().getWorld().spawnFallingBlock(b.getLocation().add(0.5, 0, 0.5), b.getType(),
(byte) 0);
block.setDropItem(false);
int index = entry.getValue().indexOf(b);
BlockFace f = index == 6 || index == 7 ? BlockFace.SELF
: UtilShapes.getSideBlockFaces(face, true)[index > 6 ? 0 : 1];
block.setVelocity(new Vector((face.getModX() * 0.65) + (f.getModX() * (0.05 + getMod(10))), 0.2 + getMod(15),
(face.getModZ() * 0.65) + (f.getModZ() * (0.05 + getMod(10)))));
_fallingBlocks.add(block);
b.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, b.getTypeId());
b.setType(Material.AIR);
}
}
}
}
}

View File

@ -36,7 +36,7 @@ import net.minecraft.server.v1_7_R4.World;
public class CustomExplosion extends Explosion
{
private Player _owner;
private org.bukkit.entity.LivingEntity _owner;
private boolean _damageOwner;
private int _i = 16;
private World _world;
@ -142,7 +142,7 @@ public class CustomExplosion extends Explosion
return this;
}
public CustomExplosion setPlayer(Player player, boolean damageExplosionOwner)
public CustomExplosion setPlayer(org.bukkit.entity.LivingEntity player, boolean damageExplosionOwner)
{
_owner = player;
_damageOwner = damageExplosionOwner;
@ -319,7 +319,7 @@ public class CustomExplosion extends Explosion
}
}
ExplosionEvent event = _owner == null ? new ExplosionEvent(blockList) : new ExplosionEvent(blockList, _owner);
ExplosionEvent event = _owner == null || !(_owner instanceof Player) ? new ExplosionEvent(blockList) : new ExplosionEvent(blockList, (Player) _owner);
this._world.getServer().getPluginManager().callEvent(event);
this.blocks.clear();