mirror of
https://github.com/darksaid98/SiegeEngines.git
synced 2026-12-03 14:38:53 +00:00
projectiles refactor
This commit is contained in:
1 parent
80a058a2f1
commit
339fad98f3
9 files changed
+203
-126
No files matched your search
@@ -6,7 +6,7 @@ import java.util.HashMap;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import com.github.alathra.siegeengines.projectile.EntityProjectile;
|
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.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@@ -70,7 +70,7 @@ public class SiegeEngine implements Cloneable {
|
|||||||
// Passed parameters
|
// Passed parameters
|
||||||
public String name = "Unnammed Siege Engine";
|
public String name = "Unnammed Siege Engine";
|
||||||
public ItemStack fuelItem = new ItemStack(Material.GUNPOWDER);
|
public ItemStack fuelItem = new ItemStack(Material.GUNPOWDER);
|
||||||
public HashMap<ItemStack, GunnersProjectile> projectiles;
|
public HashMap<ItemStack, SiegeEngineProjectile> projectiles;
|
||||||
|
|
||||||
public int customModelID = 150;
|
public int customModelID = 150;
|
||||||
|
|
||||||
@@ -79,7 +79,7 @@ public class SiegeEngine implements Cloneable {
|
|||||||
return (SiegeEngine) super.clone();
|
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
|
// Default custom model data id if it is passes as null
|
||||||
if (customModelID == 0) {
|
if (customModelID == 0) {
|
||||||
@@ -116,11 +116,12 @@ public class SiegeEngine implements Cloneable {
|
|||||||
baseStandOffset = 0;
|
baseStandOffset = 0;
|
||||||
baseStandModelNumber = 147;
|
baseStandModelNumber = 147;
|
||||||
nextShotTime = System.currentTimeMillis();
|
nextShotTime = System.currentTimeMillis();
|
||||||
EntityProjectile defaultProj = new EntityProjectile();
|
// PLACEHOLDER. SHOULD BE WE-WRITTEN
|
||||||
defaultProj.EntityCount = 2;
|
EntityProjectile defaultProj = new EntityProjectile(new ItemStack(Material.GRASS_BLOCK));
|
||||||
defaultProj.EntityTyp = EntityType.SHULKER_BULLET;
|
defaultProj.entityCount = 2;
|
||||||
defaultProj.ParticleType = Particle.WHITE_ASH;
|
defaultProj.entityType = EntityType.SHULKER_BULLET;
|
||||||
defaultProj.SoundType = Sound.ENTITY_BLAZE_SHOOT;
|
defaultProj.particleType = Particle.WHITE_ASH;
|
||||||
|
defaultProj.soundType = Sound.ENTITY_BLAZE_SHOOT;
|
||||||
|
|
||||||
// set passed parameters as object variables
|
// set passed parameters as object variables
|
||||||
this.name = name;
|
this.name = name;
|
||||||
@@ -316,7 +317,7 @@ public class SiegeEngine implements Cloneable {
|
|||||||
// player.sendMessage("§efiring" + modelData);
|
// player.sendMessage("§efiring" + modelData);
|
||||||
if (LoadedProjectile == null) return;
|
if (LoadedProjectile == null) return;
|
||||||
if (LoadedProjectile.getType() == Material.AIR) return;
|
if (LoadedProjectile.getType() == Material.AIR) return;
|
||||||
GunnersProjectile projType = projectiles.get(LoadedProjectile);
|
SiegeEngineProjectile projType = projectiles.get(LoadedProjectile);
|
||||||
if (projType == null) return;
|
if (projType == null) return;
|
||||||
projType.Shoot(player, entity, this.GetFireLocation(living), loadedFuel * velocityPerFuel);
|
projType.Shoot(player, entity, this.GetFireLocation(living), loadedFuel * velocityPerFuel);
|
||||||
}
|
}
|
||||||
@@ -344,7 +345,7 @@ public class SiegeEngine implements Cloneable {
|
|||||||
nextModelNumber = 0;
|
nextModelNumber = 0;
|
||||||
if (LoadedProjectile == null) return;
|
if (LoadedProjectile == null) return;
|
||||||
if (LoadedProjectile.getType() == Material.AIR) return;
|
if (LoadedProjectile.getType() == Material.AIR) return;
|
||||||
GunnersProjectile projType = projectiles.get(LoadedProjectile);
|
SiegeEngineProjectile projType = projectiles.get(LoadedProjectile);
|
||||||
if (projType == null) return;
|
if (projType == null) return;
|
||||||
projType.Shoot(player, entity, this.GetFireLocation(living), loadedFuel * velocityPerFuel);
|
projType.Shoot(player, entity, this.GetFireLocation(living), loadedFuel * velocityPerFuel);
|
||||||
}, (long) delay);
|
}, (long) delay);
|
||||||
|
|||||||
@@ -9,10 +9,7 @@ import java.util.UUID;
|
|||||||
|
|
||||||
import com.github.alathra.siegeengines.command.CommandHandler;
|
import com.github.alathra.siegeengines.command.CommandHandler;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.Particle;
|
|
||||||
import org.bukkit.Sound;
|
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.EntityType;
|
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
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.listeners.RotationHandler;
|
||||||
import com.github.alathra.siegeengines.projectile.EntityProjectile;
|
import com.github.alathra.siegeengines.projectile.EntityProjectile;
|
||||||
import com.github.alathra.siegeengines.projectile.ExplosiveProjectile;
|
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 {
|
public class SiegeEngines extends JavaPlugin {
|
||||||
@@ -95,21 +92,20 @@ public class SiegeEngines extends JavaPlugin {
|
|||||||
|
|
||||||
public static void AddDefaults() {
|
public static void AddDefaults() {
|
||||||
|
|
||||||
HashMap<ItemStack, GunnersProjectile> projectileMap = new HashMap<>();
|
// 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();
|
||||||
|
|
||||||
EntityProjectile fireProj = new EntityProjectile();
|
// Trebuchet
|
||||||
fireProj.EntityCount = 4;
|
HashMap<ItemStack, SiegeEngineProjectile> trebuchetProjectiles = new HashMap<>();
|
||||||
fireProj.EntityTyp = EntityType.SMALL_FIREBALL;
|
trebuchetProjectiles.put(stoneShot.getAmmuinitionItem(), stoneShot);
|
||||||
fireProj.ParticleType = Particle.WHITE_ASH;
|
trebuchetProjectiles.put(fireballShot.getAmmuinitionItem(), fireballShot);
|
||||||
fireProj.SoundType = Sound.ENTITY_BLAZE_SHOOT;
|
trebuchetProjectiles.put(breachShot.getAmmuinitionItem(), breachShot);
|
||||||
fireProj.Inaccuracy = 0.75f;
|
|
||||||
projectileMap.put(new ItemStack(Material.FIRE_CHARGE), fireProj);
|
|
||||||
|
|
||||||
ExplosiveProjectile proj = new ExplosiveProjectile();
|
SiegeEngine trebuchet = new SiegeEngine("Trebuchet", trebuchetProjectiles, new ItemStack(Material.STRING), 122);
|
||||||
proj.ExplodePower = 1;
|
|
||||||
projectileMap.put(new ItemStack(Material.COBBLESTONE), proj);
|
|
||||||
|
|
||||||
SiegeEngine trebuchet = new SiegeEngine("Trebuchet", projectileMap, new ItemStack(Material.GUNPOWDER), 122);
|
|
||||||
trebuchet.xOffset = 3;
|
trebuchet.xOffset = 3;
|
||||||
trebuchet.yOffset = 3;
|
trebuchet.yOffset = 3;
|
||||||
trebuchet.placementOffsetY = 0.0;
|
trebuchet.placementOffsetY = 0.0;
|
||||||
@@ -117,7 +113,6 @@ public class SiegeEngines extends JavaPlugin {
|
|||||||
trebuchet.shotAmount = 1;
|
trebuchet.shotAmount = 1;
|
||||||
trebuchet.rotateStandHead = false;
|
trebuchet.rotateStandHead = false;
|
||||||
trebuchet.rotateSideways = true;
|
trebuchet.rotateSideways = true;
|
||||||
trebuchet.fuelItem = new ItemStack(Material.STRING);
|
|
||||||
trebuchet.readyModelNumber = 122;
|
trebuchet.readyModelNumber = 122;
|
||||||
trebuchet.modelNumberToFireAt = 135;
|
trebuchet.modelNumberToFireAt = 135;
|
||||||
trebuchet.millisecondsBetweenFiringStages = 2;
|
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
|
123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139
|
||||||
));
|
));
|
||||||
trebuchet.cycleThroughModelsBeforeFiring = true;
|
trebuchet.cycleThroughModelsBeforeFiring = true;
|
||||||
|
|
||||||
definedSiegeEngines.put(trebuchet.readyModelNumber, trebuchet);
|
definedSiegeEngines.put(trebuchet.readyModelNumber, trebuchet);
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
|
||||||
ExplosiveProjectile tntProj = new ExplosiveProjectile();
|
SiegeEngine siegeCannon = new SiegeEngine("Siege Cannon", siegeCannonProjectiles, new ItemStack(Material.GUNPOWDER), 141);
|
||||||
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);
|
|
||||||
siegeCannon.shotAmount = 1;
|
siegeCannon.shotAmount = 1;
|
||||||
siegeCannon.placementOffsetY = -1;
|
siegeCannon.placementOffsetY = -1;
|
||||||
siegeCannon.readyModelNumber = 141;
|
siegeCannon.readyModelNumber = 141;
|
||||||
@@ -166,8 +141,15 @@ public class SiegeEngines extends JavaPlugin {
|
|||||||
siegeCannon.rotateSideways = true;
|
siegeCannon.rotateSideways = true;
|
||||||
definedSiegeEngines.put(siegeCannon.readyModelNumber, siegeCannon);
|
definedSiegeEngines.put(siegeCannon.readyModelNumber, siegeCannon);
|
||||||
|
|
||||||
SiegeEngine navalCannon = new SiegeEngine("Naval Cannon", projectileMap, new ItemStack(Material.GUNPOWDER), 142);
|
// Naval Cannon
|
||||||
navalCannon.projectiles.put(new ItemStack(Material.COBBLESTONE), proj);
|
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.placementOffsetY = -1;
|
||||||
navalCannon.shotAmount = 1;
|
navalCannon.shotAmount = 1;
|
||||||
navalCannon.readyModelNumber = 142;
|
navalCannon.readyModelNumber = 142;
|
||||||
|
|||||||
@@ -84,20 +84,20 @@ public class ClickHandler implements Listener {
|
|||||||
|
|
||||||
projectiles.remove(event.getEntity().getUniqueId());
|
projectiles.remove(event.getEntity().getUniqueId());
|
||||||
|
|
||||||
if (proj.PlaceBlocks) {
|
if (proj.placeBlocks) {
|
||||||
TNTPrimed tntEnt = (TNTPrimed) tnt;
|
TNTPrimed tntEnt = (TNTPrimed) tnt;
|
||||||
tntEnt.setYield(0);
|
tntEnt.setYield(0);
|
||||||
tntEnt.setFuseTicks(0);
|
tntEnt.setFuseTicks(0);
|
||||||
if (event.getHitBlock() != null) {
|
if (event.getHitBlock() != null) {
|
||||||
List<Block> Blocks = sphere(event.getHitBlock().getLocation(), (int) proj.ExplodePower);
|
List<Block> Blocks = sphere(event.getHitBlock().getLocation(), (int) proj.explodePower);
|
||||||
for (int i = 0; i < proj.BlocksToPlaceAmount; i++) {
|
for (int i = 0; i < proj.blocksToPlaceAmount; i++) {
|
||||||
Block replace = getRandomElement(Blocks);
|
Block replace = getRandomElement(Blocks);
|
||||||
replace.setType(proj.BlockToPlace);
|
replace.setType(proj.blockToPlace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
TNTPrimed tntEnt = (TNTPrimed) tnt;
|
TNTPrimed tntEnt = (TNTPrimed) tnt;
|
||||||
tntEnt.setYield(proj.ExplodePower);
|
tntEnt.setYield(proj.explodePower);
|
||||||
tntEnt.setFuseTicks(0);
|
tntEnt.setFuseTicks(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,51 +5,77 @@ import com.github.alathra.siegeengines.SiegeEnginesUtil;
|
|||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
import org.bukkit.Particle;
|
import org.bukkit.Particle;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.Arrow;
|
import org.bukkit.entity.Arrow;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
public class EntityProjectile implements GunnersProjectile {
|
public class EntityProjectile extends SiegeEngineProjectile {
|
||||||
|
|
||||||
public String ProjectileType = "Entity";
|
// Defaults
|
||||||
public int EntityCount = 20;
|
public int entityCount = 20;
|
||||||
public int ArrowOnlyDamage = 6;
|
public int arrowOnlyDamage = 6;
|
||||||
public Boolean DelayedFire = false;
|
public Boolean delayedFire = false;
|
||||||
public int DelayTime = 6;
|
public int delayTime = 6;
|
||||||
public EntityType EntityTyp = EntityType.ARROW;
|
public EntityType entityType = EntityType.ARROW;
|
||||||
public float Inaccuracy = 0.2f;
|
public float inaccuracy = 0.2f;
|
||||||
public Particle ParticleType = Particle.EXPLOSION_LARGE;
|
public Particle particleType = Particle.EXPLOSION_LARGE;
|
||||||
public Sound SoundType = Sound.ENTITY_GENERIC_EXPLODE;
|
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
|
@Override
|
||||||
public void Shoot(Entity player, Entity entity, Location FireLocation, Float velocity) {
|
public void Shoot(Entity player, Entity entity, Location FireLocation, Float velocity) {
|
||||||
PlaySound = true;
|
playSound = true;
|
||||||
int baseDelay = 0;
|
int baseDelay = 0;
|
||||||
for (int i = 0; i < EntityCount; i++) {
|
for (int i = 0; i < entityCount; i++) {
|
||||||
if (DelayedFire) {
|
if (delayedFire) {
|
||||||
baseDelay += DelayTime;
|
baseDelay += delayTime;
|
||||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(SiegeEngines.getInstance(), () -> {
|
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(SiegeEngines.getInstance(), () -> {
|
||||||
|
|
||||||
CreateEntity(entity, FireLocation, velocity, player);
|
CreateEntity(entity, FireLocation, velocity, player);
|
||||||
}, (long) baseDelay);
|
}, (long) baseDelay);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
CreateEntity(entity, FireLocation, velocity, player);
|
CreateEntity(entity, FireLocation, velocity, player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean PlaySound = true;
|
|
||||||
|
|
||||||
private void CreateEntity(Entity entity, Location loc, Float velocity, Entity player) {
|
private void CreateEntity(Entity entity, Location loc, Float velocity, Entity player) {
|
||||||
World world = entity.getLocation().getWorld();
|
World world = entity.getLocation().getWorld();
|
||||||
|
|
||||||
Entity arrow = world.spawnEntity(loc, EntityTyp);
|
Entity arrow = world.spawnEntity(loc, entityType);
|
||||||
if (Inaccuracy != 0f) {
|
if (inaccuracy != 0f) {
|
||||||
arrow.setVelocity(loc.getDirection().multiply(velocity).add(Randomise())
|
arrow.setVelocity(loc.getDirection().multiply(velocity).add(Randomise())
|
||||||
.subtract(Randomise()));
|
.subtract(Randomise()));
|
||||||
} else {
|
} else {
|
||||||
@@ -68,18 +94,22 @@ public class EntityProjectile implements GunnersProjectile {
|
|||||||
if (player instanceof org.bukkit.projectiles.ProjectileSource)
|
if (player instanceof org.bukkit.projectiles.ProjectileSource)
|
||||||
arr.setShooter((org.bukkit.projectiles.ProjectileSource) player);
|
arr.setShooter((org.bukkit.projectiles.ProjectileSource) player);
|
||||||
}
|
}
|
||||||
if (PlaySound) {
|
if (playSound) {
|
||||||
world.playSound(loc, this.SoundType, 20, 2);
|
world.playSound(loc, this.soundType, 20, 2);
|
||||||
world.spawnParticle(this.ParticleType, loc.getX(), loc.getY(), loc.getZ(), 0);
|
world.spawnParticle(this.particleType, loc.getX(), loc.getY(), loc.getZ(), 0);
|
||||||
if (!DelayedFire) {
|
if (!delayedFire) {
|
||||||
PlaySound = false;
|
playSound = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Vector Randomise() {
|
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.Entity;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.Snowball;
|
import org.bukkit.entity.Snowball;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
public class ExplosiveProjectile implements GunnersProjectile {
|
public class ExplosiveProjectile extends SiegeEngineProjectile {
|
||||||
|
|
||||||
public String ProjectileType = "Explosive";
|
|
||||||
public Boolean PlaceBlocks = false;
|
// Defaults
|
||||||
public Material BlockToPlace = Material.COBWEB;
|
public Boolean placeBlocks = false;
|
||||||
public int BlocksToPlaceAmount = 3;
|
public Material blockToPlace = Material.COBWEB;
|
||||||
public float ExplodePower = 2;
|
public int blocksToPlaceAmount = 3;
|
||||||
public float Inaccuracy = 0.3f;
|
public float explodePower = 2;
|
||||||
public int ProjectilesCount = 1;
|
public float inaccuracy = 0.3f;
|
||||||
public Boolean DelayedFire = false;
|
public int projectilesCount = 1;
|
||||||
public int DelayTime = 6;
|
public Boolean delayedFire = false;
|
||||||
public Particle ParticleType = Particle.EXPLOSION_LARGE;
|
public int delayTime = 6;
|
||||||
public Sound SoundType = Sound.ENTITY_GENERIC_EXPLODE;
|
public Particle particleType = Particle.EXPLOSION_LARGE;
|
||||||
private boolean PlaySound = true;
|
public Sound soundType = Sound.ENTITY_GENERIC_EXPLODE;
|
||||||
public Boolean AlertOnLanding = false;
|
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
|
@Override
|
||||||
public void Shoot(Entity player, Entity entity, Location loc, Float velocity) {
|
public void Shoot(Entity player, Entity entity, Location loc, Float velocity) {
|
||||||
PlaySound = true;
|
playSound = true;
|
||||||
int baseDelay = 0;
|
int baseDelay = 0;
|
||||||
for (int i = 0; i < ProjectilesCount; i++) {
|
for (int i = 0; i < projectilesCount; i++) {
|
||||||
if (DelayedFire) {
|
if (delayedFire) {
|
||||||
baseDelay += DelayTime;
|
baseDelay += delayTime;
|
||||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(SiegeEngines.getInstance(), () -> {
|
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(SiegeEngines.getInstance(), () -> {
|
||||||
CreateEntity(entity, loc, velocity, player);
|
CreateEntity(entity, loc, velocity, player);
|
||||||
}, (long) baseDelay);
|
}, (long) baseDelay);
|
||||||
@@ -54,7 +83,7 @@ public class ExplosiveProjectile implements GunnersProjectile {
|
|||||||
ball.setShooter((org.bukkit.projectiles.ProjectileSource) player);
|
ball.setShooter((org.bukkit.projectiles.ProjectileSource) player);
|
||||||
ClickHandler.projectiles.put(tnt.getUniqueId(), this);
|
ClickHandler.projectiles.put(tnt.getUniqueId(), this);
|
||||||
|
|
||||||
if (Inaccuracy != 0f) {
|
if (inaccuracy != 0f) {
|
||||||
tnt.setVelocity(loc.getDirection().multiply(velocity).add(Randomise())
|
tnt.setVelocity(loc.getDirection().multiply(velocity).add(Randomise())
|
||||||
.subtract(Randomise()));
|
.subtract(Randomise()));
|
||||||
} else {
|
} else {
|
||||||
@@ -63,18 +92,22 @@ public class ExplosiveProjectile implements GunnersProjectile {
|
|||||||
tnt.setMetadata("isExplosiveProj", SiegeEnginesUtil.addMetaDataValue("true"));
|
tnt.setMetadata("isExplosiveProj", SiegeEnginesUtil.addMetaDataValue("true"));
|
||||||
Bukkit.getServer().getPluginManager().callEvent(new org.bukkit.event.entity.ProjectileLaunchEvent(tnt));
|
Bukkit.getServer().getPluginManager().callEvent(new org.bukkit.event.entity.ProjectileLaunchEvent(tnt));
|
||||||
|
|
||||||
if (PlaySound) {
|
if (playSound) {
|
||||||
world.playSound(loc, this.SoundType, 20, 2);
|
world.playSound(loc, this.soundType, 20, 2);
|
||||||
world.spawnParticle(this.ParticleType, loc.getX(), loc.getY(), loc.getZ(), 0);
|
world.spawnParticle(this.particleType, loc.getX(), loc.getY(), loc.getZ(), 0);
|
||||||
if (!DelayedFire) {
|
if (!delayedFire) {
|
||||||
PlaySound = false;
|
playSound = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Vector Randomise() {
|
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,8 +18,8 @@ import org.bukkit.potion.PotionEffect;
|
|||||||
import org.bukkit.potion.PotionEffectType;
|
import org.bukkit.potion.PotionEffectType;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
public class PotionProjectile implements GunnersProjectile {
|
public class PotionProjectile extends SiegeEngineProjectile {
|
||||||
public String ProjectileType = "Potion";
|
|
||||||
public int EntityCount = 3;
|
public int EntityCount = 3;
|
||||||
public Boolean DelayedFire = false;
|
public Boolean DelayedFire = false;
|
||||||
public int DelayTime = 6;
|
public int DelayTime = 6;
|
||||||
@@ -27,6 +27,10 @@ public class PotionProjectile implements GunnersProjectile {
|
|||||||
public Particle ParticleType = Particle.EXPLOSION_LARGE;
|
public Particle ParticleType = Particle.EXPLOSION_LARGE;
|
||||||
public Sound SoundType = Sound.ENTITY_GENERIC_EXPLODE;
|
public Sound SoundType = Sound.ENTITY_GENERIC_EXPLODE;
|
||||||
|
|
||||||
|
public PotionProjectile(ItemStack ammunitionItem) {
|
||||||
|
super(ProjectileType.POTION, ammunitionItem);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void Shoot(Entity player, Entity entity, Location loc, Float velocity) {
|
public void Shoot(Entity player, Entity entity, Location loc, Float velocity) {
|
||||||
//TODO Auto-generated method stub
|
//TODO Auto-generated method stub
|
||||||
@@ -68,4 +72,8 @@ public class PotionProjectile implements GunnersProjectile {
|
|||||||
private Vector Randomise() {
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -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