Merge branch 'ccorp2002-edits2' into sherman

This commit is contained in:
ShermansWorld committed 2024-01-27 15:17:33 -05:00
commit f5ff5f7afd
11 files changed
+203 -94

No files matched your search

+1 -1
View File
@@ -6,7 +6,7 @@
<groupId>com.github.alathra</groupId> <groupId>com.github.alathra</groupId>
<artifactId>SiegeEngines</artifactId> <artifactId>SiegeEngines</artifactId>
<version>0.7.1</version> <version>0.7.5</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>SiegeEngines</name> <name>SiegeEngines</name>
@@ -9,9 +9,9 @@ import com.github.alathra.siegeengines.projectile.EntityProjectile;
import com.github.alathra.siegeengines.projectile.FireworkProjectile; import com.github.alathra.siegeengines.projectile.FireworkProjectile;
import com.github.alathra.siegeengines.projectile.SiegeEngineProjectile; import com.github.alathra.siegeengines.projectile.SiegeEngineProjectile;
import net.md_5.bungee.api.ChatColor; import com.github.alathra.siegeengines.listeners.ClickHandler;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
@@ -75,6 +75,7 @@ public class SiegeEngine implements Cloneable {
public boolean hasBaseStand; public boolean hasBaseStand;
public double baseStandOffset; public double baseStandOffset;
public int baseStandModelNumber; public int baseStandModelNumber;
public boolean canMount = false;
// Passed parameters // Passed parameters
public String name = "Unnammed SiegeEngine"; public String name = "Unnammed SiegeEngine";
@@ -384,9 +385,13 @@ public class SiegeEngine implements Cloneable {
} }
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public boolean place(Entity player, Location l) { public boolean place(Entity player, Location l) {
return place(player,l,null);
}
@SuppressWarnings("deprecation")
public boolean place(Entity player, Location l, Entity mount) {
l.add(0.5, 0, 0.5); l.add(0.5, 0, 0.5);
NamespacedKey key = new NamespacedKey(SiegeEngines.getInstance(), "siege_engines"); NamespacedKey key = new NamespacedKey(SiegeEngines.getInstance(), "siege_engines");
if (this == null || !this.enabled) { if (this == null || !this.enabled) {
@@ -402,12 +407,13 @@ public class SiegeEngine implements Cloneable {
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;
this.ammoHolder = new SiegeEngineAmmoHolder(); this.ammoHolder = new SiegeEngineAmmoHolder();
if (this.hasBaseStand) { if (this.hasBaseStand) {
Location l2 = l; Location l2 = l;
l2.setY(l.getY() + this.baseStandOffset); l2.setY(l.getY() + this.baseStandOffset);
Entity entity3 = player.getWorld().spawnEntity(l, EntityType.ARMOR_STAND); entity3 = player.getWorld().spawnEntity(l, EntityType.ARMOR_STAND);
LivingEntity ent = (LivingEntity) entity3; LivingEntity ent = (LivingEntity) entity3;
ArmorStand stand = (ArmorStand) ent; ArmorStand stand = (ArmorStand) ent;
@@ -438,7 +444,6 @@ public class SiegeEngine implements Cloneable {
meta.setLore(this.itemLore); meta.setLore(this.itemLore);
item.setItemMeta(meta); item.setItemMeta(meta);
// entity3.addPassenger(entity2);
LivingEntity ent = (LivingEntity) entity2; LivingEntity ent = (LivingEntity) entity2;
ArmorStand stand = (ArmorStand) ent; ArmorStand stand = (ArmorStand) ent;
@@ -458,7 +463,7 @@ public class SiegeEngine implements Cloneable {
stand.setGravity(false); stand.setGravity(false);
ent.getEquipment().setHelmet(item); ent.getEquipment().setHelmet(item);
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(entity2); entities.add(entity2);
SiegeEngines.siegeEngineEntitiesPerPlayer.put(player.getUniqueId(), entities); SiegeEngines.siegeEngineEntitiesPerPlayer.put(player.getUniqueId(), entities);
@@ -466,8 +471,13 @@ public class SiegeEngine implements Cloneable {
List<Entity> newList = new ArrayList<Entity>(); List<Entity> newList = new ArrayList<Entity>();
newList.add(entity2); newList.add(entity2);
SiegeEngines.siegeEngineEntitiesPerPlayer.put(player.getUniqueId(), newList); SiegeEngines.siegeEngineEntitiesPerPlayer.put(player.getUniqueId(), newList);
} }*/
SiegeEngines.activeSiegeEngines.put(entity2.getUniqueId(), this); SiegeEngines.activeSiegeEngines.put(entity2.getUniqueId(), this);
ClickHandler.TakeControl(player,entity2);
if (mount != null && !(mount.isDead())) {
entity2.setGravity(true);
mount.addPassenger(entity2);
}
return true; return true;
} }
} }
@@ -130,6 +130,7 @@ public class SiegeEngines extends JavaPlugin {
trebuchet.firingModelNumbers = new ArrayList<>( trebuchet.firingModelNumbers = new ArrayList<>(
Arrays.asList(123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139)); Arrays.asList(123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139));
trebuchet.cycleThroughModelsWhileFiring = true; trebuchet.cycleThroughModelsWhileFiring = true;
trebuchet.canMount = Config.trebuchetCanMount;
definedSiegeEngines.put(trebuchet.readyModelNumber, trebuchet); definedSiegeEngines.put(trebuchet.readyModelNumber, trebuchet);
// Ballista // Ballista
@@ -155,6 +156,7 @@ public class SiegeEngines extends JavaPlugin {
ballista.preFireModelNumber = 143; ballista.preFireModelNumber = 143;
ballista.firingModelNumbers = new ArrayList<>(Arrays.asList(143, 144, 145)); ballista.firingModelNumbers = new ArrayList<>(Arrays.asList(143, 144, 145));
ballista.cycleThroughModelsWhileFiring = true; ballista.cycleThroughModelsWhileFiring = true;
ballista.canMount = Config.ballistaCanMount;
definedSiegeEngines.put(ballista.readyModelNumber, ballista); definedSiegeEngines.put(ballista.readyModelNumber, ballista);
// Siege Cannon // Siege Cannon
@@ -175,27 +177,30 @@ public class SiegeEngines extends JavaPlugin {
swivelCannon.firingModelNumbers = new ArrayList<Integer>(); swivelCannon.firingModelNumbers = new ArrayList<Integer>();
swivelCannon.rotateStandHead = true; swivelCannon.rotateStandHead = true;
swivelCannon.rotateSideways = true; swivelCannon.rotateSideways = true;
swivelCannon.canMount = Config.swivelCannonCanMount;
definedSiegeEngines.put(swivelCannon.readyModelNumber, swivelCannon); definedSiegeEngines.put(swivelCannon.readyModelNumber, swivelCannon);
// Naval Cannon // Naval Cannon
SiegeEngine beachCannon = new SiegeEngine("Breach Cannon", Config.breachCannonProjectiles, SiegeEngine breachCannon = new SiegeEngine("Breach Cannon", Config.breachCannonProjectiles,
new ItemStack(Material.GUNPOWDER), 142); new ItemStack(Material.GUNPOWDER), 142);
// config options // config options
beachCannon.type = SiegeEngineType.BREACH_CANNON; breachCannon.type = SiegeEngineType.BREACH_CANNON;
beachCannon.itemName = Config.breachCannonItemName; breachCannon.itemName = Config.breachCannonItemName;
beachCannon.itemLore = Config.breachCannonItemLore; breachCannon.itemLore = Config.breachCannonItemLore;
beachCannon.shotAmount = Config.breachCannonShotAmount; breachCannon.shotAmount = Config.breachCannonShotAmount;
beachCannon.velocityPerFuel = Config.breachCannonVelocityPerFuel; breachCannon.velocityPerFuel = Config.breachCannonVelocityPerFuel;
beachCannon.maxFuel = Config.breachCannonMaxFuel; breachCannon.maxFuel = Config.breachCannonMaxFuel;
beachCannon.fuelItem = new ItemStack(Config.breachCannonFuelItem); breachCannon.fuelItem = new ItemStack(Config.breachCannonFuelItem);
beachCannon.projectiles = Config.breachCannonProjectiles; breachCannon.projectiles = Config.breachCannonProjectiles;
beachCannon.placementOffsetY = -1; breachCannon.placementOffsetY = -1;
beachCannon.readyModelNumber = 142; breachCannon.readyModelNumber = 142;
beachCannon.modelNumberToFireAt = 142; breachCannon.modelNumberToFireAt = 142;
beachCannon.firingModelNumbers = new ArrayList<Integer>(); breachCannon.firingModelNumbers = new ArrayList<Integer>();
beachCannon.rotateStandHead = true; breachCannon.rotateStandHead = true;
beachCannon.rotateSideways = false; breachCannon.rotateSideways = false;
definedSiegeEngines.put(beachCannon.readyModelNumber, beachCannon); breachCannon.canMount = Config.breachCannonCanMount;
definedSiegeEngines.put(breachCannon.readyModelNumber, breachCannon);
} }
} }
@@ -1,9 +1,13 @@
package com.github.alathra.siegeengines.config; package com.github.alathra.siegeengines.config;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.World;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.Sound; import org.bukkit.Sound;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
@@ -19,8 +23,6 @@ import com.github.alathra.siegeengines.projectile.FireworkProjectile;
import com.github.alathra.siegeengines.projectile.ProjectileType; import com.github.alathra.siegeengines.projectile.ProjectileType;
import com.github.alathra.siegeengines.projectile.SiegeEngineProjectile; import com.github.alathra.siegeengines.projectile.SiegeEngineProjectile;
import net.md_5.bungee.api.ChatColor;
public class Config { public class Config {
private static FileConfiguration config; private static FileConfiguration config;
@@ -34,11 +36,15 @@ public class Config {
public static int maxSiegeEnginesControlled = 5; public static int maxSiegeEnginesControlled = 5;
public static boolean autoReload = false; public static boolean autoReload = false;
public static HashSet<World> disabledWorlds = new HashSet<>();
// Siege Engine Options - Defaults // Siege Engine Options - Defaults
public static int trebuchetShotAmount = 1; public static int trebuchetShotAmount = 1;
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 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";
public static List<String> trebuchetItemLore; public static List<String> trebuchetItemLore;
@@ -47,6 +53,7 @@ public class Config {
public static float ballistaVelocityPerFuel = 0.925f; public static float ballistaVelocityPerFuel = 0.925f;
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 HashMap<ItemStack, SiegeEngineProjectile> ballistaProjectiles = new HashMap<>(); public static HashMap<ItemStack, SiegeEngineProjectile> ballistaProjectiles = new HashMap<>();
public static String ballistaItemName = "&e&oBallista"; public static String ballistaItemName = "&e&oBallista";
public static List<String> ballistaItemLore; public static List<String> ballistaItemLore;
@@ -55,6 +62,7 @@ public class Config {
public static float swivelCannonVelocityPerFuel = 1.0125f; public static float swivelCannonVelocityPerFuel = 1.0125f;
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 HashMap<ItemStack, SiegeEngineProjectile> swivelCannonProjectiles = new HashMap<>(); public static HashMap<ItemStack, SiegeEngineProjectile> swivelCannonProjectiles = new HashMap<>();
public static String swivelCannonItemName = "&e&oSwivel Cannon"; public static String swivelCannonItemName = "&e&oSwivel Cannon";
public static List<String> swivelCannonItemLore; public static List<String> swivelCannonItemLore;
@@ -63,6 +71,7 @@ public class Config {
public static float breachCannonVelocityPerFuel = 1.075f; public static float breachCannonVelocityPerFuel = 1.075f;
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 HashMap<ItemStack, SiegeEngineProjectile> breachCannonProjectiles = new HashMap<>(); public static HashMap<ItemStack, SiegeEngineProjectile> breachCannonProjectiles = new HashMap<>();
public static String breachCannonItemName = "&e&oBreach Cannon"; public static String breachCannonItemName = "&e&oBreach Cannon";
public static List<String> breachCannonItemLore; public static List<String> breachCannonItemLore;
@@ -124,6 +133,7 @@ public class Config {
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");
ballistaCanMount = config.getBoolean("SiegeEngines.Ballista.CanMount");
try { try {
ballistaFuelItem = Material.getMaterial(config.getString("SiegeEngines.Ballista.FuelItem")); ballistaFuelItem = Material.getMaterial(config.getString("SiegeEngines.Ballista.FuelItem"));
} catch (Exception e) { } catch (Exception e) {
@@ -149,6 +159,7 @@ public class Config {
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");
swivelCannonCanMount = config.getBoolean("SiegeEngines.SwivelCannon.CanMount");
try { try {
swivelCannonFuelItem = Material.getMaterial(config.getString("SiegeEngines.SwivelCannon.FuelItem")); swivelCannonFuelItem = Material.getMaterial(config.getString("SiegeEngines.SwivelCannon.FuelItem"));
} catch (Exception e) { } catch (Exception e) {
@@ -174,6 +185,7 @@ public class Config {
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");
breachCannonCanMount = config.getBoolean("SiegeEngines.BreachCannon.CanMount");
try { try {
breachCannonFuelItem = Material.getMaterial(config.getString("SiegeEngines.BreachCannon.FuelItem")); breachCannonFuelItem = Material.getMaterial(config.getString("SiegeEngines.BreachCannon.FuelItem"));
} catch (Exception e) { } catch (Exception e) {
@@ -201,6 +213,18 @@ public class Config {
loadBallistaValues(); loadBallistaValues();
loadSwivelCannonValues(); loadSwivelCannonValues();
loadBreachCannonValues(); loadBreachCannonValues();
try {
for (String worldName : config.getStringList("DisabledWorlds")) {
World world = Bukkit.getWorld(worldName);
if (world != null) {
disabledWorlds.add(world);
}
}
SiegeEnginesLogger.info("Disabled in worlds: "+ config.getStringList("DisabledWorlds"));
} catch (Exception e) {
SiegeEnginesLogger.warn("Missing Disabled Worlds-List");
}
} }
private static void loadProjectilesConfig() { private static void loadProjectilesConfig() {
@@ -3,6 +3,7 @@ package com.github.alathra.siegeengines.listeners;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
import java.util.UUID; import java.util.UUID;
@@ -158,6 +159,10 @@ public class ClickHandler implements Listener {
} }
// If SiegeEngine found, place it // If SiegeEngine found, place it
if (siegeEngine != null) { if (siegeEngine != null) {
if (Config.disabledWorlds.contains(thePlayer.getWorld())) {
thePlayer.sendMessage("§eSiege Engines cannot be placed in this World.");
event.setCancelled(true);
}
if (fluidMaterials.contains(replaced)) { if (fluidMaterials.contains(replaced)) {
thePlayer.sendMessage("§eSiege Engines cannot be placed in Fluid Blocks."); thePlayer.sendMessage("§eSiege Engines cannot be placed in Fluid Blocks.");
event.setCancelled(true); event.setCancelled(true);
@@ -591,11 +596,12 @@ public class ClickHandler implements Listener {
} }
@EventHandler @EventHandler
public void damage(EntityDamageByEntityEvent event) { public void onProjectileDamage(EntityDamageByEntityEvent event) {
if (event.getEntity() instanceof ArmorStand) { if (event.getEntity() instanceof ArmorStand) {
if (event.getDamager() instanceof Projectile) { if (isSiegeEngine(event.getEntity(),false)) {
event.setDamage(0); if (event.getDamager() instanceof Projectile) {
event.setCancelled(true); event.setDamage(3);
}
} }
} }
} }
@@ -673,14 +679,13 @@ public class ClickHandler implements Listener {
} }
} }
// Can only have one pilot // Can only have one pilot
final List<UUID> keys = new ArrayList<>(SiegeEngines.siegeEngineEntitiesPerPlayer.keySet()); final HashSet<UUID> keys = new HashSet<>(SiegeEngines.siegeEngineEntitiesPerPlayer.keySet());
int numPilots = 0; int numPilots = 0;
for (UUID uuid : keys) { for (UUID uuid : keys) {
if (uuid.equals(player.getUniqueId())) { if (uuid.equals(player.getUniqueId())) {
continue; continue;
} }
numPilots++; numPilots++;
} }
if (numPilots > 1) { if (numPilots > 1) {
if (player instanceof Player) if (player instanceof Player)
@@ -688,11 +693,12 @@ public class ClickHandler implements Listener {
return; return;
} }
if (SiegeEngines.siegeEngineEntitiesPerPlayer.get(player.getUniqueId()) != null) { if (SiegeEngines.siegeEngineEntitiesPerPlayer.containsKey(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 already commanding too many Siege Engines!");
PlayerHandler.releasePlayerSiegeEngine(((Player) player),entity);
} }
return; return;
} }
@@ -832,8 +838,8 @@ public class ClickHandler implements Listener {
NamespacedKey key = new NamespacedKey(SiegeEngines.getInstance(), "siege_engines"); NamespacedKey key = new NamespacedKey(SiegeEngines.getInstance(), "siege_engines");
@EventHandler @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = false)
public void DeathEvent(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) {
@@ -864,16 +870,7 @@ public class ClickHandler implements Listener {
} }
} }
if (removeStands) { if (removeStands) {
for (UUID key : SiegeEngines.siegeEngineEntitiesPerPlayer.keySet()) { PlayerHandler.siegeEngineEntityDied(event.getEntity());
if (SiegeEngines.siegeEngineEntitiesPerPlayer.get(key) != null) {
final List<Entity> entities = new ArrayList<>(
SiegeEngines.siegeEngineEntitiesPerPlayer.get(key));
if (entities.contains(event.getEntity())) {
entities.remove(event.getEntity());
SiegeEngines.siegeEngineEntitiesPerPlayer.put(key, entities);
}
}
}
for (ItemStack i : items) { for (ItemStack i : items) {
if (i.getType() == Material.ARMOR_STAND) { if (i.getType() == Material.ARMOR_STAND) {
i.setAmount(0); i.setAmount(0);
@@ -1035,7 +1032,7 @@ 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.releasePlayerSiegeEngine(player,entity); if (isSiegeEngine(entity, false)) PlayerHandler.siegeEngineEntityDied(entity);
else PlayerHandler.releasePlayerSiegeEngine(player,null); else PlayerHandler.releasePlayerSiegeEngine(player,null);
if (SiegeEngines.activeSiegeEngines.containsKey(entity.getUniqueId())) { if (SiegeEngines.activeSiegeEngines.containsKey(entity.getUniqueId())) {
SiegeEngines.activeSiegeEngines.remove(entity.getUniqueId()); SiegeEngines.activeSiegeEngines.remove(entity.getUniqueId());
@@ -1113,5 +1110,62 @@ public class ClickHandler implements Listener {
} }
} }
} }
if (entity.getType() == EntityType.RAVAGER || entity.getType() == EntityType.HORSE || entity.getType() == EntityType.DONKEY) {
if (player.getInventory().getItemInMainHand().getType() == Material.CARVED_PUMPKIN) {
final ItemStack item = player.getInventory().getItemInMainHand();
if (item.getItemMeta() != null && item.getItemMeta().hasCustomModelData()) {
int customModel = item.getItemMeta().getCustomModelData();
SiegeEngine siegeEngine = null;
// Search for match in custom model data value in defined siege engines
for (SiegeEngine entry : SiegeEngines.definedSiegeEngines.values()) {
if (entry.customModelID == customModel) {
try {
siegeEngine = entry.clone();
} catch (CloneNotSupportedException e) {
}
break;
} else {
// if siege engine was broken during one of its firing stages
if (entry.firingModelNumbers.contains(customModel)) {
try {
siegeEngine = entry.clone();
} catch (CloneNotSupportedException e) {
break;
}
}
}
}
// If SiegeEngine found, place it
if (siegeEngine != null) {
if (!siegeEngine.canMount) {
player.sendMessage("§eThis type of Siege Engine cannot be mounted to mobs.");
event.setCancelled(true);
return;
}
if (Config.disabledWorlds.contains(entity.getWorld())) {
player.sendMessage("§eSiege Engines cannot be placed in this World.");
event.setCancelled(true);
}
if (fluidMaterials.contains(entity.getLocation().getBlock().getType())) {
player.sendMessage("§eSiege Engines cannot be placed in Fluid Blocks.");
event.setCancelled(true);
}
if (event.isCancelled()) {
return;
}
if (siegeEngine.place(player, entity.getLocation(),entity)) {
item.setAmount(item.getAmount() - 1);
player.getInventory().setItemInMainHand(item);
player.sendMessage("§eSiege Engine mounted to the "+entity.getType().toString().toLowerCase()+"!");
} else {
player.sendMessage(
"§eSiege Engine cannot be placed within a 2.5 Block-Radius of other Siege Engines.");
}
event.setCancelled(true);
}
}
}
return;
}
} }
} }
@@ -29,35 +29,37 @@ public class PlayerHandler implements Listener {
public void playerDeathEvent(PlayerDeathEvent event) { public void playerDeathEvent(PlayerDeathEvent event) {
playerJoinLeave(event.getPlayer()); playerJoinLeave(event.getPlayer());
} }
@EventHandler
public void entityDeathEvent(EntityDeathEvent event) {
siegeEngineEntityDied(event.getEntity());
}
public static void siegeEngineEntityDied(Entity entity) { public static void siegeEngineEntityDied(Entity entity) {
for (UUID uuid : SiegeEngines.siegeEngineEntitiesPerPlayer.keySet()) { for (UUID uuid : SiegeEngines.siegeEngineEntitiesPerPlayer.keySet()) {
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 (SiegeEngines.siegeEngineEntitiesPerPlayer.get(uuid).contains(entity.getUniqueId())) { if (SiegeEngines.siegeEngineEntitiesPerPlayer.get(uuid).contains(entity.getUniqueId())) {
list.remove(entity); list.remove(entity);
SiegeEngines.activeSiegeEngines.remove(entity.getUniqueId());
SiegeEngines.siegeEngineEntitiesPerPlayer.put(uuid,list); SiegeEngines.siegeEngineEntitiesPerPlayer.put(uuid,list);
} }
} }
} }
} }
public static void playerJoinLeave(Player player) { public static void playerJoinLeave(Player player) {
if (SiegeEngines.siegeEngineEntitiesPerPlayer.containsKey(player.getUniqueId())) { if (player == null) return;
final List<Entity> list = new ArrayList<>(SiegeEngines.siegeEngineEntitiesPerPlayer.get(player.getUniqueId())); final UUID uuid = player.getUniqueId();
if (SiegeEngines.siegeEngineEntitiesPerPlayer.containsKey(uuid)) {
final List<Entity> list = new ArrayList<>(SiegeEngines.siegeEngineEntitiesPerPlayer.get(uuid));
list.clear(); list.clear();
SiegeEngines.siegeEngineEntitiesPerPlayer.put(player.getUniqueId(),list); SiegeEngines.siegeEngineEntitiesPerPlayer.put(uuid,list);
SiegeEngines.siegeEngineEntitiesPerPlayer.remove(uuid);
} }
} }
public static void releasePlayerSiegeEngine(Player player, Entity entity) { public static void releasePlayerSiegeEngine(Player player, Entity entity) {
UUID uuid = player.getUniqueId(); if (player == null) return;
final UUID uuid = player.getUniqueId();
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())) { if (SiegeEngines.siegeEngineEntitiesPerPlayer.get(uuid).contains(entity.getUniqueId())) {
list.remove(entity); list.remove(entity);
SiegeEngines.activeSiegeEngines.remove(entity.getUniqueId());
SiegeEngines.siegeEngineEntitiesPerPlayer.put(uuid,list); SiegeEngines.siegeEngineEntitiesPerPlayer.put(uuid,list);
player.sendMessage("§eReleased this SiegeEngine!"); player.sendMessage("§eReleased this SiegeEngine!");
} }
@@ -66,6 +68,7 @@ public class PlayerHandler implements Listener {
list.clear(); list.clear();
player.sendMessage("§eReleased all SiegeEngines!"); player.sendMessage("§eReleased all SiegeEngines!");
SiegeEngines.siegeEngineEntitiesPerPlayer.put(uuid,list); SiegeEngines.siegeEngineEntitiesPerPlayer.put(uuid,list);
SiegeEngines.siegeEngineEntitiesPerPlayer.remove(uuid);
} }
} }
} }
@@ -26,30 +26,40 @@ import com.github.alathra.siegeengines.config.Config;
public class RotationHandler implements Listener { public class RotationHandler implements Listener {
@EventHandler @EventHandler
public void playerMove(PlayerMoveEvent event) { public void onPlayerMove(PlayerMoveEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
NamespacedKey key = new NamespacedKey(SiegeEngines.getInstance(), "siege_engines"); NamespacedKey key = new NamespacedKey(SiegeEngines.getInstance(), "siege_engines");
if (SiegeEngines.siegeEngineEntitiesPerPlayer.containsKey(player.getUniqueId())) { if (SiegeEngines.siegeEngineEntitiesPerPlayer.containsKey(player.getUniqueId())) {
ItemStack itemInHand = player.getInventory().getItemInMainHand(); ItemStack itemInHand = player.getInventory().getItemInMainHand();
if (itemInHand != null) { if (itemInHand != null) {
if (itemInHand.getType() != Config.controlItem) {
// TrackedStands.remove(player.getUniqueId());
return;
}
final List<Entity> list = new ArrayList<>(SiegeEngines.siegeEngineEntitiesPerPlayer.get(player.getUniqueId())); final List<Entity> list = new ArrayList<>(SiegeEngines.siegeEngineEntitiesPerPlayer.get(player.getUniqueId()));
final List<Entity> concurrentFix = new ArrayList<>(list); final List<Entity> concurrentFix = new ArrayList<>(list);
for (Entity ent : list) { for (Entity ent : list) {
if (ent != null) { if (ent != null) {
SiegeEngine equipment = SiegeEngines.activeSiegeEngines.get(ent.getUniqueId()); SiegeEngine equipment = SiegeEngines.activeSiegeEngines.get(ent.getUniqueId());
if (equipment == null) continue; if (equipment == null) continue;
final LivingEntity living = (LivingEntity) ent;
if (Config.disabledWorlds.contains(ent.getWorld())) {
PlayerHandler.siegeEngineEntityDied(ent);
living.setHealth(0.0d);
continue;
}
if (!(ent.getLocation().getWorld().equals(player.getLocation().getWorld()))) {
PlayerHandler.releasePlayerSiegeEngine(player, ent);
continue;
}
final double distance = player.getLocation().distance(ent.getLocation());
if (distance >= Config.controlDistance) {
PlayerHandler.releasePlayerSiegeEngine(player, ent);
continue;
}
if (itemInHand.getType() != Config.controlItem) {
continue;
}
if (ent.isDead()) { if (ent.isDead()) {
continue; continue;
} }
double distance = player.getLocation().distance(ent.getLocation());
if (distance <= Config.rotateDistance) { if (distance <= Config.rotateDistance) {
// player.sendMessage("§egot id");
LivingEntity living = (LivingEntity) ent;
Location loc = ent.getLocation(); Location loc = ent.getLocation();
if (equipment.rotateSideways) { if (equipment.rotateSideways) {
@@ -60,12 +70,10 @@ public class RotationHandler implements Listener {
Entity base = Bukkit.getEntity(UUID.fromString(ent.getPersistentDataContainer().get(key, PersistentDataType.STRING))); Entity base = Bukkit.getEntity(UUID.fromString(ent.getPersistentDataContainer().get(key, PersistentDataType.STRING)));
Location baseloc = base.getLocation(); Location baseloc = base.getLocation();
baseloc.setDirection(dirBetweenLocations); baseloc.setDirection(dirBetweenLocations);
base.teleport(baseloc); base.teleport(baseloc,io.papermc.paper.entity.TeleportFlag.EntityState.values());
} }
loc.setDirection(dirBetweenLocations); loc.setDirection(dirBetweenLocations);
} }
//loc.setYaw(player.getLocation().getYaw());
//loc.setPitch(player.getLocation().getPitch());
ArmorStand stand = (ArmorStand) living; ArmorStand stand = (ArmorStand) living;
@@ -84,11 +92,8 @@ public class RotationHandler implements Listener {
} }
living.teleport(loc); living.teleport(loc,io.papermc.paper.entity.TeleportFlag.EntityState.values());
equipment.ShowFireLocation(player); equipment.ShowFireLocation(player);
} else {
PlayerHandler.releasePlayerSiegeEngine(player, ent);
continue;
} }
} }
} }
@@ -24,7 +24,7 @@ public class EntityProjectile extends SiegeEngineProjectile {
public int delayTime = 6; public int delayTime = 6;
public EntityType entityType = EntityType.ARROW; public EntityType entityType = EntityType.ARROW;
public float inaccuracy = 0.2f; public float inaccuracy = 0.2f;
public Particle particleType = Particle.EXPLOSION_LARGE; public Particle particleType = Particle.CAMPFIRE_SIGNAL_SMOKE;
public Sound soundType = Sound.ENTITY_GENERIC_EXPLODE; public Sound soundType = Sound.ENTITY_GENERIC_EXPLODE;
private boolean playSound = true; private boolean playSound = true;
@@ -62,7 +62,6 @@ public class EntityProjectile extends SiegeEngineProjectile {
arrow.setVelocity(loc.getDirection().multiply(velocity)); arrow.setVelocity(loc.getDirection().multiply(velocity));
} }
arrow.setMetadata("isEntityProj", SiegeEnginesUtil.addMetaDataValue("true")); arrow.setMetadata("isEntityProj", SiegeEnginesUtil.addMetaDataValue("true"));
Bukkit.getServer().getPluginManager().callEvent(new org.bukkit.event.entity.ProjectileLaunchEvent(arrow));
if (arrow instanceof org.bukkit.entity.Projectile) { if (arrow instanceof org.bukkit.entity.Projectile) {
if (player instanceof org.bukkit.projectiles.ProjectileSource) if (player instanceof org.bukkit.projectiles.ProjectileSource)
@@ -75,6 +74,8 @@ public class EntityProjectile extends SiegeEngineProjectile {
arr.setShooter((org.bukkit.projectiles.ProjectileSource) player); arr.setShooter((org.bukkit.projectiles.ProjectileSource) player);
arr.setPickupStatus(org.bukkit.entity.AbstractArrow.PickupStatus.CREATIVE_ONLY); arr.setPickupStatus(org.bukkit.entity.AbstractArrow.PickupStatus.CREATIVE_ONLY);
} }
} else {
Bukkit.getServer().getPluginManager().callEvent(new org.bukkit.event.entity.ProjectileLaunchEvent(arrow));
} }
if (playSound) { if (playSound) {
world.playSound(loc, this.soundType, 20, 2); world.playSound(loc, this.soundType, 20, 2);
@@ -23,7 +23,7 @@ public class FireworkProjectile extends SiegeEngineProjectile {
public int delayTime = 6; public int delayTime = 6;
public EntityType entityType = EntityType.FIREWORK; public EntityType entityType = EntityType.FIREWORK;
public float inaccuracy = 0.125f; public float inaccuracy = 0.125f;
public Particle particleType = Particle.EXPLOSION_NORMAL; public Particle particleType = Particle.FLASH;
public Sound soundType = Sound.ENTITY_FIREWORK_ROCKET_BLAST_FAR; public Sound soundType = Sound.ENTITY_FIREWORK_ROCKET_BLAST_FAR;
public float velocityFactor = 0.5f; public float velocityFactor = 0.5f;
@@ -57,7 +57,7 @@ public class PotionProjectile extends SiegeEngineProjectile {
} else { } else {
arrow.setVelocity(loc.getDirection().multiply(velocity)); arrow.setVelocity(loc.getDirection().multiply(velocity));
} }
arrow.setMetadata("isExplosiveProj", SiegeEnginesUtil.addMetaDataValue("true")); arrow.setMetadata("isPotionProj", SiegeEnginesUtil.addMetaDataValue("true"));
Bukkit.getServer().getPluginManager().callEvent(new org.bukkit.event.entity.ProjectileLaunchEvent(arrow)); Bukkit.getServer().getPluginManager().callEvent(new org.bukkit.event.entity.ProjectileLaunchEvent(arrow));
ItemStack itemStack = new ItemStack(Material.SPLASH_POTION); ItemStack itemStack = new ItemStack(Material.SPLASH_POTION);
PotionMeta potionMeta = (PotionMeta) itemStack.getItemMeta(); PotionMeta potionMeta = (PotionMeta) itemStack.getItemMeta();
+26 -19
View File
@@ -15,17 +15,20 @@ config-version: 1
ControlItem: CLOCK ControlItem: CLOCK
# 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: 64 ControlDistance: 24
# The maximum distance the player can be away from the SiegeEngine before rotation control is terminated # The maximum distance the player can be away from the SiegeEngine before rotation control is terminated
RotateDistance: 32 RotateDistance: 16
# The maximum siege engines a player can control at the same time # The maximum siege engines a player can control at the same time
MaxSiegeEnginesControlled: 5 MaxSiegeEnginesControlled: 1
# The auto-reload feature by shift-clicking # The auto-reload feature by shift-clicking
AutoReload: false AutoReload: false
DisabledWorlds:
- world_nether
- World-o_nether
# ====================================== # ======================================
# | SiegeEngine Options | # | SiegeEngine Options |
@@ -34,43 +37,43 @@ AutoReload: false
Projectiles: Projectiles:
StoneShot: StoneShot:
ProjectileType: EXPLOSIVE ProjectileType: EXPLOSIVE
ExplodePower: 1.5 ExplodePower: 3.25
Inaccuracy: 0.125 Inaccuracy: 0.125
ProjectileCount: 1 ProjectileCount: 1
AmmoItem: COBBLESTONE AmmoItem: COBBLESTONE
FireSound: ENTITY_GENERIC_EXPLODE FireSound: ENTITY_GENERIC_EXPLODE
BreachShot: BreachShot:
ProjectileType: EXPLOSIVE ProjectileType: EXPLOSIVE
ExplodePower: 3.75 ExplodePower: 5.25
Inaccuracy: 0.3 Inaccuracy: 0.375
ProjectileCount: 1 ProjectileCount: 1
AmmoItem: IRON_BLOCK AmmoItem: IRON_BLOCK
FireSound: ENTITY_GENERIC_EXPLODE FireSound: ENTITY_GENERIC_EXPLODE
RepeatingShot: RepeatingShot:
ProjectileType: EXPLOSIVE ProjectileType: EXPLOSIVE
ExplodePower: 1.0 ExplodePower: 1.75
Inaccuracy: 0.325 Inaccuracy: 0.525
ProjectileCount: 5 ProjectileCount: 6
AmmoItem: TNT AmmoItem: TNT
FireSound: ENTITY_GENERIC_EXPLODE FireSound: ENTITY_GENERIC_EXPLODE
ScatterShot: ScatterShot:
ProjectileType: ENTITY ProjectileType: ENTITY
Inaccuracy: 0.325 Inaccuracy: 0.365
EntityCount: 24 EntityCount: 24
EntityType: ARROW EntityType: ARROW
AmmoItem: GRAVEL AmmoItem: GRAVEL
FireSound: ENTITY_GENERIC_EXPLODE FireSound: ITEM_CROSSBOW_SHOOT
BallistaBoltShot: BallistaBoltShot:
ProjectileType: ENTITY ProjectileType: ENTITY
Inaccuracy: 0.025 Inaccuracy: 0.0125
EntityCount: 1 EntityCount: 1
EntityType: ARROW EntityType: ARROW
AmmoItem: ARROW AmmoItem: ARROW
FireSound: ITEM_CROSSBOW_SHOOT FireSound: ITEM_CROSSBOW_SHOOT
DragonsBreath: DragonsBreath:
ProjectileType: ENTITY ProjectileType: ENTITY
Inaccuracy: 0.25 Inaccuracy: 0.125
EntityCount: 3 EntityCount: 1
EntityType: DRAGON_FIREBALL EntityType: DRAGON_FIREBALL
AmmoItem: DRAGON_BREATH AmmoItem: DRAGON_BREATH
FireSound: ENTITY_GENERIC_EXPLODE FireSound: ENTITY_GENERIC_EXPLODE
@@ -91,7 +94,7 @@ Projectiles:
SiegeEngines: SiegeEngines:
Trebuchet: Trebuchet:
ShotAmount: 1 ShotAmount: 1
VelocityPerFuel: 0.3 VelocityPerFuel: 0.75
MaxFuel: 3 MaxFuel: 3
FuelItem: STRING FuelItem: STRING
Projectiles: Projectiles:
@@ -102,9 +105,10 @@ SiegeEngines:
ItemName: "&e&lTrebuchet" ItemName: "&e&lTrebuchet"
Lore: Lore:
- "&ePlace as a block to spawn a Trebuchet" - "&ePlace as a block to spawn a Trebuchet"
CanMount: false
Ballista: Ballista:
ShotAmount: 1 ShotAmount: 1
VelocityPerFuel: 1.25 VelocityPerFuel: 0.975
MaxFuel: 2 MaxFuel: 2
FuelItem: STRING FuelItem: STRING
Projectiles: Projectiles:
@@ -115,22 +119,25 @@ SiegeEngines:
ItemName: "&e&lBallista" ItemName: "&e&lBallista"
Lore: Lore:
- "&ePlace as a block to spawn a Ballista" - "&ePlace as a block to spawn a Ballista"
CanMount: false
SwivelCannon: SwivelCannon:
ShotAmount: 1 ShotAmount: 1
VelocityPerFuel: 1.0125 VelocityPerFuel: 0.975
MaxFuel: 5 MaxFuel: 5
FuelItem: GUNPOWDER FuelItem: GUNPOWDER
Projectiles: Projectiles:
- StoneShot - StoneShot
- RepeatingShot
- ScatterShot - ScatterShot
- FireShot - FireShot
- FireworkShot - FireworkShot
ItemName: "&e&lSwivel Cannon" ItemName: "&e&lSwivel Cannon"
Lore: Lore:
- "&ePlace as a block to spawn a Swivel Cannon" - "&ePlace as a block to spawn a Swivel Cannon"
CanMount: false
BreachCannon: BreachCannon:
ShotAmount: 1 ShotAmount: 1
VelocityPerFuel: 0.975 VelocityPerFuel: 1.0625
MaxFuel: 4 MaxFuel: 4
FuelItem: GUNPOWDER FuelItem: GUNPOWDER
Projectiles: Projectiles:
@@ -142,4 +149,4 @@ SiegeEngines:
ItemName: "&e&lBreach Cannon" ItemName: "&e&lBreach Cannon"
Lore: Lore:
- "&ePlace as a block to spawn a Breach Cannon" - "&ePlace as a block to spawn a Breach Cannon"
CanMount: false