more modifications to siege weapons.
This commit is contained in:
parent
c17849b751
commit
b13494f399
@ -466,7 +466,12 @@ public class UtilBlock
|
|||||||
|
|
||||||
public static Block getHighest(World world, Location location)
|
public static Block getHighest(World world, Location location)
|
||||||
{
|
{
|
||||||
return getHighest(world, location.getBlockX(), location.getBlockZ(), null);
|
return getHighest(world, location.getBlockX(), location.getBlockZ());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Block getHighest(World world, Block block)
|
||||||
|
{
|
||||||
|
return getHighest(world, block.getLocation());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Block getHighest(World world, int x, int z, HashSet<Material> ignore)
|
public static Block getHighest(World world, int x, int z, HashSet<Material> ignore)
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
package mineplex.game.clans.clans.siege;
|
package mineplex.game.clans.clans.siege;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.block.BlockPlaceEvent;
|
import org.bukkit.event.block.BlockPlaceEvent;
|
||||||
@ -15,6 +19,7 @@ import mineplex.game.clans.clans.siege.outpost.CommandSiegeSupplies;
|
|||||||
import mineplex.game.clans.clans.siege.outpost.OutpostManager;
|
import mineplex.game.clans.clans.siege.outpost.OutpostManager;
|
||||||
import mineplex.game.clans.clans.siege.weapon.Cannon;
|
import mineplex.game.clans.clans.siege.weapon.Cannon;
|
||||||
import mineplex.game.clans.clans.siege.weapon.Catapult;
|
import mineplex.game.clans.clans.siege.weapon.Catapult;
|
||||||
|
import mineplex.game.clans.clans.siege.weapon.SiegeWeapon;
|
||||||
|
|
||||||
public class SiegeManager extends MiniPlugin
|
public class SiegeManager extends MiniPlugin
|
||||||
{
|
{
|
||||||
@ -22,6 +27,10 @@ public class SiegeManager extends MiniPlugin
|
|||||||
|
|
||||||
private OutpostManager _outpostManager;
|
private OutpostManager _outpostManager;
|
||||||
|
|
||||||
|
public static SiegeManager Instance;
|
||||||
|
|
||||||
|
public List<SiegeWeapon> LiveSiegeWeapons = new ArrayList<>();
|
||||||
|
|
||||||
public SiegeManager(JavaPlugin plugin, ClansManager clans)
|
public SiegeManager(JavaPlugin plugin, ClansManager clans)
|
||||||
{
|
{
|
||||||
super("Siege", plugin);
|
super("Siege", plugin);
|
||||||
@ -31,6 +40,8 @@ public class SiegeManager extends MiniPlugin
|
|||||||
_outpostManager = new OutpostManager(clans, this);
|
_outpostManager = new OutpostManager(clans, this);
|
||||||
|
|
||||||
addCommand(new CommandSiegeSupplies(_outpostManager));
|
addCommand(new CommandSiegeSupplies(_outpostManager));
|
||||||
|
|
||||||
|
Instance = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
@ -86,7 +97,7 @@ public class SiegeManager extends MiniPlugin
|
|||||||
|
|
||||||
public void spawnCannon(Player player, Location location)
|
public void spawnCannon(Player player, Location location)
|
||||||
{
|
{
|
||||||
new Cannon(location, _clans.getClan(player));
|
new Cannon(location, _clans.getClan(player), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean trySpawnCatapult(Player player, Location location)
|
public boolean trySpawnCatapult(Player player, Location location)
|
||||||
@ -116,8 +127,26 @@ public class SiegeManager extends MiniPlugin
|
|||||||
|
|
||||||
public void spawnCatapult(Player player, Location location)
|
public void spawnCatapult(Player player, Location location)
|
||||||
{
|
{
|
||||||
Catapult catapult = new Catapult(location, _clans.getClan(player));
|
Catapult catapult = new Catapult(location, _clans.getClan(player), this);
|
||||||
|
|
||||||
_outpostManager.getPlugin().getServer().getPluginManager().registerEvents(catapult, _outpostManager.getPlugin());
|
_outpostManager.getPlugin().getServer().getPluginManager().registerEvents(catapult, _outpostManager.getPlugin());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void dead(SiegeWeapon weapon)
|
||||||
|
{
|
||||||
|
LiveSiegeWeapons.remove(weapon);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SiegeWeapon close(Block block)
|
||||||
|
{
|
||||||
|
for (SiegeWeapon weapon : LiveSiegeWeapons)
|
||||||
|
{
|
||||||
|
if (weapon.getLocation().distance(block.getLocation()) <= weapon.getSize() + 3.d)
|
||||||
|
{
|
||||||
|
return weapon;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,53 @@
|
|||||||
|
package mineplex.game.clans.clans.siege.events;
|
||||||
|
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
|
import mineplex.game.clans.clans.siege.weapon.SiegeWeapon;
|
||||||
|
import mineplex.game.clans.clans.siege.weapon.projectile.WeaponProjectile;
|
||||||
|
|
||||||
|
public class SiegeWeaponExplodeEvent extends Event
|
||||||
|
{
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
|
private SiegeWeapon _weapon;
|
||||||
|
private WeaponProjectile _projectile;
|
||||||
|
|
||||||
|
private boolean _cancelled;
|
||||||
|
|
||||||
|
public SiegeWeaponExplodeEvent(SiegeWeapon weapon, WeaponProjectile projectile)
|
||||||
|
{
|
||||||
|
_weapon = weapon;
|
||||||
|
_projectile = projectile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SiegeWeapon getWeapon()
|
||||||
|
{
|
||||||
|
return _weapon;
|
||||||
|
}
|
||||||
|
|
||||||
|
public WeaponProjectile getProjectile()
|
||||||
|
{
|
||||||
|
return _projectile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isCancelled()
|
||||||
|
{
|
||||||
|
return _cancelled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCancelled(boolean cancelled)
|
||||||
|
{
|
||||||
|
_cancelled = cancelled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HandlerList getHandlers()
|
||||||
|
{
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList()
|
||||||
|
{
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
}
|
@ -48,6 +48,7 @@ import mineplex.core.updater.UpdateType;
|
|||||||
import mineplex.core.updater.event.UpdateEvent;
|
import mineplex.core.updater.event.UpdateEvent;
|
||||||
import mineplex.game.clans.clans.ClanInfo;
|
import mineplex.game.clans.clans.ClanInfo;
|
||||||
import mineplex.game.clans.clans.ClansBlacklist;
|
import mineplex.game.clans.clans.ClansBlacklist;
|
||||||
|
import mineplex.game.clans.clans.siege.events.SiegeWeaponExplodeEvent;
|
||||||
import mineplex.game.clans.clans.siege.weapon.Cannon;
|
import mineplex.game.clans.clans.siege.weapon.Cannon;
|
||||||
import mineplex.game.clans.clans.siege.weapon.SiegeWeapon;
|
import mineplex.game.clans.clans.siege.weapon.SiegeWeapon;
|
||||||
import mineplex.game.clans.core.repository.ClanTerritory;
|
import mineplex.game.clans.core.repository.ClanTerritory;
|
||||||
@ -97,6 +98,9 @@ public class Outpost implements Listener
|
|||||||
|
|
||||||
private long _spawnTime;
|
private long _spawnTime;
|
||||||
|
|
||||||
|
public double _maxHealth = 4500;
|
||||||
|
public double _health = _maxHealth;
|
||||||
|
|
||||||
public Outpost(OutpostManager host, ClanInfo clan, Location location, OutpostType type)
|
public Outpost(OutpostManager host, ClanInfo clan, Location location, OutpostType type)
|
||||||
{
|
{
|
||||||
_host = host;
|
_host = host;
|
||||||
@ -468,6 +472,20 @@ public class Outpost implements Listener
|
|||||||
_clan.inform("Your Clan's Outpost has been destroyed.", null);
|
_clan.inform("Your Clan's Outpost has been destroyed.", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onSiegeWeaponExplode(SiegeWeaponExplodeEvent event)
|
||||||
|
{
|
||||||
|
if (UtilAlg.inBoundingBox(event.getProjectile().getLocation(), _startCorner.clone().subtract(4, 2, 4), _endCorner.clone().add(4, 2, 4)))
|
||||||
|
{
|
||||||
|
if (getHealth() > 700)
|
||||||
|
{
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
removeHealth(800);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public ClanInfo getClan()
|
public ClanInfo getClan()
|
||||||
{
|
{
|
||||||
return _clan;
|
return _clan;
|
||||||
@ -503,4 +521,36 @@ public class Outpost implements Listener
|
|||||||
{
|
{
|
||||||
return UtilAlg.inBoundingBox(location, _siegeAreaStart.clone().subtract(.9, 0, .9), _siegeAreaEnd.clone().add(.9, 0, .9));
|
return UtilAlg.inBoundingBox(location, _siegeAreaStart.clone().subtract(.9, 0, .9), _siegeAreaEnd.clone().add(.9, 0, .9));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Health Management
|
||||||
|
|
||||||
|
public final double getHealth()
|
||||||
|
{
|
||||||
|
return _health;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final String getDisplayHealth()
|
||||||
|
{
|
||||||
|
return UtilText.getProgress(null, _health / _maxHealth, null, false, 12);
|
||||||
|
}
|
||||||
|
|
||||||
|
public final void setHealth(double health)
|
||||||
|
{
|
||||||
|
_health = UtilMath.clamp(health, 0, _maxHealth);
|
||||||
|
|
||||||
|
if (_health == 0)
|
||||||
|
{
|
||||||
|
kill();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public final void removeHealth(double health)
|
||||||
|
{
|
||||||
|
setHealth(_health - health);
|
||||||
|
}
|
||||||
|
|
||||||
|
public final void addHealth(double health)
|
||||||
|
{
|
||||||
|
setHealth(_health + health);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,7 @@ import mineplex.core.common.util.UtilServer;
|
|||||||
import mineplex.core.common.util.UtilTime;
|
import mineplex.core.common.util.UtilTime;
|
||||||
import mineplex.core.itemstack.ItemBuilder;
|
import mineplex.core.itemstack.ItemBuilder;
|
||||||
import mineplex.game.clans.clans.ClanInfo;
|
import mineplex.game.clans.clans.ClanInfo;
|
||||||
|
import mineplex.game.clans.clans.siege.SiegeManager;
|
||||||
import mineplex.game.clans.clans.siege.weapon.projectile.ProjectileAttributes;
|
import mineplex.game.clans.clans.siege.weapon.projectile.ProjectileAttributes;
|
||||||
import mineplex.game.clans.clans.siege.weapon.projectile.WeaponProjectile;
|
import mineplex.game.clans.clans.siege.weapon.projectile.WeaponProjectile;
|
||||||
import mineplex.game.clans.clans.siege.weapon.util.AccessRule;
|
import mineplex.game.clans.clans.siege.weapon.util.AccessRule;
|
||||||
@ -32,9 +33,9 @@ public class Cannon extends SiegeWeapon
|
|||||||
{
|
{
|
||||||
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 ItemStack CANNON_ITEM = new ItemBuilder(Material.IRON_BLOCK, 1).setRawTitle(C.cBlue + "Cannon").setLore(C.cWhite + "BOOM BABY!").build();
|
||||||
|
|
||||||
public Cannon(Location location, ClanInfo clan)
|
public Cannon(Location location, ClanInfo clan, SiegeManager siegeManager)
|
||||||
{
|
{
|
||||||
super(location, 600.d, "Cannon", clan, clan.Clans);
|
super(location, 1200.d, "Cannon", clan, clan.Clans, siegeManager);
|
||||||
|
|
||||||
location.add(.5, 0, .5);
|
location.add(.5, 0, .5);
|
||||||
|
|
||||||
@ -57,6 +58,11 @@ public class Cannon extends SiegeWeapon
|
|||||||
setProjectileAttributes(new ProjectileAttributes().setPrimedTnt().setDoCrater().craterSize(3).craterChanceOfAir(2.d));
|
setProjectileAttributes(new ProjectileAttributes().setPrimedTnt().setDoCrater().craterSize(3).craterChanceOfAir(2.d));
|
||||||
|
|
||||||
setFireRule(new AccessRule(AccessType.LCLICK_BB, player -> {
|
setFireRule(new AccessRule(AccessType.LCLICK_BB, player -> {
|
||||||
|
if (!isRiding(player))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (!_owner.isMember(player))
|
if (!_owner.isMember(player))
|
||||||
{
|
{
|
||||||
UtilPlayer.message(player, F.main("Clans", "This cannon is not owned by your Clan."));
|
UtilPlayer.message(player, F.main("Clans", "This cannon is not owned by your Clan."));
|
||||||
@ -75,11 +81,6 @@ public class Cannon extends SiegeWeapon
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isRiding(player))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@ -140,7 +141,7 @@ public class Cannon extends SiegeWeapon
|
|||||||
@Override
|
@Override
|
||||||
public void Fire(WeaponProjectile projectile)
|
public void Fire(WeaponProjectile projectile)
|
||||||
{
|
{
|
||||||
projectile.setLocation(projectile.getLocation().add(.5, .2, .5));
|
projectile.setLocation(projectile.getLocation().add(.0, .2, .0));
|
||||||
|
|
||||||
UtilParticle.PlayParticleToAll(ParticleType.LARGE_EXPLODE, projectile.getLocation(), new Vector(0, 0, 0), .1f, 2, ViewDist.MAX);
|
UtilParticle.PlayParticleToAll(ParticleType.LARGE_EXPLODE, projectile.getLocation(), new Vector(0, 0, 0), .1f, 2, ViewDist.MAX);
|
||||||
UtilServer.getServer().getOnlinePlayers().forEach(player -> player.playSound(projectile.getLocation(), Sound.EXPLODE, 1.f, 1.f));
|
UtilServer.getServer().getOnlinePlayers().forEach(player -> player.playSound(projectile.getLocation(), Sound.EXPLODE, 1.f, 1.f));
|
||||||
|
@ -22,6 +22,7 @@ import mineplex.core.common.util.UtilServer;
|
|||||||
import mineplex.core.common.util.UtilTime;
|
import mineplex.core.common.util.UtilTime;
|
||||||
import mineplex.core.itemstack.ItemBuilder;
|
import mineplex.core.itemstack.ItemBuilder;
|
||||||
import mineplex.game.clans.clans.ClanInfo;
|
import mineplex.game.clans.clans.ClanInfo;
|
||||||
|
import mineplex.game.clans.clans.siege.SiegeManager;
|
||||||
import mineplex.game.clans.clans.siege.weapon.projectile.ProjectileAttributes;
|
import mineplex.game.clans.clans.siege.weapon.projectile.ProjectileAttributes;
|
||||||
import mineplex.game.clans.clans.siege.weapon.projectile.WeaponProjectile;
|
import mineplex.game.clans.clans.siege.weapon.projectile.WeaponProjectile;
|
||||||
import mineplex.game.clans.clans.siege.weapon.util.AccessRule;
|
import mineplex.game.clans.clans.siege.weapon.util.AccessRule;
|
||||||
@ -32,13 +33,13 @@ public class Catapult extends SiegeWeapon
|
|||||||
{
|
{
|
||||||
public static final ItemStack CATAPULT_ITEM = new ItemBuilder(Material.GOLD_BLOCK, 1).setRawTitle(C.cBlue + "Catapult").setLore(C.cWhite + "AWHHH YEAH!!!").build();
|
public static final ItemStack CATAPULT_ITEM = new ItemBuilder(Material.GOLD_BLOCK, 1).setRawTitle(C.cBlue + "Catapult").setLore(C.cWhite + "AWHHH YEAH!!!").build();
|
||||||
|
|
||||||
public Catapult(Location location, ClanInfo clan)
|
public Catapult(Location location, ClanInfo clan, SiegeManager siegeManager)
|
||||||
{
|
{
|
||||||
super(location, 600.d, "Catapult", clan, clan.Clans);
|
super(location, 1600.d, "Catapult", clan, clan.Clans, siegeManager);
|
||||||
|
|
||||||
location.add(.5, 0, .5);
|
location.add(.5, 0, .5);
|
||||||
|
|
||||||
setBoundingBox(3);
|
setBoundingBox(1);
|
||||||
|
|
||||||
setStateInfo("Unloaded", new WeaponStateInfo(Material.PACKED_ICE, (byte) 0));
|
setStateInfo("Unloaded", new WeaponStateInfo(Material.PACKED_ICE, (byte) 0));
|
||||||
setStateInfo("Loaded", new WeaponStateInfo(Material.ENDER_PORTAL_FRAME, (byte) 0));
|
setStateInfo("Loaded", new WeaponStateInfo(Material.ENDER_PORTAL_FRAME, (byte) 0));
|
||||||
@ -57,7 +58,16 @@ public class Catapult extends SiegeWeapon
|
|||||||
|
|
||||||
setProjectileAttributes(new ProjectileAttributes().setFallingBlock().setFallingBlockType(Material.TNT).setDoCrater().craterSize(3).craterChanceOfAir(1.3d));
|
setProjectileAttributes(new ProjectileAttributes().setFallingBlock().setFallingBlockType(Material.TNT).setDoCrater().craterSize(3).craterChanceOfAir(1.3d));
|
||||||
|
|
||||||
|
_invertRotation = true;
|
||||||
|
|
||||||
|
_rotSpeed = 40.0f;
|
||||||
|
|
||||||
setFireRule(new AccessRule(AccessType.LCLICK_BB, player -> {
|
setFireRule(new AccessRule(AccessType.LCLICK_BB, player -> {
|
||||||
|
if (!isRiding(player))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (!_owner.isMember(player))
|
if (!_owner.isMember(player))
|
||||||
{
|
{
|
||||||
UtilPlayer.message(player, F.main("Clans", "This Catapult is not owned by your Clan."));
|
UtilPlayer.message(player, F.main("Clans", "This Catapult is not owned by your Clan."));
|
||||||
@ -76,11 +86,6 @@ public class Catapult extends SiegeWeapon
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isRiding(player))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@ -138,19 +143,12 @@ public class Catapult extends SiegeWeapon
|
|||||||
addEntity(armorStand, "WEAPON");
|
addEntity(armorStand, "WEAPON");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public float Rotate(float nextYaw)
|
|
||||||
{
|
|
||||||
return nextYaw + 180;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void Fire(WeaponProjectile projectile)
|
public void Fire(WeaponProjectile projectile)
|
||||||
{
|
{
|
||||||
projectile.setLocation(projectile.getLocation().add(.5, .2, .5));
|
projectile.setLocation(projectile.getLocation().add(.0, 3, .0));
|
||||||
|
|
||||||
UtilParticle.PlayParticleToAll(ParticleType.LARGE_EXPLODE, projectile.getLocation(), new Vector(0, 0, 0), .1f, 2, ViewDist.MAX);
|
UtilServer.getServer().getOnlinePlayers().forEach(player -> player.playSound(projectile.getLocation(), Sound.BAT_TAKEOFF, 2.f, .45f));
|
||||||
UtilServer.getServer().getOnlinePlayers().forEach(player -> player.playSound(projectile.getLocation(), Sound.EXPLODE, 1.f, 1.f));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -2,10 +2,13 @@ package mineplex.game.clans.clans.siege.weapon;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.entity.ArmorStand;
|
import org.bukkit.entity.ArmorStand;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -23,12 +26,15 @@ import org.bukkit.event.player.PlayerInteractEntityEvent;
|
|||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.util.EulerAngle;
|
import org.bukkit.util.EulerAngle;
|
||||||
|
import org.spigotmc.event.entity.EntityDismountEvent;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
|
|
||||||
import mineplex.core.common.util.C;
|
import mineplex.core.common.util.C;
|
||||||
import mineplex.core.common.util.F;
|
import mineplex.core.common.util.F;
|
||||||
|
import mineplex.core.common.util.UtilBlock;
|
||||||
|
import mineplex.core.common.util.UtilItem;
|
||||||
import mineplex.core.common.util.UtilMath;
|
import mineplex.core.common.util.UtilMath;
|
||||||
import mineplex.core.common.util.UtilPlayer;
|
import mineplex.core.common.util.UtilPlayer;
|
||||||
import mineplex.core.common.util.UtilServer;
|
import mineplex.core.common.util.UtilServer;
|
||||||
@ -39,6 +45,7 @@ import mineplex.core.updater.UpdateType;
|
|||||||
import mineplex.core.updater.event.UpdateEvent;
|
import mineplex.core.updater.event.UpdateEvent;
|
||||||
import mineplex.game.clans.clans.ClanInfo;
|
import mineplex.game.clans.clans.ClanInfo;
|
||||||
import mineplex.game.clans.clans.ClansManager;
|
import mineplex.game.clans.clans.ClansManager;
|
||||||
|
import mineplex.game.clans.clans.siege.SiegeManager;
|
||||||
import mineplex.game.clans.clans.siege.weapon.projectile.ProjectileAttributes;
|
import mineplex.game.clans.clans.siege.weapon.projectile.ProjectileAttributes;
|
||||||
import mineplex.game.clans.clans.siege.weapon.projectile.WeaponProjectile;
|
import mineplex.game.clans.clans.siege.weapon.projectile.WeaponProjectile;
|
||||||
import mineplex.game.clans.clans.siege.weapon.util.AccessRule;
|
import mineplex.game.clans.clans.siege.weapon.util.AccessRule;
|
||||||
@ -49,6 +56,7 @@ import mineplex.game.clans.clans.siege.weapon.util.WeaponStateInfo;
|
|||||||
public abstract class SiegeWeapon implements Listener
|
public abstract class SiegeWeapon implements Listener
|
||||||
{
|
{
|
||||||
protected ClansManager _clans;
|
protected ClansManager _clans;
|
||||||
|
protected SiegeManager _siegeManager;
|
||||||
|
|
||||||
protected ClanInfo _owner;
|
protected ClanInfo _owner;
|
||||||
protected final String _name;
|
protected final String _name;
|
||||||
@ -78,6 +86,8 @@ public abstract class SiegeWeapon implements Listener
|
|||||||
|
|
||||||
// Firing stuff
|
// Firing stuff
|
||||||
|
|
||||||
|
protected boolean _invertRotation;
|
||||||
|
|
||||||
private Material _firepowerType;
|
private Material _firepowerType;
|
||||||
private Material _ammunitionType;
|
private Material _ammunitionType;
|
||||||
|
|
||||||
@ -92,13 +102,16 @@ public abstract class SiegeWeapon implements Listener
|
|||||||
private ProjectileAttributes _projectileAttributes;
|
private ProjectileAttributes _projectileAttributes;
|
||||||
private WeaponProjectile _projectile;
|
private WeaponProjectile _projectile;
|
||||||
|
|
||||||
|
protected float _rotSpeed = 20.f;
|
||||||
|
|
||||||
private long _lastRight = -1;
|
private long _lastRight = -1;
|
||||||
private long _lastLeft = -1;
|
private long _lastLeft = -1;
|
||||||
|
|
||||||
protected long _lastFired;
|
protected long _lastFired;
|
||||||
|
|
||||||
public SiegeWeapon(Location location, double maxHealth, String name, ClanInfo owner, ClansManager clansManager)
|
public SiegeWeapon(Location location, double maxHealth, String name, ClanInfo owner, ClansManager clansManager, SiegeManager siegeManager)
|
||||||
{
|
{
|
||||||
|
_siegeManager = siegeManager;
|
||||||
_location = location;
|
_location = location;
|
||||||
_name = name;
|
_name = name;
|
||||||
_health = _maxHealth = maxHealth;
|
_health = _maxHealth = maxHealth;
|
||||||
@ -143,7 +156,7 @@ public abstract class SiegeWeapon implements Listener
|
|||||||
|
|
||||||
_boundingBoxSize = size;
|
_boundingBoxSize = size;
|
||||||
|
|
||||||
_collisionBox = size == 1 ? BarrierCollisionBox.single(_location.clone()) : BarrierCollisionBox.all(_location.clone().subtract((size - 1) / 2, 0, (size - 1) / 2), _location.clone().add(((size - 1) / 2) + .5, size - 1, ((size - 1) / 2) + .5));
|
_collisionBox = size == 1 ? BarrierCollisionBox.single(_location.clone()) : BarrierCollisionBox.all(_location.clone().subtract((size - 1) / 2, 0, (size - 1) / 2), _location.clone().add(((size - 1) / 2) + .2, size - 1, ((size - 1) / 2) + .2));
|
||||||
_collisionBox.Construct();
|
_collisionBox.Construct();
|
||||||
_collisionBox.registerRight((block, player) -> handleRightClick(player));
|
_collisionBox.registerRight((block, player) -> handleRightClick(player));
|
||||||
_collisionBox.registerLeft((block, player) -> handleLeftClick(player));
|
_collisionBox.registerLeft((block, player) -> handleLeftClick(player));
|
||||||
@ -178,7 +191,7 @@ public abstract class SiegeWeapon implements Listener
|
|||||||
{
|
{
|
||||||
ArmorStand armorStand = (ArmorStand) getEntity("WEAPON");
|
ArmorStand armorStand = (ArmorStand) getEntity("WEAPON");
|
||||||
double standYaw = Math.toDegrees(armorStand.getHeadPose().getY()) % 360;
|
double standYaw = Math.toDegrees(armorStand.getHeadPose().getY()) % 360;
|
||||||
double riderYaw = getRider().getLocation().getYaw() % 360;
|
double riderYaw = (getRider().getLocation().getYaw() + (_invertRotation ? 180 : 0)) % 360;
|
||||||
|
|
||||||
// riderYaw = 350 and standYaw = 20
|
// riderYaw = 350 and standYaw = 20
|
||||||
// dif should be -30 and not 330
|
// dif should be -30 and not 330
|
||||||
@ -186,7 +199,7 @@ public abstract class SiegeWeapon implements Listener
|
|||||||
if (dif > 180) dif -= 360;
|
if (dif > 180) dif -= 360;
|
||||||
if (dif < -180) dif += 360;
|
if (dif < -180) dif += 360;
|
||||||
|
|
||||||
double yaw = Rotate((float) ((float)standYaw + Math.min(dif / 20.f, 4f)));
|
double yaw = (float) ((float)standYaw + Math.min(dif / _rotSpeed, 4f));
|
||||||
|
|
||||||
armorStand.setHeadPose(new EulerAngle(0, Math.toRadians(yaw), 0));
|
armorStand.setHeadPose(new EulerAngle(0, Math.toRadians(yaw), 0));
|
||||||
}
|
}
|
||||||
@ -326,6 +339,8 @@ public abstract class SiegeWeapon implements Listener
|
|||||||
_comprisedOf.clear();
|
_comprisedOf.clear();
|
||||||
_infoHologram.stop();
|
_infoHologram.stop();
|
||||||
|
|
||||||
|
_siegeManager.dead(this);
|
||||||
|
|
||||||
HandlerList.unregisterAll(this);
|
HandlerList.unregisterAll(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -376,6 +391,51 @@ public abstract class SiegeWeapon implements Listener
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void dismount(Player player)
|
||||||
|
{
|
||||||
|
//2 in ecah
|
||||||
|
|
||||||
|
Block origin = player.getLocation().getBlock();
|
||||||
|
|
||||||
|
BlockFace[] faces = { BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST };
|
||||||
|
|
||||||
|
Block suitable = null;
|
||||||
|
|
||||||
|
findAir: for (int yTests = 0; yTests < _boundingBoxSize; yTests++)
|
||||||
|
{
|
||||||
|
final int fyt = yTests;
|
||||||
|
|
||||||
|
Function<Block, Block> function = block -> {
|
||||||
|
Block up = block;
|
||||||
|
|
||||||
|
for (int x = 0; x < fyt; x++)
|
||||||
|
{
|
||||||
|
up = up.getRelative(BlockFace.UP);
|
||||||
|
}
|
||||||
|
|
||||||
|
return up;
|
||||||
|
};
|
||||||
|
|
||||||
|
for (BlockFace face : faces)
|
||||||
|
{
|
||||||
|
Block testFor = origin.getRelative(face).getRelative(face);
|
||||||
|
|
||||||
|
if (UtilItem.isBoundless(function.apply(testFor).getType()))
|
||||||
|
{
|
||||||
|
suitable = function.apply(testFor);
|
||||||
|
break findAir;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (suitable == null)
|
||||||
|
{
|
||||||
|
suitable = UtilBlock.getHighest(origin.getWorld(), origin).getRelative(BlockFace.UP);
|
||||||
|
}
|
||||||
|
|
||||||
|
player.teleport(suitable.getRelative(BlockFace.UP).getLocation());
|
||||||
|
}
|
||||||
|
|
||||||
private void handleLeftClick(Player player)
|
private void handleLeftClick(Player player)
|
||||||
{
|
{
|
||||||
if (_lastLeft == -1)
|
if (_lastLeft == -1)
|
||||||
@ -448,11 +508,6 @@ public abstract class SiegeWeapon implements Listener
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
protected float Rotate(float yaw)
|
|
||||||
{
|
|
||||||
return yaw;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Entity Management
|
// Entity Management
|
||||||
|
|
||||||
protected final void addEntity(Entity entity, String uniqueName)
|
protected final void addEntity(Entity entity, String uniqueName)
|
||||||
@ -671,6 +726,15 @@ public abstract class SiegeWeapon implements Listener
|
|||||||
}, 3L);
|
}, 3L);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onDismount(EntityDismountEvent event)
|
||||||
|
{
|
||||||
|
if (event.getDismounted().equals(getEntity("PLAYERMOUNT")))
|
||||||
|
{
|
||||||
|
dismount((Player) event.getEntity());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onInteract(PlayerInteractAtEntityEvent event)
|
public void onInteract(PlayerInteractAtEntityEvent event)
|
||||||
{
|
{
|
||||||
@ -701,6 +765,17 @@ public abstract class SiegeWeapon implements Listener
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public boolean inProtection(Block block)
|
||||||
|
{
|
||||||
|
if (block.getLocation().distance(_location) < _boundingBoxSize + 1.65 && block.getLocation().getY() <= _location.getY() + 2)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onInteract(PlayerArmorStandManipulateEvent event)
|
public void onInteract(PlayerArmorStandManipulateEvent event)
|
||||||
{
|
{
|
||||||
@ -724,4 +799,14 @@ public abstract class SiegeWeapon implements Listener
|
|||||||
Tick();
|
Tick();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Location getLocation()
|
||||||
|
{
|
||||||
|
return _location;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getSize()
|
||||||
|
{
|
||||||
|
return _boundingBoxSize;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,8 @@ import mineplex.core.common.util.UtilParticle.ViewDist;
|
|||||||
import mineplex.core.common.util.UtilServer;
|
import mineplex.core.common.util.UtilServer;
|
||||||
import mineplex.core.updater.UpdateType;
|
import mineplex.core.updater.UpdateType;
|
||||||
import mineplex.core.updater.event.UpdateEvent;
|
import mineplex.core.updater.event.UpdateEvent;
|
||||||
|
import mineplex.game.clans.clans.siege.SiegeManager;
|
||||||
|
import mineplex.game.clans.clans.siege.events.SiegeWeaponExplodeEvent;
|
||||||
import mineplex.game.clans.clans.siege.weapon.SiegeWeapon;
|
import mineplex.game.clans.clans.siege.weapon.SiegeWeapon;
|
||||||
|
|
||||||
public class Crater implements Listener
|
public class Crater implements Listener
|
||||||
@ -41,7 +43,7 @@ public class Crater implements Listener
|
|||||||
|
|
||||||
private final List<CraterBlock> _blocks;
|
private final List<CraterBlock> _blocks;
|
||||||
|
|
||||||
public Crater(SiegeWeapon weapon, Location origin, int size, double airChance, boolean doFire)
|
public Crater(SiegeWeapon weapon, WeaponProjectile projectile, Location origin, int size, double airChance, boolean doFire)
|
||||||
{
|
{
|
||||||
_weapon = weapon;
|
_weapon = weapon;
|
||||||
_origin = origin;
|
_origin = origin;
|
||||||
@ -101,6 +103,7 @@ public class Crater implements Listener
|
|||||||
HashMap<Block, Double> blockList = new HashMap<Block, Double>();
|
HashMap<Block, Double> blockList = new HashMap<Block, Double>();
|
||||||
int iR = (int) _size + 1;
|
int iR = (int) _size + 1;
|
||||||
|
|
||||||
|
loop:
|
||||||
for (int x = -iR; x <= iR; x++)
|
for (int x = -iR; x <= iR; x++)
|
||||||
{
|
{
|
||||||
for (int z = -iR; z <= iR; z++)
|
for (int z = -iR; z <= iR; z++)
|
||||||
@ -113,7 +116,14 @@ public class Crater implements Listener
|
|||||||
|
|
||||||
if (offset <= _size)
|
if (offset <= _size)
|
||||||
{
|
{
|
||||||
blockList.put(curBlock, offset);
|
SiegeWeapon weapon = SiegeManager.Instance.close(curBlock);
|
||||||
|
if (weapon != null)
|
||||||
|
{
|
||||||
|
weapon.removeHealth(453);
|
||||||
|
break loop;
|
||||||
|
}
|
||||||
|
|
||||||
|
blockList.put(curBlock, Double.valueOf(offset));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -122,7 +132,7 @@ public class Crater implements Listener
|
|||||||
for (Entry<Block, Double> entry : blockList.entrySet())
|
for (Entry<Block, Double> entry : blockList.entrySet())
|
||||||
{
|
{
|
||||||
Block block = entry.getKey();
|
Block block = entry.getKey();
|
||||||
double distance = entry.getValue();
|
double distance = entry.getValue().doubleValue();
|
||||||
|
|
||||||
boolean air = distance <= _airChance || (Math.random() > (distance) / 3.65d);
|
boolean air = distance <= _airChance || (Math.random() > (distance) / 3.65d);
|
||||||
|
|
||||||
@ -154,7 +164,7 @@ public class Crater implements Listener
|
|||||||
for (Entry<Block, Double> entry : blockList.entrySet())
|
for (Entry<Block, Double> entry : blockList.entrySet())
|
||||||
{
|
{
|
||||||
Block block = entry.getKey();
|
Block block = entry.getKey();
|
||||||
double distance = entry.getValue();
|
double distance = entry.getValue().doubleValue();
|
||||||
|
|
||||||
if (block.getType() == Material.AIR) continue;
|
if (block.getType() == Material.AIR) continue;
|
||||||
|
|
||||||
@ -167,6 +177,7 @@ public class Crater implements Listener
|
|||||||
!block.getRelative(BlockFace.DOWN).getType().equals(CHARRED_TYPE))
|
!block.getRelative(BlockFace.DOWN).getType().equals(CHARRED_TYPE))
|
||||||
{
|
{
|
||||||
_blocks.add(new CraterBlock(block.getLocation(), distance, CHARRED_TYPE));
|
_blocks.add(new CraterBlock(block.getLocation(), distance, CHARRED_TYPE));
|
||||||
|
|
||||||
if (_fire)
|
if (_fire)
|
||||||
{
|
{
|
||||||
_blocks.add(new CraterBlock(block.getRelative(BlockFace.UP).getLocation(), distance, Material.FIRE));
|
_blocks.add(new CraterBlock(block.getRelative(BlockFace.UP).getLocation(), distance, Material.FIRE));
|
||||||
|
@ -19,6 +19,7 @@ import mineplex.core.common.util.UtilItem;
|
|||||||
import mineplex.core.common.util.UtilServer;
|
import mineplex.core.common.util.UtilServer;
|
||||||
import mineplex.core.updater.UpdateType;
|
import mineplex.core.updater.UpdateType;
|
||||||
import mineplex.core.updater.event.UpdateEvent;
|
import mineplex.core.updater.event.UpdateEvent;
|
||||||
|
import mineplex.game.clans.clans.siege.events.SiegeWeaponExplodeEvent;
|
||||||
import mineplex.game.clans.clans.siege.weapon.SiegeWeapon;
|
import mineplex.game.clans.clans.siege.weapon.SiegeWeapon;
|
||||||
|
|
||||||
public class WeaponProjectile implements Listener
|
public class WeaponProjectile implements Listener
|
||||||
@ -95,7 +96,14 @@ public class WeaponProjectile implements Listener
|
|||||||
.filter(block -> !UtilItem.isBoundless(block.getType()))
|
.filter(block -> !UtilItem.isBoundless(block.getType()))
|
||||||
.iterator().hasNext() && _projectileEntity.getTicksLived() >= 10)
|
.iterator().hasNext() && _projectileEntity.getTicksLived() >= 10)
|
||||||
{
|
{
|
||||||
new Crater(_weapon, UtilBlock.nearestFloor(_projectileEntity.getLocation()), _attributes._craterSize, _attributes._craterChanceOfAir, _attributes._craterDoFire);
|
SiegeWeaponExplodeEvent newEvent = new SiegeWeaponExplodeEvent(_weapon, this);
|
||||||
|
|
||||||
|
UtilServer.getPluginManager().callEvent(newEvent);
|
||||||
|
|
||||||
|
if (!newEvent.isCancelled())
|
||||||
|
{
|
||||||
|
new Crater(_weapon, this, UtilBlock.nearestFloor(_projectileEntity.getLocation()), _attributes._craterSize, _attributes._craterChanceOfAir, _attributes._craterDoFire);
|
||||||
|
}
|
||||||
|
|
||||||
UtilServer.getServer().getOnlinePlayers().forEach(player -> player.playSound(_projectileEntity.getLocation(), Sound.EXPLODE, 1.f, 1.f));
|
UtilServer.getServer().getOnlinePlayers().forEach(player -> player.playSound(_projectileEntity.getLocation(), Sound.EXPLODE, 1.f, 1.f));
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user