diff --git a/bin/CrunchProjectiles/CrunchProjectile.class b/bin/CrunchProjectiles/CrunchProjectile.class index 4eefbe6..e4d4f45 100644 Binary files a/bin/CrunchProjectiles/CrunchProjectile.class and b/bin/CrunchProjectiles/CrunchProjectile.class differ diff --git a/bin/CrunchProjectiles/EntityProjectile.class b/bin/CrunchProjectiles/EntityProjectile.class index cbd1a9b..5d12652 100644 Binary files a/bin/CrunchProjectiles/EntityProjectile.class and b/bin/CrunchProjectiles/EntityProjectile.class differ diff --git a/bin/CrunchProjectiles/ExplosiveProjectile.class b/bin/CrunchProjectiles/ExplosiveProjectile.class index 51d2389..6dbfc4f 100644 Binary files a/bin/CrunchProjectiles/ExplosiveProjectile.class and b/bin/CrunchProjectiles/ExplosiveProjectile.class differ diff --git a/bin/CrunchProjectiles/PotionProjectile.class b/bin/CrunchProjectiles/PotionProjectile.class index f2d031c..b457201 100644 Binary files a/bin/CrunchProjectiles/PotionProjectile.class and b/bin/CrunchProjectiles/PotionProjectile.class differ diff --git a/bin/siegeCore/ClickHandler.class b/bin/siegeCore/ClickHandler.class index 110fbc8..bfb49a5 100644 Binary files a/bin/siegeCore/ClickHandler.class and b/bin/siegeCore/ClickHandler.class differ diff --git a/bin/siegeCore/CrunchSiegeCore$SiegeCommand.class b/bin/siegeCore/CrunchSiegeCore$SiegeCommand.class index e67d907..f105348 100644 Binary files a/bin/siegeCore/CrunchSiegeCore$SiegeCommand.class and b/bin/siegeCore/CrunchSiegeCore$SiegeCommand.class differ diff --git a/bin/siegeCore/CrunchSiegeCore.class b/bin/siegeCore/CrunchSiegeCore.class index e55f144..1331f0a 100644 Binary files a/bin/siegeCore/CrunchSiegeCore.class and b/bin/siegeCore/CrunchSiegeCore.class differ diff --git a/bin/siegeCore/RotationHandler.class b/bin/siegeCore/RotationHandler.class index f9a1952..ada42f5 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 3161d46..de43743 100644 Binary files a/bin/siegeCore/SiegeEquipment.class and b/bin/siegeCore/SiegeEquipment.class differ diff --git a/src/CrunchProjectiles/CrunchProjectile.java b/src/CrunchProjectiles/CrunchProjectile.java index 937bbfc..62f5b02 100644 --- a/src/CrunchProjectiles/CrunchProjectile.java +++ b/src/CrunchProjectiles/CrunchProjectile.java @@ -9,7 +9,7 @@ import org.bukkit.plugin.java.JavaPlugin; public interface CrunchProjectile { - public void Shoot(Player player, Entity entity, double XOffset, double YOffset, Float velocity); + public void Shoot(Player player, Entity entity, Location fireLocation, Float velocity); public String ProjectileType = "Default"; } diff --git a/src/CrunchProjectiles/EntityProjectile.java b/src/CrunchProjectiles/EntityProjectile.java index 9c22388..446fcc4 100644 --- a/src/CrunchProjectiles/EntityProjectile.java +++ b/src/CrunchProjectiles/EntityProjectile.java @@ -27,30 +27,28 @@ public class EntityProjectile implements CrunchProjectile{ public Particle ParticleType = Particle.EXPLOSION_LARGE; public Sound SoundType = Sound.ENTITY_GENERIC_EXPLODE; @Override - public void Shoot(Player player, Entity entity, double XOffset, double YOffset, Float velocity) { + public void Shoot(Player player, Entity entity, Location FireLocation, Float velocity) { int baseDelay = 0; for (int i = 0; i < EntityCount; i++) { if (DelayedFire) { baseDelay += DelayTime; Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(CrunchSiegeCore.plugin, () -> { - CreateEntity(entity, XOffset, YOffset, velocity); + CreateEntity(entity, FireLocation, velocity); }, (long) baseDelay); } else { - CreateEntity(entity, XOffset, YOffset, velocity); + CreateEntity(entity, FireLocation, velocity); } // } } } - private void CreateEntity(Entity entity, double XOffset, double YOffset, Float velocity) { + private void CreateEntity(Entity entity, Location loc, Float velocity) { World world = entity.getLocation().getWorld(); LivingEntity living = (LivingEntity) entity; - Location loc = living.getEyeLocation(); - Vector direction = entity.getLocation().getDirection().multiply(XOffset); - loc.add(direction); + Entity arrow = world.spawnEntity(loc, EntityTyp); if (Inaccuracy != 0f) { diff --git a/src/CrunchProjectiles/ExplosiveProjectile.java b/src/CrunchProjectiles/ExplosiveProjectile.java index 236df24..c5c0352 100644 --- a/src/CrunchProjectiles/ExplosiveProjectile.java +++ b/src/CrunchProjectiles/ExplosiveProjectile.java @@ -27,29 +27,26 @@ public class ExplosiveProjectile implements CrunchProjectile { public Particle ParticleType = Particle.EXPLOSION_LARGE; public Sound SoundType = Sound.ENTITY_GENERIC_EXPLODE; @Override - public void Shoot(Player player, Entity entity, double XOffset, double YOffset, Float velocity) { + public void Shoot(Player player, Entity entity, Location loc, Float velocity) { int baseDelay = 0; for (int i = 0; i < ProjectilesCount; i++) { if (DelayedFire) { baseDelay += DelayTime; Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(CrunchSiegeCore.plugin, () -> { - CreateEntity(entity, XOffset, YOffset, velocity); + CreateEntity(entity, loc, velocity); }, (long) baseDelay); } else { - CreateEntity(entity, XOffset, YOffset, velocity); + CreateEntity(entity,loc, velocity); } // } } } - private void CreateEntity(Entity entity, double XOffset, double YOffset, Float velocity) { + private void CreateEntity(Entity entity, Location loc, Float velocity) { LivingEntity living = (LivingEntity) entity; - Location loc = living.getEyeLocation(); - Vector direction = entity.getLocation().getDirection().multiply(XOffset); - loc.add(direction); World world = entity.getLocation().getWorld(); Entity tnt = world.spawnEntity(loc, EntityType.SNOWBALL); ClickHandler.projectiles.put(tnt.getUniqueId(), this); diff --git a/src/CrunchProjectiles/PotionProjectile.java b/src/CrunchProjectiles/PotionProjectile.java index 0c6f9aa..da8c332 100644 --- a/src/CrunchProjectiles/PotionProjectile.java +++ b/src/CrunchProjectiles/PotionProjectile.java @@ -32,7 +32,7 @@ public class PotionProjectile implements CrunchProjectile { public Sound SoundType = Sound.ENTITY_GENERIC_EXPLODE; @Override - public void Shoot(Player player, Entity entity, double XOffset, double YOffset, Float velocity) { + public void Shoot(Player player, Entity entity, Location loc, Float velocity) { // TODO Auto-generated method stub int baseDelay = 0; for (int i = 0; i < EntityCount; i++) { @@ -40,23 +40,20 @@ public class PotionProjectile implements CrunchProjectile { baseDelay += DelayTime; Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(CrunchSiegeCore.plugin, () -> { - CreateEntity(entity, XOffset, YOffset, velocity); + CreateEntity(entity,loc, velocity); }, (long) baseDelay); } else { - CreateEntity(entity, XOffset, YOffset, velocity); + CreateEntity(entity, loc, velocity); } // } } } - private void CreateEntity(Entity entity, double XOffset, double YOffset, Float velocity) { + private void CreateEntity(Entity entity, Location loc, Float velocity) { World world = entity.getLocation().getWorld(); LivingEntity living = (LivingEntity) entity; - Location loc = living.getEyeLocation(); - Vector direction = entity.getLocation().getDirection().multiply(XOffset); - loc.add(direction); Entity arrow = world.spawnEntity(loc, EntityType.SPLASH_POTION); if (Inaccuracy != 0f) { diff --git a/src/siegeCore/ClickHandler.java b/src/siegeCore/ClickHandler.java index 446287e..4bb7c26 100644 --- a/src/siegeCore/ClickHandler.java +++ b/src/siegeCore/ClickHandler.java @@ -133,14 +133,14 @@ public class ClickHandler implements Listener { return; } -// if (ItemInHand.getType() == Material.PAPER) { -// ItemMeta meta = ItemInHand.getItemMeta(); -// if (meta.hasCustomModelData() && meta.getCustomModelData() == 505050505) { -// CrunchSiegeCore.CreateTrebuchet(player); -// ItemInHand.setAmount(ItemInHand.getAmount() - 1); -// return; -// } -// } + // if (ItemInHand.getType() == Material.PAPER) { + // ItemMeta meta = ItemInHand.getItemMeta(); + // if (meta.hasCustomModelData() && meta.getCustomModelData() == 505050505) { + // CrunchSiegeCore.CreateTrebuchet(player); + // ItemInHand.setAmount(ItemInHand.getAmount() - 1); + // return; + // } + // } if (event.getAction() == Action.LEFT_CLICK_AIR) { @@ -183,9 +183,8 @@ public class ClickHandler implements Listener { } 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()); if (equip == null || !equip.Enabled) { @@ -201,7 +200,10 @@ public class ClickHandler implements Listener { equip.Entity = entity; equip.EntityId = entity.getUniqueId(); } - + stand.addEquipmentLock(EquipmentSlot.HEAD, LockType.REMOVING_OR_CHANGING); + stand.addEquipmentLock(EquipmentSlot.LEGS, LockType.ADDING_OR_CHANGING); + stand.addEquipmentLock(EquipmentSlot.CHEST, LockType.ADDING_OR_CHANGING); + stand.addEquipmentLock(EquipmentSlot.FEET, LockType.ADDING_OR_CHANGING); if (CrunchSiegeCore.TrackedStands.containsKey(player.getUniqueId())) { List entities = CrunchSiegeCore.TrackedStands.get(player.getUniqueId()); entities.add(entity); @@ -246,10 +248,21 @@ public class ClickHandler implements Listener { return; } loc.setPitch((float) (loc.getPitch() - amount)); - stand.setHeadPose(new EulerAngle(loc.getDirection().getY()*(-1),0,0)); + SiegeEquipment equipment = CrunchSiegeCore.equipment.get(ent.getUniqueId()); + if (equipment != null) { + + equipment.ShowFireLocation(player); + if (equipment.RotateStandHead) { + stand.setHeadPose(new EulerAngle(loc.getDirection().getY()*(-1),0,0)); + } + + } + ent.teleport(loc); + + } } @@ -265,9 +278,17 @@ public class ClickHandler implements Listener { if (loc.getPitch() == 85 || loc.getPitch() + amount > 85) { return; } + SiegeEquipment equipment = CrunchSiegeCore.equipment.get(ent.getUniqueId()); + if (equipment != null) { + equipment.ShowFireLocation(player); + if (equipment.RotateStandHead) { + stand.setHeadPose(new EulerAngle(loc.getDirection().getY()*(-1),0,0)); + + } + } loc.setPitch((float) (loc.getPitch() + amount)); - stand.setHeadPose(new EulerAngle(loc.getDirection().getY()*(-1),0,0)); + ent.teleport(loc); } } diff --git a/src/siegeCore/CrunchSiegeCore.java b/src/siegeCore/CrunchSiegeCore.java index d747f0b..a58f379 100644 --- a/src/siegeCore/CrunchSiegeCore.java +++ b/src/siegeCore/CrunchSiegeCore.java @@ -61,6 +61,28 @@ public class CrunchSiegeCore extends JavaPlugin { public static Random random = new Random(); private static String Path; + + @SuppressWarnings("deprecation") + @Override + public void onDisable() { + for (SiegeEquipment equip : equipment.values()) { + if (equip.Entity != null) { + ItemStack item = new ItemStack(Material.CARVED_PUMPKIN); + ItemMeta meta = item.getItemMeta(); + equip.AmmoHolder = new EquipmentMagazine(); + + meta.setCustomModelData(equip.ReadyModelNumber); + meta.setDisplayName("§e" + equip.EquipmentName +" spawn item"); + List Lore = new ArrayList(); + Lore.add("§ePlace as a block to spawn a " + equip.EquipmentName + " or put on an armour stand."); + meta.setLore(Lore); + item.setItemMeta(meta); + + ((LivingEntity) equip.Entity).getEquipment().setHelmet(item); + } + } + } + @SuppressWarnings("deprecation") @Override public void onEnable() { @@ -206,15 +228,15 @@ public class CrunchSiegeCore extends JavaPlugin { fireProj.SoundType = Sound.ENTITY_BLAZE_SHOOT; equip.Projectiles.put(Material.DIAMOND, fireProj); - EntityProjectile pig = new EntityProjectile(); - pig.EntityCount = 100; - pig.DelayedFire = true; - pig.DelayTime = 3; - pig.EntityTyp = EntityType.ARROW; - pig.SoundType = Sound.ITEM_CROSSBOW_SHOOT; - pig.ParticleType = Particle.GLOW; - equip.Projectiles.put(Material.PORKCHOP, pig); - equip.Projectiles.put(Material.BONE, new PotionProjectile()); +// EntityProjectile pig = new EntityProjectile(); +// pig.EntityCount = 100; +// pig.DelayedFire = true; +// pig.DelayTime = 3; +// pig.EntityTyp = EntityType.ARROW; +// pig.SoundType = Sound.ITEM_CROSSBOW_SHOOT; +// pig.ParticleType = Particle.GLOW; +// equip.Projectiles.put(Material.PORKCHOP, pig); + // equip.Projectiles.put(Material.BONE, new PotionProjectile()); ItemStack item = new ItemStack(Material.CARVED_PUMPKIN); equip.ReadyModelNumber = 122; equip.ModelNumberToFireAt = 135; @@ -227,18 +249,7 @@ public class CrunchSiegeCore extends JavaPlugin { DefinedEquipment.put(equip.ReadyModelNumber, equip); } - public static Location getCenter(Location loc) { - return new Location(loc.getWorld(), - getRelativeCoord(loc.getBlockX()), - getRelativeCoord(loc.getBlockY()), - getRelativeCoord(loc.getBlockZ())); - } - - private static double getRelativeCoord(int i) { - double d = i; - d = d < 0 ? d - .5 : d + .5; - return d; - } + public static Boolean CreateTrebuchet(Player player, int CustomModelData, Location l) { //l.setY(l.getY() - 1); l.add(0.5, 0, 0.5); @@ -253,10 +264,14 @@ public class CrunchSiegeCore extends JavaPlugin { ItemMeta meta = item.getItemMeta(); equip.AmmoHolder = new EquipmentMagazine(); - - meta.setCustomModelData(CustomModelData); + meta.setCustomModelData(equip.ReadyModelNumber); + meta.setDisplayName("§e" + equip.EquipmentName +" spawn item"); + List Lore = new ArrayList(); + Lore.add("§ePlace as a block to spawn a " + equip.EquipmentName + " or put on an armour stand."); + meta.setLore(Lore); item.setItemMeta(meta); + LivingEntity ent = (LivingEntity) entity2; ArmorStand stand = (ArmorStand) ent; equip.Entity = entity2; diff --git a/src/siegeCore/RotationHandler.java b/src/siegeCore/RotationHandler.java index ec42f77..c8ba06e 100644 --- a/src/siegeCore/RotationHandler.java +++ b/src/siegeCore/RotationHandler.java @@ -1,7 +1,11 @@ package siegeCore; +import java.awt.Color; + import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.Particle; +import org.bukkit.block.Block; import org.bukkit.entity.ArmorStand; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; @@ -10,6 +14,7 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.inventory.ItemStack; +import org.bukkit.util.BlockIterator; import org.bukkit.util.EulerAngle; import org.bukkit.util.Vector; @@ -59,16 +64,24 @@ public class RotationHandler implements Listener { if (loc.getPitch() > 85) { loc.setPitch(85); } + if (equipment.RotateStandHead) { stand.setHeadPose(new EulerAngle(loc.getDirection().getY()*(-1),0,0)); - + } } living.teleport(loc); + equipment.ShowFireLocation(player); } } } } } } + + Vector getDirectionBetweenLocations(Location Start, Location End) { + Vector from = Start.toVector(); + Vector to = End.toVector(); + return to.subtract(from); + } } diff --git a/src/siegeCore/SiegeEquipment.java b/src/siegeCore/SiegeEquipment.java index b9691ed..e833c3d 100644 --- a/src/siegeCore/SiegeEquipment.java +++ b/src/siegeCore/SiegeEquipment.java @@ -35,7 +35,7 @@ public class SiegeEquipment implements Cloneable { public Boolean Enabled = false; public UUID EntityId; public Entity Entity; - + public Boolean RotateStandHead = true; public HashMap Projectiles = new HashMap() ; public String WorldName; @@ -103,6 +103,38 @@ public class SiegeEquipment implements Cloneable { } + public Location GetFireLocation(LivingEntity living) { + Location loc = living.getEyeLocation(); + Vector direction = living.getLocation().getDirection().multiply(XOffset); + loc.add(direction); + if (this.YOffset > 0) { + loc.setY(loc.getY() + this.YOffset); + } + else { + loc.setY(loc.getY() - this.YOffset); + } + + return loc; + } + + public void ShowFireLocation(Player player) { + LivingEntity living = (LivingEntity) this.Entity; + if (living != null) { + Location origin = this.GetFireLocation(living); + Vector direction = origin.getDirection(); + direction.multiply(5 /* the range */); + Location destination = origin.clone().add(direction); + + direction.normalize(); + for (int i = 0; i < 3 /* range */; i+= 1) { + Location spawn = origin.add(direction); + + player.spawnParticle(Particle.CLOUD, spawn, 1, 0,0,0,0); + } + } + + } + public void Fire(Player player, float delay) { if (System.currentTimeMillis() < this.NextShotTime) { player.sendMessage("Cannot fire for another " + CrunchSiegeCore.convertTime(this.NextShotTime - System.currentTimeMillis())); @@ -129,10 +161,12 @@ public class SiegeEquipment implements Cloneable { this.TaskNumber = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(CrunchSiegeCore.plugin, () -> { - Location loc = living.getEyeLocation(); - Vector direction = Entity.getLocation().getDirection().multiply(XOffset); + Random random = new Random(); float randomVar = random.nextFloat() * (6 - -6) + -6; + Location loc = living.getEyeLocation(); + Vector direction = Entity.getLocation().getDirection().multiply(XOffset); + loc.add(direction.multiply(randomVar)); loc.setYaw(loc.getYaw() + randomVar); @@ -177,7 +211,7 @@ public class SiegeEquipment implements Cloneable { // player.sendMessage("" + modelData); CrunchSiegeCore.UpdateEntityIdModel(this.Entity, modelData, this.WorldName); if (modelData == this.ModelNumberToFireAt) { - Projectiles.get(LoadedProjectile).Shoot(player, this.Entity, XOffset, YOffset, loadedFuel * this.VelocityPerFuel); + Projectiles.get(LoadedProjectile).Shoot(player, this.Entity, this.GetFireLocation(living), loadedFuel * this.VelocityPerFuel); } this.NextModelNumber += 1; @@ -200,7 +234,7 @@ public class SiegeEquipment implements Cloneable { this.NextModelNumber = 0; - Projectiles.get(LoadedProjectile).Shoot(player, this.Entity, XOffset, YOffset, loadedFuel * this.VelocityPerFuel); + Projectiles.get(LoadedProjectile).Shoot(player, this.Entity, this.GetFireLocation(living), loadedFuel * this.VelocityPerFuel); }, (long) delay); }