pushing to beta to change to alpha
This commit is contained in:
parent
40c52ac557
commit
cc48d98208
@ -142,4 +142,14 @@ public class UtilMath
|
||||
|
||||
return ((double) rand) / 100.d;
|
||||
}
|
||||
|
||||
public static <T> T getLast(List<T> list)
|
||||
{
|
||||
return list.isEmpty() ? null : list.get(list.size() - 1);
|
||||
}
|
||||
|
||||
public static <T> T getFirst(List<T> list)
|
||||
{
|
||||
return list.isEmpty() ? null : list.get(0);
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,17 @@
|
||||
package mineplex.game.clans.clans.siege;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import mineplex.core.MiniPlugin;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.UtilInv;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
import mineplex.game.clans.clans.ClansManager;
|
||||
import mineplex.game.clans.clans.siege.cannon.Cannon;
|
||||
import mineplex.game.clans.clans.siege.outpost.OutpostManager;
|
||||
|
||||
public class SiegeManager extends MiniPlugin
|
||||
@ -20,4 +28,51 @@ public class SiegeManager extends MiniPlugin
|
||||
|
||||
_outpostManager = new OutpostManager(clans, this);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockPlace(BlockPlaceEvent event)
|
||||
{
|
||||
if (event.getItemInHand().isSimilar(Cannon.CANNON_ITEM))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
|
||||
if (trySpawnCannon(event.getPlayer(), event.getBlock().getLocation()))
|
||||
{
|
||||
event.getPlayer().setItemInHand(UtilInv.decrement(event.getPlayer().getItemInHand()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean trySpawnCannon(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 (_clans.getClanUtility().isClaimed(location))
|
||||
{
|
||||
UtilPlayer.message(player, F.main("Clans", "A cannon must be placed in unclaimed territory."));
|
||||
return false;
|
||||
}
|
||||
|
||||
// if (!isInOutpostSiegeArea(location, _clans.getClan(player)))
|
||||
// {
|
||||
// UtilPlayer.message(player, F.main("Clans", "A cannon must be placed in your own Clan's Outpost."));
|
||||
// return false;
|
||||
// }
|
||||
|
||||
spawnCannon(player, location);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void spawnCannon(Player player, Location location)
|
||||
{
|
||||
Cannon cannon = new Cannon(location);
|
||||
|
||||
_outpostManager.getPlugin().getServer().getPluginManager().registerEvents(cannon, _outpostManager.getPlugin());
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,8 @@
|
||||
package mineplex.game.clans.clans.siege.cannon;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
@ -20,10 +23,10 @@ import org.bukkit.util.EulerAngle;
|
||||
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.UtilEnt;
|
||||
import mineplex.core.common.util.UtilMath;
|
||||
import mineplex.core.itemstack.ItemBuilder;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
import mineplex.game.clans.clans.siege.outpost.Outpost;
|
||||
|
||||
public class Cannon implements Listener
|
||||
{
|
||||
@ -37,22 +40,25 @@ public class Cannon implements Listener
|
||||
|
||||
// Entity Information
|
||||
private ArmorStand _armorStand;
|
||||
private Slime _filler;
|
||||
private Slime _filler2;
|
||||
|
||||
private List<Entity> _fillers;
|
||||
|
||||
public Cannon(Location location)
|
||||
{
|
||||
_location = location;
|
||||
_state = CannonState.UNLOADED;
|
||||
|
||||
_fillers = new LinkedList<>();
|
||||
|
||||
updateEntities();
|
||||
}
|
||||
|
||||
public void cleanup()
|
||||
{
|
||||
if (_armorStand != null) _armorStand.remove();
|
||||
if (_filler != null) _filler.remove();
|
||||
if (_filler2 != null) _filler2.remove();
|
||||
|
||||
_fillers.forEach(Entity::remove);
|
||||
|
||||
HandlerList.unregisterAll(this);
|
||||
}
|
||||
|
||||
@ -63,28 +69,33 @@ public class Cannon implements Listener
|
||||
_armorStand = _location.getWorld().spawn(getArmorStandLocation(), ArmorStand.class);
|
||||
}
|
||||
|
||||
if (_filler == null)
|
||||
if (_fillers.isEmpty())
|
||||
{
|
||||
_filler = _location.getWorld().spawn(getArmorStandLocation(), Slime.class);
|
||||
Slime slime = getArmorStandLocation().getWorld().spawn(getArmorStandLocation(), Slime.class);
|
||||
|
||||
UtilEnt.silence(slime, true);
|
||||
UtilEnt.Vegetate(slime);
|
||||
|
||||
slime.setSize(-1);
|
||||
slime.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 99999999, 1, true, false));
|
||||
|
||||
_armorStand.setPassenger(slime);
|
||||
|
||||
_fillers.add(slime);
|
||||
|
||||
slime = getArmorStandLocation().getWorld().spawn(getArmorStandLocation(), Slime.class);
|
||||
|
||||
UtilEnt.silence(slime, true);
|
||||
UtilEnt.Vegetate(slime);
|
||||
|
||||
slime.setSize(-1);
|
||||
slime.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 99999999, 1, true, false));
|
||||
|
||||
UtilMath.getLast(_fillers).setPassenger(slime);
|
||||
|
||||
_fillers.add(slime);
|
||||
}
|
||||
|
||||
if (_filler2 == null)
|
||||
{
|
||||
_filler2 = _location.getWorld().spawn(getArmorStandLocation(), Slime.class);
|
||||
}
|
||||
|
||||
_filler.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 99999999, 1, true, false));
|
||||
_filler.setSize(-1);
|
||||
_armorStand.setPassenger(_filler);
|
||||
UtilEnt.Vegetate(_filler);
|
||||
UtilEnt.silence(_filler, true);
|
||||
|
||||
_filler2.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 99999999, 1, true, false));
|
||||
_filler2.setSize(-1);
|
||||
_filler.setPassenger(_filler2);
|
||||
UtilEnt.Vegetate(_filler2);
|
||||
UtilEnt.silence(_filler2, true);
|
||||
|
||||
UtilEnt.setFakeHead(_armorStand, true);
|
||||
_armorStand.teleport(getArmorStandLocation());
|
||||
_armorStand.setVisible(false);
|
||||
@ -116,12 +127,12 @@ public class Cannon implements Listener
|
||||
@EventHandler
|
||||
public void onInteract(PlayerInteractAtEntityEvent event)
|
||||
{
|
||||
if (event.getRightClicked().equals(_filler) || event.getRightClicked().equals(_filler2))
|
||||
if (_fillers.contains(event.getRightClicked()))
|
||||
{
|
||||
Entity passenger = _filler2.getPassenger();
|
||||
Entity passenger = UtilMath.getLast(_fillers);
|
||||
if (passenger == null)
|
||||
{
|
||||
_filler2.setPassenger(event.getPlayer());
|
||||
UtilMath.getLast(_fillers).setPassenger(event.getPlayer());
|
||||
|
||||
_rider = event.getPlayer();
|
||||
}
|
||||
@ -133,12 +144,12 @@ public class Cannon implements Listener
|
||||
@EventHandler
|
||||
public void onInteract(PlayerInteractEntityEvent event)
|
||||
{
|
||||
if (event.getRightClicked().equals(_filler) || event.getRightClicked().equals(_filler2))
|
||||
if (_fillers.contains(event.getRightClicked()))
|
||||
{
|
||||
Entity passenger = _filler2.getPassenger();
|
||||
Entity passenger = UtilMath.getLast(_fillers).getPassenger();
|
||||
if (passenger == null)
|
||||
{
|
||||
_filler2.setPassenger(event.getPlayer());
|
||||
UtilMath.getLast(_fillers).setPassenger(event.getPlayer());
|
||||
|
||||
_rider = event.getPlayer();
|
||||
}
|
||||
@ -150,12 +161,12 @@ public class Cannon implements Listener
|
||||
@EventHandler
|
||||
public void onInteract(PlayerArmorStandManipulateEvent event)
|
||||
{
|
||||
if (event.getRightClicked().equals(_armorStand))
|
||||
if (_fillers.contains(event.getRightClicked()))
|
||||
{
|
||||
Entity passenger = _filler2.getPassenger();
|
||||
Entity passenger = UtilMath.getLast(_fillers).getPassenger();
|
||||
if (passenger == null)
|
||||
{
|
||||
_filler2.setPassenger(event.getPlayer());
|
||||
UtilMath.getLast(_fillers).setPassenger(event.getPlayer());
|
||||
|
||||
_rider = event.getPlayer();
|
||||
}
|
||||
@ -172,7 +183,7 @@ public class Cannon implements Listener
|
||||
return;
|
||||
}
|
||||
|
||||
if (_rider != null && !_rider.equals(_filler2.getPassenger()))
|
||||
if (_rider != null && !_rider.equals(UtilMath.getLast(_fillers).getPassenger()))
|
||||
{
|
||||
_rider = null;
|
||||
}
|
||||
@ -192,7 +203,7 @@ public class Cannon implements Listener
|
||||
@EventHandler
|
||||
public void onDamage(EntityDamageEvent event)
|
||||
{
|
||||
if (_armorStand != null && _armorStand.equals(event.getEntity()) || _filler != null && _filler.equals(event.getEntity()) || _filler2 != null && _filler2.equals(event.getEntity()))
|
||||
if (_armorStand != null && _armorStand.equals(event.getEntity()) || _fillers.contains(event.getEntity()))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
@ -5,13 +5,15 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import mineplex.core.command.CommandBase;
|
||||
import mineplex.core.common.Rank;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
import mineplex.game.clans.clans.siege.cannon.Cannon;
|
||||
|
||||
public class Meow extends CommandBase<OutpostManager>
|
||||
public class CommandSiegeSupplies extends CommandBase<OutpostManager>
|
||||
{
|
||||
public Meow(OutpostManager plugin)
|
||||
public CommandSiegeSupplies(OutpostManager plugin)
|
||||
{
|
||||
super(plugin, Rank.ALL, "meow");
|
||||
super(plugin, Rank.CMOD, "siegesupplies");
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -25,5 +27,7 @@ public class Meow extends CommandBase<OutpostManager>
|
||||
|
||||
caller.getInventory().addItem(outpost);
|
||||
caller.getInventory().addItem(cannons);
|
||||
|
||||
UtilPlayer.message(caller, F.main("Clans", "Received supplies for a siege."));
|
||||
}
|
||||
}
|
@ -237,16 +237,7 @@ public class Outpost implements Listener
|
||||
@EventHandler
|
||||
public void onBlockPlace(BlockPlaceEvent event)
|
||||
{
|
||||
if (event.getItemInHand().isSimilar(Cannon.CANNON_ITEM))
|
||||
{
|
||||
event.setCancelled(true);
|
||||
|
||||
if (_host.spawnCannon(event.getPlayer(), event.getBlock().getLocation()))
|
||||
{
|
||||
event.getPlayer().setItemInHand(UtilInv.decrement(event.getPlayer().getItemInHand()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (event.isCancelled()) return;
|
||||
|
||||
if (UtilAlg.inBoundingBox(event.getBlock().getLocation(), _startCorner.clone().subtract(.5, 0, .5), _endCorner))
|
||||
{
|
||||
@ -513,14 +504,6 @@ public class Outpost implements Listener
|
||||
// AREA IN WHICH CANNONS AND OTHER SIEGE WEAPONS CAN BE PLACED
|
||||
public boolean isInSiegeArea(Location location)
|
||||
{
|
||||
return UtilAlg.inBoundingBox(location, _siegeAreaStart.clone().subtract(.9, 0, .9), _siegeAreaEnd);
|
||||
}
|
||||
|
||||
public void spawnCannon(Player player, Location location)
|
||||
{
|
||||
Cannon cannon = new Cannon(location);
|
||||
|
||||
_host.getPlugin().getServer().getPluginManager().registerEvents(cannon, _host.getPlugin());
|
||||
_cannons.add(cannon);
|
||||
return UtilAlg.inBoundingBox(location, _siegeAreaStart.clone().subtract(.9, 0, .9), _siegeAreaEnd.clone().add(.9, 0, .9));
|
||||
}
|
||||
}
|
||||
|
@ -48,32 +48,7 @@ public class OutpostManager extends MiniPlugin
|
||||
|
||||
_removalQueue = new ArrayList<>();
|
||||
|
||||
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;
|
||||
addCommand(new CommandSiegeSupplies(this));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
|
Loading…
Reference in New Issue
Block a user