Improve siege weapons

This commit is contained in:
AlexTheCoder 2017-06-12 01:03:15 -04:00
parent 3d88c2c9a5
commit d2d3b88651
7 changed files with 216 additions and 48 deletions

View File

@ -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))
{

View File

@ -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()

View File

@ -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()));

View File

@ -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;
}

View File

@ -493,6 +493,10 @@ public abstract class SiegeWeapon implements Listener
removeHealth(getHealth());
return;
}
if (_ownerClan.getOnlinePlayers().contains(player))
{
return;
}
if (_lastLeft == -1)
{

View File

@ -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<LivingEntity, Double> hitMap = UtilEnt.getInRadius(_origin, 3.5);
Map<LivingEntity, Double> 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");

View File

@ -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;