refactor: reorganize project

This commit is contained in:
darksaid98 committed 2023-10-23 01:44:29 +02:00
1 parent 1e69394db7
commit 673172954c
19 files changed
+155 -201

No files matched your search

@@ -0,0 +1,89 @@
package com.github.alathra.siegeengines.projectile;
import com.github.alathra.siegeengines.SiegeEngines;
import org.bukkit.Bukkit;
import org.bukkit.Location;
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.entity.LivingEntity;
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;
@Override
public void Shoot(Entity player, Entity entity, Location FireLocation, Float velocity) {
PlaySound = true;
int baseDelay = 0;
for (int i = 0; i < EntityCount; i++) {
if (DelayedFire) {
baseDelay += DelayTime;
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(SiegeEngines.plugin, () -> {
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();
LivingEntity living = (LivingEntity) entity;
Entity arrow = world.spawnEntity(loc, EntityTyp);
if (Inaccuracy != 0f) {
arrow.setVelocity(loc.getDirection().multiply(velocity).add(Randomise())
.subtract(Randomise()));
}
else {
arrow.setVelocity(loc.getDirection().multiply(velocity));
}
arrow.setMetadata("isEntityProj",SiegeEngines.addMetaDataValue("true"));
Bukkit.getServer().getPluginManager().callEvent(new org.bukkit.event.entity.ProjectileLaunchEvent(arrow));
if (arrow instanceof org.bukkit.entity.Projectile) {
if (player instanceof org.bukkit.projectiles.ProjectileSource)
((org.bukkit.entity.Projectile)arrow).setShooter((org.bukkit.projectiles.ProjectileSource)player);
}
if (arrow instanceof Arrow) {
Arrow arr = (Arrow) arrow;
arr.setDamage(8);
if (player instanceof org.bukkit.projectiles.ProjectileSource)
arr.setShooter((org.bukkit.projectiles.ProjectileSource)player);
//arr.setBasePotionData(arg0);
}
// MiscDisguise miscDisguise = new MiscDisguise(DisguiseType.DROPPED_ITEM, Material.IRON_NUGGET);
// DisguiseAPI.disguiseEntity(arrow, miscDisguise);
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));
}
}
@@ -0,0 +1,90 @@
package com.github.alathra.siegeengines.projectile;
import com.github.alathra.siegeengines.SiegeEngines;
import com.github.alathra.siegeengines.listeners.ClickHandler;
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.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Snowball;
import org.bukkit.util.Vector;
//import me.libraryaddict.disguise.disguisetypes.DisguiseType;
//import me.libraryaddict.disguise.disguisetypes.MiscDisguise;
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;
@Override
public void Shoot(Entity player, Entity entity, Location loc, Float velocity) {
PlaySound = true;
int baseDelay = 0;
for (int i = 0; i < ProjectilesCount; i++) {
if (DelayedFire) {
baseDelay += DelayTime;
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(SiegeEngines.plugin, () -> {
CreateEntity(entity, loc, velocity, player);
}, (long) baseDelay);
}
else {
CreateEntity(entity,loc, velocity, player);
}
// }
}
}
private void CreateEntity(Entity entity, Location loc, Float velocity, Entity player) {
LivingEntity living = (LivingEntity) entity;
World world = entity.getLocation().getWorld();
Entity tnt = world.spawnEntity(loc, EntityType.SNOWBALL);
Snowball ball = (Snowball) tnt;
if (player instanceof org.bukkit.projectiles.ProjectileSource)
ball.setShooter((org.bukkit.projectiles.ProjectileSource)player);
ClickHandler.projectiles.put(tnt.getUniqueId(), this);
if (Inaccuracy != 0f) {
tnt.setVelocity(loc.getDirection().multiply(velocity).add(Randomise())
.subtract(Randomise()));
}
else {
tnt.setVelocity(loc.getDirection().multiply(velocity));
}
tnt.setMetadata("isExplosiveProj",SiegeEngines.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;
}
}
// MiscDisguise miscDisguise = new MiscDisguise(DisguiseType.ARROW);
// miscDisguise.setEntity(tnt);
// miscDisguise.startDisguise();
}
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));
}
}
@@ -0,0 +1,10 @@
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";
}
@@ -0,0 +1,75 @@
package com.github.alathra.siegeengines.projectile;
import com.github.alathra.siegeengines.SiegeEngines;
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.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.ThrownPotion;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.PotionMeta;
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 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;
@Override
public void Shoot(Entity player, Entity entity, Location loc, Float velocity) {
//TODO Auto-generated method stub
int baseDelay = 0;
for (int i = 0; i < EntityCount; i++) {
if (DelayedFire) {
baseDelay += DelayTime;
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(SiegeEngines.plugin, () -> {
CreateEntity(entity,loc, velocity);
}, (long) baseDelay);
}
else {
CreateEntity(entity, loc, velocity);
}
// }
}
}
private void CreateEntity(Entity entity, Location loc, Float velocity) {
World world = entity.getLocation().getWorld();
LivingEntity living = (LivingEntity) entity;
Entity arrow = world.spawnEntity(loc, EntityType.SPLASH_POTION);
if (Inaccuracy != 0f) {
arrow.setVelocity(loc.getDirection().multiply(velocity).add(Randomise()).subtract(Randomise()));
}
else {
arrow.setVelocity(loc.getDirection().multiply(velocity));
}
arrow.setMetadata("isExplosiveProj",SiegeEngines.addMetaDataValue("true"));
Bukkit.getServer().getPluginManager().callEvent(new org.bukkit.event.entity.ProjectileLaunchEvent(arrow));
ItemStack itemStack = new ItemStack(Material.SPLASH_POTION);
PotionMeta potionMeta = (PotionMeta) itemStack.getItemMeta();
potionMeta.addCustomEffect(new PotionEffect(PotionEffectType.HARM, 100, 3, true), true);
itemStack.setItemMeta(potionMeta);
ThrownPotion potion = (ThrownPotion) arrow;
potion.setItem(itemStack);
// MiscDisguise miscDisguise = new MiscDisguise(DisguiseType.DROPPED_ITEM, Material.IRON_NUGGET);
// DisguiseAPI.disguiseEntity(arrow, miscDisguise);
world.playSound(loc, this.SoundType, 20, 2);
world.spawnParticle(this.ParticleType, loc.getX(), loc.getY(), loc.getZ(), 0);
}
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));
}
}