Bump Version (0.8.5)

Potential fix for regular armor stands.
This commit is contained in:
C_Corp2002 authored and GitHub committed 2024-02-24 14:43:26 -05:00
1 parent 40c7e39024
commit fedc87e7ce
8 files changed
+129 -51

No files matched your search

@@ -68,6 +68,7 @@ public class SiegeEngine implements Cloneable {
private int readyModelNumber;
private int nextModelNumber; // Internal
private int preFireModelNumber;
private int preLoadModelNumber;
private SiegeEngineAmmoHolder ammoHolder;
// Optional variables
@@ -111,6 +112,7 @@ public class SiegeEngine implements Cloneable {
setReadyModelNumber(customModelID);
setModelNumberToFireAt(customModelID);
setPreFireModelNumber(customModelID);
setPreLoadModelNumber(customModelID);
setFiringModelNumbers(new ArrayList<Integer>());
setAmmoHolder(new SiegeEngineAmmoHolder());
//fuelItem = new ItemStack(Material.GUNPOWDER);
@@ -681,6 +683,14 @@ public class SiegeEngine implements Cloneable {
public void setPreFireModelNumber(int preFireModelNumber) {
this.preFireModelNumber = preFireModelNumber;
}
public int getPreLoadModelNumber() {
return preLoadModelNumber;
}
public void setPreLoadModelNumber(int preLoadModelNumber) {
this.preLoadModelNumber = preLoadModelNumber;
}
public SiegeEngineAmmoHolder getAmmoHolder() {
return ammoHolder;
@@ -9,7 +9,6 @@ import java.util.UUID;
import com.github.alathra.siegeengines.command.CommandHandler;
import com.github.alathra.siegeengines.config.Config;
import com.github.alathra.siegeengines.crafting.CraftingRecipes;
import org.bukkit.Material;
import org.bukkit.entity.Entity;
@@ -70,11 +69,6 @@ public class SiegeEngines extends JavaPlugin {
}
}
commandHandler.onEnable();
// load crafting recipes if enabled in config
if (Config.craftingRecipes) {
CraftingRecipes.loadCraftingRecipes();
}
}
@SuppressWarnings("deprecation")
@@ -144,7 +138,7 @@ public class SiegeEngines extends JavaPlugin {
// Ballista
SiegeEngine ballista = new SiegeEngine("Ballista", Config.ballistaProjectiles, new ItemStack(Material.STRING),
145);
146);
// config options
ballista.setType(SiegeEngineType.BALLISTA);
ballista.setItemName(Config.ballistaItemName);
@@ -157,14 +151,15 @@ public class SiegeEngines extends JavaPlugin {
ballista.setHealth(Config.ballistaHealth);
ballista.setXOffset(1);
ballista.setYOffset(1);
ballista.setPlacementOffsetY(-0.75);
ballista.setPlacementOffsetY(-1.25);
ballista.setRotateStandHead(true);
ballista.setRotateSideways(true);
ballista.setSetModelNumberWhenFullyLoaded(true);
ballista.setReadyModelNumber(145);
ballista.setModelNumberToFireAt(145);
ballista.setReadyModelNumber(146);
ballista.setModelNumberToFireAt(146);
ballista.setPreFireModelNumber(143);
ballista.setFiringModelNumbers(new ArrayList<>(Arrays.asList(143, 144, 145)));
ballista.setPreLoadModelNumber(144);
ballista.setFiringModelNumbers(new ArrayList<>(Arrays.asList(143, 144, 145, 146)));
ballista.setCycleThroughModelsWhileFiring(true);
ballista.setMountable(Config.ballistaCanMount);
definedSiegeEngines.put(ballista.getReadyModelNumber(), ballista);
@@ -182,6 +177,7 @@ public class SiegeEngines extends JavaPlugin {
swivelCannon.setFuelItem(new ItemStack(Config.swivelCannonFuelItem));
swivelCannon.setProjectiles(Config.swivelCannonProjectiles);
swivelCannon.setHealth(Config.swivelCannonHealth);
swivelCannon.setXOffset(1);
swivelCannon.setPlacementOffsetY(-1);
swivelCannon.setReadyModelNumber(141);
swivelCannon.setModelNumberToFireAt(141);
@@ -204,6 +200,7 @@ public class SiegeEngines extends JavaPlugin {
breachCannon.setFuelItem(new ItemStack(Config.breachCannonFuelItem));
breachCannon.setProjectiles(Config.breachCannonProjectiles);
breachCannon.setHealth(Config.breachCannonHealth);
breachCannon.setXOffset(1);
breachCannon.setPlacementOffsetY(-1);
breachCannon.setReadyModelNumber(142);
breachCannon.setModelNumberToFireAt(142);
@@ -17,9 +17,11 @@ import org.bukkit.inventory.ItemStack;
import com.github.alathra.siegeengines.SiegeEngines;
import com.github.alathra.siegeengines.SiegeEnginesLogger;
import com.github.alathra.siegeengines.SiegeEnginesUtil;
import com.github.alathra.siegeengines.crafting.CraftingRecipes;
import com.github.alathra.siegeengines.projectile.EntityProjectile;
import com.github.alathra.siegeengines.projectile.ExplosiveProjectile;
import com.github.alathra.siegeengines.projectile.FireworkProjectile;
import com.github.alathra.siegeengines.projectile.PotionProjectile;
import com.github.alathra.siegeengines.projectile.ProjectileType;
import com.github.alathra.siegeengines.projectile.SiegeEngineProjectile;
@@ -307,6 +309,22 @@ public class Config {
.getDouble("Projectiles." + projectileName + ".VelocityFactor");
projectileMap.put(projectileName, fireworkProjectile);
break;
case POTION:
PotionProjectile potionProjectile = new PotionProjectile(new ItemStack(
Material.getMaterial(config.getString("Projectiles." + projectileName + ".AmmoItem"))));
potionProjectile.inaccuracy = (float) config
.getDouble("Projectiles." + projectileName + ".Inaccuracy");
potionProjectile.entityCount = config.getInt("Projectiles." + projectileName + ".EntityCount");
potionProjectile.delayTime = config.getInt("Projectiles." + projectileName + ".EntityCount");
if (potionProjectile.delayTime <= 0) {
potionProjectile.delayedFire = false;
} else {
potionProjectile.delayedFire = true;
}
potionProjectile.velocityFactor = (float) config
.getDouble("Projectiles." + projectileName + ".VelocityFactor");
projectileMap.put(projectileName, potionProjectile);
break;
default:
continue;
}
@@ -321,6 +339,17 @@ public class Config {
SiegeEngines.getInstance().reloadConfig();
SiegeEngines.getInstance().saveDefaultConfig();
initConfigVals();
// load crafting recipes if enabled in config
if (Config.craftingRecipes) {
if (!CraftingRecipes.areLoaded()) {
CraftingRecipes.loadCraftingRecipes();
}
} else {
if (CraftingRecipes.areLoaded()) {
CraftingRecipes.unloadCraftingRecipes();
}
}
}
public FileConfiguration getConfig() {
@@ -12,6 +12,8 @@ import com.github.alathra.siegeengines.api.SiegeEnginesAPI;
public class CraftingRecipes {
private static boolean areLoaded = false;
public static Recipe trebuchetRecipe() {
ItemStack trebuchet = SiegeEnginesAPI.getTrebuchetItem();
NamespacedKey key = new NamespacedKey(SiegeEngines.getInstance(),
@@ -23,7 +25,6 @@ public class CraftingRecipes {
trebuchetRecipe.setIngredient('#', Material.OAK_TRAPDOOR);
trebuchetRecipe.setIngredient('$', Material.STRING);
trebuchetRecipe.setIngredient('^', Material.BOWL);
SiegeEngines.getInstance().getServer().addRecipe(trebuchetRecipe);
return trebuchetRecipe;
}
@@ -37,7 +38,6 @@ public class CraftingRecipes {
ballistaRecipe.setIngredient('%', Material.STICK);
ballistaRecipe.setIngredient('#', Material.OAK_PLANKS);
ballistaRecipe.setIngredient('$', Material.OAK_LOG);
SiegeEngines.getInstance().getServer().addRecipe(ballistaRecipe);
return ballistaRecipe;
}
@@ -51,7 +51,6 @@ public class CraftingRecipes {
swivelCannonRecipe.setIngredient('%', Material.IRON_BLOCK);
swivelCannonRecipe.setIngredient('#', Material.CAULDRON);
swivelCannonRecipe.setIngredient('$', Material.ANVIL);
SiegeEngines.getInstance().getServer().addRecipe(swivelCannonRecipe);
return swivelCannonRecipe;
}
@@ -65,15 +64,31 @@ public class CraftingRecipes {
breachCannonRecipe.setIngredient('%', SiegeEnginesAPI.getSwivelCannonItem());
breachCannonRecipe.setIngredient('#', Material.CAULDRON);
breachCannonRecipe.setIngredient('$', Material.ANVIL);
SiegeEngines.getInstance().getServer().addRecipe(breachCannonRecipe);
return breachCannonRecipe;
}
public static void loadCraftingRecipes() {
trebuchetRecipe();
ballistaRecipe();
swivelCannonRecipe();
breachCannonRecipe();
SiegeEngines.getInstance().getServer().addRecipe(trebuchetRecipe());
SiegeEngines.getInstance().getServer().addRecipe(ballistaRecipe());
SiegeEngines.getInstance().getServer().addRecipe(swivelCannonRecipe());
SiegeEngines.getInstance().getServer().addRecipe(breachCannonRecipe());
areLoaded = true;
}
public static void unloadCraftingRecipes() {
SiegeEngines.getInstance().getServer().removeRecipe(new NamespacedKey(SiegeEngines.getInstance(),
SiegeEngines.getInstance().getName() + "trebuchetRecipe"));
SiegeEngines.getInstance().getServer().removeRecipe(new NamespacedKey(SiegeEngines.getInstance(),
SiegeEngines.getInstance().getName() + "ballistaRecipe"));
SiegeEngines.getInstance().getServer().removeRecipe(new NamespacedKey(SiegeEngines.getInstance(),
SiegeEngines.getInstance().getName() + "swivelCannonRecipe"));
SiegeEngines.getInstance().getServer().removeRecipe(new NamespacedKey(SiegeEngines.getInstance(),
SiegeEngines.getInstance().getName() + "breachCannonRecipe"));
areLoaded = false;
}
public static boolean areLoaded() {
return areLoaded;
}
}
@@ -17,6 +17,7 @@ import com.github.alathra.siegeengines.SiegeEnginesUtil;
import com.github.alathra.siegeengines.SiegeEngine;
import com.github.alathra.siegeengines.projectile.ExplosiveProjectile;
import com.github.alathra.siegeengines.projectile.FireworkProjectile;
import com.github.alathra.siegeengines.projectile.PotionProjectile;
import org.bukkit.Bukkit;
import org.bukkit.Location;
@@ -39,7 +40,6 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
@@ -298,7 +298,8 @@ public class ClickHandler implements Listener {
return true;
}
inventoryItem = inventoryItem.clone();
if (!(stack.isSimilar(inventoryItem)) && (stack.getType() != Material.FIREWORK_ROCKET))
if (!(stack.isSimilar(inventoryItem)) && (stack.getType() != Material.FIREWORK_ROCKET)
&& (stack.getType() != Material.SPLASH_POTION))
continue;
inventoryItem.setAmount(1);
if (stack.getType() != Material.FIREWORK_ROCKET && stack.isSimilar(inventoryItem)
@@ -317,6 +318,15 @@ public class ClickHandler implements Listener {
siegeEngine.getProjectiles().put(inventoryItem, proj);
return true;
}
if (stack.getType() == Material.SPLASH_POTION && inventoryItem.getType() == stack.getType()
&& siegeEngine.getAmmoHolder().getLoadedProjectile() == 0) {
siegeEngine.getAmmoHolder().setLoadedProjectile(1);
siegeEngine.getAmmoHolder().setMaterialName(inventoryItem);
state.getInventory().removeItem(inventoryItem);
PotionProjectile proj = new PotionProjectile(inventoryItem);
siegeEngine.getProjectiles().put(inventoryItem, proj);
return true;
}
continue;
}
return false;
@@ -619,10 +629,12 @@ public class ClickHandler implements Listener {
}
}
@EventHandler(priority = EventPriority.LOWEST)
@EventHandler(priority = EventPriority.NORMAL)
public void onEngineDamage(EntityDamageByEntityEvent event) {
if (event.getEntity() instanceof ArmorStand) {
ArmorStand stand = (ArmorStand)event.getEntity();
if (isSiegeEngine(stand,false)) return;
if (event.isCancelled()) return;
if (event.getDamager() instanceof Player) {
PlayerHandler.releasePlayerSiegeEngine((Player)(event.getDamager()),event.getEntity());
}
@@ -650,12 +662,14 @@ public class ClickHandler implements Listener {
}
final List<UUID> keys = new ArrayList<>(SiegeEngines.siegeEngineEntitiesPerPlayer.keySet());
int numPilots = 0;
for (UUID player : keys) {
if (SiegeEngines.siegeEngineEntitiesPerPlayer.get(player) != null) {
if (SiegeEngines.siegeEngineEntitiesPerPlayer.get(player).contains(entity)) {
final List<Entity> entities = new ArrayList<>(
SiegeEngines.siegeEngineEntitiesPerPlayer.get(player));
numPilots++;
if (add) {
for (UUID player : keys) {
if (SiegeEngines.siegeEngineEntitiesPerPlayer.get(player) != null) {
if (SiegeEngines.siegeEngineEntitiesPerPlayer.get(player).contains(entity)) {
final List<Entity> entities = new ArrayList<>(
SiegeEngines.siegeEngineEntitiesPerPlayer.get(player));
numPilots++;
}
}
}
// Can only have one pilot
@@ -1108,13 +1122,17 @@ public class ClickHandler implements Listener {
sendSiegeEngineHelpMSG(player, siegeEngine);
// If fully loaded && requires change in animation when loaded (i.e. ballista)
if (!siegeEngine.canLoadFuel() && siegeEngine.isSetModelNumberWhenFullyLoaded()) {
SiegeEnginesUtil.UpdateEntityIdModel(siegeEngine.getEntity(), siegeEngine.getPreFireModelNumber(), siegeEngine.getWorldName());
SiegeEnginesUtil.UpdateEntityIdModel(siegeEngine.getEntity(), siegeEngine.getPreLoadModelNumber(), siegeEngine.getWorldName());
}
}
}
}
if (pulledHeldAmmoFromPlayer(player, siegeEngine)) {
player.sendMessage("§eAdded ammunition to this Siege Engine.");
// If requires change in animation when loaded with a projectile (i.e. ballista)
if (siegeEngine.isSetModelNumberWhenFullyLoaded()) {
SiegeEnginesUtil.UpdateEntityIdModel(siegeEngine.getEntity(), siegeEngine.getPreFireModelNumber(), siegeEngine.getWorldName());
}
return;
}
if (itemInHand == null || itemInHand.getType() == Material.AIR
@@ -20,24 +20,25 @@ import org.bukkit.util.Vector;
public class PotionProjectile extends SiegeEngineProjectile {
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;
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;
public float velocityFactor = 1.0f;
public PotionProjectile(ItemStack ammunitionItem) {
super(ProjectileType.POTION, ammunitionItem);
}
@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;
for (int i = 0; i < entityCount; i++) {
if (delayedFire) {
baseDelay += delayTime;
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(SiegeEngines.getInstance(), () -> {
CreateEntity(entity, loc, velocity);
@@ -52,25 +53,27 @@ public class PotionProjectile extends SiegeEngineProjectile {
World world = entity.getLocation().getWorld();
Entity arrow = world.spawnEntity(loc, EntityType.SPLASH_POTION);
if (Inaccuracy != 0f) {
if (inaccuracy != 0f) {
arrow.setVelocity(loc.getDirection().multiply(velocity).add(Randomise()).subtract(Randomise()));
} else {
arrow.setVelocity(loc.getDirection().multiply(velocity));
}
arrow.setMetadata("isPotionProj", SiegeEnginesUtil.addMetaDataValue("true"));
Bukkit.getServer().getPluginManager().callEvent(new org.bukkit.event.entity.ProjectileLaunchEvent(arrow));
ItemStack itemStack = new ItemStack(Material.SPLASH_POTION);
ItemStack itemStack = this.getAmmuinitionItem();
PotionMeta potionMeta = (PotionMeta) itemStack.getItemMeta();
potionMeta.addCustomEffect(new PotionEffect(PotionEffectType.HARM, 100, 3, true), true);
System.out.println(potionMeta.toString());
System.out.println(itemStack.toString());
potionMeta.getBasePotionData();
itemStack.setItemMeta(potionMeta);
ThrownPotion potion = (ThrownPotion) arrow;
potion.setItem(itemStack);
world.playSound(loc, this.SoundType, 20, 2);
world.spawnParticle(this.ParticleType, loc.getX(), loc.getY(), loc.getZ(), 0);
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));
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() {