refactors

This commit is contained in:
TheCrunchy committed 2023-07-03 18:34:38 +01:00
1 parent 61c4963bb1
commit 129839368b
15 files changed
+171 -83

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.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,11 @@
package CrunchProjectiles;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
public interface CrunchProjectile {
public void Shoot(Player player, Entity entity, Location loc, Float velocity);
}
@@ -0,0 +1,40 @@
package CrunchProjectiles;
import org.bukkit.Location;
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.Fireball;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import siegeCore.CrunchSiegeCore;
public class EntityProjectile implements CrunchProjectile{
public int EntityCount = 20;
public int ArrowOnlyDamage = 6;
public EntityType EntityTyp = EntityType.ARROW;
@Override
public void Shoot(Player player, Entity entity, Location loc, Float velocity) {
for (int i = 0; i < EntityCount; i++) {
World world = entity.getLocation().getWorld();
Entity arrow = world.spawnEntity(loc, EntityTyp);
arrow.setVelocity(loc.getDirection().multiply(velocity).add(new Vector(CrunchSiegeCore.random.nextDouble(), CrunchSiegeCore.random.nextDouble(), CrunchSiegeCore.random.nextDouble())
.subtract(new Vector(CrunchSiegeCore.random.nextDouble(), CrunchSiegeCore.random.nextDouble(), CrunchSiegeCore.random.nextDouble()))));
if (arrow instanceof Arrow) {
Arrow arr = (Arrow) arrow;
arr.setDamage(8);
}
// MiscDisguise miscDisguise = new MiscDisguise(DisguiseType.DROPPED_ITEM, Material.IRON_NUGGET);
// DisguiseAPI.disguiseEntity(arrow, miscDisguise);
world.playSound(entity.getLocation(), Sound.ITEM_CROSSBOW_SHOOT, 20, 2);
// }
}
}
}
@@ -0,0 +1,39 @@
package CrunchProjectiles;
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.Player;
import org.bukkit.inventory.ItemStack;
import siegeCore.ClickHandler;
import siegeCore.CrunchSiegeCore;
public class ExplosiveProjectile implements CrunchProjectile {
public int Radius = 2;
public float Inaccuracy = 3.0f;
public int ProjectilesCount = 1;
@Override
public void Shoot(Player player, Entity entity, Location loc, Float velocity) {
for (int i = 0; i < ProjectilesCount; i++) {
if (Inaccuracy > 0) {
float randomVar = CrunchSiegeCore.random.nextFloat() * (Inaccuracy - (Inaccuracy * -1)) + (Inaccuracy * -1);
loc.setYaw(loc.getYaw() + randomVar);
}
World world = entity.getLocation().getWorld();
Entity tnt = world.spawnEntity(loc, EntityType.SNOWBALL);
ClickHandler.projectiles.put(tnt.getUniqueId(), this);
tnt.setVelocity(loc.getDirection().multiply(velocity));
world.playSound(loc, Sound.ENTITY_GENERIC_EXPLODE, 20, 2);
world.spawnParticle(Particle.EXPLOSION_LARGE, loc.getX(), loc.getY(), loc.getZ(), 0);
}
}
}
+4 -2
View File
@@ -44,16 +44,18 @@ import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
import org.bukkit.util.EulerAngle; import org.bukkit.util.EulerAngle;
import CrunchProjectiles.ExplosiveProjectile;
public class ClickHandler implements Listener { public class ClickHandler implements Listener {
public float MinDelay = 5; public float MinDelay = 5;
public static HashMap<UUID, SiegeProjectile> projectiles = new HashMap<UUID, SiegeProjectile>(); public static HashMap<UUID, ExplosiveProjectile> projectiles = new HashMap<UUID, ExplosiveProjectile>();
@EventHandler @EventHandler
public void onHit(ProjectileHitEvent event) { public void onHit(ProjectileHitEvent event) {
if ((event.getEntity() instanceof Snowball) && projectiles.containsKey(event.getEntity().getUniqueId())) { if ((event.getEntity() instanceof Snowball) && projectiles.containsKey(event.getEntity().getUniqueId())) {
SiegeProjectile proj = projectiles.get(event.getEntity().getUniqueId()); ExplosiveProjectile proj = projectiles.get(event.getEntity().getUniqueId());
Entity snowball = event.getEntity(); Entity snowball = event.getEntity();
Location loc = snowball.getLocation(); Location loc = snowball.getLocation();
World world = event.getEntity().getWorld(); World world = event.getEntity().getWorld();
+23 -5
View File
@@ -47,10 +47,16 @@ 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;
import CrunchProjectiles.EntityProjectile;
import CrunchProjectiles.CrunchProjectile;
import CrunchProjectiles.ExplosiveProjectile;
public class CrunchSiegeCore extends JavaPlugin { public class CrunchSiegeCore extends JavaPlugin {
public static Plugin plugin; public static Plugin plugin;
public static Random random = new Random();
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@Override @Override
public void onEnable() { public void onEnable() {
@@ -115,11 +121,23 @@ public class CrunchSiegeCore extends JavaPlugin {
public static void AddDefined() { public static void AddDefined() {
SiegeEquipment equip = new SiegeEquipment(); SiegeEquipment equip = new SiegeEquipment();
equip.Projectiles.put(Material.COBBLESTONE, new SiegeProjectile(1, false)); ExplosiveProjectile proj = new ExplosiveProjectile();
equip.Projectiles.put(Material.TNT, new SiegeProjectile(1, false)); proj.Radius = 1;
equip.Projectiles.put(Material.COPPER_BLOCK, new SiegeProjectile(4, false)); equip.Projectiles.put(Material.COBBLESTONE, proj);
equip.Projectiles.put(Material.GRAVEL, new SiegeProjectile(1, false)); proj = new ExplosiveProjectile();
equip.Projectiles.put(Material.FIREWORK_STAR, new SiegeProjectile(1, false)); proj.Radius = 1;
proj.ProjectilesCount = 3;
proj.Inaccuracy = 12;
equip.Projectiles.put(Material.TNT, proj);
proj = new ExplosiveProjectile();
proj.Radius = 4;
proj.ProjectilesCount = 1;
equip.Projectiles.put(Material.COPPER_BLOCK, proj);
equip.Projectiles.put(Material.GRAVEL, new EntityProjectile());
EntityProjectile fireProj = new EntityProjectile();
fireProj.EntityCount = 3;
fireProj.EntityTyp = EntityType.SMALL_FIREBALL;
equip.Projectiles.put(Material.DIAMOND, fireProj);
ItemStack item = new ItemStack(Material.CARVED_PUMPKIN); ItemStack item = new ItemStack(Material.CARVED_PUMPKIN);
equip.ReadyModelNumber = 122; equip.ReadyModelNumber = 122;
equip.ModelNumberToFireAt = 135; equip.ModelNumberToFireAt = 135;
+54 -61
View File
@@ -20,6 +20,8 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import CrunchProjectiles.CrunchProjectile;
import CrunchProjectiles.ExplosiveProjectile;
import me.libraryaddict.disguise.DisguiseAPI; import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.disguisetypes.DisguiseType; import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import me.libraryaddict.disguise.disguisetypes.MiscDisguise; import me.libraryaddict.disguise.disguisetypes.MiscDisguise;
@@ -36,7 +38,7 @@ public class SiegeEquipment implements Cloneable {
public ItemStack ItemToPlace; public ItemStack ItemToPlace;
public HashMap<Material, SiegeProjectile> Projectiles = new HashMap<Material, SiegeProjectile>() ; public HashMap<Material, CrunchProjectile> Projectiles = new HashMap<Material, CrunchProjectile>() ;
public String ItemToUseForModel; public String ItemToUseForModel;
@@ -127,7 +129,7 @@ public class SiegeEquipment implements Cloneable {
return; return;
} }
this.WorldName = Entity.getWorld().getName(); this.WorldName = Entity.getWorld().getName();
this.NextShotTime = System.currentTimeMillis() + 6000; this.NextShotTime = System.currentTimeMillis() + 1000;
if (this.CycleThroughModelsBeforeFiring) { if (this.CycleThroughModelsBeforeFiring) {
@@ -182,7 +184,7 @@ public class SiegeEquipment implements Cloneable {
// player.sendMessage("" + modelData); // player.sendMessage("" + modelData);
CrunchSiegeCore.UpdateEntityIdModel(this.Entity, modelData, this.WorldName); CrunchSiegeCore.UpdateEntityIdModel(this.Entity, modelData, this.WorldName);
if (modelData == this.ModelNumberToFireAt) { if (modelData == this.ModelNumberToFireAt) {
Shoot(loc, loadedFuel, LoadedProjectile); Projectiles.get(LoadedProjectile).Shoot(player, this.Entity, loc, loadedFuel * this.VelocityPerFuel);
} }
this.NextModelNumber += 1; this.NextModelNumber += 1;
@@ -208,69 +210,60 @@ public class SiegeEquipment implements Cloneable {
// player.sendMessage("Cannot fire for another " + CrunchSiegeCore.convertTime(this.NextShotTime - System.currentTimeMillis())); // player.sendMessage("Cannot fire for another " + CrunchSiegeCore.convertTime(this.NextShotTime - System.currentTimeMillis()));
Shoot(loc, loadedFuel, LoadedProjectile); Projectiles.get(LoadedProjectile).Shoot(player, this.Entity, loc, loadedFuel * this.VelocityPerFuel);
}, (long) delay); }, (long) delay);
} }
} }
public static Random random = new Random();
public void Shoot(Location loc, float loadedFuel, Material LoadedProjectile) { //
// public void Shoot(Location loc, float loadedFuel, Material LoadedProjectile) {
switch (LoadedProjectile) { //
// switch (LoadedProjectile) {
case COBBLESTONE: //
case COPPER_BLOCK: // case COBBLESTONE:
{ // case COPPER_BLOCK:
float randomVar = random.nextFloat() * (6 - -6) + -6; // {
loc.setYaw(loc.getYaw() + randomVar); // float randomVar = random.nextFloat() * (6 - -6) + -6;
Entity tnt = Bukkit.getServer().getWorld(this.WorldName).spawnEntity(loc, EntityType.SNOWBALL); // loc.setYaw(loc.getYaw() + randomVar);
ClickHandler.projectiles.put(tnt.getUniqueId(), Projectiles.get(LoadedProjectile)); // Entity tnt = Bukkit.getServer().getWorld(this.WorldName).spawnEntity(loc, EntityType.SNOWBALL);
tnt.setVelocity(loc.getDirection().multiply(loadedFuel * this.VelocityPerFuel)); // ClickHandler.projectiles.put(tnt.getUniqueId(), );
Bukkit.getServer().getWorld(this.WorldName).playSound(this.location, Sound.ENTITY_GENERIC_EXPLODE, 20, 2); // tnt.setVelocity(loc.getDirection().multiply(loadedFuel * this.VelocityPerFuel));
Bukkit.getServer().getWorld(this.WorldName).spawnParticle(Particle.EXPLOSION_LARGE, loc.getX(), loc.getY(), loc.getZ(), 0); // Bukkit.getServer().getWorld(this.WorldName).playSound(this.location, Sound.ENTITY_GENERIC_EXPLODE, 20, 2);
} // Bukkit.getServer().getWorld(this.WorldName).spawnParticle(Particle.EXPLOSION_LARGE, loc.getX(), loc.getY(), loc.getZ(), 0);
break; // }
case GRAVEL: // break;
{ // case GRAVEL:
for (int i = 0; i < 20; i++) { // {
Entity arrow = Bukkit.getServer().getWorld(this.WorldName).spawnEntity(loc, EntityType.ARROW);
arrow.setVelocity(loc.getDirection().multiply(loadedFuel * this.VelocityPerFuel / 2).add(new Vector(random.nextDouble(), random.nextDouble(), random.nextDouble())
.subtract(new Vector(random.nextDouble(), random.nextDouble(), random.nextDouble()))));
Arrow arr = (Arrow) arrow;
arr.setDamage(3 * loadedFuel);
// MiscDisguise miscDisguise = new MiscDisguise(DisguiseType.DROPPED_ITEM, Material.IRON_NUGGET);
// DisguiseAPI.disguiseEntity(arrow, miscDisguise);
Bukkit.getServer().getWorld(this.WorldName).playSound(this.location, Sound.ITEM_CROSSBOW_SHOOT, 20, 2);
}
}
break;
case TNT:
{
for (int i = 0; i < 5; i++) {
//float randomVar = random.nextFloat() * (15 - -15) + -15;
Entity tnt = Bukkit.getServer().getWorld(this.WorldName).spawnEntity(loc, EntityType.SNOWBALL);
ClickHandler.projectiles.put(tnt.getUniqueId(), Projectiles.get(LoadedProjectile));
tnt.setVelocity(loc.getDirection().multiply(loadedFuel * this.VelocityPerFuel).add(new Vector(random.nextDouble(), random.nextDouble(), random.nextDouble())
.subtract(new Vector(random.nextDouble(), random.nextDouble(), random.nextDouble()))));
Bukkit.getServer().getWorld(this.WorldName).playSound(this.location, Sound.ENTITY_GENERIC_EXPLODE, 20, 2);
Bukkit.getServer().getWorld(this.WorldName).spawnParticle(Particle.EXPLOSION_LARGE, loc.getX(), loc.getY(), loc.getZ(), 0);
}
}
break;
case FIREWORK_STAR:
{
for (int i = 0; i < 4; i++) {
Entity arrow = Bukkit.getServer().getWorld(this.WorldName).spawnEntity(loc, EntityType.SMALL_FIREBALL);
arrow.setVelocity(loc.getDirection().multiply(loadedFuel * this.VelocityPerFuel).add(new Vector(random.nextDouble(), random.nextDouble(), random.nextDouble())
.subtract(new Vector(random.nextDouble(), random.nextDouble(), random.nextDouble()))));
Bukkit.getServer().getWorld(this.WorldName).playSound(this.location, Sound.ITEM_CROSSBOW_SHOOT, 20, 2);
}
}
break;
}
// }
} // break;
// case TNT:
// {
// for (int i = 0; i < 5; i++) {
// //float randomVar = random.nextFloat() * (15 - -15) + -15;
// Entity tnt = Bukkit.getServer().getWorld(this.WorldName).spawnEntity(loc, EntityType.SNOWBALL);
// ClickHandler.projectiles.put(tnt.getUniqueId(), Projectiles.get(LoadedProjectile));
// tnt.setVelocity(loc.getDirection().multiply(loadedFuel * this.VelocityPerFuel).add(new Vector(random.nextDouble(), random.nextDouble(), random.nextDouble())
// .subtract(new Vector(random.nextDouble(), random.nextDouble(), random.nextDouble()))));
// Bukkit.getServer().getWorld(this.WorldName).playSound(this.location, Sound.ENTITY_GENERIC_EXPLODE, 20, 2);
// Bukkit.getServer().getWorld(this.WorldName).spawnParticle(Particle.EXPLOSION_LARGE, loc.getX(), loc.getY(), loc.getZ(), 0);
// }
// }
// break;
// case FIREWORK_STAR:
// {
// for (int i = 0; i < 4; i++) {
// Entity arrow = Bukkit.getServer().getWorld(this.WorldName).spawnEntity(loc, EntityType.SMALL_FIREBALL);
// arrow.setVelocity(loc.getDirection().multiply(loadedFuel * this.VelocityPerFuel).add(new Vector(random.nextDouble(), random.nextDouble(), random.nextDouble())
// .subtract(new Vector(random.nextDouble(), random.nextDouble(), random.nextDouble()))));
// Bukkit.getServer().getWorld(this.WorldName).playSound(this.location, Sound.ITEM_CROSSBOW_SHOOT, 20, 2);
// }
// }
// break;
// }
//
//
// }
} }
-15
View File
@@ -1,15 +0,0 @@
package siegeCore;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
public class SiegeProjectile {
public int Radius = 2;
public Boolean DoFire = false;
public SiegeProjectile(int rad, boolean fire) {
Radius = rad;
DoFire = fire;
}
}