mirror of
https://github.com/darksaid98/SiegeEngines.git
synced 2026-12-01 14:38:55 +00:00
projectiles refactor
This commit is contained in:
1 parent
80a058a2f1
commit
339fad98f3
9 files changed
+210
-133
No files matched your search
@@ -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<ItemStack, GunnersProjectile> projectiles;
|
||||
public HashMap<ItemStack, SiegeEngineProjectile> 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<ItemStack, GunnersProjectile> projectiles, @NotNull ItemStack fuelItem, int customModelID) {
|
||||
public SiegeEngine(@NotNull String name, @NotNull HashMap<ItemStack, SiegeEngineProjectile> 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);
|
||||
|
||||
@@ -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<ItemStack, GunnersProjectile> 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<ItemStack, SiegeEngineProjectile> 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<ItemStack, SiegeEngineProjectile> 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<ItemStack, SiegeEngineProjectile> 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;
|
||||
|
||||
@@ -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<Block> Blocks = sphere(event.getHitBlock().getLocation(), (int) proj.ExplodePower);
|
||||
for (int i = 0; i < proj.BlocksToPlaceAmount; i++) {
|
||||
List<Block> 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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.github.alathra.siegeengines.projectile;
|
||||
|
||||
public enum ProjectileType {
|
||||
DEFAULT, ENTITY, EXPLOSIVE, POTION;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user