mirror of
https://github.com/darksaid98/SiegeEngines.git
synced 2026-12-01 14:38:55 +00:00
refactor
This commit is contained in:
1 parent
6250d17520
commit
6e36cce455
6 files changed
+482
-516
No files matched your search
@@ -0,0 +1,343 @@
|
||||
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.Particle;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
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 EquipmentMagazine 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 = 0;
|
||||
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 EquipmentMagazine();
|
||||
//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;
|
||||
if (projectiles.keySet().isEmpty() || projectiles.isEmpty())
|
||||
projectiles.put(new ItemStack(Material.GUNPOWDER), defaultProj);
|
||||
for (ItemStack mat : projectiles.keySet()) {
|
||||
projectiles.put(mat, projectiles.get(mat));
|
||||
}
|
||||
|
||||
// set passed parameters as object variables
|
||||
|
||||
this.name = name;
|
||||
this.projectiles = projectiles;
|
||||
this.fuelItem = fuelItem;
|
||||
this.customModelID = customModelID;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
if (projectiles.containsKey(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 */);
|
||||
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() < 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.plugin, () -> {
|
||||
if (living == null || living.isDead()) {
|
||||
Bukkit.getServer().getScheduler().cancelTask(taskNumber);
|
||||
return;
|
||||
}
|
||||
|
||||
if (hasFired) {
|
||||
Bukkit.getServer().getScheduler().cancelTask(taskNumber);
|
||||
taskNumber = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(SiegeEngines.plugin, () -> {
|
||||
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;
|
||||
SiegeEngines.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);
|
||||
SiegeEngines.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);
|
||||
SiegeEngines.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.plugin, () -> {
|
||||
//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);
|
||||
|
||||
}
|
||||
}
|
||||
//}
|
||||
|
||||
}
|
||||
@@ -26,8 +26,7 @@ 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.jetbrains.annotations.NotNull;
|
||||
import org.bukkit.metadata.MetadataValueAdapter;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
|
||||
@@ -71,10 +70,10 @@ public class SiegeEngines extends JavaPlugin {
|
||||
TrackedStands.clear();
|
||||
DefinedEquipment.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 : DefinedEquipment.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,20 +84,20 @@ public class SiegeEngines extends JavaPlugin {
|
||||
@Override
|
||||
public void onDisable() {
|
||||
commandHandler.onDisable();
|
||||
for (SiegeEquipment equip : equipment.values()) {
|
||||
if (equip.Entity != null) {
|
||||
for (SiegeEngine siegeEngine : equipment.values()) {
|
||||
if (siegeEngine.entity != null) {
|
||||
ItemStack item = new ItemStack(Material.CARVED_PUMPKIN);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
equip.AmmoHolder = new EquipmentMagazine();
|
||||
siegeEngine.ammoHolder = new EquipmentMagazine();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -107,7 +106,7 @@ public class SiegeEngines extends JavaPlugin {
|
||||
return new FixedMetadataValue(Bukkit.getServer().getPluginManager().getPlugin("SiegeEngines"), value);
|
||||
}
|
||||
|
||||
public static SiegeEquipment CreateClone(Integer ModelId) {
|
||||
public static SiegeEngine CreateClone(Integer ModelId) {
|
||||
try {
|
||||
return DefinedEquipment.get(ModelId).clone();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
@@ -117,11 +116,11 @@ public class SiegeEngines extends JavaPlugin {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static HashMap<Integer, SiegeEquipment> DefinedEquipment = new HashMap<Integer, SiegeEquipment>();
|
||||
public static HashMap<Integer, SiegeEngine> DefinedEquipment = new HashMap<Integer, SiegeEngine>();
|
||||
|
||||
public static HashMap<UUID, List<Entity>> TrackedStands = new HashMap<UUID, List<Entity>>();
|
||||
|
||||
public static HashMap<UUID, SiegeEquipment> equipment = new HashMap<UUID, SiegeEquipment>();
|
||||
public static HashMap<UUID, SiegeEngine> equipment = new HashMap<UUID, SiegeEngine>();
|
||||
|
||||
public static String convertTime(long time) {
|
||||
|
||||
@@ -140,94 +139,49 @@ public class SiegeEngines extends JavaPlugin {
|
||||
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;
|
||||
//String name, Integer XOffset, Integer YOffset, Integer fuelMax, Float fuelVelocityMod, Integer customModelId, HashMap<ItemStack, GunnersProjectile> projObj
|
||||
//@NotNull String name, @NotNull HashMap<ItemStack, GunnersProjectile> projectiles, @NotNull ItemStack fuelItem, int customModelID
|
||||
SiegeEngine trebuchet = new SiegeEngine("Trebuchet", new HashMap<ItemStack, GunnersProjectile>(), new ItemStack(Material.GUNPOWDER), 150);
|
||||
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;
|
||||
DefinedEquipment.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,43 +189,43 @@ 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);
|
||||
DefinedEquipment.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);
|
||||
DefinedEquipment.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) {
|
||||
SiegeEngine siegeEngine = CreateClone(CustomModelData);
|
||||
if (siegeEngine == null || !siegeEngine.enabled) {
|
||||
return false;
|
||||
}
|
||||
l.setY(l.getY() + 1);
|
||||
@@ -280,17 +234,17 @@ public class SiegeEngines extends JavaPlugin {
|
||||
ItemStack item = new ItemStack(Material.CARVED_PUMPKIN);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
String id = "";
|
||||
equip.AmmoHolder = new EquipmentMagazine();
|
||||
if (equip.HasBaseStand) {
|
||||
siegeEngine.ammoHolder = new EquipmentMagazine();
|
||||
if (siegeEngine.hasBaseStand) {
|
||||
|
||||
Location l2 = l;
|
||||
l2.setY(l.getY() + equip.BaseStandOffset);
|
||||
l2.setY(l.getY() + siegeEngine.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);
|
||||
meta.setCustomModelData(siegeEngine.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);
|
||||
@@ -302,20 +256,20 @@ public class SiegeEngines extends JavaPlugin {
|
||||
stand.setBasePlate(false);
|
||||
// stand.setSmall(true);
|
||||
item.setItemMeta(meta);
|
||||
stand.setInvisible(equip.AllowInvisibleStand);
|
||||
stand.setInvisible(siegeEngine.allowInvisibleStand);
|
||||
ent.getEquipment().setHelmet(item);
|
||||
stand.setGravity(false);
|
||||
stand.setMarker(true);
|
||||
}
|
||||
l.setY(l.getY() + equip.PlacementOffsetY);
|
||||
l.setY(l.getY() + siegeEngine.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");
|
||||
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);
|
||||
|
||||
@@ -323,9 +277,9 @@ public class SiegeEngines extends JavaPlugin {
|
||||
|
||||
LivingEntity ent = (LivingEntity) entity2;
|
||||
ArmorStand stand = (ArmorStand) ent;
|
||||
equip.Entity = entity2;
|
||||
siegeEngine.entity = entity2;
|
||||
|
||||
equip.EntityId = entity2.getUniqueId();
|
||||
siegeEngine.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);
|
||||
@@ -334,7 +288,7 @@ public class SiegeEngines extends JavaPlugin {
|
||||
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.setInvisible(siegeEngine.allowInvisibleStand);
|
||||
stand.setBasePlate(true);
|
||||
|
||||
stand.setGravity(false);
|
||||
@@ -348,7 +302,7 @@ public class SiegeEngines extends JavaPlugin {
|
||||
newList.add(entity2);
|
||||
TrackedStands.put(player.getUniqueId(), newList);
|
||||
}
|
||||
equipment.put(entity2.getUniqueId(), equip);
|
||||
equipment.put(entity2.getUniqueId(), siegeEngine);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -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,6 +1,6 @@
|
||||
package com.github.alathra.siegeengines.command;
|
||||
|
||||
import com.github.alathra.siegeengines.SiegeEquipment;
|
||||
import com.github.alathra.siegeengines.SiegeEngine;
|
||||
import com.github.alathra.siegeengines.projectile.GunnersProjectile;
|
||||
import com.github.milkdrinkers.colorparser.ColorParser;
|
||||
import dev.jorel.commandapi.CommandAPIBukkit;
|
||||
@@ -49,7 +49,7 @@ public class SiegeEnginesCommand {
|
||||
new StringArgument("equipmentid")
|
||||
.replaceSuggestions(
|
||||
ArgumentSuggestions.strings(
|
||||
DefinedEquipment.values().stream().map(SiegeEquipment -> SiegeEquipment.EquipmentId).toList()
|
||||
DefinedEquipment.values().stream().map(SiegeEquipment -> SiegeEquipment.id).toList()
|
||||
)
|
||||
),
|
||||
new PlayerArgument("target")
|
||||
@@ -76,7 +76,7 @@ public class SiegeEnginesCommand {
|
||||
|
||||
Player player = (Player) args.getOptional("target").orElse(sender);
|
||||
|
||||
for (SiegeEquipment SiegeEquipment : DefinedEquipment.values()) {
|
||||
for (SiegeEngine SiegeEquipment : DefinedEquipment.values()) {
|
||||
if (SiegeEquipment.equals(equipmentId)) {
|
||||
giveEquipment(player, SiegeEquipment);
|
||||
break;
|
||||
@@ -88,7 +88,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 : DefinedEquipment.values()) {
|
||||
giveEquipment(player, i);
|
||||
}
|
||||
}
|
||||
@@ -103,23 +103,23 @@ public class SiegeEnginesCommand {
|
||||
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 : DefinedEquipment.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);
|
||||
|
||||
@@ -44,15 +44,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;
|
||||
@@ -64,16 +58,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();
|
||||
}
|
||||
@@ -92,7 +76,6 @@ public class ClickHandler implements Listener {
|
||||
}
|
||||
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());
|
||||
@@ -101,16 +84,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++) {
|
||||
@@ -201,7 +174,7 @@ public class ClickHandler implements Listener {
|
||||
SiegeEngines.TrackedStands.get(player.getUniqueId()).remove(ent);
|
||||
continue;
|
||||
}
|
||||
SiegeEquipment siege = SiegeEngines.equipment.get(ent.getUniqueId());
|
||||
SiegeEngine siege = SiegeEngines.equipment.get(ent.getUniqueId());
|
||||
if (counter > 4)
|
||||
return;
|
||||
if (ent == null || ent.isDead()) {
|
||||
@@ -219,9 +192,7 @@ public class ClickHandler implements Listener {
|
||||
} else {
|
||||
if (player instanceof Player) {
|
||||
}
|
||||
//player.sendMessage("§eAmmunition Not Loaded");
|
||||
}
|
||||
// player.sendMessage(String.format("§e" +actualDelay));
|
||||
|
||||
}
|
||||
}
|
||||
@@ -290,8 +261,8 @@ public class ClickHandler implements Listener {
|
||||
for (Entity entity : entities) {
|
||||
|
||||
if (SiegeEngines.equipment.containsKey(entity.getUniqueId())) {
|
||||
SiegeEquipment equip = SiegeEngines.equipment.get(entity.getUniqueId());
|
||||
if (equip != null && equip.Enabled && !(entity.isDead())) {
|
||||
SiegeEngine equip = SiegeEngines.equipment.get(entity.getUniqueId());
|
||||
if (equip != null && equip.enabled && !(entity.isDead())) {
|
||||
equip.Fire(player,10f,1);
|
||||
}
|
||||
}
|
||||
@@ -309,22 +280,22 @@ public class ClickHandler implements Listener {
|
||||
foundAmmo = false;
|
||||
if ((entity.isDead())) continue;
|
||||
if (SiegeEngines.equipment.containsKey(entity.getUniqueId())) {
|
||||
SiegeEquipment equip = SiegeEngines.equipment.get(entity.getUniqueId());
|
||||
if (equip == null || !equip.Enabled) {
|
||||
SiegeEngine equip = SiegeEngines.equipment.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);
|
||||
@@ -334,15 +305,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);
|
||||
@@ -352,15 +323,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);
|
||||
@@ -371,14 +342,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;
|
||||
@@ -396,11 +367,11 @@ public class ClickHandler implements Listener {
|
||||
foundAmmo = false;
|
||||
if ((entity.isDead())) continue;
|
||||
if (SiegeEngines.equipment.containsKey(entity.getUniqueId())) {
|
||||
SiegeEquipment equip = SiegeEngines.equipment.get(entity.getUniqueId());
|
||||
if (equip == null || !equip.Enabled) {
|
||||
SiegeEngine equip = SiegeEngines.equipment.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());
|
||||
@@ -412,7 +383,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);
|
||||
}
|
||||
@@ -429,7 +400,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);
|
||||
}
|
||||
@@ -446,7 +417,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);
|
||||
}
|
||||
@@ -460,7 +431,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;
|
||||
@@ -516,7 +487,7 @@ 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);
|
||||
@@ -525,17 +496,17 @@ public class ClickHandler implements Listener {
|
||||
|
||||
if (SiegeEngines.equipment.containsKey(entity.getUniqueId())) {
|
||||
equip = SiegeEngines.equipment.get(entity.getUniqueId());
|
||||
if (equip == null || !equip.Enabled) {
|
||||
if (equip == null || !equip.enabled) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
equip = SiegeEngines.CreateClone(living.getEquipment().getHelmet().getItemMeta().getCustomModelData());
|
||||
if (equip == null || !equip.Enabled) {
|
||||
if (equip == null || !equip.enabled) {
|
||||
return;
|
||||
}
|
||||
equip.AmmoHolder = new EquipmentMagazine();
|
||||
equip.Entity = entity;
|
||||
equip.EntityId = entity.getUniqueId();
|
||||
equip.ammoHolder = new EquipmentMagazine();
|
||||
equip.entity = entity;
|
||||
equip.entityId = entity.getUniqueId();
|
||||
}
|
||||
stand.addEquipmentLock(EquipmentSlot.HEAD, LockType.REMOVING_OR_CHANGING);
|
||||
stand.addEquipmentLock(EquipmentSlot.LEGS, LockType.ADDING_OR_CHANGING);
|
||||
@@ -586,11 +557,11 @@ public class ClickHandler implements Listener {
|
||||
return;
|
||||
}
|
||||
loc.setPitch((float) (loc.getPitch() - amount));
|
||||
SiegeEquipment equipment = SiegeEngines.equipment.get(ent.getUniqueId());
|
||||
SiegeEngine equipment = SiegeEngines.equipment.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);
|
||||
@@ -605,11 +576,11 @@ public class ClickHandler implements Listener {
|
||||
return;
|
||||
}
|
||||
loc.setPitch((float) (loc.getPitch() - amount));
|
||||
SiegeEquipment equipment = SiegeEngines.equipment.get(ent.getUniqueId());
|
||||
SiegeEngine equipment = SiegeEngines.equipment.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);
|
||||
@@ -623,12 +594,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.equipment.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));
|
||||
|
||||
}
|
||||
@@ -699,7 +670,7 @@ public class ClickHandler implements Listener {
|
||||
continue;
|
||||
}
|
||||
|
||||
SiegeEquipment equipment = SiegeEngines.equipment.get(ent.getUniqueId());
|
||||
SiegeEngine equipment = SiegeEngines.equipment.get(ent.getUniqueId());
|
||||
if (equipment != null) {
|
||||
equipment.LoadFuel(player);
|
||||
}
|
||||
@@ -711,7 +682,7 @@ public class ClickHandler implements Listener {
|
||||
if (ent.isDead()) {
|
||||
continue;
|
||||
}
|
||||
SiegeEquipment equipment = SiegeEngines.equipment.get(ent.getUniqueId());
|
||||
SiegeEngine equipment = SiegeEngines.equipment.get(ent.getUniqueId());
|
||||
if (equipment != null) {
|
||||
equipment.LoadProjectile(player, projectile);
|
||||
}
|
||||
@@ -842,7 +813,7 @@ public class ClickHandler implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
SiegeEquipment equipment = SiegeEngines.equipment.get(entity.getUniqueId());
|
||||
SiegeEngine equipment = SiegeEngines.equipment.get(entity.getUniqueId());
|
||||
event.setCancelled(true);
|
||||
|
||||
if (itemInHand == null || itemInHand.getType() == Material.AIR) {
|
||||
@@ -851,32 +822,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 {
|
||||
@@ -40,7 +40,7 @@ public class RotationHandler implements Listener {
|
||||
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.equipment.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));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user