From 6c2b40d63aea26c6b8de6436a65829b736eda733 Mon Sep 17 00:00:00 2001 From: Shaun Bennett Date: Sun, 13 Dec 2015 15:40:32 -0500 Subject: [PATCH] Cannon work --- Plugins/.idea/compiler.xml | 2 +- .../game/clans/clans/ClansManager.java | 2 + .../game/clans/clans/siege/SiegeManager.java | 25 ++++++ .../game/clans/clans/siege/cannon/Cannon.java | 90 +++++++++++++++++++ .../clans/clans/siege/cannon/CannonState.java | 28 ++++++ 5 files changed, 146 insertions(+), 1 deletion(-) create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/Cannon.java create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CannonState.java diff --git a/Plugins/.idea/compiler.xml b/Plugins/.idea/compiler.xml index df8666836..ec08cea77 100644 --- a/Plugins/.idea/compiler.xml +++ b/Plugins/.idea/compiler.xml @@ -23,7 +23,7 @@ - + diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java index d97ad7c78..2f16b18e5 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java @@ -86,6 +86,7 @@ import mineplex.game.clans.clans.redis.ClanDeleteCommandHandler; import mineplex.game.clans.clans.redis.ClanLoadCommandHandler; import mineplex.game.clans.clans.regions.ClansRegions; import mineplex.game.clans.clans.scoreboard.ClansScoreboardManager; +import mineplex.game.clans.clans.siege.SiegeManager; import mineplex.game.clans.clans.stuck.StuckManager; import mineplex.game.clans.clans.supplyDrop.SupplyDropManager; import mineplex.game.clans.clans.tntGenerator.TntGeneratorManager; @@ -246,6 +247,7 @@ public class ClansManager extends MiniClientPluginimplements IRelati _itemMapManager = new ItemMapManager(this, _worldEvent); new TntGeneratorManager(plugin, this); new SupplyDropManager(plugin, this); + new SiegeManager(plugin); _explosion = new Explosion(plugin, blockRestore); 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 new file mode 100644 index 000000000..81b7df231 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/SiegeManager.java @@ -0,0 +1,25 @@ +package mineplex.game.clans.clans.siege; + +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; +import org.bukkit.plugin.java.JavaPlugin; + +import mineplex.core.MiniPlugin; +import mineplex.game.clans.clans.siege.cannon.Cannon; + +public class SiegeManager extends MiniPlugin +{ + public SiegeManager(JavaPlugin plugin) + { + super("Siege", plugin); + } + + @EventHandler + public void debug(PlayerCommandPreprocessEvent event) + { + if (event.getMessage().contains("cannon")) + { + Cannon.spawnCannon(getPlugin(), event.getPlayer().getLocation()); + } + } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/Cannon.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/Cannon.java new file mode 100644 index 000000000..809297362 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/Cannon.java @@ -0,0 +1,90 @@ +package mineplex.game.clans.clans.siege.cannon; + +import org.bukkit.Location; +import org.bukkit.entity.ArmorStand; +import org.bukkit.entity.Entity; +import org.bukkit.event.EventHandler; +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; + +public class Cannon implements Listener +{ + private Location _location; + private CannonState _state; + + // Entity Information + private ArmorStand _armorStand; + + private Cannon(Location location) + { + _location = location; + _state = CannonState.EMPTY; + + updateEntities(); + } + + private void updateEntities() + { + if (_armorStand == null) + { + _armorStand = _location.getWorld().spawn(getArmorStandLocation(), ArmorStand.class); + } + + _armorStand.teleport(getArmorStandLocation()); + _armorStand.setVisible(false); + _armorStand.setGravity(false); + _armorStand.setHelmet(new ItemStack(_state.getMaterial(), 1, (short) 0, _state.getData())); + } + + private Location getArmorStandLocation() + { + return _location.clone().add(0, -0.5, 0); + } + + private void setState(CannonState state) + { + _state = state; + updateEntities(); + } + + /* + * Events + */ + + @EventHandler + public void onInteract(PlayerArmorStandManipulateEvent event) + { + if (_armorStand != null && _armorStand.equals(event.getRightClicked())) + { + Entity passenger = _armorStand.getPassenger(); + if (passenger == null) + { + _armorStand.setPassenger(event.getPlayer()); + } + + event.setCancelled(true); + } + } + + @EventHandler + public void onDamage(EntityDamageEvent event) + { + if (_armorStand != null && _armorStand.equals(event.getEntity())) + { + event.setCancelled(true); + } + } + + public static Cannon spawnCannon(JavaPlugin plugin, Location location) + { + System.out.println("Spawning Cannon at location " + location); + + Cannon cannon = new Cannon(location); + plugin.getServer().getPluginManager().registerEvents(cannon, plugin); + return cannon; + } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CannonState.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CannonState.java new file mode 100644 index 000000000..5f0ffd27e --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/siege/cannon/CannonState.java @@ -0,0 +1,28 @@ +package mineplex.game.clans.clans.siege.cannon; + +import org.bukkit.Material; + +public enum CannonState +{ + EMPTY(Material.SPONGE, (byte) 0), + LOADED(Material.SPONGE, (byte) 1); + + private Material _material; + private byte _data; + + CannonState(Material material, byte data) + { + _material = material; + _data = data; + } + + public byte getData() + { + return _data; + } + + public Material getMaterial() + { + return _material; + } +}