Merge branch 'main' into chris-feat-potion-projectile

This commit is contained in:
Christopher Vieira authored and GitHub committed 2024-02-07 21:21:35 -05:00
commit 2d9efb22bb
10 files changed
+220 -63

No files matched your search

+1 -2
View File
@@ -6,8 +6,7 @@
<groupId>com.github.alathra</groupId> <groupId>com.github.alathra</groupId>
<artifactId>SiegeEngines</artifactId> <artifactId>SiegeEngines</artifactId>
<version>0.8.4</version> <version>0.8.3</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>SiegeEngines</name> <name>SiegeEngines</name>
@@ -48,7 +48,7 @@ public class SiegeEngine implements Cloneable {
private int maxFuel; private int maxFuel;
private double placementOffsetY; private double placementOffsetY;
private float velocityPerFuel; private float velocityPerFuel;
private double baseHealth = 5.0d;
// Firing variables // Firing variables
private int shotAmount; private int shotAmount;
private long nextShotTime; // Internal private long nextShotTime; // Internal
@@ -397,17 +397,17 @@ public class SiegeEngine implements Cloneable {
if (this == null || !this.getEnabled()) { if (this == null || !this.getEnabled()) {
return false; return false;
} }
for (Entity ent : l.getWorld().getNearbyEntities(l,2.5d,2.5d,2.5d)) {
if (SiegeEngines.activeSiegeEngines.keySet().contains(ent.getUniqueId())) {
return false;
}
}
l.setY(l.getY() + 1); l.setY(l.getY() + 1);
l.setDirection(player.getFacing().getDirection()); l.setDirection(player.getFacing().getDirection());
ItemStack item = new ItemStack(Material.CARVED_PUMPKIN); ItemStack item = new ItemStack(Material.CARVED_PUMPKIN);
ItemMeta meta = item.getItemMeta(); ItemMeta meta = item.getItemMeta();
String id = ""; String id = "";
Entity entity3 = null; Entity entity3 = null;
for (Entity enti : l.getWorld().getNearbyEntities(l,2.5d,2.5d,2.5d)) {
if (SiegeEngines.activeSiegeEngines.keySet().contains(enti.getUniqueId())) {
return false;
}
}
this.setAmmoHolder(new SiegeEngineAmmoHolder()); this.setAmmoHolder(new SiegeEngineAmmoHolder());
if (this.hasBaseStand) { if (this.hasBaseStand) {
@@ -472,8 +472,9 @@ public class SiegeEngine implements Cloneable {
newList.add(entity2); newList.add(entity2);
SiegeEngines.siegeEngineEntitiesPerPlayer.put(player.getUniqueId(), newList); SiegeEngines.siegeEngineEntitiesPerPlayer.put(player.getUniqueId(), newList);
}*/ }*/
SiegeEngines.activeSiegeEngines.put(entity2.getUniqueId(), this); stand.setMaxHealth(baseHealth);
ClickHandler.TakeControl(player,entity2); stand.setHealth(baseHealth);
SiegeEngines.activeSiegeEngines.put(stand.getUniqueId(), this);
if (mount != null && !(mount.isDead())) { if (mount != null && !(mount.isDead())) {
entity2.setGravity(true); entity2.setGravity(true);
mount.addPassenger(entity2); mount.addPassenger(entity2);
@@ -529,6 +530,14 @@ public class SiegeEngine implements Cloneable {
this.worldName = worldName; this.worldName = worldName;
} }
public double getHealth() {
return baseHealth;
}
public void setHealth(double health) {
this.baseHealth = health;
}
public Entity getEntity() { public Entity getEntity() {
return entity; return entity;
} }
@@ -59,6 +59,8 @@ public class SiegeEngines extends JavaPlugin {
getServer().getPluginManager().registerEvents(new RotationHandler(), this); getServer().getPluginManager().registerEvents(new RotationHandler(), this);
getServer().getPluginManager().registerEvents(new ClickHandler(), this); getServer().getPluginManager().registerEvents(new ClickHandler(), this);
getServer().getPluginManager().registerEvents(new PlayerHandler(), this); getServer().getPluginManager().registerEvents(new PlayerHandler(), this);
ClickHandler.items.clear();
ClickHandler.items.add(new ItemStack(Material.ARMOR_STAND));
addDefaults(); addDefaults();
for (SiegeEngine i : definedSiegeEngines.values()) { for (SiegeEngine i : definedSiegeEngines.values()) {
System.out.println("§eEnabled Weapon : " + i.getEngineName()); System.out.println("§eEnabled Weapon : " + i.getEngineName());
@@ -124,6 +126,7 @@ public class SiegeEngines extends JavaPlugin {
trebuchet.setMaxFuel(Config.trebuchetMaxFuel); trebuchet.setMaxFuel(Config.trebuchetMaxFuel);
trebuchet.setFuelItem(new ItemStack(Config.trebuchetFuelItem)); trebuchet.setFuelItem(new ItemStack(Config.trebuchetFuelItem));
trebuchet.setProjectiles(Config.trebuchetProjectiles); trebuchet.setProjectiles(Config.trebuchetProjectiles);
trebuchet.setHealth(Config.trebuchetHealth);
trebuchet.setXOffset(3); trebuchet.setXOffset(3);
trebuchet.setYOffset(3); trebuchet.setYOffset(3);
trebuchet.setPlacementOffsetY(0.0); trebuchet.setPlacementOffsetY(0.0);
@@ -151,6 +154,7 @@ public class SiegeEngines extends JavaPlugin {
ballista.setMaxFuel(Config.ballistaMaxFuel); ballista.setMaxFuel(Config.ballistaMaxFuel);
ballista.setFuelItem(new ItemStack(Config.ballistaFuelItem)); ballista.setFuelItem(new ItemStack(Config.ballistaFuelItem));
ballista.setProjectiles(Config.ballistaProjectiles); ballista.setProjectiles(Config.ballistaProjectiles);
ballista.setHealth(Config.ballistaHealth);
ballista.setXOffset(1); ballista.setXOffset(1);
ballista.setYOffset(1); ballista.setYOffset(1);
ballista.setPlacementOffsetY(-0.75); ballista.setPlacementOffsetY(-0.75);
@@ -177,6 +181,7 @@ public class SiegeEngines extends JavaPlugin {
swivelCannon.setMaxFuel(Config.swivelCannonMaxFuel); swivelCannon.setMaxFuel(Config.swivelCannonMaxFuel);
swivelCannon.setFuelItem(new ItemStack(Config.swivelCannonFuelItem)); swivelCannon.setFuelItem(new ItemStack(Config.swivelCannonFuelItem));
swivelCannon.setProjectiles(Config.swivelCannonProjectiles); swivelCannon.setProjectiles(Config.swivelCannonProjectiles);
swivelCannon.setHealth(Config.swivelCannonHealth);
swivelCannon.setPlacementOffsetY(-1); swivelCannon.setPlacementOffsetY(-1);
swivelCannon.setReadyModelNumber(141); swivelCannon.setReadyModelNumber(141);
swivelCannon.setModelNumberToFireAt(141); swivelCannon.setModelNumberToFireAt(141);
@@ -198,6 +203,7 @@ public class SiegeEngines extends JavaPlugin {
breachCannon.setMaxFuel(Config.breachCannonMaxFuel); breachCannon.setMaxFuel(Config.breachCannonMaxFuel);
breachCannon.setFuelItem(new ItemStack(Config.breachCannonFuelItem)); breachCannon.setFuelItem(new ItemStack(Config.breachCannonFuelItem));
breachCannon.setProjectiles(Config.breachCannonProjectiles); breachCannon.setProjectiles(Config.breachCannonProjectiles);
breachCannon.setHealth(Config.breachCannonHealth);
breachCannon.setPlacementOffsetY(-1); breachCannon.setPlacementOffsetY(-1);
breachCannon.setReadyModelNumber(142); breachCannon.setReadyModelNumber(142);
breachCannon.setModelNumberToFireAt(142); breachCannon.setModelNumberToFireAt(142);
@@ -1,18 +1,24 @@
package com.github.alathra.siegeengines; package com.github.alathra.siegeengines;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import com.github.alathra.siegeengines.config.Config;
public class SiegeEnginesLogger { public class SiegeEnginesLogger {
public static void info(String msg) { public static void info(String msg) {
Bukkit.getLogger().info("[" + SiegeEngines.getInstance().getName() + "]" + msg); Bukkit.getLogger().info("[" + SiegeEngines.getInstance().getName() + "] " + msg);
}
public static void debug(String msg) {
if (!Config.doDebug) return;
Bukkit.getLogger().info("(DEBUG) [" + SiegeEngines.getInstance().getName() + "] " + msg);
} }
public static void warn(String msg) { public static void warn(String msg) {
Bukkit.getLogger().warning("[" + SiegeEngines.getInstance().getName() + "]" + msg); Bukkit.getLogger().warning("[" + SiegeEngines.getInstance().getName() + "] " + msg);
} }
public static void severe(String msg) { public static void severe(String msg) {
Bukkit.getLogger().severe("[" + SiegeEngines.getInstance().getName() + "]" + msg); Bukkit.getLogger().severe("[" + SiegeEngines.getInstance().getName() + "] " + msg);
} }
} }
@@ -3,11 +3,22 @@ package com.github.alathra.siegeengines.api;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.entity.Entity;
import com.github.alathra.siegeengines.SiegeEngine;
import com.github.alathra.siegeengines.SiegeEngines;
import com.github.alathra.siegeengines.config.Config; import com.github.alathra.siegeengines.config.Config;
public class SiegeEnginesAPI { public class SiegeEnginesAPI {
public static SiegeEngine getSiegeEngineFromEntity(Entity entity) {
if (SiegeEngines.activeSiegeEngines.containsKey(entity.getUniqueId())) {
return SiegeEngines.activeSiegeEngines.get(entity.getUniqueId());
} else {
return null;
}
}
public static ItemStack getTrebuchetItem() { public static ItemStack getTrebuchetItem() {
ItemStack trebuchetItem = new ItemStack(Material.CARVED_PUMPKIN); ItemStack trebuchetItem = new ItemStack(Material.CARVED_PUMPKIN);
ItemMeta meta = trebuchetItem.getItemMeta(); ItemMeta meta = trebuchetItem.getItemMeta();
@@ -37,8 +37,9 @@ public class Config {
public static int rotateDistance = 32; public static int rotateDistance = 32;
public static int maxSiegeEnginesControlled = 5; public static int maxSiegeEnginesControlled = 5;
public static boolean autoReload = false; public static boolean autoReload = false;
public static boolean arrowDamageToggle = false;
public static boolean craftingRecipes = true; public static boolean craftingRecipes = true;
public static boolean doDebug = false;
public static HashSet<World> disabledWorlds = new HashSet<>(); public static HashSet<World> disabledWorlds = new HashSet<>();
@@ -47,6 +48,7 @@ public class Config {
public static float trebuchetVelocityPerFuel = 0.3f; public static float trebuchetVelocityPerFuel = 0.3f;
public static int trebuchetMaxFuel = 3; public static int trebuchetMaxFuel = 3;
public static Material trebuchetFuelItem = Material.STRING; public static Material trebuchetFuelItem = Material.STRING;
public static double trebuchetHealth = 8d;
public static boolean trebuchetCanMount = false; public static boolean trebuchetCanMount = false;
public static HashMap<ItemStack, SiegeEngineProjectile> trebuchetProjectiles = new HashMap<>(); public static HashMap<ItemStack, SiegeEngineProjectile> trebuchetProjectiles = new HashMap<>();
public static String trebuchetItemName = "&e&oTrebuchet"; public static String trebuchetItemName = "&e&oTrebuchet";
@@ -54,6 +56,7 @@ public class Config {
public static int ballistaShotAmount = 1; public static int ballistaShotAmount = 1;
public static float ballistaVelocityPerFuel = 0.925f; public static float ballistaVelocityPerFuel = 0.925f;
public static double ballistaHealth = 5d;
public static int ballistaMaxFuel = 4; public static int ballistaMaxFuel = 4;
public static Material ballistaFuelItem = Material.STRING; public static Material ballistaFuelItem = Material.STRING;
public static boolean ballistaCanMount = false; public static boolean ballistaCanMount = false;
@@ -63,6 +66,7 @@ public class Config {
public static int swivelCannonShotAmount = 1; public static int swivelCannonShotAmount = 1;
public static float swivelCannonVelocityPerFuel = 1.0125f; public static float swivelCannonVelocityPerFuel = 1.0125f;
public static double swivelCannonHealth = 15d;
public static int swivelCannonMaxFuel = 5; public static int swivelCannonMaxFuel = 5;
public static Material swivelCannonFuelItem = Material.GUNPOWDER; public static Material swivelCannonFuelItem = Material.GUNPOWDER;
public static boolean swivelCannonCanMount = false; public static boolean swivelCannonCanMount = false;
@@ -72,6 +76,7 @@ public class Config {
public static int breachCannonShotAmount = 1; public static int breachCannonShotAmount = 1;
public static float breachCannonVelocityPerFuel = 1.075f; public static float breachCannonVelocityPerFuel = 1.075f;
public static double breachCannonHealth = 25d;
public static int breachCannonMaxFuel = 4; public static int breachCannonMaxFuel = 4;
public static Material breachCannonFuelItem = Material.GUNPOWDER; public static Material breachCannonFuelItem = Material.GUNPOWDER;
public static boolean breachCannonCanMount = false; public static boolean breachCannonCanMount = false;
@@ -99,7 +104,9 @@ public class Config {
controlDistance = config.getInt("ControlDistance"); controlDistance = config.getInt("ControlDistance");
rotateDistance = config.getInt("RotateDistance"); rotateDistance = config.getInt("RotateDistance");
arrowDamageToggle = config.getBoolean("DealArrowDamage");
maxSiegeEnginesControlled = config.getInt("MaxSiegeEnginesControlled"); maxSiegeEnginesControlled = config.getInt("MaxSiegeEnginesControlled");
doDebug = config.getBoolean("Debug");
autoReload = config.getBoolean("AutoReload"); autoReload = config.getBoolean("AutoReload");
craftingRecipes = config.getBoolean("CraftingRecipes"); craftingRecipes = config.getBoolean("CraftingRecipes");
@@ -109,6 +116,7 @@ public class Config {
} }
private static void loadTrebuchetValues() { private static void loadTrebuchetValues() {
trebuchetHealth = config.getDouble("SiegeEngines.Trebuchet.Health");
trebuchetShotAmount = config.getInt("SiegeEngines.Trebuchet.ShotAmount"); trebuchetShotAmount = config.getInt("SiegeEngines.Trebuchet.ShotAmount");
trebuchetVelocityPerFuel = (float) config.getDouble("SiegeEngines.Trebuchet.VelocityPerFuel"); trebuchetVelocityPerFuel = (float) config.getDouble("SiegeEngines.Trebuchet.VelocityPerFuel");
trebuchetMaxFuel = config.getInt("SiegeEngines.Trebuchet.MaxFuel"); trebuchetMaxFuel = config.getInt("SiegeEngines.Trebuchet.MaxFuel");
@@ -134,6 +142,7 @@ public class Config {
} }
private static void loadBallistaValues() { private static void loadBallistaValues() {
ballistaHealth = config.getDouble("SiegeEngines.Ballista.Health");
ballistaShotAmount = config.getInt("SiegeEngines.Ballista.ShotAmount"); ballistaShotAmount = config.getInt("SiegeEngines.Ballista.ShotAmount");
ballistaVelocityPerFuel = (float) config.getDouble("SiegeEngines.Ballista.VelocityPerFuel"); ballistaVelocityPerFuel = (float) config.getDouble("SiegeEngines.Ballista.VelocityPerFuel");
ballistaMaxFuel = config.getInt("SiegeEngines.Ballista.MaxFuel"); ballistaMaxFuel = config.getInt("SiegeEngines.Ballista.MaxFuel");
@@ -160,6 +169,7 @@ public class Config {
} }
private static void loadSwivelCannonValues() { private static void loadSwivelCannonValues() {
swivelCannonHealth = config.getDouble("SiegeEngines.SwivelCannon.Health");
swivelCannonShotAmount = config.getInt("SiegeEngines.SwivelCannon.ShotAmount"); swivelCannonShotAmount = config.getInt("SiegeEngines.SwivelCannon.ShotAmount");
swivelCannonVelocityPerFuel = (float) config.getDouble("SiegeEngines.SwivelCannon.VelocityPerFuel"); swivelCannonVelocityPerFuel = (float) config.getDouble("SiegeEngines.SwivelCannon.VelocityPerFuel");
swivelCannonMaxFuel = config.getInt("SiegeEngines.SwivelCannon.MaxFuel"); swivelCannonMaxFuel = config.getInt("SiegeEngines.SwivelCannon.MaxFuel");
@@ -186,6 +196,7 @@ public class Config {
} }
private static void loadBreachCannonValues() { private static void loadBreachCannonValues() {
breachCannonHealth = config.getDouble("SiegeEngines.BreachCannon.Health");
breachCannonShotAmount = config.getInt("SiegeEngines.BreachCannon.ShotAmount"); breachCannonShotAmount = config.getInt("SiegeEngines.BreachCannon.ShotAmount");
breachCannonVelocityPerFuel = (float) config.getDouble("SiegeEngines.BreachCannon.VelocityPerFuel"); breachCannonVelocityPerFuel = (float) config.getDouble("SiegeEngines.BreachCannon.VelocityPerFuel");
breachCannonMaxFuel = config.getInt("SiegeEngines.BreachCannon.MaxFuel"); breachCannonMaxFuel = config.getInt("SiegeEngines.BreachCannon.MaxFuel");
@@ -10,6 +10,7 @@ import java.util.UUID;
import com.github.alathra.siegeengines.config.Config; import com.github.alathra.siegeengines.config.Config;
import com.github.alathra.siegeengines.SiegeEngineAmmoHolder; import com.github.alathra.siegeengines.SiegeEngineAmmoHolder;
import com.github.alathra.siegeengines.SiegeEnginesLogger;
import com.github.alathra.siegeengines.SiegeEngines; import com.github.alathra.siegeengines.SiegeEngines;
import com.github.alathra.siegeengines.SiegeEnginesUtil; import com.github.alathra.siegeengines.SiegeEnginesUtil;
@@ -39,6 +40,7 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.Action; import org.bukkit.event.block.Action;
import org.bukkit.event.block.SignChangeEvent; import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntityExplodeEvent;
@@ -55,6 +57,7 @@ import org.bukkit.util.EulerAngle;
public class ClickHandler implements Listener { public class ClickHandler implements Listener {
public float MinDelay = 5; public float MinDelay = 5;
public static final ArrayList<ItemStack> items = new ArrayList<>();
public static HashMap<UUID, ExplosiveProjectile> projectiles = new HashMap<UUID, ExplosiveProjectile>(); public static HashMap<UUID, ExplosiveProjectile> projectiles = new HashMap<UUID, ExplosiveProjectile>();
public static EnumSet<Material> fluidMaterials = EnumSet.of(Material.WATER, Material.LAVA, Material.BUBBLE_COLUMN, public static EnumSet<Material> fluidMaterials = EnumSet.of(Material.WATER, Material.LAVA, Material.BUBBLE_COLUMN,
@@ -73,6 +76,29 @@ public class ClickHandler implements Listener {
@EventHandler @EventHandler
public void onHit(ProjectileHitEvent event) { public void onHit(ProjectileHitEvent event) {
if ((event.getEntity() instanceof Projectile)) {
for (Entity entity : event.getEntity().getNearbyEntities(2, 2, 2)) {
if (entity instanceof ArmorStand) {
ArmorStand stand = (ArmorStand) entity;
if (isSiegeEngine(stand,false)) {
event.setCancelled(true);
if (!Config.arrowDamageToggle) continue;
SiegeEnginesLogger.debug("HEALTH BEOFRE SHOT : "+stand.getHealth());
if (stand.getHealth()-2 > 0) {
stand.setHealth(stand.getHealth()-2);
} else {
EntityDeathEvent death = new EntityDeathEvent(stand,items,0);
Bukkit.getServer().getPluginManager().callEvent(death);
if (!death.isCancelled()) stand.setHealth(0.0f);
}
SiegeEnginesLogger.debug("HEALTH AFTER SHOT : "+stand.getHealth());
if (stand.isDead()) {
PlayerHandler.siegeEngineEntityDied(stand);
}
}
}
}
}
if ((event.getEntity() instanceof Projectile) if ((event.getEntity() instanceof Projectile)
&& projectiles.containsKey(event.getEntity().getUniqueId())) { && projectiles.containsKey(event.getEntity().getUniqueId())) {
ExplosiveProjectile proj = projectiles.get(event.getEntity().getUniqueId()); ExplosiveProjectile proj = projectiles.get(event.getEntity().getUniqueId());
@@ -146,8 +172,8 @@ public class ClickHandler implements Listener {
try { try {
siegeEngine = entry.clone(); siegeEngine = entry.clone();
} catch (CloneNotSupportedException e) { } catch (CloneNotSupportedException e) {
break;
} }
break;
} else { } else {
// if siege engine was broken during one of its firing stages // if siege engine was broken during one of its firing stages
if (entry.getFiringModelNumbers().contains(customModel)) { if (entry.getFiringModelNumbers().contains(customModel)) {
@@ -435,7 +461,6 @@ public class ClickHandler implements Listener {
@EventHandler @EventHandler
public void interact(PlayerInteractEvent event) { public void interact(PlayerInteractEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
ItemStack ItemInHand = event.getPlayer().getInventory().getItemInMainHand(); ItemStack ItemInHand = event.getPlayer().getInventory().getItemInMainHand();
if (ItemInHand == null) { if (ItemInHand == null) {
return; return;
@@ -606,15 +631,24 @@ public class ClickHandler implements Listener {
} }
} }
@EventHandler(priority = EventPriority.LOWEST)
@EventHandler public void onEngineDamage(EntityDamageByEntityEvent event) {
public void onProjectileDamage(EntityDamageByEntityEvent event) {
if (event.getEntity() instanceof ArmorStand) { if (event.getEntity() instanceof ArmorStand) {
if (isSiegeEngine(event.getEntity(),false)) { ArmorStand stand = (ArmorStand)event.getEntity();
if (event.getDamager() instanceof Projectile) { if (event.getDamager() instanceof Player) {
event.setDamage(3); PlayerHandler.releasePlayerSiegeEngine((Player)(event.getDamager()),event.getEntity());
}
} }
SiegeEnginesLogger.debug("HEALTH BEOFRE HIT : "+stand.getHealth());
if (stand.getHealth()-2 > 0) {
stand.setHealth(stand.getHealth()-2);
} else {
EntityDeathEvent death = new EntityDeathEvent(stand,items,0);
Bukkit.getServer().getPluginManager().callEvent(death);
if (death.isCancelled()) return;
stand.setHealth(0.0f);
PlayerHandler.siegeEngineEntityDied(event.getEntity());
}
SiegeEnginesLogger.debug("HEALTH AFTER HIT : "+stand.getHealth());
} }
} }
@@ -634,10 +668,6 @@ public class ClickHandler implements Listener {
final List<Entity> entities = new ArrayList<>( final List<Entity> entities = new ArrayList<>(
SiegeEngines.siegeEngineEntitiesPerPlayer.get(player)); SiegeEngines.siegeEngineEntitiesPerPlayer.get(player));
numPilots++; numPilots++;
if (numPilots > 1) {
entities.remove(entity);
}
SiegeEngines.siegeEngineEntitiesPerPlayer.put(player, entities);
} }
} }
// Can only have one pilot // Can only have one pilot
@@ -651,6 +681,7 @@ public class ClickHandler implements Listener {
stand.addEquipmentLock(EquipmentSlot.FEET, LockType.ADDING_OR_CHANGING); stand.addEquipmentLock(EquipmentSlot.FEET, LockType.ADDING_OR_CHANGING);
stand.setBasePlate(true); stand.setBasePlate(true);
SiegeEnginesLogger.debug("ACTIVE ENGINES : " + SiegeEngines.activeSiegeEngines);
if (SiegeEngines.activeSiegeEngines.containsKey(entity.getUniqueId())) { if (SiegeEngines.activeSiegeEngines.containsKey(entity.getUniqueId())) {
equip = SiegeEngines.activeSiegeEngines.get(entity.getUniqueId()); equip = SiegeEngines.activeSiegeEngines.get(entity.getUniqueId());
if (equip == null || !equip.getEnabled()) { if (equip == null || !equip.getEnabled()) {
@@ -671,12 +702,8 @@ public class ClickHandler implements Listener {
stand.addEquipmentLock(EquipmentSlot.CHEST, LockType.ADDING_OR_CHANGING); stand.addEquipmentLock(EquipmentSlot.CHEST, LockType.ADDING_OR_CHANGING);
stand.addEquipmentLock(EquipmentSlot.FEET, LockType.ADDING_OR_CHANGING); stand.addEquipmentLock(EquipmentSlot.FEET, LockType.ADDING_OR_CHANGING);
stand.setBasePlate(true); stand.setBasePlate(true);
if (numPilots > 1) {
return false;
}
if (add)
SiegeEngines.activeSiegeEngines.put(entity.getUniqueId(), equip);
// player.sendMessage("§eNow controlling the equipment."); // player.sendMessage("§eNow controlling the equipment.");
if (add) SiegeEngines.activeSiegeEngines.put(entity.getUniqueId(),equip);
return true; return true;
} }
return false; return false;
@@ -700,16 +727,16 @@ public class ClickHandler implements Listener {
numPilots++; numPilots++;
} }
if (numPilots > 1) { if (numPilots > 1) {
if (player instanceof Player) if (player instanceof Player) ((Player) player).sendMessage("§eOnly one Player may command this Siege Engine!");
((Player) player).sendMessage("§eOnly one Player may command this Siege Engine!");
return; return;
} }
if (SiegeEngines.siegeEngineEntitiesPerPlayer.containsKey(player.getUniqueId())) { if (SiegeEngines.siegeEngineEntitiesPerPlayer.containsKey(player.getUniqueId())) {
SiegeEnginesLogger.debug("CURRENT ENGINES : " + SiegeEngines.siegeEngineEntitiesPerPlayer.get(player.getUniqueId()));
if (SiegeEngines.siegeEngineEntitiesPerPlayer.get(player.getUniqueId()) if (SiegeEngines.siegeEngineEntitiesPerPlayer.get(player.getUniqueId())
.size() > Config.maxSiegeEnginesControlled) { .size() > Config.maxSiegeEnginesControlled) {
if (player instanceof Player) { if (player instanceof Player) {
((Player) player).sendMessage("§eYou are already commanding too many Siege Engines!"); ((Player) player).sendMessage("§eYou are commanding too many Siege Engines!");
PlayerHandler.releasePlayerSiegeEngine(((Player) player),entity); PlayerHandler.releasePlayerSiegeEngine(((Player) player),entity);
} }
return; return;
@@ -753,12 +780,15 @@ public class ClickHandler implements Listener {
if (SiegeEngines.siegeEngineEntitiesPerPlayer.containsKey(player.getUniqueId())) { if (SiegeEngines.siegeEngineEntitiesPerPlayer.containsKey(player.getUniqueId())) {
List<Entity> entities = SiegeEngines.siegeEngineEntitiesPerPlayer.get(player.getUniqueId()); List<Entity> entities = SiegeEngines.siegeEngineEntitiesPerPlayer.get(player.getUniqueId());
entities.add(entity); entities.add(entity);
SiegeEngines.siegeEngineEntitiesPerPlayer.remove(player.getUniqueId());
SiegeEngines.siegeEngineEntitiesPerPlayer.put(player.getUniqueId(), entities); SiegeEngines.siegeEngineEntitiesPerPlayer.put(player.getUniqueId(), entities);
} else { } else {
List<Entity> newList = new ArrayList<Entity>(); List<Entity> newList = new ArrayList<Entity>();
newList.add(entity); newList.add(entity);
SiegeEngines.siegeEngineEntitiesPerPlayer.remove(player.getUniqueId());
SiegeEngines.siegeEngineEntitiesPerPlayer.put(player.getUniqueId(), newList); SiegeEngines.siegeEngineEntitiesPerPlayer.put(player.getUniqueId(), newList);
} }
SiegeEnginesLogger.debug("NEW ENGINES : " + SiegeEngines.siegeEngineEntitiesPerPlayer.get(player.getUniqueId()));
SiegeEngines.activeSiegeEngines.put(entity.getUniqueId(), equip); SiegeEngines.activeSiegeEngines.put(entity.getUniqueId(), equip);
// player.sendMessage("§eNow controlling the equipment."); // player.sendMessage("§eNow controlling the equipment.");
if (player instanceof Player) { if (player instanceof Player) {
@@ -850,9 +880,9 @@ public class ClickHandler implements Listener {
NamespacedKey key = new NamespacedKey(SiegeEngines.getInstance(), "siege_engines"); NamespacedKey key = new NamespacedKey(SiegeEngines.getInstance(), "siege_engines");
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = false) @EventHandler(priority = EventPriority.LOWEST)
public void onSiegeEngineDeathEvent(EntityDeathEvent event) { public void onSiegeEngineDeathEvent(EntityDeathEvent event) {
Boolean removeStands = false; boolean removeStands = false;
List<ItemStack> items = event.getDrops(); List<ItemStack> items = event.getDrops();
if (event.getEntity() instanceof ArmorStand) { if (event.getEntity() instanceof ArmorStand) {
if (event.getEntity().getPersistentDataContainer().has(key, PersistentDataType.STRING)) { if (event.getEntity().getPersistentDataContainer().has(key, PersistentDataType.STRING)) {
@@ -882,9 +912,10 @@ public class ClickHandler implements Listener {
} }
} }
if (removeStands) { if (removeStands) {
PlayerHandler.siegeEngineEntityDied(event.getEntity());
for (ItemStack i : items) { for (ItemStack i : items) {
if (i.getType() == Material.ARMOR_STAND) { if (i.getType() == Material.ARMOR_STAND) {
PlayerHandler.siegeEngineEntityDied(event.getEntity(),false);
SiegeEngines.activeSiegeEngines.remove(event.getEntity().getUniqueId());
i.setAmount(0); i.setAmount(0);
return; return;
} }
@@ -939,10 +970,11 @@ public class ClickHandler implements Listener {
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@EventHandler @EventHandler(priority = EventPriority.LOW)
public void onPlayerClickSign(PlayerInteractEvent event) { public void onPlayerClickSign(PlayerInteractEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
if (event.getClickedBlock() != null && event.getClickedBlock().getType().toString().contains("SIGN")) { if (event.getClickedBlock() != null && event.getClickedBlock().getType().toString().contains("_SIGN")) {
if (event.isCancelled()) return;
Sign sign = (Sign) event.getClickedBlock().getState(); Sign sign = (Sign) event.getClickedBlock().getState();
if (sign.getLine(0).equalsIgnoreCase("[Fire]") && event.getAction() == Action.RIGHT_CLICK_BLOCK) { if (sign.getLine(0).equalsIgnoreCase("[Fire]") && event.getAction() == Action.RIGHT_CLICK_BLOCK) {
if (!SiegeEngines.siegeEngineEntitiesPerPlayer.containsKey(player.getUniqueId())) { if (!SiegeEngines.siegeEngineEntitiesPerPlayer.containsKey(player.getUniqueId())) {
@@ -1033,7 +1065,7 @@ public class ClickHandler implements Listener {
} }
} }
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = false) @EventHandler(priority = EventPriority.LOW)
public void onEntityClick(PlayerInteractAtEntityEvent event) { public void onEntityClick(PlayerInteractAtEntityEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
ItemStack itemInHand = player.getInventory().getItemInMainHand(); ItemStack itemInHand = player.getInventory().getItemInMainHand();
@@ -1044,12 +1076,13 @@ public class ClickHandler implements Listener {
if (entity.getType() == EntityType.ARMOR_STAND) { if (entity.getType() == EntityType.ARMOR_STAND) {
if ((itemInHand.getType() == Material.AIR || itemInHand == null)) { if ((itemInHand.getType() == Material.AIR || itemInHand == null)) {
if (player.isSneaking()) { if (player.isSneaking()) {
if (isSiegeEngine(entity, false)) PlayerHandler.siegeEngineEntityDied(entity); if (!(SiegeEngines.activeSiegeEngines.containsKey(entity.getUniqueId()))) {
else PlayerHandler.releasePlayerSiegeEngine(player,null); return;
if (SiegeEngines.activeSiegeEngines.containsKey(entity.getUniqueId())) { }
SiegeEngines.activeSiegeEngines.remove(entity.getUniqueId()); PlayerHandler.siegeEngineEntityDied(entity,true);
if (isSiegeEngine(entity, false)) {
PlayerHandler.releasePlayerSiegeEngine(player,entity);
} }
player.sendMessage("§eReleased this SiegeEngine!");
return; return;
} }
} }
@@ -2,9 +2,13 @@ package com.github.alathra.siegeengines.listeners;
import java.util.UUID; import java.util.UUID;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet;
import java.util.List; import java.util.List;
import com.github.alathra.siegeengines.SiegeEngines; import com.github.alathra.siegeengines.SiegeEngines;
import com.github.alathra.siegeengines.SiegeEnginesLogger;
import org.bukkit.Bukkit;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@@ -30,13 +34,29 @@ public class PlayerHandler implements Listener {
playerJoinLeave(event.getPlayer()); playerJoinLeave(event.getPlayer());
} }
public static void siegeEngineEntityDied(Entity entity) { public static void siegeEngineEntityDied(Entity entity) {
for (UUID uuid : SiegeEngines.siegeEngineEntitiesPerPlayer.keySet()) { siegeEngineEntityDied(entity,true);
}
public static void siegeEngineEntityDied(Entity entity, boolean silent) {
final HashSet<UUID> Ids = new HashSet<>(SiegeEngines.activeSiegeEngines.keySet());
final HashSet<UUID> playerIds = new HashSet<>(SiegeEngines.siegeEngineEntitiesPerPlayer.keySet());
for (UUID uuid : playerIds) {
if (SiegeEngines.siegeEngineEntitiesPerPlayer.containsKey(uuid)) { if (SiegeEngines.siegeEngineEntitiesPerPlayer.containsKey(uuid)) {
final List<Entity> list = new ArrayList<>(SiegeEngines.siegeEngineEntitiesPerPlayer.get(uuid));
if (SiegeEngines.siegeEngineEntitiesPerPlayer.get(uuid).contains(entity.getUniqueId())) { for (UUID eUuid : Ids) {
list.remove(entity); if (Bukkit.getEntity(eUuid) == null || Bukkit.getEntity(eUuid).isDead() || !Bukkit.getEntity(eUuid).isValid()) {
SiegeEngines.activeSiegeEngines.remove(entity.getUniqueId()); SiegeEngines.activeSiegeEngines.remove(eUuid);
SiegeEngines.siegeEngineEntitiesPerPlayer.put(uuid,list); if (SiegeEngines.siegeEngineEntitiesPerPlayer.get(uuid) != null) SiegeEngines.siegeEngineEntitiesPerPlayer.get(uuid).remove(Bukkit.getEntity(eUuid));
}
}
SiegeEngines.activeSiegeEngines.remove(entity.getUniqueId());
SiegeEngines.siegeEngineEntitiesPerPlayer.get(uuid).remove(entity);
SiegeEnginesLogger.debug("ENGINE DISABLED/DEAD "+entity.getUniqueId().toString());
}
if (!silent) Bukkit.getPlayer(uuid).sendMessage("§eSiege Engine destroyed!");
for (UUID eUuid : Ids) {
if (Bukkit.getEntity(eUuid) == null || Bukkit.getEntity(eUuid).isDead() || !Bukkit.getEntity(eUuid).isValid()) {
SiegeEngines.activeSiegeEngines.remove(eUuid);
if (SiegeEngines.siegeEngineEntitiesPerPlayer.get(uuid) != null) SiegeEngines.siegeEngineEntitiesPerPlayer.get(uuid).remove(Bukkit.getEntity(eUuid));
} }
} }
} }
@@ -44,11 +64,23 @@ public class PlayerHandler implements Listener {
public static void playerJoinLeave(Player player) { public static void playerJoinLeave(Player player) {
if (player == null) return; if (player == null) return;
final UUID uuid = player.getUniqueId(); final UUID uuid = player.getUniqueId();
SiegeEnginesLogger.debug("CLEARING PLAYER-ENGINES "+player.getName());
if (SiegeEngines.siegeEngineEntitiesPerPlayer.containsKey(uuid)) { if (SiegeEngines.siegeEngineEntitiesPerPlayer.containsKey(uuid)) {
final List<Entity> list = new ArrayList<>(SiegeEngines.siegeEngineEntitiesPerPlayer.get(uuid)); final List<Entity> list = new ArrayList<>(SiegeEngines.siegeEngineEntitiesPerPlayer.get(uuid));
list.clear(); list.clear();
SiegeEngines.siegeEngineEntitiesPerPlayer.put(uuid,list); SiegeEngines.siegeEngineEntitiesPerPlayer.put(uuid,list);
SiegeEngines.siegeEngineEntitiesPerPlayer.remove(uuid); SiegeEngines.siegeEngineEntitiesPerPlayer.remove(uuid);
HashSet<UUID> Ids = new HashSet<>(SiegeEngines.activeSiegeEngines.keySet());
if (SiegeEngines.siegeEngineEntitiesPerPlayer.get(uuid) != null) SiegeEngines.siegeEngineEntitiesPerPlayer.get(uuid).clear();
for (UUID eUuid : Ids) {
if (Bukkit.getEntity(eUuid) == null || Bukkit.getEntity(eUuid).isDead() || !Bukkit.getEntity(eUuid).isValid()) {
SiegeEngines.activeSiegeEngines.remove(eUuid);
if (SiegeEngines.siegeEngineEntitiesPerPlayer.get(uuid) != null) SiegeEngines.siegeEngineEntitiesPerPlayer.get(uuid).remove(Bukkit.getEntity(eUuid));
}
}
}
if (SiegeEngines.siegeEngineEntitiesPerPlayer.get(uuid) != null) {
SiegeEnginesLogger.debug("LEFT-OVER ENGINES? "+SiegeEngines.siegeEngineEntitiesPerPlayer.get(uuid).toString());
} }
} }
public static void releasePlayerSiegeEngine(Player player, Entity entity) { public static void releasePlayerSiegeEngine(Player player, Entity entity) {
@@ -57,17 +89,48 @@ public class PlayerHandler implements Listener {
if (SiegeEngines.siegeEngineEntitiesPerPlayer.containsKey(uuid)) { if (SiegeEngines.siegeEngineEntitiesPerPlayer.containsKey(uuid)) {
final List<Entity> list = new ArrayList<>(SiegeEngines.siegeEngineEntitiesPerPlayer.get(uuid)); final List<Entity> list = new ArrayList<>(SiegeEngines.siegeEngineEntitiesPerPlayer.get(uuid));
if (entity != null) { if (entity != null) {
if (SiegeEngines.siegeEngineEntitiesPerPlayer.get(uuid).contains(entity.getUniqueId())) { final HashSet<UUID> Ids = new HashSet<>(SiegeEngines.activeSiegeEngines.keySet());
list.remove(entity); if ((list.contains(entity))) {
SiegeEngines.activeSiegeEngines.remove(entity.getUniqueId()); for (UUID eUuid : Ids) {
SiegeEngines.siegeEngineEntitiesPerPlayer.put(uuid,list); if (Bukkit.getEntity(eUuid) == null || Bukkit.getEntity(eUuid).isDead() || !Bukkit.getEntity(eUuid).isValid()) {
player.sendMessage("§eReleased this SiegeEngine!"); SiegeEngines.activeSiegeEngines.remove(eUuid);
if (SiegeEngines.siegeEngineEntitiesPerPlayer.get(uuid) != null) SiegeEngines.siegeEngineEntitiesPerPlayer.get(uuid).remove(Bukkit.getEntity(eUuid));
}
}
if (SiegeEngines.siegeEngineEntitiesPerPlayer.get(uuid).contains(entity.getUniqueId())) {
list.remove(entity);
if (entity.isDead()) {
SiegeEngines.siegeEngineEntitiesPerPlayer.get(uuid).remove(entity);
SiegeEngines.activeSiegeEngines.remove(entity.getUniqueId());
}
if (!entity.isValid()) {
SiegeEngines.siegeEngineEntitiesPerPlayer.get(uuid).remove(entity);
SiegeEngines.activeSiegeEngines.remove(entity.getUniqueId());
}
SiegeEngines.siegeEngineEntitiesPerPlayer.put(uuid,list);
SiegeEngines.siegeEngineEntitiesPerPlayer.get(uuid).remove(entity);
}
SiegeEnginesLogger.debug("ENGINE RELEASED "+entity.getUniqueId().toString());
if (entity.isDead()) {
SiegeEngines.siegeEngineEntitiesPerPlayer.get(uuid).remove(entity);
SiegeEngines.activeSiegeEngines.remove(entity.getUniqueId());
}
if (!entity.isValid()) {
SiegeEngines.siegeEngineEntitiesPerPlayer.get(uuid).remove(entity);
SiegeEngines.activeSiegeEngines.remove(entity.getUniqueId());
}
SiegeEngines.siegeEngineEntitiesPerPlayer.get(uuid).remove(entity);
player.sendMessage("§eReleased this Siege Engine!");
return;
} }
return; }
if (SiegeEngines.siegeEngineEntitiesPerPlayer.get(uuid) != null) {
SiegeEnginesLogger.debug("LEFT-OVER ENGINES? "+SiegeEngines.siegeEngineEntitiesPerPlayer.get(uuid).toString());
} }
list.clear(); list.clear();
player.sendMessage("§eReleased all SiegeEngines!"); player.sendMessage("§eReleased all Siege Engines!");
SiegeEngines.siegeEngineEntitiesPerPlayer.put(uuid,list); SiegeEngines.siegeEngineEntitiesPerPlayer.put(uuid,list);
SiegeEngines.siegeEngineEntitiesPerPlayer.get(uuid).clear();
SiegeEngines.siegeEngineEntitiesPerPlayer.remove(uuid); SiegeEngines.siegeEngineEntitiesPerPlayer.remove(uuid);
} }
} }
@@ -40,14 +40,22 @@ public class RotationHandler implements Listener {
if (equipment == null) continue; if (equipment == null) continue;
final LivingEntity living = (LivingEntity) ent; final LivingEntity living = (LivingEntity) ent;
if (Config.disabledWorlds.contains(ent.getWorld())) { if (Config.disabledWorlds.contains(ent.getWorld())) {
PlayerHandler.siegeEngineEntityDied(ent);
living.setHealth(0.0d); living.setHealth(0.0d);
PlayerHandler.siegeEngineEntityDied(ent);
continue; continue;
} }
if (!(ent.getLocation().getWorld().equals(player.getLocation().getWorld()))) { if (!(ent.getLocation().getWorld().equals(player.getLocation().getWorld()))) {
PlayerHandler.releasePlayerSiegeEngine(player, ent); PlayerHandler.releasePlayerSiegeEngine(player, ent);
continue; continue;
} }
if (ent.isDead()) {
PlayerHandler.releasePlayerSiegeEngine(player, ent);
continue;
}
if (!ent.isValid()) {
PlayerHandler.releasePlayerSiegeEngine(player, ent);
continue;
}
final double distance = player.getLocation().distance(ent.getLocation()); final double distance = player.getLocation().distance(ent.getLocation());
if (distance >= Config.controlDistance) { if (distance >= Config.controlDistance) {
PlayerHandler.releasePlayerSiegeEngine(player, ent); PlayerHandler.releasePlayerSiegeEngine(player, ent);
@@ -56,9 +64,6 @@ public class RotationHandler implements Listener {
if (itemInHand.getType() != Config.controlItem) { if (itemInHand.getType() != Config.controlItem) {
continue; continue;
} }
if (ent.isDead()) {
continue;
}
if (distance <= Config.rotateDistance) { if (distance <= Config.rotateDistance) {
Location loc = ent.getLocation(); Location loc = ent.getLocation();
+14
View File
@@ -15,10 +15,16 @@ config-version: 1
# | GENERAL SETTINGS | # | GENERAL SETTINGS |
# ===================================== # =====================================
# Enable/Disable Debug logging.
Debug: false
# The item used to aim and fire siege engines # The item used to aim and fire siege engines
# Must be a valid material. See https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/Material.html # Must be a valid material. See https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/Material.html
ControlItem: CLOCK ControlItem: CLOCK
# Allows the disabling of Arrow Damage towards Siege Engines.
DealArrowDamage: true
# The maxmimum distance the player can be away from the SiegeEngine before total control is terminated # The maxmimum distance the player can be away from the SiegeEngine before total control is terminated
ControlDistance: 24 ControlDistance: 24
@@ -91,6 +97,9 @@ Projectiles:
Inaccuracy: 0.125 Inaccuracy: 0.125
EntityCount: 1 EntityCount: 1
VelocityFactor: 1.0 VelocityFactor: 1.0
Inaccuracy: 0.65
EntityCount: 3
VelocityFactor: 1.125
EntityType: DRAGON_FIREBALL EntityType: DRAGON_FIREBALL
AmmoItem: DRAGON_BREATH AmmoItem: DRAGON_BREATH
FireSound: ENTITY_GENERIC_EXPLODE FireSound: ENTITY_GENERIC_EXPLODE
@@ -119,6 +128,7 @@ Projectiles:
SiegeEngines: SiegeEngines:
Trebuchet: Trebuchet:
Health: 8
ShotAmount: 1 ShotAmount: 1
VelocityPerFuel: 0.75 VelocityPerFuel: 0.75
MaxFuel: 3 MaxFuel: 3
@@ -133,6 +143,7 @@ SiegeEngines:
- "&ePlace as a block to spawn a Trebuchet" - "&ePlace as a block to spawn a Trebuchet"
CanMount: false CanMount: false
Ballista: Ballista:
Health: 5
ShotAmount: 1 ShotAmount: 1
VelocityPerFuel: 2.0 VelocityPerFuel: 2.0
MaxFuel: 2 MaxFuel: 2
@@ -148,6 +159,7 @@ SiegeEngines:
- "&ePlace as a block to spawn a Ballista" - "&ePlace as a block to spawn a Ballista"
CanMount: false CanMount: false
SwivelCannon: SwivelCannon:
Health: 15
ShotAmount: 1 ShotAmount: 1
VelocityPerFuel: 0.975 VelocityPerFuel: 0.975
MaxFuel: 5 MaxFuel: 5
@@ -163,6 +175,7 @@ SiegeEngines:
- "&ePlace as a block to spawn a Swivel Cannon" - "&ePlace as a block to spawn a Swivel Cannon"
CanMount: false CanMount: false
BreachCannon: BreachCannon:
Health: 25
ShotAmount: 1 ShotAmount: 1
VelocityPerFuel: 1.0625 VelocityPerFuel: 1.0625
MaxFuel: 4 MaxFuel: 4
@@ -172,6 +185,7 @@ SiegeEngines:
- RepeatingShot - RepeatingShot
- BreachShot - BreachShot
- FireShot - FireShot
- DragonsBreath
- FireworkShot - FireworkShot
ItemName: "&e&lBreach Cannon" ItemName: "&e&lBreach Cannon"
Lore: Lore: