Updated Some stuff, Ported over my Changes

Hi!
This commit is contained in:
C_Corp2002 committed 2024-01-05 21:59:11 -05:00
1 parent 4283710716
commit 09eecbb8ee
4 files changed
+1500 -1478

No files matched your search

@@ -1,405 +1,411 @@
package com.github.alathra.siegeengines;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Random;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import com.github.alathra.siegeengines.command.CommandHandler;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.Particle;
import org.bukkit.Sound;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.ArmorStand.LockType;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.metadata.MetadataValueAdapter;
import org.bukkit.metadata.FixedMetadataValue;
//import com.palmergames.bukkit.towny.Towny;
import com.github.alathra.siegeengines.listeners.ClickHandler;
import com.github.alathra.siegeengines.listeners.RotationHandler;
import com.github.alathra.siegeengines.projectile.EntityProjectile;
import com.github.alathra.siegeengines.projectile.ExplosiveProjectile;
import com.github.alathra.siegeengines.projectile.GunnersProjectile;
//import GunnersProjectiles.EntityProjectile;
//import GunnersProjectiles.GunnersProjectile;
//import GunnersProjectiles.ExplosiveProjectile;
//import GunnersProjectiles.PotionProjectile;
public class SiegeEngines extends JavaPlugin {
public static SiegeEngines instance;
public static Plugin plugin;
public static MetadataValueAdapter metadata;
public static Random random = new Random();
private static String Path;
private CommandHandler commandHandler;
//public static Towny towny;
public static SiegeEngines getInstance() {
return instance;
}
@Override
public void onLoad() {
plugin = this;
commandHandler = new CommandHandler(this);
commandHandler.onLoad();
}
@SuppressWarnings("deprecation")
@Override
public void onEnable() {
instance = this;
Path = this.getDataFolder().getAbsolutePath();
//this.getCommand("SiegeEngines").setExecutor(new GunnersCommand()); // Fixed Start-up
getServer().getPluginManager().registerEvents(new RotationHandler(), this);
getServer().getPluginManager().registerEvents(new ClickHandler(), this);
//StorageManager.setup(Path, plugin);
equipment.clear();
TrackedStands.clear();
DefinedEquipment.clear();
//AddDefaults();
//HashMap<ItemStack,GunnersProjectile> projObj = new HashMap<>();
//GunnerEquipment equip = CreateNewGun(null, null, null, null, null, null, projObj);
for (SiegeEquipment i : DefinedEquipment.values()) {
System.out.println("§eEnabled Weapon : " + i.EquipmentName);
System.out.println("§eWeapon Propellant/\"Fuel\" ItemStacks : " + i.FuelMaterial);
for (ItemStack proj : i.Projectiles.keySet()) {
System.out.println("§eWeapon Projectile ItemStacks : " + proj);
}
}
commandHandler.onEnable();
}
@SuppressWarnings("deprecation")
@Override
public void onDisable() {
commandHandler.onDisable();
for (SiegeEquipment equip : equipment.values()) {
if (equip.Entity != null) {
ItemStack item = new ItemStack(Material.CARVED_PUMPKIN);
ItemMeta meta = item.getItemMeta();
equip.AmmoHolder = new EquipmentMagazine();
meta.setCustomModelData(equip.ReadyModelNumber);
meta.setDisplayName("§e" + equip.EquipmentName + " Item");
List<String> Lore = new ArrayList<String>();
Lore.add("§ePlace as a block to spawn a " + equip.EquipmentName + " or put on an Armor Stand.");
meta.setLore(Lore);
item.setItemMeta(meta);
((LivingEntity) equip.Entity).getEquipment().setHelmet(item);
}
}
}
public static FixedMetadataValue addMetaDataValue(Object value) {
return new FixedMetadataValue(Bukkit.getServer().getPluginManager().getPlugin("SiegeEngines"), value);
}
public static SiegeEquipment CreateClone(Integer ModelId) {
try {
return DefinedEquipment.get(ModelId).clone();
} catch (CloneNotSupportedException e) {
// TODO Auto-generated catch block
}
return null;
}
public static HashMap<Integer, SiegeEquipment> DefinedEquipment = new HashMap<Integer, SiegeEquipment>();
public static HashMap<UUID, List<Entity>> TrackedStands = new HashMap<UUID, List<Entity>>();
public static HashMap<UUID, SiegeEquipment> equipment = new HashMap<UUID, SiegeEquipment>();
public static String convertTime(long time) {
long days = TimeUnit.MILLISECONDS.toDays(time);
time -= TimeUnit.DAYS.toMillis(days);
long hours = TimeUnit.MILLISECONDS.toHours(time);
time -= TimeUnit.HOURS.toMillis(hours);
long minutes = TimeUnit.MILLISECONDS.toMinutes(time);
time -= TimeUnit.MINUTES.toMillis(minutes);
long seconds = TimeUnit.MILLISECONDS.toSeconds(time);
String timeLeftFormatted = String.format("§e" + minutes + " Minutes " + seconds + " Seconds§f");
return timeLeftFormatted;
}
public static SiegeEquipment CreateNewGun(String name, Integer XOffset, Integer YOffset, Integer fuelMax, Float fuelVelocityMod, Integer customModelId, HashMap<ItemStack, GunnersProjectile> projObj) {
SiegeEquipment equip = new SiegeEquipment();
if (customModelId == null || customModelId == 0)
customModelId = 150;
if (name == null)
name = "Light Turret";
if (XOffset == null)
XOffset = 0;
if (YOffset == null)
YOffset = 0;
if (fuelMax == null)
fuelMax = 0;
if (fuelVelocityMod == null)
fuelVelocityMod = 0.95f;
equip.EquipmentName = name;
equip.EquipmentId = equip.EquipmentName.replaceAll(" ", "_").toLowerCase();
equip.XOffset = XOffset;
equip.YOffset = YOffset;
equip.RotateStandHead = true;
equip.RotateSideways = true;
equip.PlacementOffsetY = -1.125f;
equip.ReadyModelNumber = customModelId;
equip.ModelNumberToFireAt = customModelId;
equip.FiringModelNumbers = new ArrayList<Integer>();
equip.VelocityPerFuel = fuelVelocityMod;
equip.FuelMaterial = new ItemStack(Material.GUNPOWDER);
equip.CycleThroughModelsBeforeFiring = false;
equip.AllowInvisibleStand = false;
equip.MaxFuel = fuelMax;
equip.shotAmount = 1;
equip.AmmoHolder.LoadedFuel = fuelMax;
EntityProjectile defaultProj = new EntityProjectile();
defaultProj.EntityCount = 2;
defaultProj.EntityTyp = EntityType.SHULKER_BULLET;
defaultProj.ParticleType = Particle.WHITE_ASH;
defaultProj.SoundType = Sound.ENTITY_BLAZE_SHOOT;
if (projObj.keySet().isEmpty() || projObj.isEmpty())
projObj.put(new ItemStack(Material.GUNPOWDER), defaultProj);
for (ItemStack mat : projObj.keySet()) {
equip.Projectiles.put(mat, projObj.get(mat));
}
DefinedEquipment.put(equip.ReadyModelNumber, equip);
return equip;
}
public static void AddDefaults() {
SiegeEquipment equip = new SiegeEquipment();
equip.EquipmentName = "Trebuchet";
equip.XOffset = 5;
equip.YOffset = 5;
equip.VelocityPerFuel = 0.3f;
ExplosiveProjectile proj = new ExplosiveProjectile();
proj.ExplodePower = 2;
equip.shotAmount = 1;
equip.RotateStandHead = false;
equip.RotateSideways = true;
equip.FuelMaterial = new ItemStack(Material.STRING);
equip.Projectiles.put(new ItemStack(Material.COBBLESTONE), proj);
equip.ReadyModelNumber = 122;
equip.ModelNumberToFireAt = 135;
equip.MillisecondsBetweenFiringStages = 2;
equip.MillisecondsBetweenReloadingStages = 10;
equip.FiringModelNumbers = new ArrayList<>(Arrays.asList(
123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139
));
equip.CycleThroughModelsBeforeFiring = true;
DefinedEquipment.put(equip.ReadyModelNumber, equip);
equip = new SiegeEquipment();
equip.EquipmentName = "Naval Cannon";
equip.Projectiles.put(new ItemStack(Material.COBBLESTONE), proj);
equip.PlacementOffsetY = -1;
equip.shotAmount = 1;
equip.ReadyModelNumber = 142;
equip.ModelNumberToFireAt = 142;
equip.FiringModelNumbers = new ArrayList<Integer>();
equip.RotateStandHead = true;
equip.RotateSideways = false;
proj = new ExplosiveProjectile();
proj.ExplodePower = 1;
proj.ProjectilesCount = 3;
proj.DelayedFire = true;
proj.Inaccuracy = 0.75f;
equip.Projectiles.put(new ItemStack(Material.TNT), proj);
proj = new ExplosiveProjectile();
proj.ExplodePower = 4;
proj.ProjectilesCount = 1;
equip.Projectiles.put(new ItemStack(Material.COPPER_BLOCK), proj);
EntityProjectile fireProj = new EntityProjectile();
fireProj.EntityCount = 2;
fireProj.EntityTyp = EntityType.SMALL_FIREBALL;
fireProj.ParticleType = Particle.WHITE_ASH;
fireProj.SoundType = Sound.ENTITY_BLAZE_SHOOT;
equip.Projectiles.put(new ItemStack(Material.FIRE_CHARGE), fireProj);
DefinedEquipment.put(equip.ReadyModelNumber, equip);
equip = new SiegeEquipment();
equip.EquipmentName = "Siege Cannon";
proj.ExplodePower = 2;
equip.Projectiles.put(new ItemStack(Material.COBBLESTONE), proj);
equip.shotAmount = 1;
equip.PlacementOffsetY = -1;
equip.ReadyModelNumber = 141;
equip.ModelNumberToFireAt = 141;
equip.FiringModelNumbers = new ArrayList<Integer>();
equip.RotateStandHead = true;
equip.RotateSideways = true;
proj = new ExplosiveProjectile();
proj.ExplodePower = 1;
proj.ProjectilesCount = 3;
proj.DelayedFire = true;
proj.Inaccuracy = 0.5f;
equip.Projectiles.put(new ItemStack(Material.TNT), proj);
proj = new ExplosiveProjectile();
proj.ExplodePower = 4;
proj.ProjectilesCount = 1;
equip.Projectiles.put(new ItemStack(Material.COPPER_BLOCK), proj);
equip.Projectiles.put(new ItemStack(Material.GRAVEL), new EntityProjectile());
DefinedEquipment.put(equip.ReadyModelNumber, equip);
// EntityProjectile pig = new EntityProjectile();
// pig.EntityCount = 100;
// pig.DelayedFire = true;
// pig.DelayTime = 3;
// pig.EntityTyp = EntityType.ARROW;
// pig.SoundType = Sound.ITEM_CROSSBOW_SHOOT;
// pig.ParticleType = Particle.GLOW;
// equip.Projectiles.put(Material.PORKCHOP, pig);
// equip.Projectiles.put(Material.BONE, new PotionProjectile());
}
public static Boolean CreateCannon(Entity player, int CustomModelData, Location l) {
//l.setY(l.getY() - 1);
l.add(0.5, 0, 0.5);
NamespacedKey key = new NamespacedKey(SiegeEngines.plugin, "cannons");
SiegeEquipment equip = CreateClone(CustomModelData);
if (equip == null || !equip.Enabled) {
return false;
}
l.setY(l.getY() + 1);
int maxNearby = 0;
l.setDirection(player.getFacing().getDirection());
ItemStack item = new ItemStack(Material.CARVED_PUMPKIN);
ItemMeta meta = item.getItemMeta();
String id = "";
equip.AmmoHolder = new EquipmentMagazine();
if (equip.HaseBaseStand) {
Location l2 = l;
l2.setY(l.getY() + equip.BaseStandOffset);
Entity entity3 = player.getWorld().spawnEntity(l, EntityType.ARMOR_STAND);
LivingEntity ent = (LivingEntity) entity3;
ArmorStand stand = (ArmorStand) ent;
id = entity3.getUniqueId().toString();
meta.setCustomModelData(equip.BaseStandModelNumber);
stand.addEquipmentLock(EquipmentSlot.HEAD, LockType.REMOVING_OR_CHANGING);
stand.addEquipmentLock(EquipmentSlot.LEGS, LockType.ADDING_OR_CHANGING);
stand.addEquipmentLock(EquipmentSlot.CHEST, LockType.ADDING_OR_CHANGING);
stand.addEquipmentLock(EquipmentSlot.FEET, LockType.ADDING_OR_CHANGING);
stand.addEquipmentLock(EquipmentSlot.HAND, LockType.REMOVING_OR_CHANGING);
stand.addEquipmentLock(EquipmentSlot.OFF_HAND, LockType.ADDING_OR_CHANGING);
stand.addEquipmentLock(EquipmentSlot.HAND, LockType.REMOVING_OR_CHANGING);
stand.addEquipmentLock(EquipmentSlot.OFF_HAND, LockType.REMOVING_OR_CHANGING);
stand.setBasePlate(false);
// stand.setSmall(true);
item.setItemMeta(meta);
stand.setInvisible(equip.AllowInvisibleStand);
ent.getEquipment().setHelmet(item);
stand.setGravity(false);
stand.setMarker(true);
}
l.setY(l.getY() + equip.PlacementOffsetY);
Entity entity2 = player.getWorld().spawnEntity(l, EntityType.ARMOR_STAND);
if (id != "") {
entity2.getPersistentDataContainer().set(key, PersistentDataType.STRING, id);
}
meta.setCustomModelData(equip.ReadyModelNumber);
meta.setDisplayName("§e" + equip.EquipmentName + " Item");
List<String> Lore = new ArrayList<String>();
Lore.add("§ePlace as a block to spawn a " + equip.EquipmentName + " or put on an Armor Stand.");
meta.setLore(Lore);
item.setItemMeta(meta);
// entity3.addPassenger(entity2);
LivingEntity ent = (LivingEntity) entity2;
ArmorStand stand = (ArmorStand) ent;
equip.Entity = entity2;
for (Entity le : l.getNearbyEntities(5, 5, 5)) {
if (maxNearby >= 4) {
ent.damage(100.0d, player);
return false;
}
if (le instanceof ArmorStand)
maxNearby++;
}
equip.EntityId = entity2.getUniqueId();
stand.addEquipmentLock(EquipmentSlot.HEAD, LockType.REMOVING_OR_CHANGING);
stand.addEquipmentLock(EquipmentSlot.LEGS, LockType.ADDING_OR_CHANGING);
stand.addEquipmentLock(EquipmentSlot.CHEST, LockType.ADDING_OR_CHANGING);
stand.addEquipmentLock(EquipmentSlot.FEET, LockType.ADDING_OR_CHANGING);
stand.addEquipmentLock(EquipmentSlot.HAND, LockType.REMOVING_OR_CHANGING);
stand.addEquipmentLock(EquipmentSlot.OFF_HAND, LockType.ADDING_OR_CHANGING);
stand.addEquipmentLock(EquipmentSlot.HAND, LockType.REMOVING_OR_CHANGING);
stand.addEquipmentLock(EquipmentSlot.OFF_HAND, LockType.REMOVING_OR_CHANGING);
stand.setInvisible(equip.AllowInvisibleStand);
stand.setBasePlate(false);
ent.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 2000000, 1));
// stand.setSmall(true);
stand.setGravity(false);
//stand.setSmall(true);
ent.getEquipment().setHelmet(item);
if (TrackedStands.containsKey(player.getUniqueId())) {
List<Entity> entities = TrackedStands.get(player.getUniqueId());
entities.add(entity2);
TrackedStands.put(player.getUniqueId(), entities);
} else {
List<Entity> newList = new ArrayList<Entity>();
newList.add(entity2);
TrackedStands.put(player.getUniqueId(), newList);
}
equipment.put(entity2.getUniqueId(), equip);
return true;
}
public static void UpdateEntityIdModel(Entity ent, int modelNumber, String WorldName) {
if (ent instanceof LivingEntity) {
LivingEntity liv = (LivingEntity) ent;
ItemStack Helmet = liv.getEquipment().getHelmet();
if (Helmet != null) {
ItemMeta meta = Helmet.getItemMeta();
meta.setCustomModelData(modelNumber);
Helmet.setItemMeta(meta);
liv.getEquipment().setHelmet(Helmet);
// plugin.getLogger().log(Level.INFO, "Updating stand?");
}
}
}
}
package com.github.alathra.siegeengines;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Random;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import com.github.alathra.siegeengines.command.CommandHandler;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.Particle;
import org.bukkit.Sound;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.ArmorStand.LockType;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.metadata.MetadataValueAdapter;
import org.bukkit.metadata.FixedMetadataValue;
//import com.palmergames.bukkit.towny.Towny;
import com.github.alathra.siegeengines.listeners.ClickHandler;
import com.github.alathra.siegeengines.listeners.RotationHandler;
import com.github.alathra.siegeengines.projectile.EntityProjectile;
import com.github.alathra.siegeengines.projectile.ExplosiveProjectile;
import com.github.alathra.siegeengines.projectile.GunnersProjectile;
//import GunnersProjectiles.EntityProjectile;
//import GunnersProjectiles.GunnersProjectile;
//import GunnersProjectiles.ExplosiveProjectile;
//import GunnersProjectiles.PotionProjectile;
public class SiegeEngines extends JavaPlugin {
public static SiegeEngines instance;
public static Plugin plugin;
public static MetadataValueAdapter metadata;
public static Random random = new Random();
private static String Path;
private CommandHandler commandHandler;
//public static Towny towny;
public static SiegeEngines getInstance() {
return instance;
}
@Override
public void onLoad() {
plugin = this;
commandHandler = new CommandHandler(this);
commandHandler.onLoad();
}
@SuppressWarnings("deprecation")
@Override
public void onEnable() {
instance = this;
Path = this.getDataFolder().getAbsolutePath();
//this.getCommand("SiegeEngines").setExecutor(new GunnersCommand()); // Fixed Start-up
getServer().getPluginManager().registerEvents(new RotationHandler(), this);
getServer().getPluginManager().registerEvents(new ClickHandler(), this);
//StorageManager.setup(Path, plugin);
equipment.clear();
TrackedStands.clear();
DefinedEquipment.clear();
//AddDefaults();
//HashMap<ItemStack,GunnersProjectile> projObj = new HashMap<>();
//GunnerEquipment equip = CreateNewGun(null, null, null, null, null, null, projObj);
for (SiegeEquipment i : DefinedEquipment.values()) {
System.out.println("§eEnabled Weapon : " + i.EquipmentName);
System.out.println("§eWeapon Propellant/\"Fuel\" ItemStacks : " + i.FuelMaterial);
for (ItemStack proj : i.Projectiles.keySet()) {
System.out.println("§eWeapon Projectile ItemStacks : " + proj);
}
}
commandHandler.onEnable();
}
@SuppressWarnings("deprecation")
@Override
public void onDisable() {
commandHandler.onDisable();
for (SiegeEquipment equip : equipment.values()) {
if (equip.Entity != null) {
ItemStack item = new ItemStack(Material.CARVED_PUMPKIN);
ItemMeta meta = item.getItemMeta();
equip.AmmoHolder = new EquipmentMagazine();
meta.setCustomModelData(equip.ReadyModelNumber);
meta.setDisplayName("§e" + equip.EquipmentName + " Item");
List<String> Lore = new ArrayList<String>();
Lore.add("§ePlace as a block to spawn a " + equip.EquipmentName + " or put on an Armor Stand.");
meta.setLore(Lore);
item.setItemMeta(meta);
((LivingEntity) equip.Entity).getEquipment().setHelmet(item);
}
}
}
public static FixedMetadataValue addMetaDataValue(Object value) {
return new FixedMetadataValue(Bukkit.getServer().getPluginManager().getPlugin("SiegeEngines"), value);
}
public static SiegeEquipment CreateClone(Integer ModelId) {
try {
return DefinedEquipment.get(ModelId).clone();
} catch (CloneNotSupportedException e) {
// TODO Auto-generated catch block
}
return null;
}
public static HashMap<Integer, SiegeEquipment> DefinedEquipment = new HashMap<Integer, SiegeEquipment>();
public static HashMap<UUID, List<Entity>> TrackedStands = new HashMap<UUID, List<Entity>>();
public static HashMap<UUID, SiegeEquipment> equipment = new HashMap<UUID, SiegeEquipment>();
public static String convertTime(long time) {
long days = TimeUnit.MILLISECONDS.toDays(time);
time -= TimeUnit.DAYS.toMillis(days);
long hours = TimeUnit.MILLISECONDS.toHours(time);
time -= TimeUnit.HOURS.toMillis(hours);
long minutes = TimeUnit.MILLISECONDS.toMinutes(time);
time -= TimeUnit.MINUTES.toMillis(minutes);
long seconds = TimeUnit.MILLISECONDS.toSeconds(time);
String timeLeftFormatted = String.format("§e" + minutes + " Minutes " + seconds + " Seconds§f");
return timeLeftFormatted;
}
public static SiegeEquipment CreateNewGun(String name, Integer XOffset, Integer YOffset, Integer fuelMax, Float fuelVelocityMod, Integer customModelId, HashMap<ItemStack, GunnersProjectile> projObj) {
SiegeEquipment equip = new SiegeEquipment();
if (customModelId == null || customModelId == 0)
customModelId = 150;
if (name == null)
name = "Unnamed Cannon";
if (XOffset == null)
XOffset = 0;
if (YOffset == null)
YOffset = 0;
if (fuelMax == null)
fuelMax = 0;
if (fuelVelocityMod == null)
fuelVelocityMod = 0.95f;
equip.EquipmentName = name;
equip.EquipmentId = equip.EquipmentName.replaceAll(" ", "_").toLowerCase();
equip.XOffset = XOffset;
equip.YOffset = YOffset;
equip.RotateStandHead = true;
equip.RotateSideways = true;
equip.PlacementOffsetY = -1.125f;
equip.ReadyModelNumber = customModelId;
equip.ModelNumberToFireAt = customModelId;
equip.FiringModelNumbers = new ArrayList<Integer>();
equip.VelocityPerFuel = fuelVelocityMod;
equip.FuelMaterial = new ItemStack(Material.GUNPOWDER);
equip.CycleThroughModelsBeforeFiring = false;
equip.AllowInvisibleStand = false;
equip.MaxFuel = fuelMax;
equip.shotAmount = 1;
equip.AmmoHolder.LoadedFuel = fuelMax;
EntityProjectile defaultProj = new EntityProjectile();
defaultProj.EntityCount = 2;
defaultProj.EntityTyp = EntityType.SHULKER_BULLET;
defaultProj.ParticleType = Particle.WHITE_ASH;
defaultProj.SoundType = Sound.ENTITY_BLAZE_SHOOT;
if (projObj.keySet().isEmpty() || projObj.isEmpty())
projObj.put(new ItemStack(Material.GUNPOWDER), defaultProj);
for (ItemStack mat : projObj.keySet()) {
equip.Projectiles.put(mat, projObj.get(mat));
}
DefinedEquipment.put(equip.ReadyModelNumber, equip);
return equip;
}
public static void AddDefaults() {
SiegeEquipment equip = new SiegeEquipment();
equip.EquipmentName = "Trebuchet";
equip.XOffset = 5;
equip.YOffset = 5;
equip.VelocityPerFuel = 0.3f;
ExplosiveProjectile proj = new ExplosiveProjectile();
proj.ExplodePower = 1;
equip.shotAmount = 2;
equip.RotateStandHead = false;
equip.RotateSideways = true;
equip.FuelMaterial = new ItemStack(Material.STRING);
equip.Projectiles.put(new ItemStack(Material.COBBLESTONE), proj);
equip.ReadyModelNumber = 122;
equip.ModelNumberToFireAt = 135;
equip.MillisecondsBetweenFiringStages = 2;
equip.MillisecondsBetweenReloadingStages = 10;
equip.FiringModelNumbers = new ArrayList<>(Arrays.asList(
123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139
));
equip.CycleThroughModelsBeforeFiring = true;
DefinedEquipment.put(equip.ReadyModelNumber, equip);
equip = new SiegeEquipment();
equip.EquipmentName = "Naval Cannon";
equip.Projectiles.put(new ItemStack(Material.COBBLESTONE), proj);
equip.PlacementOffsetY = -1;
equip.shotAmount = 1;
equip.ReadyModelNumber = 142;
equip.ModelNumberToFireAt = 142;
equip.FiringModelNumbers = new ArrayList<Integer>();
equip.RotateStandHead = true;
equip.RotateSideways = false;
proj = new ExplosiveProjectile();
proj.ExplodePower = 1;
proj.ProjectilesCount = 5;
proj.DelayedFire = true;
proj.Inaccuracy = 0.75f;
equip.Projectiles.put(new ItemStack(Material.TNT), proj);
proj = new ExplosiveProjectile();
proj.ExplodePower = 3;
proj.ProjectilesCount = 1;
equip.Projectiles.put(new ItemStack(Material.IRON_BLOCK), proj);
EntityProjectile fireProj = new EntityProjectile();
fireProj.EntityCount = 4;
fireProj.EntityTyp = EntityType.SMALL_FIREBALL;
fireProj.ParticleType = Particle.WHITE_ASH;
fireProj.SoundType = Sound.ENTITY_BLAZE_SHOOT;
fireProj.Inaccuracy = 0.75f;
equip.Projectiles.put(new ItemStack(Material.FIRE_CHARGE), fireProj);
DefinedEquipment.put(equip.ReadyModelNumber, equip);
equip = new SiegeEquipment();
equip.EquipmentName = "Siege Cannon";
proj.ExplodePower = 2;
equip.Projectiles.put(new ItemStack(Material.COBBLESTONE), proj);
equip.shotAmount = 1;
equip.PlacementOffsetY = -1;
equip.ReadyModelNumber = 141;
equip.ModelNumberToFireAt = 141;
equip.FiringModelNumbers = new ArrayList<Integer>();
equip.RotateStandHead = true;
equip.RotateSideways = true;
proj = new ExplosiveProjectile();
proj.ExplodePower = 2;
proj.ProjectilesCount = 3;
proj.DelayedFire = true;
proj.Inaccuracy = 0.75f;
equip.Projectiles.put(new ItemStack(Material.TNT), proj);
proj = new ExplosiveProjectile();
proj.ExplodePower = 3;
proj.ProjectilesCount = 1;
equip.Projectiles.put(new ItemStack(Material.IRON_BLOCK), proj);
EntityProjectile scatterShot = new EntityProjectile();
scatterShot.Inaccuracy = 0.5f;
scatterShot.EntityCount = 24;
scatterShot.ParticleType = Particle.ELECTRIC_SPARK;
scatterShot.SoundType = Sound.ITEM_CROSSBOW_SHOOT;
equip.Projectiles.put(new ItemStack(Material.GRAVEL), scatterShot);
DefinedEquipment.put(equip.ReadyModelNumber, equip);
// EntityProjectile pig = new EntityProjectile();
// pig.EntityCount = 100;
// pig.DelayedFire = true;
// pig.DelayTime = 3;
// pig.EntityTyp = EntityType.ARROW;
// pig.SoundType = Sound.ITEM_CROSSBOW_SHOOT;
// pig.ParticleType = Particle.GLOW;
// equip.Projectiles.put(Material.PORKCHOP, pig);
// equip.Projectiles.put(Material.BONE, new PotionProjectile());
}
public static Boolean CreateCannon(Entity player, int CustomModelData, Location l) {
//l.setY(l.getY() - 1);
l.add(0.5, 0, 0.5);
NamespacedKey key = new NamespacedKey(SiegeEngines.plugin, "cannons");
SiegeEquipment equip = CreateClone(CustomModelData);
if (equip == null || !equip.Enabled) {
return false;
}
l.setY(l.getY() + 1);
int maxNearby = 0;
l.setDirection(player.getFacing().getDirection());
ItemStack item = new ItemStack(Material.CARVED_PUMPKIN);
ItemMeta meta = item.getItemMeta();
String id = "";
equip.AmmoHolder = new EquipmentMagazine();
if (equip.HaseBaseStand) {
Location l2 = l;
l2.setY(l.getY() + equip.BaseStandOffset);
Entity entity3 = player.getWorld().spawnEntity(l, EntityType.ARMOR_STAND);
LivingEntity ent = (LivingEntity) entity3;
ArmorStand stand = (ArmorStand) ent;
id = entity3.getUniqueId().toString();
meta.setCustomModelData(equip.BaseStandModelNumber);
stand.addEquipmentLock(EquipmentSlot.HEAD, LockType.REMOVING_OR_CHANGING);
stand.addEquipmentLock(EquipmentSlot.LEGS, LockType.ADDING_OR_CHANGING);
stand.addEquipmentLock(EquipmentSlot.CHEST, LockType.ADDING_OR_CHANGING);
stand.addEquipmentLock(EquipmentSlot.FEET, LockType.ADDING_OR_CHANGING);
stand.addEquipmentLock(EquipmentSlot.HAND, LockType.REMOVING_OR_CHANGING);
stand.addEquipmentLock(EquipmentSlot.OFF_HAND, LockType.ADDING_OR_CHANGING);
stand.addEquipmentLock(EquipmentSlot.HAND, LockType.REMOVING_OR_CHANGING);
stand.addEquipmentLock(EquipmentSlot.OFF_HAND, LockType.REMOVING_OR_CHANGING);
stand.setBasePlate(false);
// stand.setSmall(true);
item.setItemMeta(meta);
stand.setInvisible(equip.AllowInvisibleStand);
ent.getEquipment().setHelmet(item);
stand.setGravity(false);
stand.setMarker(true);
}
l.setY(l.getY() + equip.PlacementOffsetY);
Entity entity2 = player.getWorld().spawnEntity(l, EntityType.ARMOR_STAND);
if (id != "") {
entity2.getPersistentDataContainer().set(key, PersistentDataType.STRING, id);
}
meta.setCustomModelData(equip.ReadyModelNumber);
meta.setDisplayName("§e" + equip.EquipmentName + " Item");
List<String> Lore = new ArrayList<String>();
Lore.add("§ePlace as a block to spawn a " + equip.EquipmentName + " or put on an Armor Stand.");
meta.setLore(Lore);
item.setItemMeta(meta);
// entity3.addPassenger(entity2);
LivingEntity ent = (LivingEntity) entity2;
ArmorStand stand = (ArmorStand) ent;
equip.Entity = entity2;
for (Entity le : l.getNearbyEntities(5, 5, 5)) {
if (maxNearby >= 4) {
ent.damage(100.0d, player);
return false;
}
if (le instanceof ArmorStand)
maxNearby++;
}
equip.EntityId = entity2.getUniqueId();
stand.addEquipmentLock(EquipmentSlot.HEAD, LockType.REMOVING_OR_CHANGING);
stand.addEquipmentLock(EquipmentSlot.LEGS, LockType.ADDING_OR_CHANGING);
stand.addEquipmentLock(EquipmentSlot.CHEST, LockType.ADDING_OR_CHANGING);
stand.addEquipmentLock(EquipmentSlot.FEET, LockType.ADDING_OR_CHANGING);
stand.addEquipmentLock(EquipmentSlot.HAND, LockType.REMOVING_OR_CHANGING);
stand.addEquipmentLock(EquipmentSlot.OFF_HAND, LockType.ADDING_OR_CHANGING);
stand.addEquipmentLock(EquipmentSlot.HAND, LockType.REMOVING_OR_CHANGING);
stand.addEquipmentLock(EquipmentSlot.OFF_HAND, LockType.REMOVING_OR_CHANGING);
stand.setInvisible(equip.AllowInvisibleStand);
stand.setBasePlate(false);
ent.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 2000000, 1));
// stand.setSmall(true);
stand.setGravity(false);
//stand.setSmall(true);
ent.getEquipment().setHelmet(item);
if (TrackedStands.containsKey(player.getUniqueId())) {
List<Entity> entities = TrackedStands.get(player.getUniqueId());
entities.add(entity2);
TrackedStands.put(player.getUniqueId(), entities);
} else {
List<Entity> newList = new ArrayList<Entity>();
newList.add(entity2);
TrackedStands.put(player.getUniqueId(), newList);
}
equipment.put(entity2.getUniqueId(), equip);
return true;
}
public static void UpdateEntityIdModel(Entity ent, int modelNumber, String WorldName) {
if (ent instanceof LivingEntity) {
LivingEntity liv = (LivingEntity) ent;
ItemStack Helmet = liv.getEquipment().getHelmet();
if (Helmet != null) {
ItemMeta meta = Helmet.getItemMeta();
meta.setCustomModelData(modelNumber);
Helmet.setItemMeta(meta);
liv.getEquipment().setHelmet(Helmet);
// plugin.getLogger().log(Level.INFO, "Updating stand?");
}
}
}
}
@@ -1,131 +1,129 @@
package com.github.alathra.siegeengines.command;
import com.github.alathra.siegeengines.SiegeEquipment;
import com.github.alathra.siegeengines.config.Config;
import com.github.alathra.siegeengines.projectile.GunnersProjectile;
import com.github.milkdrinkers.colorparser.ColorParser;
import dev.jorel.commandapi.CommandAPIBukkit;
import dev.jorel.commandapi.CommandAPICommand;
import dev.jorel.commandapi.arguments.ArgumentSuggestions;
import dev.jorel.commandapi.arguments.PlayerArgument;
import dev.jorel.commandapi.arguments.StringArgument;
import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException;
import dev.jorel.commandapi.executors.CommandArguments;
import net.kyori.adventure.text.Component;
import org.bukkit.Material;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import static com.github.alathra.siegeengines.SiegeEngines.*;
public class SiegeEnginesCommand {
public SiegeEnginesCommand() {
new CommandAPICommand("siegeengines")
.withFullDescription("Example command.")
.withShortDescription("Example command.")
.withPermission("siegeengines.command")
.withSubcommands(
commandGet(),
commandGetAll(),
commandReload()
)
.executesPlayer(this::onExecute)
.register();
}
private void onExecute(CommandSender sender, CommandArguments args) {
sender.sendMessage(ColorParser.of("<yellow>Incorrect usage, /SiegeEngines get, /SiegeEngines reload").build());
}
private CommandAPICommand commandGet() {
return new CommandAPICommand("get")
.withPermission("siegeengines.command.get")
.withArguments(
new StringArgument("equipmentid")
.replaceSuggestions(
ArgumentSuggestions.strings(
DefinedEquipment.values().stream().map(gunnerEquipment -> gunnerEquipment.EquipmentId).toList()
)
),
new PlayerArgument("target")
.setOptional(true)
)
.executesPlayer(this::onGet);
}
private CommandAPICommand commandGetAll() {
return new CommandAPICommand("getAll")
.withPermission("siegeengines.command.getAll")
.executesPlayer(this::onGetAll);
}
private CommandAPICommand commandReload() {
return new CommandAPICommand("reload")
.withPermission("siegeengines.command.reload")
.executesPlayer(this::onReload);
}
private void onGet(CommandSender sender, CommandArguments args) throws WrapperCommandSyntaxException {
if (!(args.get("equipmentid") instanceof String equipmentId))
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("<red>Invalid equipment id specified.").build());
Player player = (Player) args.getOptional("target").orElse(sender);
for (SiegeEquipment gunnerEquipment : DefinedEquipment.values()) {
if (gunnerEquipment.equals(equipmentId)) {
giveEquipment(player, gunnerEquipment);
break;
}
}
}
private void onGetAll(CommandSender sender, CommandArguments args) throws WrapperCommandSyntaxException {
if (!(sender instanceof Player player))
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("<red>Only players can use this command.").build());
for (SiegeEquipment i : DefinedEquipment.values()) {
giveEquipment(player, i);
}
}
private void onReload(CommandSender sender, CommandArguments args) throws WrapperCommandSyntaxException {
if (!(sender instanceof Player))
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("<red>Only players can use this command.").build());
equipment.clear();
TrackedStands.clear();
DefinedEquipment.clear();
AddDefaults();
HashMap<ItemStack, GunnersProjectile> projObj = new HashMap<>();
SiegeEquipment equip = CreateNewGun(null, null, null, null, null, null, projObj);
for (SiegeEquipment i : DefinedEquipment.values()) {
sender.sendMessage(ColorParser.of("<yellow>Enabled Weapon : %s".formatted(i.EquipmentName)).build());
sender.sendMessage(ColorParser.of("<yellow>Weapon Propellant/\"Fuel\" ItemStacks : %s".formatted(i.FuelMaterial)).build());
for (ItemStack proj : i.Projectiles.keySet()) {
sender.sendMessage(ColorParser.of("<yellow>Weapon Projectile ItemStacks : %s".formatted(proj)).build());
}
}
Config.reload();
sender.sendMessage("<yellow>Gunners Core configs reloaded");
}
private void giveEquipment(Player player, SiegeEquipment gunnerEquipment) {
ItemStack item = new ItemStack(Material.CARVED_PUMPKIN);
ItemMeta meta = item.getItemMeta();
meta.setCustomModelData(gunnerEquipment.ReadyModelNumber);
meta.displayName(ColorParser.of("<yellow>%s Item".formatted(gunnerEquipment.EquipmentName)).build());
List<Component> lore = new ArrayList<>();
lore.add(ColorParser.of("<yellow>Place as a block to spawn a '%s'".formatted(gunnerEquipment.EquipmentName)).build());
lore.add(ColorParser.of("<yellow>or put on an Armor Stand.").build());
lore.add(ColorParser.of("<yellow>Right click to toggle visibility of stand.").build());
meta.lore(lore);
item.setItemMeta(meta);
player.getInventory().addItem(item);
}
package com.github.alathra.siegeengines.command;
import com.github.alathra.siegeengines.SiegeEquipment;
import com.github.alathra.siegeengines.projectile.GunnersProjectile;
import com.github.milkdrinkers.colorparser.ColorParser;
import dev.jorel.commandapi.CommandAPIBukkit;
import dev.jorel.commandapi.CommandAPICommand;
import dev.jorel.commandapi.arguments.ArgumentSuggestions;
import dev.jorel.commandapi.arguments.PlayerArgument;
import dev.jorel.commandapi.arguments.StringArgument;
import dev.jorel.commandapi.exceptions.WrapperCommandSyntaxException;
import dev.jorel.commandapi.executors.CommandArguments;
import net.kyori.adventure.text.Component;
import org.bukkit.Material;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import static com.github.alathra.siegeengines.SiegeEngines.*;
public class SiegeEnginesCommand {
public SiegeEnginesCommand() {
new CommandAPICommand("siegeengines")
.withFullDescription("Example command.")
.withShortDescription("Example command.")
.withPermission("siegeengines.command")
.withSubcommands(
commandGet(),
commandGetAll(),
commandReload()
)
.executesPlayer(this::onExecute)
.register();
}
private void onExecute(CommandSender sender, CommandArguments args) {
sender.sendMessage(ColorParser.of("<yellow>Incorrect usage, /SiegeEngines get, /SiegeEngines reload").build());
}
private CommandAPICommand commandGet() {
return new CommandAPICommand("get")
.withPermission("siegeengines.command.get")
.withArguments(
new StringArgument("equipmentid")
.replaceSuggestions(
ArgumentSuggestions.strings(
DefinedEquipment.values().stream().map(SiegeEquipment -> SiegeEquipment.EquipmentId).toList()
)
),
new PlayerArgument("target")
.setOptional(true)
)
.executesPlayer(this::onGet);
}
private CommandAPICommand commandGetAll() {
return new CommandAPICommand("getAll")
.withPermission("siegeengines.command.getAll")
.executesPlayer(this::onGetAll);
}
private CommandAPICommand commandReload() {
return new CommandAPICommand("reload")
.withPermission("siegeengines.command.reload")
.executesPlayer(this::onReload);
}
private void onGet(CommandSender sender, CommandArguments args) throws WrapperCommandSyntaxException {
if (!(args.get("equipmentid") instanceof String equipmentId))
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("<red>Invalid equipment id specified.").build());
Player player = (Player) args.getOptional("target").orElse(sender);
for (SiegeEquipment SiegeEquipment : DefinedEquipment.values()) {
if (SiegeEquipment.equals(equipmentId)) {
giveEquipment(player, SiegeEquipment);
break;
}
}
}
private void onGetAll(CommandSender sender, CommandArguments args) throws WrapperCommandSyntaxException {
if (!(sender instanceof Player player))
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("<red>Only players can use this command.").build());
for (SiegeEquipment i : DefinedEquipment.values()) {
giveEquipment(player, i);
}
}
private void onReload(CommandSender sender, CommandArguments args) throws WrapperCommandSyntaxException {
if (!(sender instanceof Player))
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("<red>Only players can use this command.").build());
equipment.clear();
TrackedStands.clear();
DefinedEquipment.clear();
AddDefaults();
HashMap<ItemStack, GunnersProjectile> projObj = new HashMap<>();
//SiegeEquipment equip = CreateNewGun(null, null, null, null, null, null, projObj);
for (SiegeEquipment i : DefinedEquipment.values()) {
sender.sendMessage(ColorParser.of("<yellow>Enabled Weapon : %s".formatted(i.EquipmentName)).build());
sender.sendMessage(ColorParser.of("<yellow>Weapon Propellant/\"Fuel\" ItemStacks : %s".formatted(i.FuelMaterial)).build());
for (ItemStack proj : i.Projectiles.keySet()) {
sender.sendMessage(ColorParser.of("<yellow>Weapon Projectile ItemStacks : %s".formatted(proj)).build());
}
}
sender.sendMessage("<yellow>Gunners Core configs reloaded");
}
private void giveEquipment(Player player, SiegeEquipment SiegeEquipment) {
ItemStack item = new ItemStack(Material.CARVED_PUMPKIN);
ItemMeta meta = item.getItemMeta();
meta.setCustomModelData(SiegeEquipment.ReadyModelNumber);
meta.displayName(ColorParser.of("<yellow>%s Item".formatted(SiegeEquipment.EquipmentName)).build());
List<Component> lore = new ArrayList<>();
lore.add(ColorParser.of("<yellow>Place as a block to spawn a '%s'".formatted(SiegeEquipment.EquipmentName)).build());
lore.add(ColorParser.of("<yellow>or put on an Armor Stand.").build());
lore.add(ColorParser.of("<yellow>Right click to toggle visibility of stand.").build());
meta.lore(lore);
item.setItemMeta(meta);
player.getInventory().addItem(item);
}
}
File diff suppressed because it is too large. Load diff
@@ -1,96 +1,99 @@
package com.github.alathra.siegeengines.listeners;
import java.util.UUID;
import com.github.alathra.siegeengines.SiegeEngines;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.NamespacedKey;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.util.EulerAngle;
import org.bukkit.util.Vector;
import com.github.alathra.siegeengines.SiegeEquipment;
import com.github.alathra.siegeengines.config.Config;
public class RotationHandler implements Listener {
@EventHandler
public void playerMove(PlayerMoveEvent event) {
Player player = event.getPlayer();
NamespacedKey key = new NamespacedKey(SiegeEngines.plugin, "cannons");
if (SiegeEngines.TrackedStands.containsKey(player.getUniqueId())) {
ItemStack itemInHand = player.getInventory().getItemInMainHand();
if (itemInHand != null) {
if (itemInHand.getType() != Config.controlItem) {
// TrackedStands.remove(player.getUniqueId());
return;
}
for (Entity ent : SiegeEngines.TrackedStands.get(player.getUniqueId())) {
if (ent != null) {
SiegeEquipment equipment = SiegeEngines.equipment.get(ent.getUniqueId());
if (ent.isDead()) {
continue;
}
double distance = player.getLocation().distance(ent.getLocation());
if (distance <= 250) {
// player.sendMessage("§egot id");
LivingEntity living = (LivingEntity) ent;
Location loc = ent.getLocation();
if (equipment.RotateSideways) {
Location direction = player.getLocation().add(player.getLocation().getDirection().multiply(50));
Vector dirBetweenLocations = direction.toVector().subtract(loc.toVector());
if (ent.getPersistentDataContainer().has(key, PersistentDataType.STRING)) {
Entity base = Bukkit.getEntity(UUID.fromString(ent.getPersistentDataContainer().get(key, PersistentDataType.STRING)));
Location baseloc = base.getLocation();
baseloc.setDirection(dirBetweenLocations);
base.teleport(baseloc);
}
loc.setDirection(dirBetweenLocations);
}
//loc.setYaw(player.getLocation().getYaw());
//loc.setPitch(player.getLocation().getPitch());
ArmorStand stand = (ArmorStand) living;
if (equipment.RotateUpDown) {
loc.setPitch(player.getLocation().getPitch());
if (loc.getPitch() < -85) {
loc.setPitch(-85);
}
if (loc.getPitch() > 85) {
loc.setPitch(85);
}
if (equipment.RotateStandHead) {
stand.setHeadPose(new EulerAngle(loc.getDirection().getY() * (-1), 0, 0));
}
}
living.teleport(loc);
equipment.ShowFireLocation(player);
}
}
}
}
}
}
Vector getDirectionBetweenLocations(Location Start, Location End) {
Vector from = Start.toVector();
Vector to = End.toVector();
return to.subtract(from);
}
}
package com.github.alathra.siegeengines.listeners;
import java.util.UUID;
import com.github.alathra.siegeengines.SiegeEngines;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.NamespacedKey;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.util.EulerAngle;
import org.bukkit.util.Vector;
import com.github.alathra.siegeengines.SiegeEquipment;
import com.github.alathra.siegeengines.config.Config;
public class RotationHandler implements Listener {
@EventHandler
public void playerMove(PlayerMoveEvent event) {
Player player = event.getPlayer();
NamespacedKey key = new NamespacedKey(SiegeEngines.plugin, "cannons");
if (SiegeEngines.TrackedStands.containsKey(player.getUniqueId())) {
ItemStack itemInHand = player.getInventory().getItemInMainHand();
if (itemInHand != null) {
if (itemInHand.getType() != Config.controlItem) {
// TrackedStands.remove(player.getUniqueId());
return;
}
for (Entity ent : SiegeEngines.TrackedStands.get(player.getUniqueId())) {
if (ent != null) {
SiegeEquipment equipment = SiegeEngines.equipment.get(ent.getUniqueId());
if (ent.isDead()) {
continue;
}
double distance = player.getLocation().distance(ent.getLocation());
if (distance <= 32) {
// player.sendMessage("§egot id");
LivingEntity living = (LivingEntity) ent;
Location loc = ent.getLocation();
if (equipment.RotateSideways) {
Location direction = player.getLocation().add(player.getLocation().getDirection().multiply(50));
Vector dirBetweenLocations = direction.toVector().subtract(loc.toVector());
if (ent.getPersistentDataContainer().has(key, PersistentDataType.STRING)) {
Entity base = Bukkit.getEntity(UUID.fromString(ent.getPersistentDataContainer().get(key, PersistentDataType.STRING)));
Location baseloc = base.getLocation();
baseloc.setDirection(dirBetweenLocations);
base.teleport(baseloc);
}
loc.setDirection(dirBetweenLocations);
}
//loc.setYaw(player.getLocation().getYaw());
//loc.setPitch(player.getLocation().getPitch());
ArmorStand stand = (ArmorStand) living;
if (equipment.RotateUpDown) {
loc.setPitch(player.getLocation().getPitch());
if (loc.getPitch() < -85) {
loc.setPitch(-85);
}
if (loc.getPitch() > 85) {
loc.setPitch(85);
}
if (equipment.RotateStandHead) {
stand.setHeadPose(new EulerAngle(loc.getDirection().getY() * (-1), 0, 0));
}
}
living.teleport(loc);
equipment.ShowFireLocation(player);
} else {
SiegeEngines.TrackedStands.get(player.getUniqueId()).remove(ent);
continue;
}
}
}
}
}
}
public Vector getDirectionBetweenLocations(Location Start, Location End) {
Vector from = Start.toVector();
Vector to = End.toVector();
return to.subtract(from);
}
}