refactors

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

No files matched your search

+4 -2
View File
@@ -44,16 +44,18 @@ import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.util.EulerAngle;
import CrunchProjectiles.ExplosiveProjectile;
public class ClickHandler implements Listener {
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
public void onHit(ProjectileHitEvent event) {
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();
Location loc = snowball.getLocation();
World world = event.getEntity().getWorld();
+24 -6
View File
@@ -47,10 +47,16 @@ import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.util.Vector;
import CrunchProjectiles.EntityProjectile;
import CrunchProjectiles.CrunchProjectile;
import CrunchProjectiles.ExplosiveProjectile;
public class CrunchSiegeCore extends JavaPlugin {
public static Plugin plugin;
public static Random random = new Random();
@SuppressWarnings("deprecation")
@Override
public void onEnable() {
@@ -115,11 +121,23 @@ public class CrunchSiegeCore extends JavaPlugin {
public static void AddDefined() {
SiegeEquipment equip = new SiegeEquipment();
equip.Projectiles.put(Material.COBBLESTONE, new SiegeProjectile(1, false));
equip.Projectiles.put(Material.TNT, new SiegeProjectile(1, false));
equip.Projectiles.put(Material.COPPER_BLOCK, new SiegeProjectile(4, false));
equip.Projectiles.put(Material.GRAVEL, new SiegeProjectile(1, false));
equip.Projectiles.put(Material.FIREWORK_STAR, new SiegeProjectile(1, false));
ExplosiveProjectile proj = new ExplosiveProjectile();
proj.Radius = 1;
equip.Projectiles.put(Material.COBBLESTONE, proj);
proj = new ExplosiveProjectile();
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);
equip.ReadyModelNumber = 122;
equip.ModelNumberToFireAt = 135;
+66 -73
View File
@@ -20,6 +20,8 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;
import CrunchProjectiles.CrunchProjectile;
import CrunchProjectiles.ExplosiveProjectile;
import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import me.libraryaddict.disguise.disguisetypes.MiscDisguise;
@@ -36,8 +38,8 @@ public class SiegeEquipment implements Cloneable {
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 WorldName;
@@ -46,7 +48,7 @@ public class SiegeEquipment implements Cloneable {
public int YOffset = 0;
public int MaxFuel = 5;
public float VelocityPerFuel = 0.75f;
public Material FuelMaterial = Material.GUNPOWDER;
public Material FuelMaterial = Material.GUNPOWDER;
public int FuseTime;
public long NextShotTime = System.currentTimeMillis();
@@ -97,7 +99,7 @@ public class SiegeEquipment implements Cloneable {
return false;
}
}
return false;
}
@@ -114,11 +116,11 @@ public class SiegeEquipment implements Cloneable {
}
float loadedFuel = this.AmmoHolder.LoadedFuel;
Material LoadedProjectile = this.AmmoHolder.MaterialName;
this.AmmoHolder.LoadedFuel = 0;
this.AmmoHolder.LoadedProjectile = 0;
this.AmmoHolder.MaterialName = Material.BEDROCK;
LivingEntity living = (LivingEntity) Entity;
if (living.getEquipment() == null || living.getEquipment().getHelmet() == null || living.getEquipment().getHelmet().getItemMeta() == null) {
return;
@@ -127,12 +129,12 @@ public class SiegeEquipment implements Cloneable {
return;
}
this.WorldName = Entity.getWorld().getName();
this.NextShotTime = System.currentTimeMillis() + 6000;
this.NextShotTime = System.currentTimeMillis() + 1000;
if (this.CycleThroughModelsBeforeFiring) {
this.TaskNumber = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(CrunchSiegeCore.plugin, () -> {
Location loc = living.getEyeLocation();
Vector direction = Entity.getLocation().getDirection().multiply(XOffset);
Random random = new Random();
@@ -140,8 +142,8 @@ public class SiegeEquipment implements Cloneable {
loc.add(direction.multiply(randomVar));
loc.setYaw(loc.getYaw() + randomVar);
this.NextModelNumber = 0;
this.location = loc;
@@ -182,7 +184,7 @@ public class SiegeEquipment implements Cloneable {
// player.sendMessage("" + modelData);
CrunchSiegeCore.UpdateEntityIdModel(this.Entity, modelData, this.WorldName);
if (modelData == this.ModelNumberToFireAt) {
Shoot(loc, loadedFuel, LoadedProjectile);
Projectiles.get(LoadedProjectile).Shoot(player, this.Entity, loc, loadedFuel * this.VelocityPerFuel);
}
this.NextModelNumber += 1;
@@ -200,77 +202,68 @@ public class SiegeEquipment implements Cloneable {
Location loc = living.getEyeLocation();
Vector direction = Entity.getLocation().getDirection().multiply(XOffset);
loc.add(direction);
this.NextModelNumber = 0;
this.location = loc;
// 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);
}
}
public static Random random = new Random();
public void Shoot(Location loc, float loadedFuel, Material LoadedProjectile) {
switch (LoadedProjectile) {
case COBBLESTONE:
case COPPER_BLOCK:
{
float randomVar = random.nextFloat() * (6 - -6) + -6;
loc.setYaw(loc.getYaw() + randomVar);
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));
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:
{
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;
}
//
// public void Shoot(Location loc, float loadedFuel, Material LoadedProjectile) {
//
// switch (LoadedProjectile) {
//
// case COBBLESTONE:
// case COPPER_BLOCK:
// {
// float randomVar = random.nextFloat() * (6 - -6) + -6;
// loc.setYaw(loc.getYaw() + randomVar);
// Entity tnt = Bukkit.getServer().getWorld(this.WorldName).spawnEntity(loc, EntityType.SNOWBALL);
// ClickHandler.projectiles.put(tnt.getUniqueId(), );
// tnt.setVelocity(loc.getDirection().multiply(loadedFuel * this.VelocityPerFuel));
// 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 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;
}
}