From 339fad98f35ea6d4146df4e88a5a3bc30b79cbb4 Mon Sep 17 00:00:00 2001 From: ShermansWorld <77093412+ShermansWorld@users.noreply.github.com> Date: Sun, 7 Jan 2024 12:43:57 -0500 Subject: [PATCH] projectiles refactor --- .../alathra/siegeengines/SiegeEngine.java | 21 ++--- .../alathra/siegeengines/SiegeEngines.java | 86 ++++++++----------- .../siegeengines/listeners/ClickHandler.java | 10 +-- .../projectile/EntityProjectile.java | 82 ++++++++++++------ .../projectile/ExplosiveProjectile.java | 85 ++++++++++++------ .../projectile/GunnersProjectile.java | 11 --- .../projectile/PotionProjectile.java | 14 ++- .../projectile/ProjectileType.java | 5 ++ .../projectile/SiegeEngineProjectile.java | 29 +++++++ 9 files changed, 210 insertions(+), 133 deletions(-) delete mode 100644 src/main/java/com/github/alathra/siegeengines/projectile/GunnersProjectile.java create mode 100644 src/main/java/com/github/alathra/siegeengines/projectile/ProjectileType.java create mode 100644 src/main/java/com/github/alathra/siegeengines/projectile/SiegeEngineProjectile.java diff --git a/src/main/java/com/github/alathra/siegeengines/SiegeEngine.java b/src/main/java/com/github/alathra/siegeengines/SiegeEngine.java index 5838ba5..b3dbe22 100644 --- a/src/main/java/com/github/alathra/siegeengines/SiegeEngine.java +++ b/src/main/java/com/github/alathra/siegeengines/SiegeEngine.java @@ -6,7 +6,7 @@ import java.util.HashMap; import java.util.UUID; import com.github.alathra.siegeengines.projectile.EntityProjectile; -import com.github.alathra.siegeengines.projectile.GunnersProjectile; +import com.github.alathra.siegeengines.projectile.SiegeEngineProjectile; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; @@ -70,7 +70,7 @@ public class SiegeEngine implements Cloneable { // Passed parameters public String name = "Unnammed Siege Engine"; public ItemStack fuelItem = new ItemStack(Material.GUNPOWDER); - public HashMap projectiles; + public HashMap projectiles; public int customModelID = 150; @@ -79,7 +79,7 @@ public class SiegeEngine implements Cloneable { return (SiegeEngine) super.clone(); } - public SiegeEngine(@NotNull String name, @NotNull HashMap projectiles, @NotNull ItemStack fuelItem, int customModelID) { + public SiegeEngine(@NotNull String name, @NotNull HashMap projectiles, @NotNull ItemStack fuelItem, int customModelID) { // Default custom model data id if it is passes as null if (customModelID == 0) { @@ -116,11 +116,12 @@ public class SiegeEngine implements Cloneable { baseStandOffset = 0; baseStandModelNumber = 147; nextShotTime = System.currentTimeMillis(); - EntityProjectile defaultProj = new EntityProjectile(); - defaultProj.EntityCount = 2; - defaultProj.EntityTyp = EntityType.SHULKER_BULLET; - defaultProj.ParticleType = Particle.WHITE_ASH; - defaultProj.SoundType = Sound.ENTITY_BLAZE_SHOOT; + // PLACEHOLDER. SHOULD BE WE-WRITTEN + EntityProjectile defaultProj = new EntityProjectile(new ItemStack(Material.GRASS_BLOCK)); + defaultProj.entityCount = 2; + defaultProj.entityType = EntityType.SHULKER_BULLET; + defaultProj.particleType = Particle.WHITE_ASH; + defaultProj.soundType = Sound.ENTITY_BLAZE_SHOOT; // set passed parameters as object variables this.name = name; @@ -316,7 +317,7 @@ public class SiegeEngine implements Cloneable { // player.sendMessage("§efiring" + modelData); if (LoadedProjectile == null) return; if (LoadedProjectile.getType() == Material.AIR) return; - GunnersProjectile projType = projectiles.get(LoadedProjectile); + SiegeEngineProjectile projType = projectiles.get(LoadedProjectile); if (projType == null) return; projType.Shoot(player, entity, this.GetFireLocation(living), loadedFuel * velocityPerFuel); } @@ -344,7 +345,7 @@ public class SiegeEngine implements Cloneable { nextModelNumber = 0; if (LoadedProjectile == null) return; if (LoadedProjectile.getType() == Material.AIR) return; - GunnersProjectile projType = projectiles.get(LoadedProjectile); + SiegeEngineProjectile projType = projectiles.get(LoadedProjectile); if (projType == null) return; projType.Shoot(player, entity, this.GetFireLocation(living), loadedFuel * velocityPerFuel); }, (long) delay); diff --git a/src/main/java/com/github/alathra/siegeengines/SiegeEngines.java b/src/main/java/com/github/alathra/siegeengines/SiegeEngines.java index 7d87e03..b8912cd 100644 --- a/src/main/java/com/github/alathra/siegeengines/SiegeEngines.java +++ b/src/main/java/com/github/alathra/siegeengines/SiegeEngines.java @@ -9,10 +9,7 @@ import java.util.UUID; import com.github.alathra.siegeengines.command.CommandHandler; import org.bukkit.Material; -import org.bukkit.Particle; -import org.bukkit.Sound; import org.bukkit.entity.Entity; -import org.bukkit.entity.EntityType; import org.bukkit.entity.LivingEntity; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; @@ -23,7 +20,7 @@ import com.github.alathra.siegeengines.listeners.ClickHandler; import com.github.alathra.siegeengines.listeners.RotationHandler; import com.github.alathra.siegeengines.projectile.EntityProjectile; import com.github.alathra.siegeengines.projectile.ExplosiveProjectile; -import com.github.alathra.siegeengines.projectile.GunnersProjectile; +import com.github.alathra.siegeengines.projectile.SiegeEngineProjectile; public class SiegeEngines extends JavaPlugin { @@ -94,22 +91,21 @@ public class SiegeEngines extends JavaPlugin { } public static void AddDefaults() { - - HashMap projectileMap = new HashMap<>(); - - EntityProjectile fireProj = new EntityProjectile(); - fireProj.EntityCount = 4; - fireProj.EntityTyp = EntityType.SMALL_FIREBALL; - fireProj.ParticleType = Particle.WHITE_ASH; - fireProj.SoundType = Sound.ENTITY_BLAZE_SHOOT; - fireProj.Inaccuracy = 0.75f; - projectileMap.put(new ItemStack(Material.FIRE_CHARGE), fireProj); - - ExplosiveProjectile proj = new ExplosiveProjectile(); - proj.ExplodePower = 1; - projectileMap.put(new ItemStack(Material.COBBLESTONE), proj); - - SiegeEngine trebuchet = new SiegeEngine("Trebuchet", projectileMap, new ItemStack(Material.GUNPOWDER), 122); + + // Predefined projectiles with default values + SiegeEngineProjectile fireballShot = EntityProjectile.getDefaultFireballShot(); + SiegeEngineProjectile stoneShot = ExplosiveProjectile.getDefaultStoneShot(); + SiegeEngineProjectile repeatingShot = ExplosiveProjectile.getDefaultRepeatingShot(); + SiegeEngineProjectile breachShot = ExplosiveProjectile.getDefaultBreachShot(); + SiegeEngineProjectile scatterShot = EntityProjectile.getDefaultScatterShot(); + + // Trebuchet + HashMap trebuchetProjectiles = new HashMap<>(); + trebuchetProjectiles.put(stoneShot.getAmmuinitionItem(), stoneShot); + trebuchetProjectiles.put(fireballShot.getAmmuinitionItem(), fireballShot); + trebuchetProjectiles.put(breachShot.getAmmuinitionItem(), breachShot); + + SiegeEngine trebuchet = new SiegeEngine("Trebuchet", trebuchetProjectiles, new ItemStack(Material.STRING), 122); trebuchet.xOffset = 3; trebuchet.yOffset = 3; trebuchet.placementOffsetY = 0.0; @@ -117,7 +113,6 @@ public class SiegeEngines extends JavaPlugin { trebuchet.shotAmount = 1; trebuchet.rotateStandHead = false; trebuchet.rotateSideways = true; - trebuchet.fuelItem = new ItemStack(Material.STRING); trebuchet.readyModelNumber = 122; trebuchet.modelNumberToFireAt = 135; trebuchet.millisecondsBetweenFiringStages = 2; @@ -126,37 +121,17 @@ public class SiegeEngines extends JavaPlugin { 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139 )); trebuchet.cycleThroughModelsBeforeFiring = true; - definedSiegeEngines.put(trebuchet.readyModelNumber, trebuchet); - - - ExplosiveProjectile tntProj = new ExplosiveProjectile(); - tntProj.ExplodePower = 1; - tntProj.ProjectilesCount = 5; - tntProj.DelayedFire = true; - tntProj.Inaccuracy = 0.75f; - projectileMap.put(new ItemStack(Material.TNT), tntProj); - - ExplosiveProjectile breachShot = new ExplosiveProjectile(); - breachShot.ExplodePower = 3; - breachShot.ProjectilesCount = 1; - projectileMap.put(new ItemStack(Material.IRON_BLOCK), breachShot); - - EntityProjectile scatterShot = new EntityProjectile(); - scatterShot.Inaccuracy = 0.5f; - scatterShot.EntityCount = 24; - scatterShot.ParticleType = Particle.ELECTRIC_SPARK; - scatterShot.SoundType = Sound.ITEM_CROSSBOW_SHOOT; - projectileMap.put(new ItemStack(Material.GRAVEL), scatterShot); - - ExplosiveProjectile repeatingShot = new ExplosiveProjectile(); - repeatingShot.ExplodePower = 2; - repeatingShot.ProjectilesCount = 3; - repeatingShot.DelayedFire = true; - repeatingShot.Inaccuracy = 0.35f; - projectileMap.put(new ItemStack(Material.TNT), repeatingShot); - SiegeEngine siegeCannon = new SiegeEngine("Siege Cannon", projectileMap, new ItemStack(Material.GUNPOWDER), 141); + // Siege Cannon + HashMap siegeCannonProjectiles = new HashMap<>(); + siegeCannonProjectiles.put(stoneShot.getAmmuinitionItem(), stoneShot); + siegeCannonProjectiles.put(fireballShot.getAmmuinitionItem(), fireballShot); + siegeCannonProjectiles.put(breachShot.getAmmuinitionItem(), breachShot); + siegeCannonProjectiles.put(repeatingShot.getAmmuinitionItem(), repeatingShot); + siegeCannonProjectiles.put(scatterShot.getAmmuinitionItem(), scatterShot); + + SiegeEngine siegeCannon = new SiegeEngine("Siege Cannon", siegeCannonProjectiles, new ItemStack(Material.GUNPOWDER), 141); siegeCannon.shotAmount = 1; siegeCannon.placementOffsetY = -1; siegeCannon.readyModelNumber = 141; @@ -166,8 +141,15 @@ public class SiegeEngines extends JavaPlugin { siegeCannon.rotateSideways = true; definedSiegeEngines.put(siegeCannon.readyModelNumber, siegeCannon); - SiegeEngine navalCannon = new SiegeEngine("Naval Cannon", projectileMap, new ItemStack(Material.GUNPOWDER), 142); - navalCannon.projectiles.put(new ItemStack(Material.COBBLESTONE), proj); + // Naval Cannon + HashMap navalCannonProjectiles = new HashMap<>(); + siegeCannonProjectiles.put(stoneShot.getAmmuinitionItem(), stoneShot); + siegeCannonProjectiles.put(fireballShot.getAmmuinitionItem(), fireballShot); + siegeCannonProjectiles.put(breachShot.getAmmuinitionItem(), breachShot); + siegeCannonProjectiles.put(repeatingShot.getAmmuinitionItem(), repeatingShot); + siegeCannonProjectiles.put(scatterShot.getAmmuinitionItem(), scatterShot); + + SiegeEngine navalCannon = new SiegeEngine("Naval Cannon", navalCannonProjectiles, new ItemStack(Material.GUNPOWDER), 142); navalCannon.placementOffsetY = -1; navalCannon.shotAmount = 1; navalCannon.readyModelNumber = 142; diff --git a/src/main/java/com/github/alathra/siegeengines/listeners/ClickHandler.java b/src/main/java/com/github/alathra/siegeengines/listeners/ClickHandler.java index 20ff585..bb0231b 100644 --- a/src/main/java/com/github/alathra/siegeengines/listeners/ClickHandler.java +++ b/src/main/java/com/github/alathra/siegeengines/listeners/ClickHandler.java @@ -84,20 +84,20 @@ public class ClickHandler implements Listener { projectiles.remove(event.getEntity().getUniqueId()); - if (proj.PlaceBlocks) { + if (proj.placeBlocks) { TNTPrimed tntEnt = (TNTPrimed) tnt; tntEnt.setYield(0); tntEnt.setFuseTicks(0); if (event.getHitBlock() != null) { - List Blocks = sphere(event.getHitBlock().getLocation(), (int) proj.ExplodePower); - for (int i = 0; i < proj.BlocksToPlaceAmount; i++) { + List Blocks = sphere(event.getHitBlock().getLocation(), (int) proj.explodePower); + for (int i = 0; i < proj.blocksToPlaceAmount; i++) { Block replace = getRandomElement(Blocks); - replace.setType(proj.BlockToPlace); + replace.setType(proj.blockToPlace); } } } else { TNTPrimed tntEnt = (TNTPrimed) tnt; - tntEnt.setYield(proj.ExplodePower); + tntEnt.setYield(proj.explodePower); tntEnt.setFuseTicks(0); } } diff --git a/src/main/java/com/github/alathra/siegeengines/projectile/EntityProjectile.java b/src/main/java/com/github/alathra/siegeengines/projectile/EntityProjectile.java index b86159c..fbc6da9 100644 --- a/src/main/java/com/github/alathra/siegeengines/projectile/EntityProjectile.java +++ b/src/main/java/com/github/alathra/siegeengines/projectile/EntityProjectile.java @@ -5,51 +5,77 @@ import com.github.alathra.siegeengines.SiegeEnginesUtil; import org.bukkit.Bukkit; import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.Particle; import org.bukkit.Sound; import org.bukkit.World; import org.bukkit.entity.Arrow; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; +import org.bukkit.inventory.ItemStack; import org.bukkit.util.Vector; -public class EntityProjectile implements GunnersProjectile { - - public String ProjectileType = "Entity"; - public int EntityCount = 20; - public int ArrowOnlyDamage = 6; - public Boolean DelayedFire = false; - public int DelayTime = 6; - public EntityType EntityTyp = EntityType.ARROW; - public float Inaccuracy = 0.2f; - public Particle ParticleType = Particle.EXPLOSION_LARGE; - public Sound SoundType = Sound.ENTITY_GENERIC_EXPLODE; +public class EntityProjectile extends SiegeEngineProjectile { + + // Defaults + public int entityCount = 20; + public int arrowOnlyDamage = 6; + public Boolean delayedFire = false; + public int delayTime = 6; + public EntityType entityType = EntityType.ARROW; + public float inaccuracy = 0.2f; + public Particle particleType = Particle.EXPLOSION_LARGE; + public Sound soundType = Sound.ENTITY_GENERIC_EXPLODE; + + private boolean playSound = true; + + public EntityProjectile(ItemStack ammunitionItem) { + super(ProjectileType.ENTITY, ammunitionItem); + + // Defaults + } + + public static EntityProjectile getDefaultFireballShot() { + EntityProjectile fireProj = new EntityProjectile(new ItemStack(Material.FIRE_CHARGE)); + fireProj.entityCount = 4; + fireProj.entityType = EntityType.SMALL_FIREBALL; + fireProj.particleType = Particle.WHITE_ASH; + fireProj.soundType = Sound.ENTITY_BLAZE_SHOOT; + fireProj.inaccuracy = 0.75f; + return fireProj; + } + + public static EntityProjectile getDefaultScatterShot() { + EntityProjectile scatterProj = new EntityProjectile(new ItemStack(Material.TNT)); + scatterProj.inaccuracy = 0.5f; + scatterProj.entityCount = 24; + scatterProj.particleType = Particle.ELECTRIC_SPARK; + scatterProj.soundType = Sound.ITEM_CROSSBOW_SHOOT; + return scatterProj; + } @Override public void Shoot(Entity player, Entity entity, Location FireLocation, Float velocity) { - PlaySound = true; + playSound = true; int baseDelay = 0; - for (int i = 0; i < EntityCount; i++) { - if (DelayedFire) { - baseDelay += DelayTime; + for (int i = 0; i < entityCount; i++) { + if (delayedFire) { + baseDelay += delayTime; Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(SiegeEngines.getInstance(), () -> { CreateEntity(entity, FireLocation, velocity, player); }, (long) baseDelay); } else { - CreateEntity(entity, FireLocation, velocity, player); } } } - private boolean PlaySound = true; - private void CreateEntity(Entity entity, Location loc, Float velocity, Entity player) { World world = entity.getLocation().getWorld(); - Entity arrow = world.spawnEntity(loc, EntityTyp); - if (Inaccuracy != 0f) { + Entity arrow = world.spawnEntity(loc, entityType); + if (inaccuracy != 0f) { arrow.setVelocity(loc.getDirection().multiply(velocity).add(Randomise()) .subtract(Randomise())); } else { @@ -68,18 +94,22 @@ public class EntityProjectile implements GunnersProjectile { if (player instanceof org.bukkit.projectiles.ProjectileSource) arr.setShooter((org.bukkit.projectiles.ProjectileSource) player); } - if (PlaySound) { - world.playSound(loc, this.SoundType, 20, 2); - world.spawnParticle(this.ParticleType, loc.getX(), loc.getY(), loc.getZ(), 0); - if (!DelayedFire) { - PlaySound = false; + if (playSound) { + world.playSound(loc, this.soundType, 20, 2); + world.spawnParticle(this.particleType, loc.getX(), loc.getY(), loc.getZ(), 0); + if (!delayedFire) { + playSound = false; } } } private Vector Randomise() { - return new Vector(SiegeEngines.random.nextFloat() * (Inaccuracy - (Inaccuracy * -1)) + (Inaccuracy * -1), SiegeEngines.random.nextFloat() * (Inaccuracy - (Inaccuracy * -1)) + (Inaccuracy * -1), SiegeEngines.random.nextFloat() * (Inaccuracy - (Inaccuracy * -1)) + (Inaccuracy * -1)); + return new Vector(SiegeEngines.random.nextFloat() * (inaccuracy - (inaccuracy * -1)) + (inaccuracy * -1), SiegeEngines.random.nextFloat() * (inaccuracy - (inaccuracy * -1)) + (inaccuracy * -1), SiegeEngines.random.nextFloat() * (inaccuracy - (inaccuracy * -1)) + (inaccuracy * -1)); } + + public ProjectileType getProjectileType() { + return projectileType; + } } diff --git a/src/main/java/com/github/alathra/siegeengines/projectile/ExplosiveProjectile.java b/src/main/java/com/github/alathra/siegeengines/projectile/ExplosiveProjectile.java index 7696d10..68df99a 100644 --- a/src/main/java/com/github/alathra/siegeengines/projectile/ExplosiveProjectile.java +++ b/src/main/java/com/github/alathra/siegeengines/projectile/ExplosiveProjectile.java @@ -12,31 +12,60 @@ import org.bukkit.World; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.Snowball; +import org.bukkit.inventory.ItemStack; import org.bukkit.util.Vector; -public class ExplosiveProjectile implements GunnersProjectile { - - public String ProjectileType = "Explosive"; - public Boolean PlaceBlocks = false; - public Material BlockToPlace = Material.COBWEB; - public int BlocksToPlaceAmount = 3; - public float ExplodePower = 2; - public float Inaccuracy = 0.3f; - public int ProjectilesCount = 1; - public Boolean DelayedFire = false; - public int DelayTime = 6; - public Particle ParticleType = Particle.EXPLOSION_LARGE; - public Sound SoundType = Sound.ENTITY_GENERIC_EXPLODE; - private boolean PlaySound = true; - public Boolean AlertOnLanding = false; +public class ExplosiveProjectile extends SiegeEngineProjectile { + + // Defaults + public Boolean placeBlocks = false; + public Material blockToPlace = Material.COBWEB; + public int blocksToPlaceAmount = 3; + public float explodePower = 2; + public float inaccuracy = 0.3f; + public int projectilesCount = 1; + public Boolean delayedFire = false; + public int delayTime = 6; + public Particle particleType = Particle.EXPLOSION_LARGE; + public Sound soundType = Sound.ENTITY_GENERIC_EXPLODE; + public Boolean alertOnLanding = false; + + private boolean playSound = true; + + public ExplosiveProjectile(ItemStack ammunitionItem) { + super(ProjectileType.EXPLOSIVE, ammunitionItem); + } + + public static ExplosiveProjectile getDefaultStoneShot() { + ExplosiveProjectile stoneProj = new ExplosiveProjectile(new ItemStack(Material.COBBLESTONE)); + stoneProj.explodePower = 1; + return stoneProj; + } + + public static ExplosiveProjectile getDefaultRepeatingShot() { + ExplosiveProjectile repeatingProj = new ExplosiveProjectile(new ItemStack(Material.TNT)); + repeatingProj.explodePower = 1; + repeatingProj.projectilesCount = 5; + repeatingProj.delayedFire = true; + repeatingProj.inaccuracy = 0.75f; + return repeatingProj; + } + + public static ExplosiveProjectile getDefaultBreachShot() { + ExplosiveProjectile breachProj = new ExplosiveProjectile(new ItemStack(Material.IRON_BLOCK)); + breachProj.explodePower = 3; + breachProj.projectilesCount = 1; + return breachProj; + } + @Override public void Shoot(Entity player, Entity entity, Location loc, Float velocity) { - PlaySound = true; + playSound = true; int baseDelay = 0; - for (int i = 0; i < ProjectilesCount; i++) { - if (DelayedFire) { - baseDelay += DelayTime; + for (int i = 0; i < projectilesCount; i++) { + if (delayedFire) { + baseDelay += delayTime; Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(SiegeEngines.getInstance(), () -> { CreateEntity(entity, loc, velocity, player); }, (long) baseDelay); @@ -54,7 +83,7 @@ public class ExplosiveProjectile implements GunnersProjectile { ball.setShooter((org.bukkit.projectiles.ProjectileSource) player); ClickHandler.projectiles.put(tnt.getUniqueId(), this); - if (Inaccuracy != 0f) { + if (inaccuracy != 0f) { tnt.setVelocity(loc.getDirection().multiply(velocity).add(Randomise()) .subtract(Randomise())); } else { @@ -63,19 +92,23 @@ public class ExplosiveProjectile implements GunnersProjectile { tnt.setMetadata("isExplosiveProj", SiegeEnginesUtil.addMetaDataValue("true")); Bukkit.getServer().getPluginManager().callEvent(new org.bukkit.event.entity.ProjectileLaunchEvent(tnt)); - if (PlaySound) { - world.playSound(loc, this.SoundType, 20, 2); - world.spawnParticle(this.ParticleType, loc.getX(), loc.getY(), loc.getZ(), 0); - if (!DelayedFire) { - PlaySound = false; + if (playSound) { + world.playSound(loc, this.soundType, 20, 2); + world.spawnParticle(this.particleType, loc.getX(), loc.getY(), loc.getZ(), 0); + if (!delayedFire) { + playSound = false; } } } private Vector Randomise() { - return new Vector(SiegeEngines.random.nextFloat() * (Inaccuracy - (Inaccuracy * -1)) + (Inaccuracy * -1), SiegeEngines.random.nextFloat() * (Inaccuracy - (Inaccuracy * -1)) + (Inaccuracy * -1), SiegeEngines.random.nextFloat() * (Inaccuracy - (Inaccuracy * -1)) + (Inaccuracy * -1)); + return new Vector(SiegeEngines.random.nextFloat() * (inaccuracy - (inaccuracy * -1)) + (inaccuracy * -1), SiegeEngines.random.nextFloat() * (inaccuracy - (inaccuracy * -1)) + (inaccuracy * -1), SiegeEngines.random.nextFloat() * (inaccuracy - (inaccuracy * -1)) + (inaccuracy * -1)); } + + public ProjectileType getProjectileType() { + return projectileType; + } } diff --git a/src/main/java/com/github/alathra/siegeengines/projectile/GunnersProjectile.java b/src/main/java/com/github/alathra/siegeengines/projectile/GunnersProjectile.java deleted file mode 100644 index ce06a07..0000000 --- a/src/main/java/com/github/alathra/siegeengines/projectile/GunnersProjectile.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.github.alathra.siegeengines.projectile; - -import org.bukkit.Location; -import org.bukkit.entity.Entity; - -public interface GunnersProjectile { - public void Shoot(Entity player, Entity entity, Location fireLocation, Float velocity); - - public String ProjectileType = "Default"; -} - diff --git a/src/main/java/com/github/alathra/siegeengines/projectile/PotionProjectile.java b/src/main/java/com/github/alathra/siegeengines/projectile/PotionProjectile.java index 99f1fd0..8c9542e 100644 --- a/src/main/java/com/github/alathra/siegeengines/projectile/PotionProjectile.java +++ b/src/main/java/com/github/alathra/siegeengines/projectile/PotionProjectile.java @@ -18,15 +18,19 @@ import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; import org.bukkit.util.Vector; -public class PotionProjectile implements GunnersProjectile { - public String ProjectileType = "Potion"; +public class PotionProjectile extends SiegeEngineProjectile { + public int EntityCount = 3; public Boolean DelayedFire = false; public int DelayTime = 6; public float Inaccuracy = 0.1f; public Particle ParticleType = Particle.EXPLOSION_LARGE; public Sound SoundType = Sound.ENTITY_GENERIC_EXPLODE; - + + public PotionProjectile(ItemStack ammunitionItem) { + super(ProjectileType.POTION, ammunitionItem); + } + @Override public void Shoot(Entity player, Entity entity, Location loc, Float velocity) { //TODO Auto-generated method stub @@ -68,4 +72,8 @@ public class PotionProjectile implements GunnersProjectile { private Vector Randomise() { return new Vector(SiegeEngines.random.nextFloat() * (Inaccuracy - (Inaccuracy * -1)) + (Inaccuracy * -1), SiegeEngines.random.nextFloat() * (Inaccuracy - (Inaccuracy * -1)) + (Inaccuracy * -1), SiegeEngines.random.nextFloat() * (Inaccuracy - (Inaccuracy * -1)) + (Inaccuracy * -1)); } + + public ProjectileType getProjectileType() { + return projectileType; + } } diff --git a/src/main/java/com/github/alathra/siegeengines/projectile/ProjectileType.java b/src/main/java/com/github/alathra/siegeengines/projectile/ProjectileType.java new file mode 100644 index 0000000..e5895b3 --- /dev/null +++ b/src/main/java/com/github/alathra/siegeengines/projectile/ProjectileType.java @@ -0,0 +1,5 @@ +package com.github.alathra.siegeengines.projectile; + +public enum ProjectileType { + DEFAULT, ENTITY, EXPLOSIVE, POTION; +} diff --git a/src/main/java/com/github/alathra/siegeengines/projectile/SiegeEngineProjectile.java b/src/main/java/com/github/alathra/siegeengines/projectile/SiegeEngineProjectile.java new file mode 100644 index 0000000..5d2597a --- /dev/null +++ b/src/main/java/com/github/alathra/siegeengines/projectile/SiegeEngineProjectile.java @@ -0,0 +1,29 @@ +package com.github.alathra.siegeengines.projectile; + +import org.bukkit.Location; +import org.bukkit.entity.Entity; +import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; + +public abstract class SiegeEngineProjectile { + + protected ProjectileType projectileType; + protected ItemStack ammunitionItem; + + public SiegeEngineProjectile(ProjectileType projectileType, @NotNull ItemStack ammunitionItem ) { + this.projectileType = projectileType; + this.ammunitionItem = ammunitionItem; + } + + public abstract void Shoot(Entity player, Entity entity, Location fireLocation, Float velocity); + + public ProjectileType getType() { + return projectileType; + } + + public ItemStack getAmmuinitionItem() { + return ammunitionItem; + } + +} +