From d2d3b88651f592c1efc4b202ff7d58dd50afc915 Mon Sep 17 00:00:00 2001 From: AlexTheCoder Date: Mon, 12 Jun 2017 01:03:15 -0400 Subject: [PATCH] Improve siege weapons --- .../game/clans/clans/siege/SiegeManager.java | 57 ++++++ .../clans/clans/siege/outpost/Outpost.java | 167 ++++++++++++++---- .../clans/siege/outpost/OutpostManager.java | 17 +- .../repository/tokens/SiegeWeaponToken.java | 8 +- .../clans/clans/siege/weapon/SiegeWeapon.java | 4 + .../clans/siege/weapon/projectile/Crater.java | 4 +- .../weapon/projectile/WeaponProjectile.java | 7 - 7 files changed, 216 insertions(+), 48 deletions(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java index ab406664c..38ce9f2fc 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java @@ -10,6 +10,7 @@ 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.itemstack.ItemStackFactory; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.game.clans.clans.ClansManager; @@ -217,6 +218,16 @@ public class SiegeManager extends MiniPlugin { event.setCancelled(true); + int health = ItemStackFactory.Instance.GetLoreVar(event.getPlayer().getItemInHand(), "Health", 0); + if (health != 0) + { + if (trySpawnCannon(event.getPlayer(), event.getBlock().getLocation())) + { + event.getPlayer().setItemInHand(UtilInv.decrement(event.getPlayer().getItemInHand())); + } + return; + } + if (trySpawnCannon(event.getPlayer(), event.getBlock().getLocation())) { event.getPlayer().setItemInHand(UtilInv.decrement(event.getPlayer().getItemInHand())); @@ -236,6 +247,46 @@ public class SiegeManager extends MiniPlugin // } } + public boolean trySpawnCannon(Player player, Location location, int health) + { + if (_clansManager.getNetherManager().isInNether(player)) + { + _clansManager.message(player, "You are not allowed to place this in " + F.clansNether("The Nether") + "."); + + return false; + } + if (_clansManager.getWorldEvent().getRaidManager().isInRaid(player.getLocation())) + { + _clansManager.message(player, "You are not allowed to place this in a raid."); + + return false; + } + + if (!_clansManager.isInClan(player)) + { + UtilPlayer.message(player, F.main("Clans", "You must be in a Clan to place a Cannon.")); + return false; + } + + if (_clansManager.hasTimer(player)) + { + UtilPlayer.message(player, F.main("Clans", "You cannot place a Cannon whilst protected from pvp.")); + return false; + } + + ClanTerritory claim = _clansManager.getClanUtility().getClaim(location); + + if (claim != null && !claim.Owner.equals(_clansManager.getClan(player).getName())) + { + UtilPlayer.message(player, F.main("Clans", "You must place a Cannon in the Wilderness or your own Territory.")); + return false; + } + + spawnCannon(player, location).setHealth(health); + + return true; + } + public boolean trySpawnCannon(Player player, Location location) { if (_clansManager.getNetherManager().isInNether(player)) @@ -244,6 +295,12 @@ public class SiegeManager extends MiniPlugin return false; } + if (_clansManager.getWorldEvent().getRaidManager().isInRaid(player.getLocation())) + { + _clansManager.message(player, "You are not allowed to place this in a raid."); + + return false; + } if (!_clansManager.isInClan(player)) { diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java index f49712a83..c20834e30 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/Outpost.java @@ -64,11 +64,13 @@ import net.minecraft.server.v1_8_R3.AxisAlignedBB; public class Outpost implements Listener { - protected static final long MAX_LIFETIME = 30 * 60 * 1000; // 30 minutes + protected static final long MAX_LIFETIME = 45 * 60 * 1000; // 30 minutes public static final ItemStack OUTPOST_ITEM = new ItemBuilder(Material.BEACON, 1).setRawTitle(C.Reset + C.cBlue + "Outpost").build(); public static final long PREP_TIME = 2 * 60 * 1000; + private static final int MAX_HEALTH = 100; + private OutpostManager _outpostManager; private final int _uniqueId; @@ -104,10 +106,18 @@ public class Outpost implements Listener private Hologram _lifetimeLeft; + private int _health; + + private long _lastDamage; + + private long _lastRegen; + public Outpost(OutpostManager outpostManager, OutpostToken token) { _outpostManager = outpostManager; + _health = MAX_HEALTH; + _uniqueId = token.UniqueId; _ownerClan = token.OwnerClan; @@ -138,7 +148,36 @@ public class Outpost implements Listener return; if (clickType == ClickType.LEFT || clickType == ClickType.SHIFT_LEFT) - kill(); + { + if (_outpostManager.getClansManager().hasTimer(player)) + { + UtilPlayer.message(player, F.main("Clans", "You cannot destroy an Outpost whilst protected from PvP.")); + return; + } + if (!UtilTime.elapsed(_lastDamage, 5000)) + { + return; + } + if (_health <= 2) + { + UtilPlayer.message(player, F.main("Clans", "You have destroyed " + F.elem(_ownerClan.getName()) + "'s Outpost!")); + + _core.getBlock().setType(Material.AIR); + + _ownerClan.inform("Your Outpost has been destroyed!", null); + UtilTextMiddle.display("Siege", "Your Outpost has been destroyed", 20, 100, 20, _ownerClan.getOnlinePlayersArray()); + + if (getState() == OutpostState.AWAITING) + cleanup(); + else + kill(); + + return; + } + + _lastDamage = System.currentTimeMillis(); + _health -= 2; + } } }); @@ -166,6 +205,8 @@ public class Outpost implements Listener { _outpostManager = outpostManager; + _health = MAX_HEALTH; + _uniqueId = outpostManager.getSiegeManager().randomId(); _ownerClan = clan; @@ -211,7 +252,36 @@ public class Outpost implements Listener return; if (clickType == ClickType.LEFT || clickType == ClickType.SHIFT_LEFT) - kill(); + { + if (_outpostManager.getClansManager().hasTimer(player)) + { + UtilPlayer.message(player, F.main("Clans", "You cannot destroy an Outpost whilst protected from PvP.")); + return; + } + if (!UtilTime.elapsed(_lastDamage, 5000)) + { + return; + } + if (_health <= 2) + { + UtilPlayer.message(player, F.main("Clans", "You have destroyed " + F.elem(_ownerClan.getName()) + "'s Outpost!")); + + _core.getBlock().setType(Material.AIR); + + _ownerClan.inform("Your Outpost has been destroyed!", null); + UtilTextMiddle.display("Siege", "Your Outpost has been destroyed", 20, 100, 20, _ownerClan.getOnlinePlayersArray()); + + if (getState() == OutpostState.AWAITING) + cleanup(); + else + kill(); + + return; + } + + _lastDamage = System.currentTimeMillis(); + _health -= 2; + } } }); } @@ -306,26 +376,35 @@ public class Outpost implements Listener { if (event.getBlock().getLocation().equals(_core) && getState() == OutpostState.LIVE) { - - if(_outpostManager.getClansManager().hasTimer(event.getPlayer())) + event.setCancelled(true); + if (_outpostManager.getClansManager().hasTimer(event.getPlayer())) { UtilPlayer.message(event.getPlayer(), F.main("Clans", "You cannot destroy an Outpost whilst protected from PvP.")); - event.setCancelled(true); return; } - UtilPlayer.message(event.getPlayer(), F.main("Clans", "You have destroyed " + F.elem(_ownerClan.getName()) + "'s Outpost!")); + if (!UtilTime.elapsed(_lastDamage, 5000)) + { + return; + } + if (_health <= 2) + { + UtilPlayer.message(event.getPlayer(), F.main("Clans", "You have destroyed " + F.elem(_ownerClan.getName()) + "'s Outpost!")); + + _core.getBlock().setType(Material.AIR); + + _ownerClan.inform("Your Outpost has been destroyed!", null); + UtilTextMiddle.display("Siege", "Your Outpost has been destroyed", 20, 100, 20, _ownerClan.getOnlinePlayersArray()); + + if (getState() == OutpostState.AWAITING) + cleanup(); + else + kill(); + + return; + } - _core.getBlock().setType(Material.AIR); - - _ownerClan.inform("Your Outpost has been destroyed!", null); - UtilTextMiddle.display("Siege", "Your Outpost has been destroyed", 20, 100, 20, _ownerClan.getOnlinePlayersArray()); - - if (getState() == OutpostState.AWAITING) - cleanup(); - else - kill(); - - event.setCancelled(true); + _lastDamage = System.currentTimeMillis(); + _health -= 2; } } @@ -344,20 +423,35 @@ public class Outpost implements Listener if (event.getBlock().getLocation().equals(_core) && getState() == OutpostState.LIVE) { - UtilPlayer.message(event.getPlayer(), F.main("Clans", "You have destroyed " + F.elem(_ownerClan.getName()) + "'s Outpost!")); - - _core.getBlock().setType(Material.AIR); - - _ownerClan.inform("Your Outpost has been destroyed!", null); - UtilTextMiddle.display("Siege", "Your Outpost has been destroyed", 20, 100, 20, _ownerClan.getOnlinePlayersArray()); - - if (getState() == OutpostState.AWAITING) - cleanup(); - else - kill(); - event.setCancelled(true); - return; + if (_outpostManager.getClansManager().hasTimer(event.getPlayer())) + { + UtilPlayer.message(event.getPlayer(), F.main("Clans", "You cannot destroy an Outpost whilst protected from PvP.")); + return; + } + if (!UtilTime.elapsed(_lastDamage, 5000)) + { + return; + } + if (_health <= 2) + { + UtilPlayer.message(event.getPlayer(), F.main("Clans", "You have destroyed " + F.elem(_ownerClan.getName()) + "'s Outpost!")); + + _core.getBlock().setType(Material.AIR); + + _ownerClan.inform("Your Outpost has been destroyed!", null); + UtilTextMiddle.display("Siege", "Your Outpost has been destroyed", 20, 100, 20, _ownerClan.getOnlinePlayersArray()); + + if (getState() == OutpostState.AWAITING) + cleanup(); + else + kill(); + + return; + } + + _lastDamage = System.currentTimeMillis(); + _health -= 2; } if (UtilAlg.inBoundingBox(event.getBlock().getLocation(), _startCorner.clone().subtract(.5, 0, .5), _endCorner)) @@ -425,7 +519,9 @@ public class Outpost implements Listener } if (_lifetimeLeft != null) - _lifetimeLeft.setText("Despawning in " + F.time(UtilTime.MakeStr(MAX_LIFETIME - (System.currentTimeMillis() - _timeSpawned)))); + { + _lifetimeLeft.setText("Health: " + _health, "Despawning in " + F.time(UtilTime.MakeStr(MAX_LIFETIME - (System.currentTimeMillis() - _timeSpawned)))); + } if (_state == OutpostState.CONSTRUCTING) { @@ -482,6 +578,11 @@ public class Outpost implements Listener { kill(); } + if (_health < MAX_HEALTH && UtilTime.elapsed(_lastDamage, 15000) && UtilTime.elapsed(_lastRegen, 1000)) + { + _lastRegen = System.currentTimeMillis(); + _health++; + } } } @@ -519,6 +620,7 @@ public class Outpost implements Listener //Inform nearby Clans for (int chunkX = -3; chunkX < 3; chunkX++) + { for (int chunkZ = -3; chunkZ < 3; chunkZ++) { ClanTerritory territory = _ownerClan.Clans.getClanUtility().getClaim(_origin.getWorld().getChunkAt(_origin.getChunk().getX() + chunkX, _origin.getChunk().getZ() + chunkZ)); @@ -531,6 +633,7 @@ public class Outpost implements Listener UtilTextMiddle.display("Siege", "A Siege has been declared on your Clan!", 20, 100, 20, clan.getOnlinePlayersArray()); } } + } } public void kill() diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostManager.java index 559fc6b4b..149498943 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/outpost/OutpostManager.java @@ -75,13 +75,20 @@ public class OutpostManager extends MiniPlugin return false; } + if (_clansManager.getWorldEvent().getRaidManager().isInRaid(player.getLocation())) + { + _clansManager.message(player, "You are not allowed to place this in a raid."); + + return false; + } + if (!_clansManager.isInClan(player)) { UtilPlayer.message(player, F.main("Clans", "You must be in a Clan to place an Outpost.")); return false; } - if(_clansManager.hasTimer(player)) + if (_clansManager.hasTimer(player)) { UtilPlayer.message(player, F.main("Clans", "You can't place an Outpost whilst protected from PvP.")); return false; @@ -123,6 +130,7 @@ public class OutpostManager extends MiniPlugin } for (int x = -2; x < 2; x++) + { for (int z = -2; z < 2; z++) { Chunk chunk = location.getWorld().getChunkAt(location.getChunk().getX() + x, location.getChunk().getZ() + z); @@ -138,10 +146,12 @@ public class OutpostManager extends MiniPlugin } } } + } boolean gut = false; for (int x = -6; x < 6; x++) + { for (int z = -6; z < 6; z++) { Chunk chunk = location.getWorld().getChunkAt(location.getChunk().getX() + x, location.getChunk().getZ() + z); @@ -159,6 +169,7 @@ public class OutpostManager extends MiniPlugin } } } + } /* das ist schlecht */ if (!gut) @@ -168,7 +179,9 @@ public class OutpostManager extends MiniPlugin } for (int x = -type._size; x < type._size; x++) + { for (int y = -1; y < type._ySize; y++) + { for (int z = -type._size; z < type._size; z++) { Location loc = location.clone().add(x, y, z); @@ -179,6 +192,8 @@ public class OutpostManager extends MiniPlugin return false; } } + } + } _outposts.put(clan.getName(), new Outpost(this, clan, location, type)); _idToOutpost.put(Integer.valueOf(_outposts.get(clan.getName()).getUniqueId()), _outposts.get(clan.getName())); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/repository/tokens/SiegeWeaponToken.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/repository/tokens/SiegeWeaponToken.java index 638aa800c..274039ed8 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/repository/tokens/SiegeWeaponToken.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/repository/tokens/SiegeWeaponToken.java @@ -1,8 +1,5 @@ package mineplex.game.clans.clans.siege.repository.tokens; -import java.util.Map; -import java.util.UUID; - import org.bukkit.Location; import mineplex.game.clans.clans.ClanInfo; @@ -15,6 +12,5 @@ public class SiegeWeaponToken public Location Location; public int Health; public int Yaw; - public long LastFired; - -} + public long LastFired; +} \ No newline at end of file diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java index 4f6602afa..d0fa8832b 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/SiegeWeapon.java @@ -493,6 +493,10 @@ public abstract class SiegeWeapon implements Listener removeHealth(getHealth()); return; } + if (_ownerClan.getOnlinePlayers().contains(player)) + { + return; + } if (_lastLeft == -1) { diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/projectile/Crater.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/projectile/Crater.java index 0b1630995..c8bbf60ca 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/projectile/Crater.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/projectile/Crater.java @@ -1,7 +1,7 @@ package mineplex.game.clans.clans.siege.weapon.projectile; -import java.util.HashMap; import java.util.List; +import java.util.Map; import org.bukkit.Location; import org.bukkit.Material; @@ -110,7 +110,7 @@ public class Crater } }, 1L); - HashMap hitMap = UtilEnt.getInRadius(_origin, 3.5); + Map hitMap = UtilEnt.getInRadius(_origin, 3.5); for (LivingEntity hit : hitMap.keySet()) { ClansManager.getInstance().getDamageManager().NewDamageEvent(hit, _cause, null, DamageCause.ENTITY_EXPLOSION, 7 / hitMap.get(hit), true, true, false, _cause.getName(), "Siege Cannon"); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/projectile/WeaponProjectile.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/projectile/WeaponProjectile.java index 75cd73e49..2cfa6e336 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/projectile/WeaponProjectile.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/weapon/projectile/WeaponProjectile.java @@ -3,20 +3,13 @@ package mineplex.game.clans.clans.siege.weapon.projectile; import org.bukkit.Location; import org.bukkit.Sound; import org.bukkit.entity.Entity; -import org.bukkit.entity.FallingBlock; import org.bukkit.entity.Player; import org.bukkit.entity.TNTPrimed; import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; import org.bukkit.event.HandlerList; import org.bukkit.event.Listener; -import org.bukkit.event.entity.EntityChangeBlockEvent; -import org.bukkit.event.entity.EntityExplodeEvent; -import org.bukkit.util.Vector; -import mineplex.core.common.util.UtilAlg; import mineplex.core.common.util.UtilBlock; -import mineplex.core.common.util.UtilItem; import mineplex.core.common.util.UtilServer; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent;