Merge branch 'ccorp2002-edits'

This commit is contained in:
ShermansWorld committed 2024-01-06 18:18:38 -05:00
commit 6250d17520
3 files changed
+376 -348

No files matched your search

@@ -276,13 +276,12 @@ public class SiegeEngines extends JavaPlugin {
}
l.setY(l.getY() + 1);
int maxNearby = 0;
l.setDirection(player.getFacing().getDirection());
ItemStack item = new ItemStack(Material.CARVED_PUMPKIN);
ItemMeta meta = item.getItemMeta();
String id = "";
equip.AmmoHolder = new EquipmentMagazine();
if (equip.HaseBaseStand) {
if (equip.HasBaseStand) {
Location l2 = l;
l2.setY(l.getY() + equip.BaseStandOffset);
@@ -325,14 +324,6 @@ public class SiegeEngines extends JavaPlugin {
LivingEntity ent = (LivingEntity) entity2;
ArmorStand stand = (ArmorStand) ent;
equip.Entity = entity2;
for (Entity le : l.getNearbyEntities(5, 5, 5)) {
if (maxNearby >= 4) {
ent.damage(100.0d, player);
return false;
}
if (le instanceof ArmorStand)
maxNearby++;
}
equip.EntityId = entity2.getUniqueId();
stand.addEquipmentLock(EquipmentSlot.HEAD, LockType.REMOVING_OR_CHANGING);
@@ -344,8 +335,7 @@ public class SiegeEngines extends JavaPlugin {
stand.addEquipmentLock(EquipmentSlot.HAND, LockType.REMOVING_OR_CHANGING);
stand.addEquipmentLock(EquipmentSlot.OFF_HAND, LockType.REMOVING_OR_CHANGING);
stand.setInvisible(equip.AllowInvisibleStand);
stand.setBasePlate(false);
ent.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 2000000, 1));
stand.setBasePlate(true);
stand.setGravity(false);
ent.getEquipment().setHelmet(item);
@@ -1,284 +1,293 @@
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 = 7;
public int YOffset = 0;
public int PitchOffset = 0;
public int MaxFuel = 5;
public double PlacementOffsetY = 0;
public float VelocityPerFuel = 1.75f;
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 HaseBaseStand = 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 Ammo to Weapon");
itemInHand.setAmount(itemInHand.getAmount() - 1);
return true;
}
return false;
}
public void SaveState() {
}
public Location GetFireLocation(LivingEntity living) {
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 = 3;
float loadedFuel = this.AmmoHolder.LoadedFuel;
ItemStack LoadedProjectile = this.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() != 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);
Projectiles.get(LoadedProjectile).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;
Projectiles.get(LoadedProjectile).Shoot(player, this.Entity, this.GetFireLocation(living), loadedFuel * this.VelocityPerFuel);
}, (long) delay);
}
}
//}
}
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);
}
}
//}
}
@@ -151,6 +151,8 @@ public class ClickHandler implements Listener {
@EventHandler(priority = EventPriority.HIGH)
public void BlockPlaceEvent(org.bukkit.event.block.BlockPlaceEvent event) {
Player thePlayer = event.getPlayer();
if (event.isCancelled())
return;
if (event.isCancelled())
return;
if (event.getPlayer().getInventory().getItemInMainHand().getType() == Material.CARVED_PUMPKIN) {
@@ -196,6 +198,7 @@ public class ClickHandler implements Listener {
}
double distance = player.getLocation().distance(ent.getLocation());
if (distance >= Config.controlDistance) {
SiegeEngines.TrackedStands.get(player.getUniqueId()).remove(ent);
continue;
}
SiegeEquipment siege = SiegeEngines.equipment.get(ent.getUniqueId());
@@ -244,14 +247,16 @@ 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++) {
//ItemStack[] contents = inv.getStorageContents();
/*for(int i = 0; i < contents.length; i++) {
if(contents[i] == null) continue;
if(contents[i].isSimilar(m)) {
return true;
}
}
return false;
}*/
//m.setAmount(1);
return inv.containsAtLeast(m,m.getAmount());
//return false;
}
@EventHandler
@@ -279,7 +284,11 @@ public class ClickHandler implements Listener {
}
if (!player.isSneaking()) {
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())) {
@@ -287,12 +296,17 @@ public class ClickHandler implements Listener {
}
}
}
return;
}
if (SiegeEngines.TrackedStands.containsKey(player.getUniqueId())) {
List<Entity> entities = SiegeEngines.TrackedStands.get(player.getUniqueId());
if (entities == null) {
return;
}
player.sendMessage("§eReloading Ammunition");
boolean foundAmmo = false;
for (Entity entity : entities) {
boolean foundAmmo = false;
foundAmmo = false;
if ((entity.isDead())) continue;
if (SiegeEngines.equipment.containsKey(entity.getUniqueId())) {
SiegeEquipment equip = SiegeEngines.equipment.get(entity.getUniqueId());
@@ -306,7 +320,7 @@ public class ClickHandler implements Listener {
if (foundAmmo)
continue;
if (!hasItem((Inventory)state.getInventory(),stack))
continue;
continue;
state.getInventory().removeItem(stack);//setStorageContents(updateContents(state.getInventory(),stack,1));
//state.update(true,true);
equip.AmmoHolder.LoadedProjectile = 1;
@@ -316,7 +330,7 @@ public class ClickHandler implements Listener {
//state.update(true,true);
}
if (foundAmmo)
continue;
break;
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());
@@ -324,7 +338,7 @@ public class ClickHandler implements Listener {
if (foundAmmo)
continue;
if (!hasItem((Inventory)state.getInventory(),stack))
continue;
continue;
state.getInventory().removeItem(stack);//setStorageContents(updateContents(state.getInventory(),stack,1));
//state.update(true,true);
equip.AmmoHolder.LoadedProjectile = 1;
@@ -334,7 +348,7 @@ public class ClickHandler implements Listener {
//state.update(true,true);
}
if (foundAmmo)
continue;
break;
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());
@@ -342,7 +356,7 @@ public class ClickHandler implements Listener {
if (foundAmmo)
continue;
if (!hasItem((Inventory)state.getInventory(),stack))
continue;
continue;
state.getInventory().removeItem(stack);//setStorageContents(updateContents(state.getInventory(),stack,1));
//state.update(true,true);
equip.AmmoHolder.LoadedProjectile = 1;
@@ -352,72 +366,50 @@ public class ClickHandler implements Listener {
//state.update(true,true);
}
if (foundAmmo)
continue;
break;
if (!player.isSneaking())
return;
break;
if (!foundAmmo) {
for (ItemStack inventoryItem : event.getPlayer().getInventory().getContents()) {
for (ItemStack stack : equip.Projectiles.keySet()) {
if (foundAmmo)
continue;
if (!hasItem(event.getPlayer().getInventory(),stack))
continue;
continue;
if (stack.isSimilar(inventoryItem) && equip.AmmoHolder.LoadedProjectile == 0) {
equip.AmmoHolder.LoadedProjectile = 1;
equip.AmmoHolder.MaterialName = stack;
inventoryItem.setAmount(inventoryItem.getAmount() - 1);
foundAmmo = true;
break;
}
}
}
}
}
}
if (!foundAmmo) {
event.getPlayer().sendMessage("§eCould not load Ammunition.");
}
player.sendMessage("§eReloading Propellant");
for (Entity entity : entities) {
boolean foundAmmo = false;
foundAmmo = false;
if ((entity.isDead())) continue;
if (SiegeEngines.equipment.containsKey(entity.getUniqueId())) {
SiegeEquipment equip = SiegeEngines.equipment.get(entity.getUniqueId());
if (equip == null || !equip.Enabled) {
continue;
}
ItemStack stack = equip.FuelMaterial;
if (entity.getLocation().getBlock().getType() == Material.BARREL || entity.getLocation().getBlock().getType() == Material.CHEST) {
Block inv = entity.getLocation().getBlock();
Container state = ((Container) inv.getState());
ItemStack stack = equip.FuelMaterial;
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.LoadedFuel += 1;
foundAmmo = true;
//state.update(true,true);
}
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());
ItemStack stack = equip.FuelMaterial;
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.LoadedFuel += 1;
foundAmmo = true;
//state.update(true,true);
}
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());
ItemStack stack = equip.FuelMaterial;
if (foundAmmo)
if (!equip.CanLoadFuel())
continue;
if (!hasItem((Inventory)state.getInventory(),stack))
continue;
state.getInventory().removeItem(stack);//setStorageContents(updateContents(state.getInventory(),stack,1));
//state.update(true,true);
equip.AmmoHolder.LoadedFuel += 1;
@@ -425,22 +417,59 @@ public class ClickHandler implements Listener {
//state.update(true,true);
}
if (foundAmmo)
continue;
break;
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());
if (foundAmmo)
continue;
if (!hasItem((Inventory)state.getInventory(),stack))
continue;
state.getInventory().removeItem(stack);//setStorageContents(updateContents(state.getInventory(),stack,1));
//state.update(true,true);
if (!equip.CanLoadFuel())
continue;
equip.AmmoHolder.LoadedFuel += 1;
foundAmmo = true;
//state.update(true,true);
}
if (foundAmmo)
break;
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());
if (foundAmmo)
continue;
if (!hasItem((Inventory)state.getInventory(),stack))
continue;
if (!equip.CanLoadFuel())
continue;
state.getInventory().removeItem(stack);//setStorageContents(updateContents(state.getInventory(),stack,1));
//state.update(true,true);
equip.AmmoHolder.LoadedFuel += 1;
foundAmmo = true;
//state.update(true,true);
}
if (foundAmmo)
break;
if (!player.isSneaking())
return;
break;
if (!foundAmmo) {
for (ItemStack inventoryItem : event.getPlayer().getInventory().getContents()) {
if (hasItem((Inventory)event.getPlayer().getInventory(),stack)) {
if (foundAmmo)
continue;
break;
if (!equip.CanLoadFuel())
continue;
if (equip.FuelMaterial.isSimilar(inventoryItem)) {
equip.AmmoHolder.LoadedFuel += 1;
inventoryItem.setAmount(inventoryItem.getAmount() - 1);
foundAmmo = true;
}
equip.AmmoHolder.LoadedFuel += 1;
stack.setAmount(1);
event.getPlayer().getInventory().removeItem(stack);
foundAmmo = true;
break;
}
}
if (!foundAmmo) {
event.getPlayer().sendMessage("§eCould not load Propellant.");
}
}
}
return;
@@ -848,7 +877,7 @@ public class ClickHandler implements Listener {
if (stack.isSimilar(itemInHand) && equipment.AmmoHolder.LoadedProjectile == 0) {
equipment.AmmoHolder.LoadedProjectile = 1;
equipment.AmmoHolder.MaterialName = stack;
player.sendMessage("§eAdding Ammo to Weapon");
player.sendMessage("§eAdding Ammunition to Weapon");
itemInHand.setAmount(itemInHand.getAmount() - 1);
return;
}