cannon + siege work with outposts, also moved outposts to the clans.siege package

This commit is contained in:
NewGarbo 2016-01-14 19:53:29 +00:00
parent 595ab0d763
commit 70444ff508
12 changed files with 133 additions and 64 deletions

View File

@ -396,4 +396,21 @@ public class UtilInv
return amount;
}
public static ItemStack decrement(ItemStack item)
{
ItemStack newItem;
if (item.getAmount() == 1)
{
newItem = null;
}
else
{
newItem = item;
newItem.setAmount(newItem.getAmount() - 1);
}
return newItem;
}
}

View File

@ -1,23 +1,14 @@
package mineplex.game.clans.clans.siege;
import org.apache.commons.lang.Validate;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.MiniPlugin;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.outpost.OutpostManager;
import mineplex.game.clans.clans.siege.cannon.Cannon;
import mineplex.game.clans.clans.siege.outpost.OutpostManager;
public class SiegeManager extends MiniPlugin
{
@ -33,35 +24,6 @@ public class SiegeManager extends MiniPlugin
_clans = clans;
_outpostManager = new OutpostManager(clans);
}
@EventHandler(priority = EventPriority.LOWEST)
public void onPlaceBlock(BlockPlaceEvent event)
{
if (event.getItemInHand().isSimilar(CANNON_ITEM))
{
if (!spawnCannon(event.getPlayer(), event.getBlock().getLocation()))
{
event.setCancelled(true);
}
}
}
public boolean spawnCannon(Player player, Location location)
{
if (!_clans.isInClan(player))
{
UtilPlayer.message(player, F.main("Clans", "You must be in a Clan to place a cannon."));
return false;
}
if (!_outpostManager.isInOutpostSiegeArea(location, _clans.getClan(player)))
{
UtilPlayer.message(player, F.main("Clans", "A cannon must be placed in your own Clan's Outpost."));
return false;
}
return true;
_outpostManager = new OutpostManager(clans, this);
}
}

View File

@ -3,31 +3,39 @@ package mineplex.game.clans.clans.siege.cannon;
import org.bukkit.Location;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.player.PlayerArmorStandManipulateEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.game.clans.clans.siege.outpost.Outpost;
public class Cannon implements Listener
{
private Location _location;
private CannonState _state;
private Outpost _outpost;
// Entity Information
private ArmorStand _armorStand;
private Cannon(Location location)
public Cannon(Outpost outpost, Location location)
{
_outpost = outpost;
_location = location;
_state = CannonState.EMPTY;
updateEntities();
}
public void cleanup()
{
_armorStand.remove();
HandlerList.unregisterAll(this);
}
private void updateEntities()
{
if (_armorStand == null)
@ -38,12 +46,12 @@ public class Cannon implements Listener
_armorStand.teleport(getArmorStandLocation());
_armorStand.setVisible(false);
_armorStand.setGravity(false);
_armorStand.setHelmet(new ItemStack(_state.getMaterial(), 1, (short) 0, _state.getData()));
_armorStand.setHelmet(_state.toItemStack());
}
private Location getArmorStandLocation()
{
return _location.clone().add(0, -0.5, 0);
return _location.clone().add(.5, -1.3, .5);
}
private void setState(CannonState state)
@ -51,6 +59,16 @@ public class Cannon implements Listener
_state = state;
updateEntities();
}
public void load()
{
setState(CannonState.LOADED);
}
public void fire()
{
setState(CannonState.EMPTY);
}
@EventHandler
public void onInteract(PlayerArmorStandManipulateEvent event)

View File

@ -1,6 +1,7 @@
package mineplex.game.clans.clans.siege.cannon;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
public enum CannonState
{
@ -25,4 +26,9 @@ public enum CannonState
{
return _material;
}
public ItemStack toItemStack()
{
return new ItemStack(_material, 1, (short) 0, _data);
}
}

View File

@ -1,4 +1,4 @@
package mineplex.game.clans.clans.outpost;
package mineplex.game.clans.clans.siege.outpost;
import org.bukkit.entity.Player;

View File

