cannons updates

This commit is contained in:
NewGarbo 2016-01-24 20:56:47 +00:00
parent a41521d6a9
commit 0252436990
7 changed files with 227 additions and 68 deletions

View File

@ -516,7 +516,7 @@ public class UtilAlg
return new AxisAlignedBB(a.getX(), a.getY(), a.getZ(), b.getX(), b.getY(), b.getZ());
}
public static Location offset(Location location, double strength, float yaw, boolean reverse)
public static Location moveForward(Location location, double strength, float yaw, boolean reverse)
{
double x = location.getX();
double z = location.getZ();
@ -526,10 +526,10 @@ public class UtilAlg
x = reverse ? (x + strength * Math.sin(rad)) : (x - strength * Math.sin(rad));
z = reverse ? (z - strength * Math.cos(rad)) : (z + strength * Math.cos(rad));
return new Location(location.getWorld(), x, location.getY(), z);
return new Location(location.getWorld(), x, location.getY(), z, location.getYaw(), location.getPitch());
}
public static Location offset(Location location, double strength, float yaw, float pitch, boolean reverse)
public static Location moveForward(Location location, double strength, float yaw, float pitch, boolean reverse)
{
double x = location.getX();
double y = location.getY();

View File

@ -1409,4 +1409,21 @@ public class UtilBlock
return itemStacks;
}
public static Location nearestFloor(Location location)
{
if (!UtilItem.isBoundless(location.getBlock().getType()))
{
return location.clone();
}
Location gr = location.clone();
while (UtilItem.isBoundless(gr.getBlock().getType()) && gr.getY() > 0)
{
gr.subtract(0, 0.5, 0);
}
return gr.getBlock().getLocation();
}
}

View File

@ -277,12 +277,9 @@ public class ItemBuilder
ItemBuilder newBuilder = new ItemBuilder(_mat);
newBuilder.setTitle(_title);
for (String lore : _lore)
{
newBuilder.addLore(lore);
}
_lore.forEach(newBuilder::addLore);
for (Map.Entry<Enchantment, Integer> entry : _enchants.entrySet())
{
newBuilder.addEnchantment(entry.getKey(), entry.getValue());

View File

@ -87,8 +87,8 @@ public class ClansBanCommand extends CommandBase<ClansBanManager>
}
else
{
UtilPlayer.message(caller, C.cGold + "/cp <username> <timeInDays(number)/p(ermanent)> <description> - Bans the specified player for the specified amount of time");
UtilPlayer.message(caller, C.cGold + "/cp <username> - Displays the \"Clans Punish\" UI, and will display all of the player's past bans (including current ones)");
UtilPlayer.message(caller, C.cGold + "/cb <username> <timeInDays(number)/p(ermanent)> <description> - Bans the specified player for the specified amount of time");
UtilPlayer.message(caller, C.cGold + "/cb <username> - Displays the \"Clans Punish\" UI, and will display all of the player's past bans (including current ones)");
}
}
}

View File

