Merge branch 'sherman'

This commit is contained in:
ShermansWorld committed 2024-01-06 21:46:55 -05:00
commit 601936eb15
15 files changed
+717 -787

No files matched your search

+1 -1
View File
@@ -6,7 +6,7 @@
<groupId>com.github.alathra</groupId>
<artifactId>SiegeEngines</artifactId>
<version>0.5.3</version>
<version>0.5.5</version>
<packaging>jar</packaging>
<name>SiegeEngines</name>
@@ -1,10 +0,0 @@
package com.github.alathra.siegeengines;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
public class EquipmentMagazine {
public int LoadedFuel = 0;
public int LoadedProjectile = 0;
public ItemStack MaterialName = new ItemStack(Material.AIR, 1);
}
@@ -0,0 +1,432 @@
package com.github.alathra.siegeengines;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
import com.github.alathra.siegeengines.projectile.EntityProjectile;
import com.github.alathra.siegeengines.projectile.GunnersProjectile;
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.entity.ArmorStand;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.ArmorStand.LockType;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull;
public class SiegeEngine implements Cloneable {
// Core variables
public Boolean enabled;
public String id;
public String worldName;
public UUID entityId;
public Entity entity;
public int yOffset;
public int xOffset;
public int pitchOffset;
public int maxFuel;
public double placementOffsetY;
public float velocityPerFuel;
// Firing variables
public int shotAmount;
public long nextShotTime;
public int millisecondsBetweenFiringStages;
public int millisecondsBetweenReloadingStages;
public int millisecondsToLoad;
public int modelNumberToFireAt;
public boolean cycleThroughModelsBeforeFiring;
public boolean rotateSideways;
public boolean rotateUpDown;
public boolean rotateStandHead;
public boolean hasFired;
public boolean hasReloaded;
public int taskNumber;
public List<Integer> firingModelNumbers;
public int readyModelNumber;
public int nextModelNumber;
public SiegeEngineAmmoHolder ammoHolder;
// Optional variables
public boolean allowInvisibleStand;
public boolean hasBaseStand;
public double baseStandOffset;
public int baseStandModelNumber;
// Passed parameters
public String name = "Unnammed Siege Engine";
public ItemStack fuelItem = new ItemStack(Material.GUNPOWDER);
public HashMap<ItemStack, GunnersProjectile> projectiles;
public int customModelID = 150;
@Override
public SiegeEngine clone() throws CloneNotSupportedException {
return (SiegeEngine) super.clone();
}
public SiegeEngine(@NotNull String name, @NotNull HashMap<ItemStack, GunnersProjectile> projectiles, @NotNull ItemStack fuelItem, int customModelID) {
//String name, Integer XOffset, Integer YOffset, Integer fuelMax, Float fuelVelocityMod, Integer customModelId, HashMap<ItemStack, GunnersProjectile> projObj
// Default custom model data id if it is passes as null
if (customModelID == 0) {
customModelID = 150;
}
// Set Default values
xOffset = 0;
yOffset = 2;
maxFuel = 5;
velocityPerFuel = 1.0125f;
id = name.replaceAll(" ", "_").toLowerCase();
rotateStandHead = true;
rotateSideways = true;
placementOffsetY = -1.125f;
readyModelNumber = customModelID;
modelNumberToFireAt = customModelID;
firingModelNumbers = new ArrayList<Integer>();
ammoHolder = new SiegeEngineAmmoHolder();
//fuelItem = new ItemStack(Material.GUNPOWDER);
cycleThroughModelsBeforeFiring = false;
allowInvisibleStand = false;
shotAmount = 1;
ammoHolder.loadedFuel = maxFuel;
enabled = true;
cycleThroughModelsBeforeFiring = false;
rotateSideways = false;
rotateUpDown = true;
rotateStandHead = true;
hasFired = false;
hasReloaded = false;
allowInvisibleStand = false;
hasBaseStand = false;
baseStandOffset = 0;
baseStandModelNumber = 147;
nextShotTime = System.currentTimeMillis();
EntityProjectile defaultProj = new EntityProjectile();
defaultProj.EntityCount = 2;
defaultProj.EntityTyp = EntityType.SHULKER_BULLET;
defaultProj.ParticleType = Particle.WHITE_ASH;
defaultProj.SoundType = Sound.ENTITY_BLAZE_SHOOT;
// set passed parameters as object variables
this.name = name;
this.fuelItem = fuelItem;
this.customModelID = customModelID;
// set projectiles
if (projectiles.keySet().isEmpty() || projectiles.isEmpty()) {
this.projectiles.put(new ItemStack(Material.GUNPOWDER), defaultProj);
} else {
this.projectiles = projectiles;
}
}
public boolean equals(String EquipmentId) {
return id.equals(EquipmentId);
}
public Boolean isLoaded() {
if (this.maxFuel <= 0 && ammoHolder.loadedProjectile >= 1)
return true;
return (ammoHolder.loadedFuel > 0 && ammoHolder.loadedProjectile >= 1);
}
public Boolean CanLoadFuel() {
return ammoHolder.loadedFuel < maxFuel;
}
public Boolean LoadFuel(Entity player) {
if (ammoHolder.loadedFuel == maxFuel) {
return true;
}
if (!(player instanceof Player)) {
ammoHolder.loadedFuel = maxFuel;
return true;
}
if (((Player) player).getInventory().containsAtLeast(fuelItem, 1) || fuelItem.getType() == Material.AIR) {
if (CanLoadFuel()) {
this.ammoHolder.loadedFuel += 1;
//SaveState();
((Player) player).getInventory().removeItem(fuelItem);
((Player) player).sendMessage("§eLoaded " + ammoHolder.loadedFuel + "/" + maxFuel);
return true;
} else {
return false;
}
}
return false;
}
public Boolean LoadProjectile(Entity player, ItemStack itemInHand) {
if (itemInHand.getAmount() <= 0) {
return false;
}
if (!(player instanceof Player)) {
ammoHolder.loadedProjectile = 1;
ammoHolder.loadedFuel = maxFuel;
ammoHolder.materialName = itemInHand;
return true;
}
for (ItemStack im : projectiles.keySet()) {
if(im.getType().equals(itemInHand.getType()) && ammoHolder.loadedProjectile == 0) {
ammoHolder.loadedProjectile = 1;
ammoHolder.materialName = itemInHand;
((Player) player).sendMessage("§eAdding Ammunition to Weapon");
itemInHand.setAmount(itemInHand.getAmount() - 1);
return true;
}
}
return false;
}
public Location GetFireLocation(LivingEntity living) {
if (living == null)
return null;
Location loc = living.getEyeLocation();
Vector direction = living.getLocation().getDirection().multiply(xOffset);
loc.add(direction);
if (yOffset > 0) {
loc.setY(loc.getY() + yOffset);
} else {
loc.setY(loc.getY() - yOffset);
}
loc.setPitch(loc.getPitch() + pitchOffset);
return loc;
}
public void ShowFireLocation(Entity player) {
LivingEntity living = (LivingEntity) entity;
if (player instanceof Player) {
if (living != null) {
Location origin = this.GetFireLocation(living);
Vector direction = origin.getDirection();
direction.multiply(5 /* the range */);
direction.normalize();
for (int i = 0; i < 3 /* range */; i += 1) {
Location spawn = origin.add(direction);
((Player) player).spawnParticle(Particle.CLOUD, spawn, 1, 0, 0, 0, 0);
}
}
}
}
public void Fire(Entity player, float delay, Integer amount) {
if (amount == null || amount == 0)
amount = this.shotAmount;
this.shotAmount = amount;
if (System.currentTimeMillis() < nextShotTime) {
return;
}
if (ammoHolder.loadedFuel <= 0)
ammoHolder.loadedFuel = 0;
float loadedFuel = ammoHolder.loadedFuel;
ItemStack LoadedProjectile = ammoHolder.materialName;
LivingEntity living = (LivingEntity) entity;
if (living == null || living.getEquipment() == null || living.getEquipment().getHelmet() == null || living.getEquipment().getHelmet().getItemMeta() == null) {
return;
}
if (living.getEquipment().getHelmet().getItemMeta().getCustomModelData() != readyModelNumber) {
if (player instanceof Player) {
((Player) player).sendMessage("§eCannot fire yet!");
}
return;
}
ammoHolder.loadedFuel = 0;
ammoHolder.loadedProjectile = 0;
ammoHolder.materialName = new ItemStack(Material.AIR, 1);
worldName = entity.getWorld().getName();
nextShotTime = System.currentTimeMillis() + 1000;
//for (int i = 0; i <= this.shotAmount /* range */; i += 1) {
if (living == null || living.isDead()) {
return;
}
if (cycleThroughModelsBeforeFiring) {
this.taskNumber = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(SiegeEngines.getInstance(), () -> {
if (living == null || living.isDead()) {
Bukkit.getServer().getScheduler().cancelTask(taskNumber);
return;
}
if (hasFired) {
Bukkit.getServer().getScheduler().cancelTask(taskNumber);
taskNumber = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(SiegeEngines.getInstance(), () -> {
if (living == null || living.isDead()) {
Bukkit.getServer().getScheduler().cancelTask(taskNumber);
return;
}
// player.sendMessage("§etask");
if (hasReloaded) {
Bukkit.getServer().getScheduler().cancelTask(taskNumber);
hasReloaded = false;
hasFired = false;
nextModelNumber = 0;
SiegeEnginesUtil.UpdateEntityIdModel(entity, readyModelNumber, worldName);
taskNumber = 0;
} else {
//firing stages
if (nextModelNumber - 1 <= firingModelNumbers.size() && nextModelNumber - 1 >= 0) {
int modelData = firingModelNumbers.get(nextModelNumber - 1);
// player.sendMessage("§e" + modelData);
SiegeEnginesUtil.UpdateEntityIdModel(entity, modelData, worldName);
nextModelNumber -= 1;
} else {
// plugin.getLogger().log(Level.INFO, "its reloaded");
hasReloaded = true;
}
}
}, 0, millisecondsBetweenReloadingStages);
} else {
//firing stages
if (nextModelNumber < firingModelNumbers.size()) {
int modelData = firingModelNumbers.get(nextModelNumber);
// player.sendMessage("§e" + modelData);
SiegeEnginesUtil.UpdateEntityIdModel(entity, modelData, worldName);
if (modelData == modelNumberToFireAt) {
// player.sendMessage("§efiring" + modelData);
if (LoadedProjectile == null) return;
if (LoadedProjectile.getType() == Material.AIR) return;
GunnersProjectile projType = projectiles.get(LoadedProjectile);
if (projType == null) return;
projType.Shoot(player, entity, this.GetFireLocation(living), loadedFuel * velocityPerFuel);
}
nextModelNumber += 1;
} else {
hasFired = true;
}
}
}, 0, millisecondsBetweenFiringStages);
} else {
taskNumber = Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(SiegeEngines.getInstance(), () -> {
//player.sendMessage("§etask");
if (living == null || living.isDead()) {
Bukkit.getServer().getScheduler().cancelTask(taskNumber);
return;
}
Location loc = living.getEyeLocation();
Vector direction = entity.getLocation().getDirection().multiply(xOffset);
loc.add(direction);
nextModelNumber = 0;
if (LoadedProjectile == null) return;
if (LoadedProjectile.getType() == Material.AIR) return;
GunnersProjectile projType = projectiles.get(LoadedProjectile);
if (projType == null) return;
projType.Shoot(player, entity, this.GetFireLocation(living), loadedFuel * velocityPerFuel);
}, (long) delay);
}
}
@SuppressWarnings("deprecation")
public Boolean place(Entity player, Location l) {
l.add(0.5, 0, 0.5);
NamespacedKey key = new NamespacedKey(SiegeEngines.getInstance(), "siege_engines");
if (this == null || !this.enabled) {
return false;
}
l.setY(l.getY() + 1);
l.setDirection(player.getFacing().getDirection());
ItemStack item = new ItemStack(Material.CARVED_PUMPKIN);
ItemMeta meta = item.getItemMeta();
String id = "";
this.ammoHolder = new SiegeEngineAmmoHolder();
if (this.hasBaseStand) {
Location l2 = l;
l2.setY(l.getY() + this.baseStandOffset);
Entity entity3 = player.getWorld().spawnEntity(l, EntityType.ARMOR_STAND);
LivingEntity ent = (LivingEntity) entity3;
ArmorStand stand = (ArmorStand) ent;
id = entity3.getUniqueId().toString();
meta.setCustomModelData(this.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(this.allowInvisibleStand);
ent.getEquipment().setHelmet(item);
stand.setGravity(false);
stand.setMarker(true);
}
l.setY(l.getY() + this.placementOffsetY);
Entity entity2 = player.getWorld().spawnEntity(l, EntityType.ARMOR_STAND);
if (id != "") {
entity2.getPersistentDataContainer().set(key, PersistentDataType.STRING, id);
}
meta.setCustomModelData(this.readyModelNumber);
meta.setDisplayName("§e" + this.name + " Item");
List<String> Lore = new ArrayList<String>();
Lore.add("§ePlace as a block to spawn a " + this.name + " or put on an Armor Stand.");
meta.setLore(Lore);
item.setItemMeta(meta);
// entity3.addPassenger(entity2);
LivingEntity ent = (LivingEntity) entity2;
ArmorStand stand = (ArmorStand) ent;
this.entity = entity2;
this.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(this.allowInvisibleStand);
stand.setBasePlate(true);
stand.setGravity(false);
ent.getEquipment().setHelmet(item);
if (SiegeEngines.trackedStands.containsKey(player.getUniqueId())) {
List<Entity> entities = SiegeEngines.trackedStands.get(player.getUniqueId());
entities.add(entity2);
SiegeEngines.trackedStands.put(player.getUniqueId(), entities);
} else {
List<Entity> newList = new ArrayList<Entity>();
newList.add(entity2);
SiegeEngines.trackedStands.put(player.getUniqueId(), newList);
}
SiegeEngines.activeSiegeEngines.put(entity2.getUniqueId(), this);
return true;
}
}
@@ -0,0 +1,17 @@
package com.github.alathra.siegeengines;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
public class SiegeEngineAmmoHolder {
public int loadedFuel = 0;
public int loadedProjectile = 0;
public ItemStack materialName = new ItemStack(Material.AIR, 1);
public SiegeEngineAmmoHolder() {
loadedFuel = 0;
loadedProjectile = 0;
materialName = new ItemStack(Material.AIR, 1);
}
}
@@ -6,30 +6,18 @@ 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.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.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.github.alathra.siegeengines.listeners.ClickHandler;
import com.github.alathra.siegeengines.listeners.RotationHandler;
@@ -40,13 +28,15 @@ import com.github.alathra.siegeengines.projectile.GunnersProjectile;
public class SiegeEngines extends JavaPlugin {
public static SiegeEngines instance;
private CommandHandler commandHandler;
public static Plugin plugin;
public static SiegeEngines instance;
public static MetadataValueAdapter metadata;
public static Random random = new Random();
private static String Path;
private CommandHandler commandHandler;
public static HashMap<Integer, SiegeEngine> definedSiegeEngines = new HashMap<Integer, SiegeEngine>();
public static HashMap<UUID, SiegeEngine> activeSiegeEngines = new HashMap<UUID, SiegeEngine>();
public static HashMap<UUID, List<Entity>> trackedStands = new HashMap<UUID, List<Entity>>();
public static SiegeEngines getInstance() {
@@ -55,26 +45,23 @@ public class SiegeEngines extends JavaPlugin {
@Override
public void onLoad() {
plugin = this;
commandHandler = new CommandHandler(this);
commandHandler.onLoad();
instance = this;
}
@SuppressWarnings("deprecation")
@Override
public void onEnable() {
instance = this;
Path = this.getDataFolder().getAbsolutePath();
getServer().getPluginManager().registerEvents(new RotationHandler(), this);
getServer().getPluginManager().registerEvents(new ClickHandler(), this);
equipment.clear();
TrackedStands.clear();
DefinedEquipment.clear();
activeSiegeEngines.clear();
trackedStands.clear();
definedSiegeEngines.clear();
AddDefaults();
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()) {
for (SiegeEngine i : definedSiegeEngines.values()) {
System.out.println("§eEnabled Weapon : " + i.name);
System.out.println("§eWeapon Propellant/\"Fuel\" ItemStacks : " + i.fuelItem);
for (ItemStack proj : i.projectiles.keySet()) {
System.out.println("§eWeapon Projectile ItemStacks : " + proj);
}
}
@@ -85,149 +72,65 @@ public class SiegeEngines extends JavaPlugin {
@Override
public void onDisable() {
commandHandler.onDisable();
for (SiegeEquipment equip : equipment.values()) {
if (equip.Entity != null) {
for (SiegeEngine siegeEngine : activeSiegeEngines.values()) {
if (siegeEngine.entity != null) {
ItemStack item = new ItemStack(Material.CARVED_PUMPKIN);
ItemMeta meta = item.getItemMeta();
equip.AmmoHolder = new EquipmentMagazine();
siegeEngine.ammoHolder = new SiegeEngineAmmoHolder();
meta.setCustomModelData(equip.ReadyModelNumber);
meta.setDisplayName("§e" + equip.EquipmentName + " Item");
meta.setCustomModelData(siegeEngine.readyModelNumber);
meta.setDisplayName("§e" + siegeEngine.name + " Item");
List<String> Lore = new ArrayList<String>();
Lore.add("§ePlace as a block to spawn a " + equip.EquipmentName + " or put on an Armor Stand.");
Lore.add("§ePlace as a block to spawn a " + siegeEngine.name + " or put on an Armor Stand.");
meta.setLore(Lore);
item.setItemMeta(meta);
((LivingEntity) equip.Entity).getEquipment().setHelmet(item);
((LivingEntity) siegeEngine.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;
SiegeEngine trebuchet = new SiegeEngine("Trebuchet", new HashMap<ItemStack, GunnersProjectile>(), new ItemStack(Material.GUNPOWDER), 122);
trebuchet.xOffset = 5;
trebuchet.yOffset = 5;
trebuchet.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(
trebuchet.shotAmount = 2;
trebuchet.rotateStandHead = false;
trebuchet.rotateSideways = true;
trebuchet.fuelItem = new ItemStack(Material.STRING);
trebuchet.projectiles.put(new ItemStack(Material.COBBLESTONE), proj);
trebuchet.readyModelNumber = 122;
trebuchet.modelNumberToFireAt = 135;
trebuchet.millisecondsBetweenFiringStages = 2;
trebuchet.millisecondsBetweenReloadingStages = 10;
trebuchet.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);
trebuchet.cycleThroughModelsBeforeFiring = true;
definedSiegeEngines.put(trebuchet.readyModelNumber, trebuchet);
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;
SiegeEngine navalCannon = new SiegeEngine("Naval Cannon", new HashMap<ItemStack, GunnersProjectile>(), new ItemStack(Material.GUNPOWDER), 142);
navalCannon.projectiles.put(new ItemStack(Material.COBBLESTONE), proj);
navalCannon.placementOffsetY = -1;
navalCannon.shotAmount = 1;
navalCannon.readyModelNumber = 142;
navalCannon.modelNumberToFireAt = 142;
navalCannon.firingModelNumbers = new ArrayList<Integer>();
navalCannon.rotateStandHead = true;
navalCannon.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);
navalCannon.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);
navalCannon.projectiles.put(new ItemStack(Material.IRON_BLOCK), proj);
EntityProjectile fireProj = new EntityProjectile();
fireProj.EntityCount = 4;
@@ -235,137 +138,36 @@ public class SiegeEngines extends JavaPlugin {
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";
navalCannon.projectiles.put(new ItemStack(Material.FIRE_CHARGE), fireProj);
definedSiegeEngines.put(navalCannon.readyModelNumber, navalCannon);
SiegeEngine siegeCannon = new SiegeEngine("Siege Cannon", new HashMap<ItemStack, GunnersProjectile>(), new ItemStack(Material.GUNPOWDER), 141);
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;
siegeCannon.projectiles.put(new ItemStack(Material.COBBLESTONE), proj);
siegeCannon.shotAmount = 1;
siegeCannon.placementOffsetY = -1;
siegeCannon.readyModelNumber = 141;
siegeCannon.modelNumberToFireAt = 141;
siegeCannon.firingModelNumbers = new ArrayList<Integer>();
siegeCannon.rotateStandHead = true;
siegeCannon.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);
siegeCannon.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);
siegeCannon.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);
siegeCannon.projectiles.put(new ItemStack(Material.GRAVEL), scatterShot);
definedSiegeEngines.put(siegeCannon.readyModelNumber, siegeCannon);
}
public static Boolean placeEquipment(Entity player, int CustomModelData, Location l) {
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.HasBaseStand) {
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;
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(true);
stand.setGravity(false);
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);
}
}
}
}
}
@@ -5,14 +5,14 @@ import org.bukkit.Bukkit;
public class SiegeEnginesLogger {
public static void info(String msg) {
Bukkit.getLogger().info("[" + SiegeEngines.plugin.getName() + "]" + msg);
Bukkit.getLogger().info("[" + SiegeEngines.getInstance().getName() + "]" + msg);
}
public static void warn(String msg) {
Bukkit.getLogger().warning("[" + SiegeEngines.plugin.getName() + "]" + msg);
Bukkit.getLogger().warning("[" + SiegeEngines.getInstance().getName() + "]" + msg);
}
public static void severe(String msg) {
Bukkit.getLogger().severe("[" + SiegeEngines.plugin.getName() + "]" + msg);
Bukkit.getLogger().severe("[" + SiegeEngines.getInstance().getName() + "]" + msg);
}
}
@@ -0,0 +1,51 @@
package com.github.alathra.siegeengines;
import java.util.concurrent.TimeUnit;
import org.bukkit.Bukkit;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.metadata.FixedMetadataValue;
public class SiegeEnginesUtil {
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);
}
}
}
public static FixedMetadataValue addMetaDataValue(Object value) {
return new FixedMetadataValue(Bukkit.getServer().getPluginManager().getPlugin("SiegeEngines"), value);
}
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 SiegeEngine createCloneFromCustomModelData(Integer ModelId) {
try {
return SiegeEngines.definedSiegeEngines.get(ModelId).clone();
} catch (CloneNotSupportedException e) {
}
return null;
}
}
@@ -1,293 +0,0 @@
package com.github.alathra.siegeengines;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
import com.github.alathra.siegeengines.projectile.GunnersProjectile;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Particle;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;
//import GunnersProjectiles.GunnersProjectile;
//import GunnersProjectiles.ExplosiveProjectile;
//import me.libraryaddict.disguise.DisguiseAPI;
//import me.libraryaddict.disguise.disguisetypes.DisguiseType;
//import me.libraryaddict.disguise.disguisetypes.MiscDisguise;
public class SiegeEquipment implements Cloneable {
@Override
public SiegeEquipment clone() throws CloneNotSupportedException {
return (SiegeEquipment) super.clone();
}
public boolean equals(String EquipmentId) {
return this.EquipmentId.equals(EquipmentId);
}
public Boolean Enabled = true;
public UUID EntityId;
public Entity Entity;
public Integer shotAmount = 1;
public HashMap<ItemStack, GunnersProjectile> Projectiles = new HashMap<ItemStack, GunnersProjectile>();
public String WorldName;
public String EquipmentName = "Peckle Gun";
public String EquipmentId = this.EquipmentName.replaceAll(" ", "_").toLowerCase();
public int XOffset = 2;
public int YOffset = 0;
public int PitchOffset = 0;
public int MaxFuel = 5;
public double PlacementOffsetY = 0;
public float VelocityPerFuel = 1.0125f;
public ItemStack FuelMaterial = new ItemStack(Material.GUNPOWDER);
public long NextShotTime = System.currentTimeMillis();
public int MillisecondsBetweenFiringStages;
public int MillisecondsBetweenReloadingStages;
public int MillisecondsToLoad;
public int ModelNumberToFireAt;
public Boolean CycleThroughModelsBeforeFiring = false;
public Boolean RotateSideways = false;
public Boolean RotateUpDown = true;
public Boolean RotateStandHead = true;
public Boolean HasFired = false;
public Boolean HasReloaded = false;
public Boolean AllowInvisibleStand = false;
public Boolean HasBaseStand = false;
public double BaseStandOffset = 0;
public int BaseStandModelNumber = 147;
public int TaskNumber;
public int ReadyModelNumber;
public int NextModelNumber = 0;
public List<Integer> FiringModelNumbers = new ArrayList<Integer>();
public EquipmentMagazine AmmoHolder = new EquipmentMagazine();
public Boolean isLoaded() {
if (this.MaxFuel <= 0 && AmmoHolder.LoadedProjectile >= 1)
return true;
return (AmmoHolder.LoadedFuel > 0 && AmmoHolder.LoadedProjectile >= 1);
}
public Boolean CanLoadFuel() {
return AmmoHolder.LoadedFuel < MaxFuel;
}
public Boolean LoadFuel(Entity player) {
ItemStack fuelItem = this.FuelMaterial;
if (this.AmmoHolder.LoadedFuel == this.MaxFuel) {
return true;
}
if (!(player instanceof Player)) {
this.AmmoHolder.LoadedFuel = this.MaxFuel;
return true;
}
if (((Player) player).getInventory().containsAtLeast(fuelItem, 1) || fuelItem.getType() == Material.AIR) {
if (CanLoadFuel()) {
this.AmmoHolder.LoadedFuel += 1;
//SaveState();
((Player) player).getInventory().removeItem(fuelItem);
((Player) player).sendMessage("§eLoaded " + this.AmmoHolder.LoadedFuel + "/" + this.MaxFuel);
return true;
} else {
return false;
}
}
return false;
}
public Boolean LoadProjectile(Entity player, ItemStack itemInHand) {
if (itemInHand.getAmount() <= 0) {
return false;
}
if (!(player instanceof Player)) {
this.AmmoHolder.LoadedProjectile = 1;
this.AmmoHolder.LoadedFuel = this.MaxFuel;
this.AmmoHolder.MaterialName = itemInHand;
return true;
}
if (this.Projectiles.containsKey(itemInHand.getType()) && this.AmmoHolder.LoadedProjectile == 0) {
this.AmmoHolder.LoadedProjectile = 1;
this.AmmoHolder.MaterialName = itemInHand;
((Player) player).sendMessage("§eAdding Ammunition to Weapon");
itemInHand.setAmount(itemInHand.getAmount() - 1);
return true;
}
return false;
}
//public void SaveState() {
//}
public Location GetFireLocation(LivingEntity living) {
if (living == null)
return null;
Location loc = living.getEyeLocation();
Vector direction = living.getLocation().getDirection().multiply(XOffset);
loc.add(direction);
if (this.YOffset > 0) {
loc.setY(loc.getY() + this.YOffset);
} else {
loc.setY(loc.getY() - this.YOffset);
}
loc.setPitch(loc.getPitch() + this.PitchOffset);
return loc;
}
public void ShowFireLocation(Entity player) {
LivingEntity living = (LivingEntity) this.Entity;
if (player instanceof Player) {
if (living != null) {
Location origin = this.GetFireLocation(living);
Vector direction = origin.getDirection();
direction.multiply(5 /* the range */);
Location destination = origin.clone().add(direction);
direction.normalize();
for (int i = 0; i < 3 /* range */; i += 1) {
Location spawn = origin.add(direction);
((Player) player).spawnParticle(Particle.CLOUD, spawn, 1, 0, 0, 0, 0);
}
}
}
}
public void Fire(Entity player, float delay, Integer amount) {
if (amount == null || amount == 0)
amount = this.shotAmount;
this.shotAmount = amount;
if (System.currentTimeMillis() < this.NextShotTime) {
return;
}
if (this.AmmoHolder.LoadedFuel <= 0)
this.AmmoHolder.LoadedFuel = 0;
float loadedFuel = this.AmmoHolder.LoadedFuel;
ItemStack LoadedProjectile = this.AmmoHolder.MaterialName;
LivingEntity living = (LivingEntity) this.Entity;
if (living == null || living.getEquipment() == null || living.getEquipment().getHelmet() == null || living.getEquipment().getHelmet().getItemMeta() == null) {
return;
}
if (living.getEquipment().getHelmet().getItemMeta().getCustomModelData() != this.ReadyModelNumber) {
if (player instanceof Player) {
((Player) player).sendMessage("§eCannot fire yet!");
}
return;
}
this.AmmoHolder.LoadedFuel = 0;
this.AmmoHolder.LoadedProjectile = 0;
this.AmmoHolder.MaterialName = new ItemStack(Material.AIR, 1);
this.WorldName = Entity.getWorld().getName();
this.NextShotTime = System.currentTimeMillis() + 1000;
//for (int i = 0; i <= this.shotAmount /* range */; i += 1) {
if (living == null || living.isDead()) {
return;
}
if (this.CycleThroughModelsBeforeFiring) {
this.TaskNumber = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(SiegeEngines.plugin, () -> {
if (living == null || living.isDead()) {
Bukkit.getServer().getScheduler().cancelTask(this.TaskNumber);
return;
}
if (this.HasFired) {
Bukkit.getServer().getScheduler().cancelTask(this.TaskNumber);
this.TaskNumber = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(SiegeEngines.plugin, () -> {
if (living == null || living.isDead()) {
Bukkit.getServer().getScheduler().cancelTask(this.TaskNumber);
return;
}
// player.sendMessage("§etask");
if (this.HasReloaded) {
Bukkit.getServer().getScheduler().cancelTask(this.TaskNumber);
this.HasReloaded = false;
this.HasFired = false;
this.NextModelNumber = 0;
SiegeEngines.UpdateEntityIdModel(this.Entity, this.ReadyModelNumber, this.WorldName);
this.TaskNumber = 0;
} else {
//firing stages
if (this.NextModelNumber - 1 <= this.FiringModelNumbers.size() && this.NextModelNumber - 1 >= 0) {
int modelData = this.FiringModelNumbers.get(this.NextModelNumber - 1);
// player.sendMessage("§e" + modelData);
SiegeEngines.UpdateEntityIdModel(this.Entity, modelData, this.WorldName);
this.NextModelNumber -= 1;
} else {
// plugin.getLogger().log(Level.INFO, "its reloaded");
this.HasReloaded = true;
}
}
}, 0, this.MillisecondsBetweenReloadingStages);
} else {
//firing stages
if (this.NextModelNumber < this.FiringModelNumbers.size()) {
int modelData = this.FiringModelNumbers.get(this.NextModelNumber);
// player.sendMessage("§e" + modelData);
SiegeEngines.UpdateEntityIdModel(this.Entity, modelData, this.WorldName);
if (modelData == this.ModelNumberToFireAt) {
// player.sendMessage("§efiring" + modelData);
if (LoadedProjectile == null) return;
if (LoadedProjectile.getType() == Material.AIR) return;
GunnersProjectile projType = Projectiles.get(LoadedProjectile);
if (projType == null) return;
projType.Shoot(player, this.Entity, this.GetFireLocation(living), loadedFuel * this.VelocityPerFuel);
}
this.NextModelNumber += 1;
} else {
this.HasFired = true;
}
}
}, 0, this.MillisecondsBetweenFiringStages);
} else {
this.TaskNumber = Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(SiegeEngines.plugin, () -> {
//player.sendMessage("§etask");
if (living == null || living.isDead()) {
Bukkit.getServer().getScheduler().cancelTask(this.TaskNumber);
return;
}
Location loc = living.getEyeLocation();
Vector direction = Entity.getLocation().getDirection().multiply(XOffset);
loc.add(direction);
this.NextModelNumber = 0;
if (LoadedProjectile == null) return;
if (LoadedProjectile.getType() == Material.AIR) return;
GunnersProjectile projType = Projectiles.get(LoadedProjectile);
if (projType == null) return;
projType.Shoot(player, this.Entity, this.GetFireLocation(living), loadedFuel * this.VelocityPerFuel);
}, (long) delay);
}
}
//}
}
@@ -1,7 +1,6 @@
package com.github.alathra.siegeengines.command;
import com.github.alathra.siegeengines.SiegeEquipment;
import com.github.alathra.siegeengines.projectile.GunnersProjectile;
import com.github.alathra.siegeengines.SiegeEngine;
import com.github.milkdrinkers.colorparser.ColorParser;
import dev.jorel.commandapi.CommandAPIBukkit;
import dev.jorel.commandapi.CommandAPICommand;
@@ -18,7 +17,6 @@ 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.*;
@@ -49,7 +47,7 @@ public class SiegeEnginesCommand {
new StringArgument("equipmentid")
.replaceSuggestions(
ArgumentSuggestions.strings(
DefinedEquipment.values().stream().map(SiegeEquipment -> SiegeEquipment.EquipmentId).toList()
definedSiegeEngines.values().stream().map(SiegeEquipment -> SiegeEquipment.id).toList()
)
),
new PlayerArgument("target")
@@ -76,7 +74,7 @@ public class SiegeEnginesCommand {
Player player = (Player) args.getOptional("target").orElse(sender);
for (SiegeEquipment SiegeEquipment : DefinedEquipment.values()) {
for (SiegeEngine SiegeEquipment : definedSiegeEngines.values()) {
if (SiegeEquipment.equals(equipmentId)) {
giveEquipment(player, SiegeEquipment);
break;
@@ -88,7 +86,7 @@ public class SiegeEnginesCommand {
if (!(sender instanceof Player player))
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("<red>Only players can use this command.").build());
for (SiegeEquipment i : DefinedEquipment.values()) {
for (SiegeEngine i : definedSiegeEngines.values()) {
giveEquipment(player, i);
}
}
@@ -97,29 +95,27 @@ public class SiegeEnginesCommand {
if (!(sender instanceof Player))
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("<red>Only players can use this command.").build());
equipment.clear();
TrackedStands.clear();
DefinedEquipment.clear();
activeSiegeEngines.clear();
trackedStands.clear();
definedSiegeEngines.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()) {
for (SiegeEngine i : definedSiegeEngines.values()) {
sender.sendMessage(ColorParser.of("<yellow>Enabled Weapon : %s".formatted(i.name)).build());
sender.sendMessage(ColorParser.of("<yellow>Weapon Propellant/\"Fuel\" ItemStacks : %s".formatted(i.fuelItem)).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) {
private void giveEquipment(Player player, SiegeEngine 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());
meta.setCustomModelData(SiegeEquipment.readyModelNumber);
meta.displayName(ColorParser.of("<yellow>%s Item".formatted(SiegeEquipment.name)).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>Place as a block to spawn a '%s'".formatted(SiegeEquipment.name)).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);
@@ -42,7 +42,7 @@ public class Config {
initConfigVals();
}
private FileConfiguration getConfig() {
public FileConfiguration getConfig() {
return config;
}
@@ -8,13 +8,14 @@ import java.util.Random;
import java.util.UUID;
import com.github.alathra.siegeengines.config.Config;
import com.github.alathra.siegeengines.EquipmentMagazine;
import com.github.alathra.siegeengines.SiegeEngineAmmoHolder;
import com.github.alathra.siegeengines.SiegeEngines;
import com.github.alathra.siegeengines.SiegeEnginesUtil;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.Container;
import org.bukkit.block.Sign;
@@ -45,15 +46,9 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.util.EulerAngle;
import com.github.alathra.siegeengines.SiegeEquipment;
import com.github.alathra.siegeengines.SiegeEngine;
import com.github.alathra.siegeengines.projectile.ExplosiveProjectile;
//import com.palmergames.bukkit.towny.TownyAPI;
//import com.palmergames.bukkit.towny.event.actions.TownyDestroyEvent;
//import com.palmergames.bukkit.towny.object.TownBlock;
//import GunnersProjectiles.ExplosiveProjectile;
public class ClickHandler implements Listener {
public float MinDelay = 5;
@@ -66,16 +61,6 @@ public class ClickHandler implements Listener {
for (Entity entity : e.getEntity().getNearbyEntities(e.getYield() + 1, e.getYield() + 1, e.getYield() + 1)) {
if (entity instanceof ArmorStand) {
ArmorStand stand = (ArmorStand) entity;
/*if (SiegeEngines.towny != null) {
TownBlock block = TownyAPI.getInstance().getTownBlock(stand.getLocation());
if (block != null) {
if (block.hasTown()) {
if (!block.getTownBlockOwner().getPermissions().explosion) {
return;
}
}
}
}*/
stand.eject();
stand.remove();
}
@@ -93,8 +78,6 @@ public class ClickHandler implements Listener {
player.sendMessage("§eDistance to impact: " + String.format("%.2f", player.getLocation().distance(ball.getLocation())));
}
Location loc = snowball.getLocation();
World world = event.getEntity().getWorld();
// world.createExplosion(loc, proj.Radius, proj.DoFire);
Entity tnt = event.getEntity().getWorld().spawnEntity(loc, EntityType.PRIMED_TNT);
projectiles.remove(event.getEntity().getUniqueId());
@@ -103,16 +86,6 @@ public class ClickHandler implements Listener {
TNTPrimed tntEnt = (TNTPrimed) tnt;
tntEnt.setYield(0);
tntEnt.setFuseTicks(0);
/*if (SiegeEngines.towny != null) {
TownBlock block = TownyAPI.getInstance().getTownBlock(loc);
if (block != null) {
if (block.hasTown()) {
if (!block.getTownBlockOwner().getPermissions().explosion) {
return;
}
}
}
}*/
if (event.getHitBlock() != null) {
List<Block> Blocks = sphere(event.getHitBlock().getLocation(), (int) proj.ExplodePower);
for (int i = 0; i < proj.BlocksToPlaceAmount; i++) {
@@ -158,21 +131,32 @@ public class ClickHandler implements Listener {
thePlayer.sendMessage("§eGunner Equipment cannot be spawned in Fluid Blocks.");
event.setCancelled(true);
}
if (event.isCancelled())
if (event.isCancelled()) {
return;
}
if (event.getPlayer().getInventory().getItemInMainHand().getType() == Material.CARVED_PUMPKIN) {
ItemStack item = event.getPlayer().getInventory().getItemInMainHand();
if (item.getItemMeta() != null && item.getItemMeta().hasCustomModelData()) {
int customModel = item.getItemMeta().getCustomModelData();
Boolean created = SiegeEngines.placeEquipment(thePlayer, customModel, event.getBlockAgainst().getLocation());
if (created) {
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;
}
}
// If siege engine found, place it
if (siegeEngine != null) {
siegeEngine.place(thePlayer, event.getBlockAgainst().getLocation());
item.setAmount(item.getAmount() - 1);
thePlayer.getInventory().setItemInMainHand(item);
thePlayer.sendMessage("§eGunner Equipment spawned!");
} else {
thePlayer.sendMessage("§eGunner Equipment could not be spawned, is it enabled?");
event.setCancelled(true);
}
event.setCancelled(true);
}
}
}
@@ -180,37 +164,36 @@ public class ClickHandler implements Listener {
public void Shoot(Entity player, long delay) {
float actualDelay = delay;
Boolean FirstShot = true;
int counter = 0;
if (SiegeEngines.TrackedStands.get(player.getUniqueId()) == null) {
if (SiegeEngines.trackedStands.get(player.getUniqueId()) == null) {
for (Entity ent : player.getNearbyEntities(5, 5, 5)) {
if (ent instanceof ArmorStand) {
TakeControl(player, ent);
}
}
}
if (SiegeEngines.TrackedStands.get(player.getUniqueId()) == null)
if (SiegeEngines.trackedStands.get(player.getUniqueId()) == null)
return;
List<Entity> entities = new ArrayList<>(SiegeEngines.TrackedStands.get(player.getUniqueId()));
List<Entity> entities = new ArrayList<>(SiegeEngines.trackedStands.get(player.getUniqueId()));
for (Entity ent : entities) {
if (ent == null || ent.isDead()) {
SiegeEngines.TrackedStands.get(player.getUniqueId()).remove(ent);
SiegeEngines.trackedStands.get(player.getUniqueId()).remove(ent);
continue;
}
if (((LivingEntity) ent).getEquipment().getHelmet().getType() != Material.CARVED_PUMPKIN) {
SiegeEngines.TrackedStands.get(player.getUniqueId()).remove(ent);
SiegeEngines.trackedStands.get(player.getUniqueId()).remove(ent);
continue;
}
double distance = player.getLocation().distance(ent.getLocation());
if (distance >= Config.controlDistance) {
SiegeEngines.TrackedStands.get(player.getUniqueId()).remove(ent);
SiegeEngines.trackedStands.get(player.getUniqueId()).remove(ent);
continue;
}
SiegeEquipment siege = SiegeEngines.equipment.get(ent.getUniqueId());
SiegeEngine siege = SiegeEngines.activeSiegeEngines.get(ent.getUniqueId());
if (counter > 4)
return;
if (ent == null || ent.isDead()) {
SiegeEngines.TrackedStands.get(player.getUniqueId()).remove(ent);
SiegeEngines.trackedStands.get(player.getUniqueId()).remove(ent);
continue;
}
if (siege.isLoaded()) {
@@ -224,9 +207,7 @@ public class ClickHandler implements Listener {
} else {
if (player instanceof Player) {
}
//player.sendMessage("§eAmmunition Not Loaded");
}
// player.sendMessage(String.format("§e" +actualDelay));
}
}
@@ -252,16 +233,7 @@ public class ClickHandler implements Listener {
}
public static boolean hasItem(Inventory inv, ItemStack m) {
//ItemStack[] contents = inv.getStorageContents();
/*for(int i = 0; i < contents.length; i++) {
if(contents[i] == null) continue;
if(contents[i].isSimilar(m)) {
return true;
}
}*/
//m.setAmount(1);
return inv.containsAtLeast(m,m.getAmount());
//return false;
}
@EventHandler
@@ -273,38 +245,28 @@ public class ClickHandler implements Listener {
return;
}
// if (ItemInHand.getType() == Material.PAPER) {
// ItemMeta meta = ItemInHand.getItemMeta();
// if (meta.hasCustomModelData() && meta.getCustomModelData() == 505050505) {
// SiegeEngines.CreateCannon(player);
// ItemInHand.setAmount(ItemInHand.getAmount() - 1);
// return;
// }
// }
if (event.getAction() == Action.RIGHT_CLICK_AIR) {
if (ItemInHand.getType() != Config.controlItem) {
return;
}
if (!player.isSneaking()) {
List<Entity> entities = SiegeEngines.TrackedStands.get(player.getUniqueId());
List<Entity> entities = SiegeEngines.trackedStands.get(player.getUniqueId());
if (entities == null) {
return;
}
for (Entity entity : entities) {
if (SiegeEngines.equipment.containsKey(entity.getUniqueId())) {
SiegeEquipment equip = SiegeEngines.equipment.get(entity.getUniqueId());
if (equip != null && equip.Enabled && !(entity.isDead())) {
if (SiegeEngines.activeSiegeEngines.containsKey(entity.getUniqueId())) {
SiegeEngine equip = SiegeEngines.activeSiegeEngines.get(entity.getUniqueId());
if (equip != null && equip.enabled && !(entity.isDead())) {
equip.Fire(player,10f,1);
}
}
}
return;
}
if (SiegeEngines.TrackedStands.containsKey(player.getUniqueId())) {
List<Entity> entities = SiegeEngines.TrackedStands.get(player.getUniqueId());
if (SiegeEngines.trackedStands.containsKey(player.getUniqueId())) {
List<Entity> entities = SiegeEngines.trackedStands.get(player.getUniqueId());
if (entities == null) {
return;
}
@@ -313,23 +275,23 @@ public class ClickHandler implements Listener {
for (Entity entity : entities) {
foundAmmo = false;
if ((entity.isDead())) continue;
if (SiegeEngines.equipment.containsKey(entity.getUniqueId())) {
SiegeEquipment equip = SiegeEngines.equipment.get(entity.getUniqueId());
if (equip == null || !equip.Enabled) {
if (SiegeEngines.activeSiegeEngines.containsKey(entity.getUniqueId())) {
SiegeEngine equip = SiegeEngines.activeSiegeEngines.get(entity.getUniqueId());
if (equip == null || !equip.enabled) {
continue;
}
if (entity.getLocation().getBlock().getType() == Material.BARREL || entity.getLocation().getBlock().getType() == Material.CHEST) {
Block inv = entity.getLocation().getBlock();
Container state = ((Container) inv.getState());
for (ItemStack stack : equip.Projectiles.keySet()) {
for (ItemStack stack : equip.projectiles.keySet()) {
if (foundAmmo)
continue;
if (!hasItem((Inventory)state.getInventory(),stack))
continue;
state.getInventory().removeItem(stack);//setStorageContents(updateContents(state.getInventory(),stack,1));
//state.update(true,true);
equip.AmmoHolder.LoadedProjectile = 1;
equip.AmmoHolder.MaterialName = stack;
equip.ammoHolder.loadedProjectile = 1;
equip.ammoHolder.materialName = stack;
foundAmmo = true;
}
//state.update(true,true);
@@ -339,15 +301,15 @@ public class ClickHandler implements Listener {
if (entity.getLocation().getBlock().getRelative(0, -1, 0).getType() == Material.BARREL || entity.getLocation().getBlock().getRelative(0, -1, 0).getType() == Material.CHEST) {
Block inv = entity.getLocation().getBlock().getRelative(0, -1, 0);
Container state = ((Container) inv.getState());
for (ItemStack stack : equip.Projectiles.keySet()) {
for (ItemStack stack : equip.projectiles.keySet()) {
if (foundAmmo)
continue;
if (!hasItem((Inventory)state.getInventory(),stack))
continue;
state.getInventory().removeItem(stack);//setStorageContents(updateContents(state.getInventory(),stack,1));
//state.update(true,true);
equip.AmmoHolder.LoadedProjectile = 1;
equip.AmmoHolder.MaterialName = stack;
equip.ammoHolder.loadedProjectile = 1;
equip.ammoHolder.materialName = stack;
foundAmmo = true;
}
//state.update(true,true);
@@ -357,15 +319,15 @@ public class ClickHandler implements Listener {
if (entity.getLocation().getBlock().getRelative(0, 1, 0).getType() == Material.BARREL || entity.getLocation().getBlock().getRelative(0, 1, 0).getType() == Material.CHEST) {
Block inv = entity.getLocation().getBlock().getRelative(0, 1, 0);
Container state = ((Container) inv.getState());
for (ItemStack stack : equip.Projectiles.keySet()) {
for (ItemStack stack : equip.projectiles.keySet()) {
if (foundAmmo)
continue;
if (!hasItem((Inventory)state.getInventory(),stack))
continue;
state.getInventory().removeItem(stack);//setStorageContents(updateContents(state.getInventory(),stack,1));
//state.update(true,true);
equip.AmmoHolder.LoadedProjectile = 1;
equip.AmmoHolder.MaterialName = stack;
equip.ammoHolder.loadedProjectile = 1;
equip.ammoHolder.materialName = stack;
foundAmmo = true;
}
//state.update(true,true);
@@ -376,14 +338,14 @@ public class ClickHandler implements Listener {
break;
if (!foundAmmo) {
for (ItemStack inventoryItem : event.getPlayer().getInventory().getContents()) {
for (ItemStack stack : equip.Projectiles.keySet()) {
for (ItemStack stack : equip.projectiles.keySet()) {
if (foundAmmo)
continue;
if (!hasItem(event.getPlayer().getInventory(),stack))
continue;
if (stack.isSimilar(inventoryItem) && equip.AmmoHolder.LoadedProjectile == 0) {
equip.AmmoHolder.LoadedProjectile = 1;
equip.AmmoHolder.MaterialName = stack;
if (stack.isSimilar(inventoryItem) && equip.ammoHolder.loadedProjectile == 0) {
equip.ammoHolder.loadedProjectile = 1;
equip.ammoHolder.materialName = stack;
inventoryItem.setAmount(inventoryItem.getAmount() - 1);
foundAmmo = true;
break;
@@ -400,12 +362,12 @@ public class ClickHandler implements Listener {
for (Entity entity : entities) {
foundAmmo = false;
if ((entity.isDead())) continue;
if (SiegeEngines.equipment.containsKey(entity.getUniqueId())) {
SiegeEquipment equip = SiegeEngines.equipment.get(entity.getUniqueId());
if (equip == null || !equip.Enabled) {
if (SiegeEngines.activeSiegeEngines.containsKey(entity.getUniqueId())) {
SiegeEngine equip = SiegeEngines.activeSiegeEngines.get(entity.getUniqueId());
if (equip == null || !equip.enabled) {
continue;
}
ItemStack stack = equip.FuelMaterial;
ItemStack stack = equip.fuelItem;
if (entity.getLocation().getBlock().getType() == Material.BARREL || entity.getLocation().getBlock().getType() == Material.CHEST) {
Block inv = entity.getLocation().getBlock();
Container state = ((Container) inv.getState());
@@ -417,7 +379,7 @@ public class ClickHandler implements Listener {
continue;
state.getInventory().removeItem(stack);//setStorageContents(updateContents(state.getInventory(),stack,1));
//state.update(true,true);
equip.AmmoHolder.LoadedFuel += 1;
equip.ammoHolder.loadedFuel += 1;
foundAmmo = true;
//state.update(true,true);
}
@@ -434,7 +396,7 @@ public class ClickHandler implements Listener {
//state.update(true,true);
if (!equip.CanLoadFuel())
continue;
equip.AmmoHolder.LoadedFuel += 1;
equip.ammoHolder.loadedFuel += 1;
foundAmmo = true;
//state.update(true,true);
}
@@ -451,7 +413,7 @@ public class ClickHandler implements Listener {
continue;
state.getInventory().removeItem(stack);//setStorageContents(updateContents(state.getInventory(),stack,1));
//state.update(true,true);
equip.AmmoHolder.LoadedFuel += 1;
equip.ammoHolder.loadedFuel += 1;
foundAmmo = true;
//state.update(true,true);
}
@@ -465,7 +427,7 @@ public class ClickHandler implements Listener {
break;
if (!equip.CanLoadFuel())
continue;
equip.AmmoHolder.LoadedFuel += 1;
equip.ammoHolder.loadedFuel += 1;
stack.setAmount(1);
event.getPlayer().getInventory().removeItem(stack);
foundAmmo = true;
@@ -485,7 +447,8 @@ public class ClickHandler implements Listener {
@EventHandler(priority = EventPriority.NORMAL)
public void onSignChange(SignChangeEvent event) {
String topline = event.getLine(0);
@SuppressWarnings("deprecation")
String topline = event.getLine(0);
if (topline == null) topline = "";
Player player = event.getPlayer();
String toplinetrimmed = topline.trim();
@@ -508,8 +471,8 @@ public class ClickHandler implements Listener {
public static void TakeControl(Entity player, Entity entity) {
LivingEntity living = (LivingEntity) entity;
if (SiegeEngines.TrackedStands.containsKey(player.getUniqueId())) {
List<Entity> entities = SiegeEngines.TrackedStands.get(player.getUniqueId());
if (SiegeEngines.trackedStands.containsKey(player.getUniqueId())) {
List<Entity> entities = SiegeEngines.trackedStands.get(player.getUniqueId());
if (entities.contains(entity)) {
return;
}
@@ -521,61 +484,58 @@ public class ClickHandler implements Listener {
}
ArmorStand stand = (ArmorStand) entity;
SiegeEquipment equip;
SiegeEngine equip;
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.setBasePlate(false);
if (SiegeEngines.equipment.containsKey(entity.getUniqueId())) {
equip = SiegeEngines.equipment.get(entity.getUniqueId());
if (equip == null || !equip.Enabled) {
if (SiegeEngines.activeSiegeEngines.containsKey(entity.getUniqueId())) {
equip = SiegeEngines.activeSiegeEngines.get(entity.getUniqueId());
if (equip == null || !equip.enabled) {
return;
}
} else {
equip = SiegeEngines.CreateClone(living.getEquipment().getHelmet().getItemMeta().getCustomModelData());
if (equip == null || !equip.Enabled) {
equip = SiegeEnginesUtil.createCloneFromCustomModelData(living.getEquipment().getHelmet().getItemMeta().getCustomModelData());
if (equip == null || !equip.enabled) {
return;
}
equip.AmmoHolder = new EquipmentMagazine();
equip.Entity = entity;
equip.EntityId = entity.getUniqueId();
equip.ammoHolder = new SiegeEngineAmmoHolder();
equip.entity = entity;
equip.entityId = entity.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.setBasePlate(false);
if (SiegeEngines.TrackedStands.containsKey(player.getUniqueId())) {
List<Entity> entities = SiegeEngines.TrackedStands.get(player.getUniqueId());
if (SiegeEngines.trackedStands.containsKey(player.getUniqueId())) {
List<Entity> entities = SiegeEngines.trackedStands.get(player.getUniqueId());
entities.add(entity);
SiegeEngines.TrackedStands.put(player.getUniqueId(), entities);
SiegeEngines.trackedStands.put(player.getUniqueId(), entities);
} else {
List<Entity> newList = new ArrayList<Entity>();
newList.add(entity);
SiegeEngines.TrackedStands.put(player.getUniqueId(), newList);
SiegeEngines.trackedStands.put(player.getUniqueId(), newList);
}
SiegeEngines.equipment.put(entity.getUniqueId(), equip);
SiegeEngines.activeSiegeEngines.put(entity.getUniqueId(), equip);
//player.sendMessage("§eNow controlling the equipment.");
}
}
public void SaveCannons(Player player, Block block) {
List<String> Ids = new ArrayList<String>();
if (!SiegeEngines.TrackedStands.containsKey(player.getUniqueId())) {
if (!SiegeEngines.trackedStands.containsKey(player.getUniqueId())) {
return;
}
for (Entity ent : SiegeEngines.TrackedStands.get(player.getUniqueId())) {
for (Entity ent : SiegeEngines.trackedStands.get(player.getUniqueId())) {
if (ent.isDead()) {
continue;
}
Ids.add(ent.getUniqueId().toString());
}
TileState state = ((TileState) block.getState());
NamespacedKey key = new NamespacedKey(SiegeEngines.plugin, "cannons");
for (Entity ent : SiegeEngines.TrackedStands.get(player.getUniqueId())) {
for (Entity ent : SiegeEngines.trackedStands.get(player.getUniqueId())) {
if (ent.isDead()) {
continue;
}
@@ -591,11 +551,11 @@ public class ClickHandler implements Listener {
return;
}
loc.setPitch((float) (loc.getPitch() - amount));
SiegeEquipment equipment = SiegeEngines.equipment.get(ent.getUniqueId());
SiegeEngine equipment = SiegeEngines.activeSiegeEngines.get(ent.getUniqueId());
if (equipment != null) {
if (player instanceof Player)
equipment.ShowFireLocation(player);
if (equipment.RotateStandHead) {
if (equipment.rotateStandHead) {
stand.setHeadPose(new EulerAngle(loc.getDirection().getY() * (-1), 0, 0));
}
ent.teleport(loc);
@@ -610,11 +570,11 @@ public class ClickHandler implements Listener {
return;
}
loc.setPitch((float) (loc.getPitch() - amount));
SiegeEquipment equipment = SiegeEngines.equipment.get(ent.getUniqueId());
SiegeEngine equipment = SiegeEngines.activeSiegeEngines.get(ent.getUniqueId());
if (equipment != null) {
if (player instanceof Player)
equipment.ShowFireLocation(player);
if (equipment.RotateStandHead) {
if (equipment.rotateStandHead) {
stand.setHeadPose(new EulerAngle(loc.getDirection().getY() * (-1), 0, 0));
}
ent.teleport(loc);
@@ -628,12 +588,12 @@ public class ClickHandler implements Listener {
if (loc.getPitch() == 85 || loc.getPitch() + amount > 85) {
return;
}
SiegeEquipment equipment = SiegeEngines.equipment.get(ent.getUniqueId());
SiegeEngine equipment = SiegeEngines.activeSiegeEngines.get(ent.getUniqueId());
if (equipment != null) {
if (player instanceof Player) {
equipment.ShowFireLocation((Player) player);
}
if (equipment.RotateStandHead) {
if (equipment.rotateStandHead) {
stand.setHeadPose(new EulerAngle(loc.getDirection().getY() * (-1), 0, 0));
}
@@ -643,7 +603,7 @@ public class ClickHandler implements Listener {
ent.teleport(loc);
}
NamespacedKey key = new NamespacedKey(SiegeEngines.plugin, "cannons");
NamespacedKey key = new NamespacedKey(SiegeEngines.getInstance(), "cannons");
@EventHandler
public void DeathEvent(EntityDeathEvent event) {
@@ -654,12 +614,12 @@ public class ClickHandler implements Listener {
Entity base = Bukkit.getEntity(UUID.fromString(event.getEntity().getPersistentDataContainer().get(key, PersistentDataType.STRING)));
base.remove();
}
if (SiegeEngines.equipment.containsKey(event.getEntity().getUniqueId())) {
if (SiegeEngines.activeSiegeEngines.containsKey(event.getEntity().getUniqueId())) {
removeStands = true;
} else {
for (ItemStack i : items) {
if (i.getType() == Material.CARVED_PUMPKIN && i.hasItemMeta() && i.getItemMeta().hasCustomModelData()) {
if (SiegeEngines.DefinedEquipment.containsKey(i.getItemMeta().getCustomModelData())) {
if (SiegeEngines.definedSiegeEngines.containsKey(i.getItemMeta().getCustomModelData())) {
removeStands = true;
break;
}
@@ -680,7 +640,7 @@ public class ClickHandler implements Listener {
public void AimUp(Entity player, float amount) {
for (Entity ent : SiegeEngines.TrackedStands.get(player.getUniqueId())) {
for (Entity ent : SiegeEngines.trackedStands.get(player.getUniqueId())) {
if (ent.isDead()) {
continue;
}
@@ -690,7 +650,7 @@ public class ClickHandler implements Listener {
public void AimDown(Entity player, float amount) {
for (Entity ent : SiegeEngines.TrackedStands.get(player.getUniqueId())) {
for (Entity ent : SiegeEngines.trackedStands.get(player.getUniqueId())) {
if (ent.isDead()) {
continue;
}
@@ -699,12 +659,12 @@ public class ClickHandler implements Listener {
}
public void LoadCannonsWithPowder(Entity player) {
for (Entity ent : SiegeEngines.TrackedStands.get(player.getUniqueId())) {
for (Entity ent : SiegeEngines.trackedStands.get(player.getUniqueId())) {
if (ent.isDead()) {
continue;
}
SiegeEquipment equipment = SiegeEngines.equipment.get(ent.getUniqueId());
SiegeEngine equipment = SiegeEngines.activeSiegeEngines.get(ent.getUniqueId());
if (equipment != null) {
equipment.LoadFuel(player);
}
@@ -712,24 +672,25 @@ public class ClickHandler implements Listener {
}
public void LoadCannonsWithProjectile(Entity player, ItemStack projectile) {
for (Entity ent : SiegeEngines.TrackedStands.get(player.getUniqueId())) {
for (Entity ent : SiegeEngines.trackedStands.get(player.getUniqueId())) {
if (ent.isDead()) {
continue;
}
SiegeEquipment equipment = SiegeEngines.equipment.get(ent.getUniqueId());
SiegeEngine equipment = SiegeEngines.activeSiegeEngines.get(ent.getUniqueId());
if (equipment != null) {
equipment.LoadProjectile(player, projectile);
}
}
}
@EventHandler
@SuppressWarnings("deprecation")
@EventHandler
public void onPlayerClickSign(PlayerInteractEvent event) {
Player player = event.getPlayer();
if (event.getClickedBlock() != null && event.getClickedBlock().getType().toString().contains("SIGN")) {
Sign sign = (Sign) event.getClickedBlock().getState();
if (sign.getLine(0).equalsIgnoreCase("[Fire]") && event.getAction() == Action.RIGHT_CLICK_BLOCK) {
if (!SiegeEngines.TrackedStands.containsKey(player.getUniqueId())) {
if (!SiegeEngines.trackedStands.containsKey(player.getUniqueId())) {
return;
}
try {
@@ -762,7 +723,7 @@ public class ClickHandler implements Listener {
}
if (sign.getLine(0).equalsIgnoreCase("[Aim]")) {
if (!SiegeEngines.TrackedStands.containsKey(player.getUniqueId())) {
if (!SiegeEngines.trackedStands.containsKey(player.getUniqueId())) {
return;
}
float amount;
@@ -783,7 +744,7 @@ public class ClickHandler implements Listener {
if (sign.getLine(0).equalsIgnoreCase("[Cannon]")) {
if (event.getAction() == Action.LEFT_CLICK_BLOCK) {
SiegeEngines.TrackedStands.remove(player.getUniqueId());
SiegeEngines.trackedStands.remove(player.getUniqueId());
player.sendMessage("§eReleasing the equipment!");
return;
}
@@ -794,9 +755,9 @@ public class ClickHandler implements Listener {
return;
}
NamespacedKey key = new NamespacedKey(SiegeEngines.plugin, "cannons");
NamespacedKey key = new NamespacedKey(SiegeEngines.getInstance(), "cannons");
TileState state = (TileState) sign.getBlock().getState();
SiegeEngines.TrackedStands.remove(player.getUniqueId());
SiegeEngines.trackedStands.remove(player.getUniqueId());
List<UUID> temp = new ArrayList<UUID>();
if (!state.getPersistentDataContainer().has(key, PersistentDataType.STRING)) {
return;
@@ -806,7 +767,6 @@ public class ClickHandler implements Listener {
temp.add(UUID.fromString(s.trim()));
}
for (UUID Id : temp) {
List<Entity> entities = new ArrayList<Entity>();
Entity ent = Bukkit.getEntity(Id);
if (ent != null) {
TakeControl(player, ent);
@@ -831,13 +791,13 @@ public class ClickHandler implements Listener {
}
if (entity.getType() == EntityType.ARMOR_STAND) {
if (itemInHand.getType() != Config.controlItem) {
SiegeEngines.TrackedStands.get(player.getUniqueId()).remove(entity);
SiegeEngines.trackedStands.get(player.getUniqueId()).remove(entity);
player.sendMessage("§eThis Equipment is no longer commanded by you.");
return;
} else {
TakeControl(player, entity);
}
if (SiegeEngines.equipment.containsKey(entity.getUniqueId())) {
if (SiegeEngines.activeSiegeEngines.containsKey(entity.getUniqueId())) {
if (itemInHand.getType() == Material.CLOCK) {
if (player.isSneaking()) {
DoAimDown(entity, 1, player);
@@ -847,7 +807,7 @@ public class ClickHandler implements Listener {
return;
}
SiegeEquipment equipment = SiegeEngines.equipment.get(entity.getUniqueId());
SiegeEngine equipment = SiegeEngines.activeSiegeEngines.get(entity.getUniqueId());
event.setCancelled(true);
if (itemInHand == null || itemInHand.getType() == Material.AIR) {
@@ -856,32 +816,23 @@ public class ClickHandler implements Listener {
stand.setInvisible(false);
player.sendMessage("§eEquipment is now breakable");
} else {
if (equipment.AllowInvisibleStand) {
if (equipment.allowInvisibleStand) {
stand.setInvisible(true);
player.sendMessage("§eEquipment is no longer breakable");
}
}
return;
}
if (itemInHand.isSimilar(equipment.FuelMaterial)) {
if (itemInHand.isSimilar(equipment.fuelItem)) {
if (!equipment.LoadFuel(player)) {
player.sendMessage("§eCould not load Propellant.");
return;
}
}
/*if (itemInHand.isSimilar(new ItemStack(Material.FLINT))) {
if (equipment.isLoaded()) {
equipment.Fire((Entity) player, 6, 1);
}
else {
player.sendMessage("§eEquipment is not loaded");
}
return;
}*/
for (ItemStack stack : equipment.Projectiles.keySet()) {
if (stack.isSimilar(itemInHand) && equipment.AmmoHolder.LoadedProjectile == 0) {
equipment.AmmoHolder.LoadedProjectile = 1;
equipment.AmmoHolder.MaterialName = stack;
for (ItemStack stack : equipment.projectiles.keySet()) {
if (stack.isSimilar(itemInHand) && equipment.ammoHolder.loadedProjectile == 0) {
equipment.ammoHolder.loadedProjectile = 1;
equipment.ammoHolder.materialName = stack;
player.sendMessage("§eAdding Ammunition to Weapon");
itemInHand.setAmount(itemInHand.getAmount() - 1);
return;
@@ -20,7 +20,7 @@ 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.SiegeEngine;
import com.github.alathra.siegeengines.config.Config;
public class RotationHandler implements Listener {
@@ -28,8 +28,8 @@ 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())) {
NamespacedKey key = new NamespacedKey(SiegeEngines.getInstance(), "cannons");
if (SiegeEngines.trackedStands.containsKey(player.getUniqueId())) {
ItemStack itemInHand = player.getInventory().getItemInMainHand();
if (itemInHand != null) {
if (itemInHand.getType() != Config.controlItem) {
@@ -37,10 +37,10 @@ public class RotationHandler implements Listener {
return;
}
final List<Entity> list = new ArrayList<>(SiegeEngines.TrackedStands.get(player.getUniqueId()));
final List<Entity> list = new ArrayList<>(SiegeEngines.trackedStands.get(player.getUniqueId()));
for (Entity ent : list) {
if (ent != null) {
SiegeEquipment equipment = SiegeEngines.equipment.get(ent.getUniqueId());
SiegeEngine equipment = SiegeEngines.activeSiegeEngines.get(ent.getUniqueId());
if (ent.isDead()) {
continue;
}
@@ -50,7 +50,7 @@ public class RotationHandler implements Listener {
LivingEntity living = (LivingEntity) ent;
Location loc = ent.getLocation();
if (equipment.RotateSideways) {
if (equipment.rotateSideways) {
Location direction = player.getLocation().add(player.getLocation().getDirection().multiply(50));
Vector dirBetweenLocations = direction.toVector().subtract(loc.toVector());
@@ -68,7 +68,7 @@ public class RotationHandler implements Listener {
ArmorStand stand = (ArmorStand) living;
if (equipment.RotateUpDown) {
if (equipment.rotateUpDown) {
loc.setPitch(player.getLocation().getPitch());
if (loc.getPitch() < -85) {
loc.setPitch(-85);
@@ -76,7 +76,7 @@ public class RotationHandler implements Listener {
if (loc.getPitch() > 85) {
loc.setPitch(85);
}
if (equipment.RotateStandHead) {
if (equipment.rotateStandHead) {
stand.setHeadPose(new EulerAngle(loc.getDirection().getY() * (-1), 0, 0));
}
}
@@ -85,7 +85,7 @@ public class RotationHandler implements Listener {
living.teleport(loc);
equipment.ShowFireLocation(player);
} else {
SiegeEngines.TrackedStands.get(player.getUniqueId()).remove(ent);
SiegeEngines.trackedStands.get(player.getUniqueId()).remove(ent);
continue;
}
}
@@ -1,6 +1,8 @@
package com.github.alathra.siegeengines.projectile;
import com.github.alathra.siegeengines.SiegeEngines;
import com.github.alathra.siegeengines.SiegeEnginesUtil;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Particle;
@@ -9,7 +11,6 @@ import org.bukkit.World;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.util.Vector;
public class EntityProjectile implements GunnersProjectile {
@@ -31,7 +32,7 @@ public class EntityProjectile implements GunnersProjectile {
for (int i = 0; i < EntityCount; i++) {
if (DelayedFire) {
baseDelay += DelayTime;
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(SiegeEngines.plugin, () -> {
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(SiegeEngines.getInstance(), () -> {
CreateEntity(entity, FireLocation, velocity, player);
}, (long) baseDelay);
@@ -39,8 +40,6 @@ public class EntityProjectile implements GunnersProjectile {
CreateEntity(entity, FireLocation, velocity, player);
}
// }
}
}
@@ -48,8 +47,7 @@ public class EntityProjectile implements GunnersProjectile {
private void CreateEntity(Entity entity, Location loc, Float velocity, Entity player) {
World world = entity.getLocation().getWorld();
LivingEntity living = (LivingEntity) entity;
Entity arrow = world.spawnEntity(loc, EntityTyp);
if (Inaccuracy != 0f) {
arrow.setVelocity(loc.getDirection().multiply(velocity).add(Randomise())
@@ -57,7 +55,7 @@ public class EntityProjectile implements GunnersProjectile {
} else {
arrow.setVelocity(loc.getDirection().multiply(velocity));
}
arrow.setMetadata("isEntityProj", SiegeEngines.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) {
@@ -69,10 +67,7 @@ public class EntityProjectile implements GunnersProjectile {
arr.setDamage(8);
if (player instanceof org.bukkit.projectiles.ProjectileSource)
arr.setShooter((org.bukkit.projectiles.ProjectileSource) player);
//arr.setBasePotionData(arg0);
}
// MiscDisguise miscDisguise = new MiscDisguise(DisguiseType.DROPPED_ITEM, Material.IRON_NUGGET);
// DisguiseAPI.disguiseEntity(arrow, miscDisguise);
if (PlaySound) {
world.playSound(loc, this.SoundType, 20, 2);
world.spawnParticle(this.ParticleType, loc.getX(), loc.getY(), loc.getZ(), 0);
@@ -1,6 +1,7 @@
package com.github.alathra.siegeengines.projectile;
import com.github.alathra.siegeengines.SiegeEngines;
import com.github.alathra.siegeengines.SiegeEnginesUtil;
import com.github.alathra.siegeengines.listeners.ClickHandler;
import org.bukkit.Bukkit;
import org.bukkit.Location;
@@ -10,11 +11,8 @@ import org.bukkit.Sound;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Snowball;
import org.bukkit.util.Vector;
//import me.libraryaddict.disguise.disguisetypes.DisguiseType;
//import me.libraryaddict.disguise.disguisetypes.MiscDisguise;
public class ExplosiveProjectile implements GunnersProjectile {
@@ -39,19 +37,16 @@ public class ExplosiveProjectile implements GunnersProjectile {
for (int i = 0; i < ProjectilesCount; i++) {
if (DelayedFire) {
baseDelay += DelayTime;
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(SiegeEngines.plugin, () -> {
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(SiegeEngines.getInstance(), () -> {
CreateEntity(entity, loc, velocity, player);
}, (long) baseDelay);
} else {
CreateEntity(entity, loc, velocity, player);
}
// }
}
}
private void CreateEntity(Entity entity, Location loc, Float velocity, Entity player) {
LivingEntity living = (LivingEntity) entity;
World world = entity.getLocation().getWorld();
Entity tnt = world.spawnEntity(loc, EntityType.SNOWBALL);
Snowball ball = (Snowball) tnt;
@@ -65,7 +60,7 @@ public class ExplosiveProjectile implements GunnersProjectile {
} else {
tnt.setVelocity(loc.getDirection().multiply(velocity));
}
tnt.setMetadata("isExplosiveProj", SiegeEngines.addMetaDataValue("true"));
tnt.setMetadata("isExplosiveProj", SiegeEnginesUtil.addMetaDataValue("true"));
Bukkit.getServer().getPluginManager().callEvent(new org.bukkit.event.entity.ProjectileLaunchEvent(tnt));
if (PlaySound) {
@@ -75,9 +70,6 @@ public class ExplosiveProjectile implements GunnersProjectile {
PlaySound = false;
}
}
// MiscDisguise miscDisguise = new MiscDisguise(DisguiseType.ARROW);
// miscDisguise.setEntity(tnt);
// miscDisguise.startDisguise();
}
@@ -1,6 +1,8 @@
package com.github.alathra.siegeengines.projectile;
import com.github.alathra.siegeengines.SiegeEngines;
import com.github.alathra.siegeengines.SiegeEnginesUtil;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
@@ -9,7 +11,6 @@ import org.bukkit.Sound;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.ThrownPotion;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.PotionMeta;
@@ -33,20 +34,18 @@ public class PotionProjectile implements GunnersProjectile {
for (int i = 0; i < EntityCount; i++) {
if (DelayedFire) {
baseDelay += DelayTime;
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(SiegeEngines.plugin, () -> {
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(SiegeEngines.getInstance(), () -> {
CreateEntity(entity, loc, velocity);
}, (long) baseDelay);
} else {
CreateEntity(entity, loc, velocity);
}
// }
}
}
private void CreateEntity(Entity entity, Location loc, Float velocity) {
World world = entity.getLocation().getWorld();
LivingEntity living = (LivingEntity) entity;
Entity arrow = world.spawnEntity(loc, EntityType.SPLASH_POTION);
if (Inaccuracy != 0f) {
@@ -54,7 +53,7 @@ public class PotionProjectile implements GunnersProjectile {
} else {
arrow.setVelocity(loc.getDirection().multiply(velocity));
}
arrow.setMetadata("isExplosiveProj", SiegeEngines.addMetaDataValue("true"));
arrow.setMetadata("isExplosiveProj", SiegeEnginesUtil.addMetaDataValue("true"));
Bukkit.getServer().getPluginManager().callEvent(new org.bukkit.event.entity.ProjectileLaunchEvent(arrow));
ItemStack itemStack = new ItemStack(Material.SPLASH_POTION);
PotionMeta potionMeta = (PotionMeta) itemStack.getItemMeta();
@@ -62,8 +61,6 @@ public class PotionProjectile implements GunnersProjectile {
itemStack.setItemMeta(potionMeta);
ThrownPotion potion = (ThrownPotion) arrow;
potion.setItem(itemStack);
// MiscDisguise miscDisguise = new MiscDisguise(DisguiseType.DROPPED_ITEM, Material.IRON_NUGGET);
// DisguiseAPI.disguiseEntity(arrow, miscDisguise);
world.playSound(loc, this.SoundType, 20, 2);
world.spawnParticle(this.ParticleType, loc.getX(), loc.getY(), loc.getZ(), 0);
}