diff --git a/bin/siegeCore/ClickHandler.class b/bin/siegeCore/ClickHandler.class index b01a4b7..6a06e31 100644 Binary files a/bin/siegeCore/ClickHandler.class and b/bin/siegeCore/ClickHandler.class differ diff --git a/bin/siegeCore/CrunchSiegeCore.class b/bin/siegeCore/CrunchSiegeCore.class index 6bc3d77..17b3843 100644 Binary files a/bin/siegeCore/CrunchSiegeCore.class and b/bin/siegeCore/CrunchSiegeCore.class differ diff --git a/bin/siegeCore/EquipmentMagazine.class b/bin/siegeCore/EquipmentMagazine.class index a7f6995..4af5684 100644 Binary files a/bin/siegeCore/EquipmentMagazine.class and b/bin/siegeCore/EquipmentMagazine.class differ diff --git a/bin/siegeCore/RotationHandler.class b/bin/siegeCore/RotationHandler.class index d022463..f9a1952 100644 Binary files a/bin/siegeCore/RotationHandler.class and b/bin/siegeCore/RotationHandler.class differ diff --git a/bin/siegeCore/SiegeEquipment.class b/bin/siegeCore/SiegeEquipment.class index 769286a..293848e 100644 Binary files a/bin/siegeCore/SiegeEquipment.class and b/bin/siegeCore/SiegeEquipment.class differ diff --git a/bin/siegeCore/SiegeProjectile.class b/bin/siegeCore/SiegeProjectile.class index cb43573..2e3d631 100644 Binary files a/bin/siegeCore/SiegeProjectile.class and b/bin/siegeCore/SiegeProjectile.class differ diff --git a/src/siegeCore/ClickHandler.java b/src/siegeCore/ClickHandler.java index 728226d..2d3fc43 100644 --- a/src/siegeCore/ClickHandler.java +++ b/src/siegeCore/ClickHandler.java @@ -18,6 +18,7 @@ import org.bukkit.block.Block; import org.bukkit.block.Sign; import org.bukkit.block.TileState; import org.bukkit.entity.ArmorStand; +import org.bukkit.entity.ArmorStand.LockType; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.LivingEntity; @@ -33,6 +34,7 @@ import org.bukkit.event.entity.ProjectileHitEvent; import org.bukkit.event.player.PlayerInteractAtEntityEvent; import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.metadata.FixedMetadataValue; @@ -83,15 +85,6 @@ public class ClickHandler implements Listener { } SiegeEquipment siege = CrunchSiegeCore.equipment.get(ent.getUniqueId()); - - - if (player.getInventory().containsAtLeast(new ItemStack(Material.COBBLESTONE), 10)) { - player.getInventory().remove(new ItemStack(Material.COBBLESTONE, 10)); - } - else { - player.sendMessage("Cannot fire, missing cobblestone, requires 10 per shot"); - continue; - } if (siege.isLoaded()) { siege.Fire(player, actualDelay); actualDelay += delay; @@ -126,7 +119,7 @@ public class ClickHandler implements Listener { if (event.getAction() == Action.LEFT_CLICK_AIR) { - if (ItemInHand.getType() != Material.STICK) { + if (ItemInHand.getType() != Material.CLOCK) { return; } @@ -152,14 +145,30 @@ public class ClickHandler implements Listener { public static void TakeControl(Player player, Entity entity) { LivingEntity living = (LivingEntity) entity; + if (CrunchSiegeCore.TrackedStands.containsKey(player.getUniqueId())) { + List entities = CrunchSiegeCore.TrackedStands.get(player.getUniqueId()); + if (entities.contains(entity)) { + return; + } + } + if (living.getEquipment().getHelmet() != null && living.getEquipment().getHelmet().getType() == Material.CARVED_PUMPKIN) { if (living.getEquipment() == null || living.getEquipment().getHelmet() == null || living.getEquipment().getHelmet().getItemMeta() == null) { return; } - SiegeEquipment equip = CrunchSiegeCore.CreateClone(living.getEquipment().getHelmet().getItemMeta().getCustomModelData()); - equip.Entity = entity; - equip.EntityId = entity.getUniqueId(); + ArmorStand stand = (ArmorStand) entity; + stand.addEquipmentLock(EquipmentSlot.HEAD, LockType.REMOVING_OR_CHANGING); + SiegeEquipment equip; + if (CrunchSiegeCore.equipment.containsKey(entity.getUniqueId())) { + equip = CrunchSiegeCore.equipment.get(entity.getUniqueId()); + } + else { + equip = CrunchSiegeCore.CreateClone(living.getEquipment().getHelmet().getItemMeta().getCustomModelData()); + equip.AmmoHolder = new EquipmentMagazine(); + equip.Entity = entity; + equip.EntityId = entity.getUniqueId(); + } if (CrunchSiegeCore.TrackedStands.containsKey(player.getUniqueId())) { List entities = CrunchSiegeCore.TrackedStands.get(player.getUniqueId()); @@ -198,7 +207,7 @@ public class ClickHandler implements Listener { Location loc = ent.getLocation(); ArmorStand stand = (ArmorStand) ent; // player.sendMessage(String.format("" + loc.getPitch())); - if (loc.getPitch() == -90 || loc.getPitch() - amount < -90) { + if (loc.getPitch() == -85 || loc.getPitch() - amount < -85) { return; } loc.setPitch((float) (loc.getPitch() - amount)); @@ -215,7 +224,7 @@ public class ClickHandler implements Listener { Location loc = ent.getLocation(); ArmorStand stand = (ArmorStand) ent; // player.sendMessage(String.format("" + loc.getPitch())); - if (loc.getPitch() == 90 || loc.getPitch() + amount > 90) { + if (loc.getPitch() == 85 || loc.getPitch() + amount > 85) { return; } @@ -313,12 +322,7 @@ public class ClickHandler implements Listener { return; } if (entity.getType() == EntityType.ARMOR_STAND){ - if (itemInHand.getType() == Material.CLOCK) { - - TakeControl(player, entity); - return; - } - + TakeControl(player, entity); if (CrunchSiegeCore.equipment.containsKey(entity.getUniqueId())) { SiegeEquipment equipment = CrunchSiegeCore.equipment.get(entity.getUniqueId()); if (itemInHand.getType().equals(equipment.FuelMaterial)) { @@ -330,7 +334,20 @@ public class ClickHandler implements Listener { } } if (itemInHand.getType().equals(Material.FLINT)) { - Shoot(player, 6); + if (equipment.isLoaded()) { + equipment.Fire(player, 6); + } + else { + player.sendMessage("Cannon is not loaded"); + } + return; + } + + if (equipment.Projectiles.containsKey(itemInHand.getType()) && !equipment.isLoaded()){ + equipment.AmmoHolder.LoadedProjectile = 1; + equipment.AmmoHolder.MaterialName = (Material) itemInHand.getType(); + player.sendMessage("Adding projectile to cannon"); + itemInHand.setAmount(itemInHand.getAmount() - 1); } return; } diff --git a/src/siegeCore/CrunchSiegeCore.java b/src/siegeCore/CrunchSiegeCore.java index f382de0..727ccba 100644 --- a/src/siegeCore/CrunchSiegeCore.java +++ b/src/siegeCore/CrunchSiegeCore.java @@ -114,7 +114,8 @@ public class CrunchSiegeCore extends JavaPlugin { } public static void AddDefined() { - SiegeEquipment equip = new SiegeEquipment(null); + SiegeEquipment equip = new SiegeEquipment(); + equip.Projectiles.put(Material.COBBLESTONE, new SiegeProjectile(2, false)); ItemStack item = new ItemStack(Material.CARVED_PUMPKIN); equip.ReadyModelNumber = 122; equip.ModelNumberToFireAt = 135; @@ -132,7 +133,7 @@ public class CrunchSiegeCore extends JavaPlugin { Location l = player.getLocation(); l.setY(l.getY() - 1); Entity entity2 = player.getWorld().spawnEntity(l, EntityType.ARMOR_STAND); - SiegeEquipment equip = new SiegeEquipment(entity2.getUniqueId()); + SiegeEquipment equip = new SiegeEquipment(); ItemStack item = new ItemStack(Material.CARVED_PUMPKIN); equip.ReadyModelNumber = 122; equip.ModelNumberToFireAt = 135; @@ -143,6 +144,7 @@ public class CrunchSiegeCore extends JavaPlugin { )); equip.CycleThroughModelsBeforeFiring = false; equip.Entity = entity2; + equip.EntityId = entity2.getUniqueId(); entity2.setCustomName("Weapon"); ItemMeta meta = item.getItemMeta(); diff --git a/src/siegeCore/EquipmentMagazine.java b/src/siegeCore/EquipmentMagazine.java index 6250aab..5b4087a 100644 --- a/src/siegeCore/EquipmentMagazine.java +++ b/src/siegeCore/EquipmentMagazine.java @@ -1,7 +1,9 @@ package siegeCore; +import org.bukkit.Material; + public class EquipmentMagazine { public int LoadedFuel = 0; public int LoadedProjectile = 0; - public String MaterialName = "NONE"; + public Material MaterialName = Material.BEDROCK; } diff --git a/src/siegeCore/RotationHandler.java b/src/siegeCore/RotationHandler.java index d8fa6d3..ec42f77 100644 --- a/src/siegeCore/RotationHandler.java +++ b/src/siegeCore/RotationHandler.java @@ -21,7 +21,7 @@ public class RotationHandler implements Listener { if (CrunchSiegeCore.TrackedStands.containsKey(player.getUniqueId())) { ItemStack itemInHand = player.getInventory().getItemInMainHand(); if (itemInHand != null) { - if (itemInHand.getType() != Material.STICK) { + if (itemInHand.getType() != Material.CLOCK) { // TrackedStands.remove(player.getUniqueId()); return; @@ -52,8 +52,15 @@ public class RotationHandler implements Listener { ArmorStand stand = (ArmorStand) living; if (equipment.RotateUpDown) { - stand.setHeadPose(new EulerAngle(player.getLocation().getDirection().getY()*(-1),0,0)); loc.setPitch(player.getLocation().getPitch()); + if (loc.getPitch() < -85) { + loc.setPitch(-85); + } + if (loc.getPitch() > 85) { + loc.setPitch(85); + } + stand.setHeadPose(new EulerAngle(loc.getDirection().getY()*(-1),0,0)); + } diff --git a/src/siegeCore/SiegeEquipment.java b/src/siegeCore/SiegeEquipment.java index 74888aa..f9bc9ec 100644 --- a/src/siegeCore/SiegeEquipment.java +++ b/src/siegeCore/SiegeEquipment.java @@ -1,6 +1,7 @@ package siegeCore; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Random; import java.util.UUID; @@ -29,6 +30,8 @@ public class SiegeEquipment implements Cloneable { public ItemStack ItemToPlace; + public HashMap Projectiles = new HashMap() ; + public String ItemToUseForModel; public String WorldName; @@ -36,7 +39,7 @@ public class SiegeEquipment implements Cloneable { public int XOffset = 7; public int YOffset = 0; public int MaxFuel = 5; - public float VelocityPerFuel = 0.5f; + public float VelocityPerFuel = 0.75f; public Material FuelMaterial = Material.GUNPOWDER; public int FuseTime; public long NextShotTime = System.currentTimeMillis(); @@ -62,16 +65,10 @@ public class SiegeEquipment implements Cloneable { public List FiringModelNumbers = new ArrayList(); - public SiegeProjectile projectile = new SiegeProjectile(2, false); - public EquipmentMagazine AmmoHolder = new EquipmentMagazine(); - public SiegeEquipment(UUID id) { - EntityId = id; - } - public Boolean isLoaded() { - return (AmmoHolder.LoadedFuel > 0 && AmmoHolder.LoadedProjectile > 1); + return (AmmoHolder.LoadedFuel > 0 && AmmoHolder.LoadedProjectile >= 1); } public Boolean CanLoadFuel() { @@ -110,26 +107,35 @@ public class SiegeEquipment implements Cloneable { return; } float loadedFuel = this.AmmoHolder.LoadedFuel; - String LoadedProjectile = this.AmmoHolder.MaterialName; + Material LoadedProjectile = this.AmmoHolder.MaterialName; this.AmmoHolder.LoadedFuel = 0; this.AmmoHolder.LoadedProjectile = 0; - this.AmmoHolder.MaterialName = Material.BEDROCK.toString(); + this.AmmoHolder.MaterialName = Material.BEDROCK; + LivingEntity living = (LivingEntity) Entity; + if (living.getEquipment() == null || living.getEquipment().getHelmet() == null || living.getEquipment().getHelmet().getItemMeta() == null) { + return; + } + if (living.getEquipment().getHelmet().getItemMeta().getCustomModelData() != this.ReadyModelNumber) { + return; + } this.WorldName = Entity.getWorld().getName(); this.NextShotTime = System.currentTimeMillis() + 6000; if (this.CycleThroughModelsBeforeFiring) { this.TaskNumber = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(CrunchSiegeCore.plugin, () -> { - LivingEntity living = (LivingEntity) Entity; + Location loc = living.getEyeLocation(); Vector direction = Entity.getLocation().getDirection().multiply(XOffset); - loc.add(direction); Random random = new Random(); + float randomVar = random.nextFloat() * (6 - -6) + -6; + loc.add(direction.multiply(randomVar)); + loc.setYaw(loc.getYaw() + randomVar); - float randomVar = random.nextFloat() * (7 - -7) + -7; - + + this.NextModelNumber = 0; this.location = loc; @@ -172,7 +178,7 @@ public class SiegeEquipment implements Cloneable { if (modelData == this.ModelNumberToFireAt) { Entity tnt = Bukkit.getServer().getWorld(this.WorldName).spawnEntity(loc, EntityType.SNOWBALL); - ClickHandler.projectiles.put(tnt.getUniqueId(), this.projectile); + ClickHandler.projectiles.put(tnt.getUniqueId(), Projectiles.get(LoadedProjectile)); tnt.setVelocity(loc.getDirection().multiply(loadedFuel * this.VelocityPerFuel)); Bukkit.getServer().getWorld(this.WorldName).playSound(this.location, Sound.ENTITY_BAT_DEATH, 20, 2); } @@ -189,20 +195,19 @@ public class SiegeEquipment implements Cloneable { this.TaskNumber = Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(CrunchSiegeCore.plugin, () -> { //player.sendMessage("task"); - LivingEntity living = (LivingEntity) Entity; + Location loc = living.getEyeLocation(); Vector direction = Entity.getLocation().getDirection().multiply(XOffset); - loc.add(direction); Random random = new Random(); - - float randomVar = random.nextFloat() * (7 - -7) + -7; - + float randomVar = random.nextFloat() * (6 - -6) + -6; + loc.add(direction); + loc.setYaw(loc.getYaw() + randomVar); this.NextModelNumber = 0; this.location = loc; // player.sendMessage("Cannot fire for another " + CrunchSiegeCore.convertTime(this.NextShotTime - System.currentTimeMillis())); Entity tnt = Bukkit.getServer().getWorld(this.WorldName).spawnEntity(loc, EntityType.SNOWBALL); - ClickHandler.projectiles.put(tnt.getUniqueId(), this.projectile); + ClickHandler.projectiles.put(tnt.getUniqueId(), Projectiles.get(LoadedProjectile)); tnt.setVelocity(loc.getDirection().multiply(loadedFuel * this.VelocityPerFuel)); Bukkit.getServer().getWorld(this.WorldName).playSound(this.location, Sound.ENTITY_GENERIC_EXPLODE, 20, 2); Bukkit.getServer().getWorld(this.WorldName).spawnParticle(Particle.EXPLOSION_LARGE, loc.getX(), loc.getY(), loc.getZ(), 0); diff --git a/src/siegeCore/SiegeProjectile.java b/src/siegeCore/SiegeProjectile.java index 65a9b49..4d927c6 100644 --- a/src/siegeCore/SiegeProjectile.java +++ b/src/siegeCore/SiegeProjectile.java @@ -12,6 +12,4 @@ public class SiegeProjectile { Radius = rad; DoFire = fire; } - - public ItemStack AmmoItem = new ItemStack(Material.COBBLESTONE, 1); }