@ -1,14 +1,13 @@
package mineplex.game.clans.clans.siege.cannon;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftArmorStand;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity;
@ -30,13 +29,11 @@ import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.util.BlockIterator;
import org.bukkit.util.EulerAngle;
import org.bukkit.util.Vector;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.NautArrayList;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilEnt;
@ -49,6 +46,7 @@ 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.recharge.Recharge;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
@ -56,13 +54,11 @@ public class Cannon implements Listener
{
public static final ItemStack CANNON_ITEM = new ItemBuilder(Material.IRON_BLOCK, 1).setRawTitle(C.cBlue + "Cannon").setLore(C.cWhite + "BOOM BABY!").build();
public static final int MAX_SULPHUR = 2;
public static final int MAX_SULPHUR = 3;
public static final int TNT_SLOT = 4;
public static final List<Integer> SULPHUR_SLOTS = Arrays.asList(1, 3, 5, 7);
public static final List<Integer> EMPTY_SLOTS = Arrays.asList(0, 2, 6, 8);
private long _lastFired = -1;
public static final List<Integer> EMPTY_SLOTS = Arrays.asList(0, 6, 8);
private Location _location;
private CannonState _state;
@ -70,20 +66,23 @@ public class Cannon implements Listener
private Player _rider;
// Entity Information
private NautArrayList<Entity> _entities;
private List<Entity> _entities;
private List<CannonCrater> _craters;
private TNTPrimed _projectile;
private Location _backLoc;
private Inventory _inventory;
private long _lastFired = -1;
public Cannon(Location location)
{
_location = location;
_state = CannonState.UNLOADED;
_entities = new NautArrayList<>();
_entities = new ArrayList<>();
_craters = new ArrayList<>();
_inventory = UtilServer.getServer().createInventory(null, InventoryType.DISPENSER, C.cRedB + "Cannon");
@ -93,6 +92,10 @@ public class Cannon implements Listener
public void cleanup()
{
_entities.forEach(Entity::remove);
_craters.forEach(CannonCrater::cleanup);
_entities.clear();
_craters.clear();
HandlerList.unregisterAll(this);
}
@ -157,32 +160,15 @@ public class Cannon implements Listener
updateEntities();
}
public void updateCannon()
{
long timeSinceLast = System.currentTimeMillis() - _lastFired;
if (timeSinceLast < 5000)
{
if (timeSinceLast <= 1500)
{
getArmorStand().teleport(getArmorStand().getLocation().clone().add(UtilAlg.getTrajectory2d(getArmorStandLocation(), _backLoc).multiply(((double) timeSinceLast) / 1500.d)));
}
else
{
getArmorStand().teleport(getArmorStand().getLocation().clone().add(UtilAlg.getTrajectory2d(_backLoc, getArmorStandLocation()).multiply(((double) timeSinceLast) / 3500.d)));
}
}
}
public void fire()
{
TNTPrimed tnt = _location.getWorld().spawn(_location, TNTPrimed.class);
TNTPrimed tnt = _location.getWorld().spawn(_location.clone().add(.5, .3, .5), TNTPrimed.class);
_projectile = tnt;
Vector velocity = UtilAlg.getTrajectory(
getArmorStand().getLocation(),
UtilAlg.offset(
UtilAlg.moveForward(
getArmorStand().getLocation(),
2.,
(float) Math.toDegrees(getArmorStand().getHeadPose().getY()), false))
@ -194,15 +180,7 @@ public class Cannon implements Listener
_inventory.setItem(TNT_SLOT, UtilInv.decrement(_inventory.getItem(TNT_SLOT)));
SULPHUR_SLOTS.forEach(_inventory::clear);
Iterator<Block> itr = new BlockIterator(new Location(getArmorStand().getLocation().getWorld(), getArmorStand().getLocation().getX(), getArmorStand().getLocation().getY(), getArmorStand().getLocation().getZ(), getArmorStand().getLocation().getYaw() + 180, getArmorStand().getLocation().getPitch()), 0, 1);
while (itr.hasNext())
{
Block block = itr.next();
_backLoc = block.getLocation();
}
UtilParticle.PlayParticleToAll(ParticleType.LARGE_EXPLODE, getArmorStandLocation(), new Vector(0, 0, 0), 1.f, 2, ViewDist.MAX);
UtilParticle.PlayParticleToAll(ParticleType.LARGE_EXPLODE, getArmorStandLocation(), new Vector(0, 0, 0), .1f, 2, ViewDist.MAX);
UtilServer.getServer().getOnlinePlayers().forEach(player -> player.playSound(getArmorStandLocation(), Sound.EXPLODE, 1.f, 1.f));
_lastFired = System.currentTimeMillis();
@ -220,19 +198,22 @@ public class Cannon implements Listener
public void updateProjectile()
{
if (_projectile != null && _projectile.getTicksLived() >= 40)
if (_projectile != null)
{
if (UtilBlock.getInBoundingBox(_projectile.getLocation().subtract(.5, .5, .5), _projectile.getLocation().add(.5, .5, .5))
.stream()
.filter(block -> !UtilItem.isBoundless(block.getType()))
.iterator().hasNext())
UtilParticle.PlayParticleToAll(ParticleType.SMOKE, _projectile.getLocation().add(0, .5, 0), new Vector(0, 0, 0), .1f, 3, ViewDist.MAX);
UtilParticle.PlayParticleToAll(ParticleType.FLAME, _projectile.getLocation().add(0, .5, 0), new Vector(0, 0, 0), .1f, 3, ViewDist.MAX);
if (Math.abs(_projectile.getVelocity().getX()) < 0.1 || Math.abs(_projectile.getVelocity().getZ()) < 0.1)
{
//Do Explosion;
_craters.add(new CannonCrater(this, UtilBlock.nearestFloor(_projectile.getLocation())));
UtilParticle.PlayParticleToAll(ParticleType.HUGE_EXPLOSION, _projectile.getLocation(), new Vector(0, 0, 0), .1f, 4, ViewDist.MAX);
UtilServer.getServer().getOnlinePlayers().forEach(player -> player.playSound(_projectile.getLocation(), Sound.EXPLODE, 1.f, 1.f));
_projectile.remove();
_projectile = null;
Bukkit.broadcastMessage("boom");
}
}
}
@ -241,7 +222,10 @@ public class Cannon implements Listener
{
if (canBeFired())
{
fire();
if (Recharge.Instance.use(_rider, "Fire Cannon", 10000 /* 10 seconds */, true, false))
{
fire();
}
}
else
{
@ -288,7 +272,7 @@ public class Cannon implements Listener
private boolean canBeFired()
{
return getTnt() > 0 && getPower() > 0;
return getTnt() > 0 && getPower() > 0 && _projectile == null;
}
@EventHandler
@ -309,8 +293,6 @@ public class Cannon implements Listener
checkInv();
updateProjectile();
updateCannon();
}
public void checkInv()
@ -452,19 +434,24 @@ public class Cannon implements Listener
if (_rider != null)
{
ArmorStand _armorStand = (ArmorStand) UtilMath.getFirst(_entities);
double standYaw = Math.toDegrees(_armorStand.getHeadPose().getY()) % 360;
if (System.currentTimeMillis() - _lastFired < 5000)
{
return;
}
ArmorStand armorStand = (ArmorStand) UtilMath.getFirst(_entities);
double standYaw = Math.toDegrees(armorStand.getHeadPose().getY()) % 360;
double riderYaw = _rider.getLocation().getYaw() % 360;
double dif = riderYaw - standYaw;
double yaw = standYaw + (dif / 20.f);
Location pos = _armorStand.getLocation();
Location pos = armorStand.getLocation();
pos.setYaw((float) yaw);
_armorStand.teleport(pos);
_armorStand.setHeadPose(new EulerAngle(0, Math.toRadians(yaw), 0));
armorStand.teleport(pos);
armorStand.setHeadPose(new EulerAngle(0, Math.toRadians(yaw), 0));
}
}

View File

@ -0,0 +1,128 @@
package mineplex.game.clans.clans.siege.cannon;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityExplodeEvent;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilItem;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilServer;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.ClansManager;
public class CannonCrater implements Listener
{
private static final long MAX_LIFEETIME = 100000 /* 10 minutes of lifetime for the fire particles */;
private static final double EXPL_RADIUS = 3;
private Cannon _host;
private Location _origin;
private long _birthTime;
private List<CraterBlock> _blocks;
public CannonCrater(Cannon cannon, Location origin)
{
_host = cannon;
_origin = origin;
_birthTime = System.currentTimeMillis();
_blocks = new ArrayList<>();
UtilServer.getServer().getPluginManager().registerEvents(this, ClansManager.getInstance().getPlugin());
createExplosion();
start();
}
@EventHandler
public void updateEffects(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
{
return;
}
}
private void start()
{
}
private void createExplosion()
{
_blocks.add(new CraterBlock(_origin, Material.AIR));
HashMap<Block, Double> blockList = new HashMap<Block, Double>();
int iR = (int) EXPL_RADIUS + 1;
for (int x = -iR; x <= iR; x++)
{
for (int z = -iR; z <= iR; z++)
{
for (int y = -iR; y <= iR; y++)
{
Block curBlock = _origin.getBlock().getRelative(x, y, z);
double offset = UtilMath.offset(_origin, curBlock.getLocation());
if (offset <= EXPL_RADIUS)
{
blockList.put(curBlock, offset);
}
}
}
}
for (Entry<Block, Double> entry : blockList.entrySet())
{
Block block = entry.getKey();
double distance = entry.getValue();
boolean air = distance <= 2 || (Math.random() > (distance) / 3.65d);
if (block.getType() == Material.AIR) continue;
if (air)
{
_blocks.add(new CraterBlock(block.getLocation(), Material.AIR));
Block above = block.getRelative(BlockFace.UP);
while (!UtilItem.isBoundless((above = above.getRelative(BlockFace.UP)).getType()))
{
_blocks.add(new CraterBlock(above.getLocation(), Material.AIR));
}
}
else if (distance > 2 && Math.random() > .75 && UtilItem.isBoundless(block.getRelative(BlockFace.UP).getType()))
{
_blocks.add(new CraterBlock(block.getLocation(), Material.COAL_BLOCK));
}
}
_blocks.forEach(CraterBlock::set);
}
protected void cleanup()
{
HandlerList.unregisterAll(this);
}
}

View File

@ -0,0 +1,30 @@
package mineplex.game.clans.clans.siege.cannon;
import org.bukkit.Location;
import org.bukkit.Material;
public class CraterBlock
{
public Material Type;
public byte Data;
public Location Location;
public CraterBlock(Location location, Material type, byte data)
{
Location = location;
Type = type;
Data = data;
}
public CraterBlock(Location location, Material type)
{
this(location, type, (byte) 0);
}
public void set()
{
Location.getBlock().setType(Type);
Location.getBlock().setData(Data);
}
}