@ -1,4 +1,4 @@
package mineplex.game.clans.clans.outpost;
package mineplex.game.clans.clans.siege.outpost;
import java.util.ArrayList;
import java.util.Collections;
@ -11,6 +11,7 @@ import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.FallingBlock;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
@ -32,6 +33,7 @@ import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilColor;
import mineplex.core.common.util.UtilEvent;
import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilEvent.ActionType;
import mineplex.core.common.util.UtilItem;
import mineplex.core.common.util.UtilMath;
@ -42,12 +44,15 @@ import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilText;
import mineplex.core.common.util.UtilTextMiddle;
import mineplex.core.common.util.UtilUI;
import mineplex.core.hologram.Hologram;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.ClansBlacklist;
import mineplex.game.clans.clans.siege.SiegeManager;
import mineplex.game.clans.clans.siege.cannon.Cannon;
import mineplex.game.clans.core.repository.ClanTerritory;
import net.minecraft.server.v1_8_R3.AxisAlignedBB;
@ -79,6 +84,8 @@ public class Outpost implements Listener
protected OutpostType _type;
private OutpostState _state;
private List<Cannon> _cannons;
private Hologram _preHologram;
private Hologram _preHologram2;
@ -105,6 +112,8 @@ public class Outpost implements Listener
_builders = new ArrayList<>();
_removalQueue = new ArrayList<>();
_cannons = new ArrayList<>();
_forceFieldStart = _startCorner.clone().subtract(3, 0, 3);
_forceFieldEnd = _endCorner.clone().add(3, 0, 3);
@ -119,7 +128,7 @@ public class Outpost implements Listener
_core = _type.getCoreLocation(_origin);
_preHologram = new Hologram(_clan.Clans.getHologramManager(), _origin.clone().add(0.5, 2.3, 0.5), F.elem(_clan.getName()) + C.cWhite + "'s Outpost block");
_preHologram = new Hologram(_clan.Clans.getHologramManager(), _origin.clone().add(0.5, 2.3, 0.5), F.elem(_clan.getName()) + C.cWhite + "'s Outpost block (Right-Click to activate)");
_preHologram2 = new Hologram(_clan.Clans.getHologramManager(), _origin.clone().add(0.5, 3, 0.5), "Despawning: " + UtilText.getProgress(null, 0, null, true));
_preHologram.start();
@ -140,6 +149,9 @@ public class Outpost implements Listener
_state = OutpostState.DEAD;
_cannons.forEach(Cannon::cleanup);
_cannons.clear();
_host.queueForRemoval(_clan.getName());
}
@ -225,6 +237,17 @@ public class Outpost implements Listener
@EventHandler
public void onBlockPlace(BlockPlaceEvent event)
{
if (event.getItemInHand().isSimilar(SiegeManager.CANNON_ITEM))
{
if (_host.spawnCannon(event.getPlayer(), event.getBlock().getLocation()))
{
event.getPlayer().setItemInHand(UtilInv.decrement(event.getPlayer().getItemInHand()));
return;
}
event.setCancelled(true);
}
if (UtilAlg.inBoundingBox(event.getBlock().getLocation(), _startCorner.clone().subtract(.5, 0, .5), _endCorner))
{
UtilPlayer.message(event.getPlayer(), F.main("Clans", "You may not place blocks in Outposts."));
@ -492,4 +515,12 @@ public class Outpost implements Listener
{
return UtilAlg.inBoundingBox(location, _siegeAreaStart.clone().subtract(.9, 0, .9), _siegeAreaEnd);
}
public void spawnCannon(Player player, Location location)
{
Cannon cannon = new Cannon(this, location);
_host.getPlugin().getServer().getPluginManager().registerEvents(cannon, _host.getPlugin());
_cannons.add(cannon);
}
}

View File

@ -1,4 +1,4 @@
package mineplex.game.clans.clans.outpost;
package mineplex.game.clans.clans.siege.outpost;
import java.util.Map;

View File

@ -1,4 +1,4 @@
package mineplex.game.clans.clans.outpost;
package mineplex.game.clans.clans.siege.outpost;
import java.util.ArrayList;
import java.util.Arrays;

View File

@ -1,4 +1,4 @@
package mineplex.game.clans.clans.outpost;
package mineplex.game.clans.clans.siege.outpost;
import java.util.List;

View File

@ -1,4 +1,4 @@
package mineplex.game.clans.clans.outpost;
package mineplex.game.clans.clans.siege.outpost;
import java.util.ArrayList;
import java.util.HashMap;
@ -26,6 +26,7 @@ import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.event.PlayerClaimTerritoryEvent;
import mineplex.game.clans.clans.siege.SiegeManager;
public class OutpostManager extends MiniPlugin
{
@ -35,10 +36,14 @@ public class OutpostManager extends MiniPlugin
private List<String> _removalQueue;
public OutpostManager(ClansManager clansManager)
private SiegeManager _siegeManager;
public OutpostManager(ClansManager clansManager, SiegeManager siegeManager)
{
super("Outpost Manager", clansManager.getPlugin());
_siegeManager = siegeManager;
_clansManager = clansManager;
_removalQueue = new ArrayList<>();
@ -46,12 +51,37 @@ public class OutpostManager extends MiniPlugin
addCommand(new Meow(this));
}
public boolean spawnCannon(Player player, Location location)
{
if (!_clansManager.isInClan(player))
{
UtilPlayer.message(player, F.main("Clans", "You must be in a Clan to place a cannon."));
return false;
}
if (_clansManager.getClanUtility().isClaimed(location))
{
UtilPlayer.message(player, F.main("Clans", "A cannon must be placed in unclaimed territory."));
return false;
}
if (!isInOutpostSiegeArea(location, _clansManager.getClan(player)))
{
UtilPlayer.message(player, F.main("Clans", "A cannon must be placed in your own Clan's Outpost."));
return false;
}
Get(_clansManager.getClan(player)).spawnCannon(player, location);
return true;
}
@EventHandler(priority = EventPriority.LOWEST)
public void onPlaceBlock(BlockPlaceEvent event)
{
if (event.getItemInHand().isSimilar(Outpost.OUTPOST_ITEM))
{
if (Spawn(event.getPlayer(), event.getBlock().getLocation(), OutpostType.MK3))
if (spawnOutpost(event.getPlayer(), event.getBlock().getLocation(), OutpostType.MK3))
{
event.getBlock().setData((byte) Outpost.OUTPOST_BLOCK_DATA);
}
@ -62,7 +92,7 @@ public class OutpostManager extends MiniPlugin
}
}
public boolean Spawn(Player player, Location location, OutpostType type)
public boolean spawnOutpost(Player player, Location location, OutpostType type)
{
if (!_clansManager.isInClan(player))
{
@ -86,7 +116,7 @@ public class OutpostManager extends MiniPlugin
if (Get(clan) != null)
{
UtilPlayer.message(player, F.main("Clans", "Your clan already has an outpost"));
UtilPlayer.message(player, F.main("Clans", "Your Clan already has an outpost."));
return false;
}
@ -98,7 +128,7 @@ public class OutpostManager extends MiniPlugin
for (Outpost outpost : _outposts.values())
{
if (UtilMath.offset(location, outpost.getExactMiddle()) < 14)
if (UtilMath.offset(location, outpost.getExactMiddle()) < type._size + 8)
{
UtilPlayer.message(player, F.main("Clans", "You cannot place an Outpost near other Outposts."));
return false;
@ -220,4 +250,9 @@ public class OutpostManager extends MiniPlugin
return _outposts.get(clan.getName().toLowerCase()).isInSiegeArea(location);
}
public SiegeManager getSiegeManager()
{
return _siegeManager;
}
}

View File

@ -1,4 +1,4 @@
package mineplex.game.clans.clans.outpost;
package mineplex.game.clans.clans.siege.outpost;
public enum OutpostState
{

View File

@ -1,4 +1,4 @@
package mineplex.game.clans.clans.outpost;
package mineplex.game.clans.clans.siege.outpost;
import java.io.File;
import java.io.FileInputStream;