mirror of
https://github.com/darksaid98/SiegeEngines.git
synced 2026-12-01 22:22:10 +00:00
refactor
This commit is contained in:
1 parent
c7587c7ea8
commit
b159cd799e
12 files changed
+31
-18
No files matched your search
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -8,6 +8,6 @@ import org.bukkit.entity.Player;
|
||||
|
||||
public interface CrunchProjectile {
|
||||
|
||||
public void Shoot(Player player, Entity entity, Location loc, Float velocity);
|
||||
public void Shoot(Player player, Entity entity, double XOffset, double YOffset, Float velocity);
|
||||
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import org.bukkit.entity.Arrow;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Fireball;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
@@ -25,24 +26,30 @@ 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, Location loc, Float velocity) {
|
||||
public void Shoot(Player player, Entity entity, double XOffset, double YOffset, Float velocity) {
|
||||
int baseDelay = 0;
|
||||
for (int i = 0; i < EntityCount; i++) {
|
||||
if (DelayedFire) {
|
||||
baseDelay += DelayTime;
|
||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(CrunchSiegeCore.plugin, () -> {
|
||||
CreateEntity(entity, loc, velocity);
|
||||
|
||||
CreateEntity(entity, XOffset, YOffset, velocity);
|
||||
}, (long) baseDelay);
|
||||
}
|
||||
else {
|
||||
CreateEntity(entity, loc, velocity);
|
||||
|
||||
CreateEntity(entity, XOffset, YOffset, velocity);
|
||||
}
|
||||
|
||||
// }
|
||||
}
|
||||
}
|
||||
private void CreateEntity(Entity entity, Location loc, Float velocity) {
|
||||
private void CreateEntity(Entity entity, double XOffset, double YOffset, 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) {
|
||||
|
||||
@@ -8,6 +8,7 @@ import org.bukkit.Sound;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.util.Vector;
|
||||
@@ -17,7 +18,7 @@ import siegeCore.CrunchSiegeCore;
|
||||
|
||||
public class ExplosiveProjectile implements CrunchProjectile {
|
||||
|
||||
public int Radius = 2;
|
||||
public int ExplodePower = 2;
|
||||
public float Inaccuracy = 0.4f;
|
||||
public int ProjectilesCount = 1;
|
||||
public Boolean DelayedFire = false;
|
||||
@@ -25,24 +26,29 @@ 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, Location loc, Float velocity) {
|
||||
public void Shoot(Player player, Entity entity, double XOffset, double YOffset, Float velocity) {
|
||||
int baseDelay = 0;
|
||||
for (int i = 0; i < ProjectilesCount; i++) {
|
||||
if (DelayedFire) {
|
||||
baseDelay += DelayTime;
|
||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(CrunchSiegeCore.plugin, () -> {
|
||||
CreateEntity(entity, loc, velocity);
|
||||
CreateEntity(entity, XOffset, YOffset, velocity);
|
||||
}, (long) baseDelay);
|
||||
}
|
||||
else {
|
||||
CreateEntity(entity, loc, velocity);
|
||||
|
||||
CreateEntity(entity, XOffset, YOffset, velocity);
|
||||
}
|
||||
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateEntity(Entity entity, Location loc, Float velocity) {
|
||||
private void CreateEntity(Entity entity, double XOffset, double YOffset, 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);
|
||||
|
||||
@@ -62,7 +62,7 @@ public class ClickHandler implements Listener {
|
||||
// world.createExplosion(loc, proj.Radius, proj.DoFire);
|
||||
Entity tnt = event.getEntity().getWorld().spawnEntity(loc, EntityType.PRIMED_TNT);
|
||||
TNTPrimed tntEnt = (TNTPrimed) tnt;
|
||||
tntEnt.setYield(proj.Radius);
|
||||
tntEnt.setYield(proj.ExplodePower);
|
||||
tntEnt.setFuseTicks(0);
|
||||
|
||||
|
||||
|
||||
@@ -123,16 +123,16 @@ public class CrunchSiegeCore extends JavaPlugin {
|
||||
public static void AddDefined() {
|
||||
SiegeEquipment equip = new SiegeEquipment();
|
||||
ExplosiveProjectile proj = new ExplosiveProjectile();
|
||||
proj.Radius = 1;
|
||||
proj.ExplodePower = 1;
|
||||
equip.Projectiles.put(Material.COBBLESTONE, proj);
|
||||
proj = new ExplosiveProjectile();
|
||||
proj.Radius = 1;
|
||||
proj.ProjectilesCount = 50;
|
||||
proj.ExplodePower = 1;
|
||||
proj.ProjectilesCount = 3;
|
||||
proj.DelayedFire = true;
|
||||
proj.Inaccuracy = 0.3f;
|
||||
proj.Inaccuracy = 0.5f;
|
||||
equip.Projectiles.put(Material.TNT, proj);
|
||||
proj = new ExplosiveProjectile();
|
||||
proj.Radius = 4;
|
||||
proj.ExplodePower = 4;
|
||||
proj.ProjectilesCount = 1;
|
||||
equip.Projectiles.put(Material.COPPER_BLOCK, proj);
|
||||
equip.Projectiles.put(Material.GRAVEL, new EntityProjectile());
|
||||
|
||||
@@ -184,7 +184,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, loc, loadedFuel * this.VelocityPerFuel);
|
||||
Projectiles.get(LoadedProjectile).Shoot(player, this.Entity, XOffset, YOffset, loadedFuel * this.VelocityPerFuel);
|
||||
}
|
||||
this.NextModelNumber += 1;
|
||||
|
||||
@@ -210,7 +210,7 @@ public class SiegeEquipment implements Cloneable {
|
||||
|
||||
// player.sendMessage("Cannot fire for another " + CrunchSiegeCore.convertTime(this.NextShotTime - System.currentTimeMillis()));
|
||||
|
||||
Projectiles.get(LoadedProjectile).Shoot(player, this.Entity, loc, loadedFuel * this.VelocityPerFuel);
|
||||
Projectiles.get(LoadedProjectile).Shoot(player, this.Entity, XOffset, YOffset, loadedFuel * this.VelocityPerFuel);
|
||||
}, (long) delay);
|
||||
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user