mirror of
https://github.com/darksaid98/SiegeEngines.git
synced 2026-12-03 14:38:53 +00:00
refactor #2
This commit is contained in:
1 parent
6e36cce455
commit
9f561fff16
14 files changed
+329
-367
No files matched your search
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>com.github.alathra</groupId>
|
<groupId>com.github.alathra</groupId>
|
||||||
<artifactId>SiegeEngines</artifactId>
|
<artifactId>SiegeEngines</artifactId>
|
||||||
<version>0.5.3</version>
|
<version>0.5.5</version>
|
||||||
|
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<name>SiegeEngines</name>
|
<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);
|
|
||||||
}
|
|
||||||
@@ -10,13 +10,19 @@ import com.github.alathra.siegeengines.projectile.GunnersProjectile;
|
|||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.NamespacedKey;
|
||||||
import org.bukkit.Particle;
|
import org.bukkit.Particle;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
|
import org.bukkit.entity.ArmorStand;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.entity.Player;
|
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.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@@ -53,7 +59,7 @@ public class SiegeEngine implements Cloneable {
|
|||||||
public List<Integer> firingModelNumbers;
|
public List<Integer> firingModelNumbers;
|
||||||
public int readyModelNumber;
|
public int readyModelNumber;
|
||||||
public int nextModelNumber;
|
public int nextModelNumber;
|
||||||
public EquipmentMagazine ammoHolder;
|
public SiegeEngineAmmoHolder ammoHolder;
|
||||||
|
|
||||||
// Optional variables
|
// Optional variables
|
||||||
public boolean allowInvisibleStand;
|
public boolean allowInvisibleStand;
|
||||||
@@ -92,12 +98,12 @@ public class SiegeEngine implements Cloneable {
|
|||||||
readyModelNumber = customModelID;
|
readyModelNumber = customModelID;
|
||||||
modelNumberToFireAt = customModelID;
|
modelNumberToFireAt = customModelID;
|
||||||
firingModelNumbers = new ArrayList<Integer>();
|
firingModelNumbers = new ArrayList<Integer>();
|
||||||
ammoHolder = new EquipmentMagazine();
|
ammoHolder = new SiegeEngineAmmoHolder();
|
||||||
//fuelItem = new ItemStack(Material.GUNPOWDER);
|
//fuelItem = new ItemStack(Material.GUNPOWDER);
|
||||||
cycleThroughModelsBeforeFiring = false;
|
cycleThroughModelsBeforeFiring = false;
|
||||||
allowInvisibleStand = false;
|
allowInvisibleStand = false;
|
||||||
shotAmount = 1;
|
shotAmount = 1;
|
||||||
ammoHolder.LoadedFuel = maxFuel;
|
ammoHolder.loadedFuel = maxFuel;
|
||||||
enabled = true;
|
enabled = true;
|
||||||
cycleThroughModelsBeforeFiring = false;
|
cycleThroughModelsBeforeFiring = false;
|
||||||
rotateSideways = false;
|
rotateSideways = false;
|
||||||
@@ -134,29 +140,29 @@ public class SiegeEngine implements Cloneable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Boolean isLoaded() {
|
public Boolean isLoaded() {
|
||||||
if (this.maxFuel <= 0 && ammoHolder.LoadedProjectile >= 1)
|
if (this.maxFuel <= 0 && ammoHolder.loadedProjectile >= 1)
|
||||||
return true;
|
return true;
|
||||||
return (ammoHolder.LoadedFuel > 0 && ammoHolder.LoadedProjectile >= 1);
|
return (ammoHolder.loadedFuel > 0 && ammoHolder.loadedProjectile >= 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean CanLoadFuel() {
|
public Boolean CanLoadFuel() {
|
||||||
return ammoHolder.LoadedFuel < maxFuel;
|
return ammoHolder.loadedFuel < maxFuel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean LoadFuel(Entity player) {
|
public Boolean LoadFuel(Entity player) {
|
||||||
if (ammoHolder.LoadedFuel == maxFuel) {
|
if (ammoHolder.loadedFuel == maxFuel) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (!(player instanceof Player)) {
|
if (!(player instanceof Player)) {
|
||||||
ammoHolder.LoadedFuel = maxFuel;
|
ammoHolder.loadedFuel = maxFuel;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (((Player) player).getInventory().containsAtLeast(fuelItem, 1) || fuelItem.getType() == Material.AIR) {
|
if (((Player) player).getInventory().containsAtLeast(fuelItem, 1) || fuelItem.getType() == Material.AIR) {
|
||||||
if (CanLoadFuel()) {
|
if (CanLoadFuel()) {
|
||||||
this.ammoHolder.LoadedFuel += 1;
|
this.ammoHolder.loadedFuel += 1;
|
||||||
//SaveState();
|
//SaveState();
|
||||||
((Player) player).getInventory().removeItem(fuelItem);
|
((Player) player).getInventory().removeItem(fuelItem);
|
||||||
((Player) player).sendMessage("§eLoaded " + ammoHolder.LoadedFuel + "/" + maxFuel);
|
((Player) player).sendMessage("§eLoaded " + ammoHolder.loadedFuel + "/" + maxFuel);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
@@ -172,17 +178,19 @@ public class SiegeEngine implements Cloneable {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!(player instanceof Player)) {
|
if (!(player instanceof Player)) {
|
||||||
ammoHolder.LoadedProjectile = 1;
|
ammoHolder.loadedProjectile = 1;
|
||||||
ammoHolder.LoadedFuel = maxFuel;
|
ammoHolder.loadedFuel = maxFuel;
|
||||||
ammoHolder.MaterialName = itemInHand;
|
ammoHolder.materialName = itemInHand;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (projectiles.containsKey(itemInHand.getType()) && ammoHolder.LoadedProjectile == 0) {
|
for (ItemStack im : projectiles.keySet()) {
|
||||||
ammoHolder.LoadedProjectile = 1;
|
if(im.getType().equals(itemInHand.getType()) && ammoHolder.loadedProjectile == 0) {
|
||||||
ammoHolder.MaterialName = itemInHand;
|
ammoHolder.loadedProjectile = 1;
|
||||||
((Player) player).sendMessage("§eAdding Ammunition to Weapon");
|
ammoHolder.materialName = itemInHand;
|
||||||
itemInHand.setAmount(itemInHand.getAmount() - 1);
|
((Player) player).sendMessage("§eAdding Ammunition to Weapon");
|
||||||
return true;
|
itemInHand.setAmount(itemInHand.getAmount() - 1);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -209,8 +217,6 @@ public class SiegeEngine implements Cloneable {
|
|||||||
Location origin = this.GetFireLocation(living);
|
Location origin = this.GetFireLocation(living);
|
||||||
Vector direction = origin.getDirection();
|
Vector direction = origin.getDirection();
|
||||||
direction.multiply(5 /* the range */);
|
direction.multiply(5 /* the range */);
|
||||||
Location destination = origin.clone().add(direction);
|
|
||||||
|
|
||||||
direction.normalize();
|
direction.normalize();
|
||||||
for (int i = 0; i < 3 /* range */; i += 1) {
|
for (int i = 0; i < 3 /* range */; i += 1) {
|
||||||
Location spawn = origin.add(direction);
|
Location spawn = origin.add(direction);
|
||||||
@@ -227,10 +233,10 @@ public class SiegeEngine implements Cloneable {
|
|||||||
if (System.currentTimeMillis() < nextShotTime) {
|
if (System.currentTimeMillis() < nextShotTime) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (ammoHolder.LoadedFuel <= 0)
|
if (ammoHolder.loadedFuel <= 0)
|
||||||
ammoHolder.LoadedFuel = 0;
|
ammoHolder.loadedFuel = 0;
|
||||||
float loadedFuel = ammoHolder.LoadedFuel;
|
float loadedFuel = ammoHolder.loadedFuel;
|
||||||
ItemStack LoadedProjectile = ammoHolder.MaterialName;
|
ItemStack LoadedProjectile = ammoHolder.materialName;
|
||||||
|
|
||||||
|
|
||||||
LivingEntity living = (LivingEntity) entity;
|
LivingEntity living = (LivingEntity) entity;
|
||||||
@@ -244,9 +250,9 @@ public class SiegeEngine implements Cloneable {
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ammoHolder.LoadedFuel = 0;
|
ammoHolder.loadedFuel = 0;
|
||||||
ammoHolder.LoadedProjectile = 0;
|
ammoHolder.loadedProjectile = 0;
|
||||||
ammoHolder.MaterialName = new ItemStack(Material.AIR, 1);
|
ammoHolder.materialName = new ItemStack(Material.AIR, 1);
|
||||||
|
|
||||||
worldName = entity.getWorld().getName();
|
worldName = entity.getWorld().getName();
|
||||||
nextShotTime = System.currentTimeMillis() + 1000;
|
nextShotTime = System.currentTimeMillis() + 1000;
|
||||||
@@ -256,7 +262,7 @@ public class SiegeEngine implements Cloneable {
|
|||||||
}
|
}
|
||||||
if (cycleThroughModelsBeforeFiring) {
|
if (cycleThroughModelsBeforeFiring) {
|
||||||
|
|
||||||
this.taskNumber = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(SiegeEngines.plugin, () -> {
|
this.taskNumber = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(SiegeEngines.getInstance(), () -> {
|
||||||
if (living == null || living.isDead()) {
|
if (living == null || living.isDead()) {
|
||||||
Bukkit.getServer().getScheduler().cancelTask(taskNumber);
|
Bukkit.getServer().getScheduler().cancelTask(taskNumber);
|
||||||
return;
|
return;
|
||||||
@@ -264,7 +270,7 @@ public class SiegeEngine implements Cloneable {
|
|||||||
|
|
||||||
if (hasFired) {
|
if (hasFired) {
|
||||||
Bukkit.getServer().getScheduler().cancelTask(taskNumber);
|
Bukkit.getServer().getScheduler().cancelTask(taskNumber);
|
||||||
taskNumber = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(SiegeEngines.plugin, () -> {
|
taskNumber = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(SiegeEngines.getInstance(), () -> {
|
||||||
if (living == null || living.isDead()) {
|
if (living == null || living.isDead()) {
|
||||||
Bukkit.getServer().getScheduler().cancelTask(taskNumber);
|
Bukkit.getServer().getScheduler().cancelTask(taskNumber);
|
||||||
return;
|
return;
|
||||||
@@ -275,14 +281,14 @@ public class SiegeEngine implements Cloneable {
|
|||||||
hasReloaded = false;
|
hasReloaded = false;
|
||||||
hasFired = false;
|
hasFired = false;
|
||||||
nextModelNumber = 0;
|
nextModelNumber = 0;
|
||||||
SiegeEngines.UpdateEntityIdModel(entity, readyModelNumber, worldName);
|
SiegeEnginesUtil.UpdateEntityIdModel(entity, readyModelNumber, worldName);
|
||||||
taskNumber = 0;
|
taskNumber = 0;
|
||||||
} else {
|
} else {
|
||||||
//firing stages
|
//firing stages
|
||||||
if (nextModelNumber - 1 <= firingModelNumbers.size() && nextModelNumber - 1 >= 0) {
|
if (nextModelNumber - 1 <= firingModelNumbers.size() && nextModelNumber - 1 >= 0) {
|
||||||
int modelData = firingModelNumbers.get(nextModelNumber - 1);
|
int modelData = firingModelNumbers.get(nextModelNumber - 1);
|
||||||
// player.sendMessage("§e" + modelData);
|
// player.sendMessage("§e" + modelData);
|
||||||
SiegeEngines.UpdateEntityIdModel(entity, modelData, worldName);
|
SiegeEnginesUtil.UpdateEntityIdModel(entity, modelData, worldName);
|
||||||
nextModelNumber -= 1;
|
nextModelNumber -= 1;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@@ -298,7 +304,7 @@ public class SiegeEngine implements Cloneable {
|
|||||||
|
|
||||||
int modelData = firingModelNumbers.get(nextModelNumber);
|
int modelData = firingModelNumbers.get(nextModelNumber);
|
||||||
// player.sendMessage("§e" + modelData);
|
// player.sendMessage("§e" + modelData);
|
||||||
SiegeEngines.UpdateEntityIdModel(entity, modelData, worldName);
|
SiegeEnginesUtil.UpdateEntityIdModel(entity, modelData, worldName);
|
||||||
if (modelData == modelNumberToFireAt) {
|
if (modelData == modelNumberToFireAt) {
|
||||||
// player.sendMessage("§efiring" + modelData);
|
// player.sendMessage("§efiring" + modelData);
|
||||||
if (LoadedProjectile == null) return;
|
if (LoadedProjectile == null) return;
|
||||||
@@ -316,7 +322,7 @@ public class SiegeEngine implements Cloneable {
|
|||||||
}
|
}
|
||||||
}, 0, millisecondsBetweenFiringStages);
|
}, 0, millisecondsBetweenFiringStages);
|
||||||
} else {
|
} else {
|
||||||
taskNumber = Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(SiegeEngines.plugin, () -> {
|
taskNumber = Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(SiegeEngines.getInstance(), () -> {
|
||||||
//player.sendMessage("§etask");
|
//player.sendMessage("§etask");
|
||||||
if (living == null || living.isDead()) {
|
if (living == null || living.isDead()) {
|
||||||
Bukkit.getServer().getScheduler().cancelTask(taskNumber);
|
Bukkit.getServer().getScheduler().cancelTask(taskNumber);
|
||||||
@@ -338,6 +344,88 @@ public class SiegeEngine implements Cloneable {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//}
|
|
||||||
|
@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,29 +6,19 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import com.github.alathra.siegeengines.command.CommandHandler;
|
import com.github.alathra.siegeengines.command.CommandHandler;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.NamespacedKey;
|
|
||||||
import org.bukkit.Particle;
|
import org.bukkit.Particle;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.entity.ArmorStand;
|
|
||||||
import org.bukkit.entity.ArmorStand.LockType;
|
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.inventory.EquipmentSlot;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.bukkit.persistence.PersistentDataType;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.bukkit.metadata.MetadataValueAdapter;
|
import org.bukkit.metadata.MetadataValueAdapter;
|
||||||
import org.bukkit.metadata.FixedMetadataValue;
|
|
||||||
|
|
||||||
import com.github.alathra.siegeengines.listeners.ClickHandler;
|
import com.github.alathra.siegeengines.listeners.ClickHandler;
|
||||||
import com.github.alathra.siegeengines.listeners.RotationHandler;
|
import com.github.alathra.siegeengines.listeners.RotationHandler;
|
||||||
@@ -39,13 +29,15 @@ import com.github.alathra.siegeengines.projectile.GunnersProjectile;
|
|||||||
|
|
||||||
public class SiegeEngines extends JavaPlugin {
|
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 MetadataValueAdapter metadata;
|
||||||
public static Random random = new Random();
|
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() {
|
public static SiegeEngines getInstance() {
|
||||||
@@ -54,23 +46,20 @@ public class SiegeEngines extends JavaPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoad() {
|
public void onLoad() {
|
||||||
plugin = this;
|
|
||||||
commandHandler = new CommandHandler(this);
|
commandHandler = new CommandHandler(this);
|
||||||
commandHandler.onLoad();
|
commandHandler.onLoad();
|
||||||
|
instance = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
instance = this;
|
|
||||||
Path = this.getDataFolder().getAbsolutePath();
|
|
||||||
getServer().getPluginManager().registerEvents(new RotationHandler(), this);
|
getServer().getPluginManager().registerEvents(new RotationHandler(), this);
|
||||||
getServer().getPluginManager().registerEvents(new ClickHandler(), this);
|
getServer().getPluginManager().registerEvents(new ClickHandler(), this);
|
||||||
equipment.clear();
|
activeSiegeEngines.clear();
|
||||||
TrackedStands.clear();
|
trackedStands.clear();
|
||||||
DefinedEquipment.clear();
|
definedSiegeEngines.clear();
|
||||||
AddDefaults();
|
AddDefaults();
|
||||||
for (SiegeEngine i : DefinedEquipment.values()) {
|
for (SiegeEngine i : definedSiegeEngines.values()) {
|
||||||
System.out.println("§eEnabled Weapon : " + i.name);
|
System.out.println("§eEnabled Weapon : " + i.name);
|
||||||
System.out.println("§eWeapon Propellant/\"Fuel\" ItemStacks : " + i.fuelItem);
|
System.out.println("§eWeapon Propellant/\"Fuel\" ItemStacks : " + i.fuelItem);
|
||||||
for (ItemStack proj : i.projectiles.keySet()) {
|
for (ItemStack proj : i.projectiles.keySet()) {
|
||||||
@@ -84,11 +73,11 @@ public class SiegeEngines extends JavaPlugin {
|
|||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
commandHandler.onDisable();
|
commandHandler.onDisable();
|
||||||
for (SiegeEngine siegeEngine : equipment.values()) {
|
for (SiegeEngine siegeEngine : activeSiegeEngines.values()) {
|
||||||
if (siegeEngine.entity != null) {
|
if (siegeEngine.entity != null) {
|
||||||
ItemStack item = new ItemStack(Material.CARVED_PUMPKIN);
|
ItemStack item = new ItemStack(Material.CARVED_PUMPKIN);
|
||||||
ItemMeta meta = item.getItemMeta();
|
ItemMeta meta = item.getItemMeta();
|
||||||
siegeEngine.ammoHolder = new EquipmentMagazine();
|
siegeEngine.ammoHolder = new SiegeEngineAmmoHolder();
|
||||||
|
|
||||||
meta.setCustomModelData(siegeEngine.readyModelNumber);
|
meta.setCustomModelData(siegeEngine.readyModelNumber);
|
||||||
meta.setDisplayName("§e" + siegeEngine.name + " Item");
|
meta.setDisplayName("§e" + siegeEngine.name + " Item");
|
||||||
@@ -102,47 +91,8 @@ public class SiegeEngines extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static FixedMetadataValue addMetaDataValue(Object value) {
|
|
||||||
return new FixedMetadataValue(Bukkit.getServer().getPluginManager().getPlugin("SiegeEngines"), value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SiegeEngine CreateClone(Integer ModelId) {
|
|
||||||
try {
|
|
||||||
return DefinedEquipment.get(ModelId).clone();
|
|
||||||
} catch (CloneNotSupportedException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
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, SiegeEngine> equipment = new HashMap<UUID, SiegeEngine>();
|
|
||||||
|
|
||||||
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 void AddDefaults() {
|
public static void AddDefaults() {
|
||||||
//String name, Integer XOffset, Integer YOffset, Integer fuelMax, Float fuelVelocityMod, Integer customModelId, HashMap<ItemStack, GunnersProjectile> projObj
|
SiegeEngine trebuchet = new SiegeEngine("Trebuchet", new HashMap<ItemStack, GunnersProjectile>(), new ItemStack(Material.GUNPOWDER), 122);
|
||||||
//@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.xOffset = 5;
|
||||||
trebuchet.yOffset = 5;
|
trebuchet.yOffset = 5;
|
||||||
trebuchet.velocityPerFuel = 0.3f;
|
trebuchet.velocityPerFuel = 0.3f;
|
||||||
@@ -161,7 +111,7 @@ public class SiegeEngines extends JavaPlugin {
|
|||||||
123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139
|
123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139
|
||||||
));
|
));
|
||||||
trebuchet.cycleThroughModelsBeforeFiring = true;
|
trebuchet.cycleThroughModelsBeforeFiring = true;
|
||||||
DefinedEquipment.put(trebuchet.readyModelNumber, trebuchet);
|
definedSiegeEngines.put(trebuchet.readyModelNumber, trebuchet);
|
||||||
|
|
||||||
SiegeEngine navalCannon = new SiegeEngine("Naval Cannon", new HashMap<ItemStack, GunnersProjectile>(), new ItemStack(Material.GUNPOWDER), 142);
|
SiegeEngine navalCannon = new SiegeEngine("Naval Cannon", new HashMap<ItemStack, GunnersProjectile>(), new ItemStack(Material.GUNPOWDER), 142);
|
||||||
navalCannon.projectiles.put(new ItemStack(Material.COBBLESTONE), proj);
|
navalCannon.projectiles.put(new ItemStack(Material.COBBLESTONE), proj);
|
||||||
@@ -190,7 +140,7 @@ public class SiegeEngines extends JavaPlugin {
|
|||||||
fireProj.SoundType = Sound.ENTITY_BLAZE_SHOOT;
|
fireProj.SoundType = Sound.ENTITY_BLAZE_SHOOT;
|
||||||
fireProj.Inaccuracy = 0.75f;
|
fireProj.Inaccuracy = 0.75f;
|
||||||
navalCannon.projectiles.put(new ItemStack(Material.FIRE_CHARGE), fireProj);
|
navalCannon.projectiles.put(new ItemStack(Material.FIRE_CHARGE), fireProj);
|
||||||
DefinedEquipment.put(navalCannon.readyModelNumber, navalCannon);
|
definedSiegeEngines.put(navalCannon.readyModelNumber, navalCannon);
|
||||||
|
|
||||||
SiegeEngine siegeCannon = new SiegeEngine("Siege Cannon", new HashMap<ItemStack, GunnersProjectile>(), new ItemStack(Material.GUNPOWDER), 141);
|
SiegeEngine siegeCannon = new SiegeEngine("Siege Cannon", new HashMap<ItemStack, GunnersProjectile>(), new ItemStack(Material.GUNPOWDER), 141);
|
||||||
proj.ExplodePower = 2;
|
proj.ExplodePower = 2;
|
||||||
@@ -218,108 +168,7 @@ public class SiegeEngines extends JavaPlugin {
|
|||||||
scatterShot.ParticleType = Particle.ELECTRIC_SPARK;
|
scatterShot.ParticleType = Particle.ELECTRIC_SPARK;
|
||||||
scatterShot.SoundType = Sound.ITEM_CROSSBOW_SHOOT;
|
scatterShot.SoundType = Sound.ITEM_CROSSBOW_SHOOT;
|
||||||
siegeCannon.projectiles.put(new ItemStack(Material.GRAVEL), scatterShot);
|
siegeCannon.projectiles.put(new ItemStack(Material.GRAVEL), scatterShot);
|
||||||
DefinedEquipment.put(siegeCannon.readyModelNumber, siegeCannon);
|
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");
|
|
||||||
SiegeEngine siegeEngine = CreateClone(CustomModelData);
|
|
||||||
if (siegeEngine == null || !siegeEngine.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 = "";
|
|
||||||
siegeEngine.ammoHolder = new EquipmentMagazine();
|
|
||||||
if (siegeEngine.hasBaseStand) {
|
|
||||||
|
|
||||||
Location l2 = l;
|
|
||||||
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(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);
|
|
||||||
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(siegeEngine.allowInvisibleStand);
|
|
||||||
ent.getEquipment().setHelmet(item);
|
|
||||||
stand.setGravity(false);
|
|
||||||
stand.setMarker(true);
|
|
||||||
}
|
|
||||||
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(siegeEngine.readyModelNumber);
|
|
||||||
meta.setDisplayName("§e" + siegeEngine.name + " Item");
|
|
||||||
List<String> Lore = new ArrayList<String>();
|
|
||||||
Lore.add("§ePlace as a block to spawn a " + siegeEngine.name + " or put on an Armor Stand.");
|
|
||||||
meta.setLore(Lore);
|
|
||||||
item.setItemMeta(meta);
|
|
||||||
|
|
||||||
// entity3.addPassenger(entity2);
|
|
||||||
|
|
||||||
LivingEntity ent = (LivingEntity) entity2;
|
|
||||||
ArmorStand stand = (ArmorStand) ent;
|
|
||||||
siegeEngine.entity = entity2;
|
|
||||||
|
|
||||||
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);
|
|
||||||
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(siegeEngine.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(), siegeEngine);
|
|
||||||
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 class SiegeEnginesLogger {
|
||||||
|
|
||||||
public static void info(String msg) {
|
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) {
|
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) {
|
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,7 +1,6 @@
|
|||||||
package com.github.alathra.siegeengines.command;
|
package com.github.alathra.siegeengines.command;
|
||||||
|
|
||||||
import com.github.alathra.siegeengines.SiegeEngine;
|
import com.github.alathra.siegeengines.SiegeEngine;
|
||||||
import com.github.alathra.siegeengines.projectile.GunnersProjectile;
|
|
||||||
import com.github.milkdrinkers.colorparser.ColorParser;
|
import com.github.milkdrinkers.colorparser.ColorParser;
|
||||||
import dev.jorel.commandapi.CommandAPIBukkit;
|
import dev.jorel.commandapi.CommandAPIBukkit;
|
||||||
import dev.jorel.commandapi.CommandAPICommand;
|
import dev.jorel.commandapi.CommandAPICommand;
|
||||||
@@ -18,7 +17,6 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static com.github.alathra.siegeengines.SiegeEngines.*;
|
import static com.github.alathra.siegeengines.SiegeEngines.*;
|
||||||
@@ -49,7 +47,7 @@ public class SiegeEnginesCommand {
|
|||||||
new StringArgument("equipmentid")
|
new StringArgument("equipmentid")
|
||||||
.replaceSuggestions(
|
.replaceSuggestions(
|
||||||
ArgumentSuggestions.strings(
|
ArgumentSuggestions.strings(
|
||||||
DefinedEquipment.values().stream().map(SiegeEquipment -> SiegeEquipment.id).toList()
|
definedSiegeEngines.values().stream().map(SiegeEquipment -> SiegeEquipment.id).toList()
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
new PlayerArgument("target")
|
new PlayerArgument("target")
|
||||||
@@ -76,7 +74,7 @@ public class SiegeEnginesCommand {
|
|||||||
|
|
||||||
Player player = (Player) args.getOptional("target").orElse(sender);
|
Player player = (Player) args.getOptional("target").orElse(sender);
|
||||||
|
|
||||||
for (SiegeEngine SiegeEquipment : DefinedEquipment.values()) {
|
for (SiegeEngine SiegeEquipment : definedSiegeEngines.values()) {
|
||||||
if (SiegeEquipment.equals(equipmentId)) {
|
if (SiegeEquipment.equals(equipmentId)) {
|
||||||
giveEquipment(player, SiegeEquipment);
|
giveEquipment(player, SiegeEquipment);
|
||||||
break;
|
break;
|
||||||
@@ -88,7 +86,7 @@ public class SiegeEnginesCommand {
|
|||||||
if (!(sender instanceof Player player))
|
if (!(sender instanceof Player player))
|
||||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("<red>Only players can use this command.").build());
|
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("<red>Only players can use this command.").build());
|
||||||
|
|
||||||
for (SiegeEngine i : DefinedEquipment.values()) {
|
for (SiegeEngine i : definedSiegeEngines.values()) {
|
||||||
giveEquipment(player, i);
|
giveEquipment(player, i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -97,13 +95,11 @@ public class SiegeEnginesCommand {
|
|||||||
if (!(sender instanceof Player))
|
if (!(sender instanceof Player))
|
||||||
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("<red>Only players can use this command.").build());
|
throw CommandAPIBukkit.failWithAdventureComponent(ColorParser.of("<red>Only players can use this command.").build());
|
||||||
|
|
||||||
equipment.clear();
|
activeSiegeEngines.clear();
|
||||||
TrackedStands.clear();
|
trackedStands.clear();
|
||||||
DefinedEquipment.clear();
|
definedSiegeEngines.clear();
|
||||||
AddDefaults();
|
AddDefaults();
|
||||||
HashMap<ItemStack, GunnersProjectile> projObj = new HashMap<>();
|
for (SiegeEngine i : definedSiegeEngines.values()) {
|
||||||
//SiegeEquipment equip = CreateNewGun(null, null, null, null, null, null, projObj);
|
|
||||||
for (SiegeEngine i : DefinedEquipment.values()) {
|
|
||||||
sender.sendMessage(ColorParser.of("<yellow>Enabled Weapon : %s".formatted(i.name)).build());
|
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());
|
sender.sendMessage(ColorParser.of("<yellow>Weapon Propellant/\"Fuel\" ItemStacks : %s".formatted(i.fuelItem)).build());
|
||||||
for (ItemStack proj : i.projectiles.keySet()) {
|
for (ItemStack proj : i.projectiles.keySet()) {
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ public class Config {
|
|||||||
initConfigVals();
|
initConfigVals();
|
||||||
}
|
}
|
||||||
|
|
||||||
private FileConfiguration getConfig() {
|
public FileConfiguration getConfig() {
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,13 +7,14 @@ import java.util.Random;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import com.github.alathra.siegeengines.config.Config;
|
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.SiegeEngines;
|
||||||
|
import com.github.alathra.siegeengines.SiegeEnginesUtil;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.Container;
|
import org.bukkit.block.Container;
|
||||||
import org.bukkit.block.Sign;
|
import org.bukkit.block.Sign;
|
||||||
@@ -75,7 +76,6 @@ public class ClickHandler implements Listener {
|
|||||||
player.sendMessage("§eDistance to impact: " + String.format("%.2f", player.getLocation().distance(ball.getLocation())));
|
player.sendMessage("§eDistance to impact: " + String.format("%.2f", player.getLocation().distance(ball.getLocation())));
|
||||||
}
|
}
|
||||||
Location loc = snowball.getLocation();
|
Location loc = snowball.getLocation();
|
||||||
World world = event.getEntity().getWorld();
|
|
||||||
Entity tnt = event.getEntity().getWorld().spawnEntity(loc, EntityType.PRIMED_TNT);
|
Entity tnt = event.getEntity().getWorld().spawnEntity(loc, EntityType.PRIMED_TNT);
|
||||||
|
|
||||||
projectiles.remove(event.getEntity().getUniqueId());
|
projectiles.remove(event.getEntity().getUniqueId());
|
||||||
@@ -124,23 +124,32 @@ public class ClickHandler implements Listener {
|
|||||||
@EventHandler(priority = EventPriority.HIGH)
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
public void BlockPlaceEvent(org.bukkit.event.block.BlockPlaceEvent event) {
|
public void BlockPlaceEvent(org.bukkit.event.block.BlockPlaceEvent event) {
|
||||||
Player thePlayer = event.getPlayer();
|
Player thePlayer = event.getPlayer();
|
||||||
if (event.isCancelled())
|
if (event.isCancelled()) {
|
||||||
return;
|
|
||||||
if (event.isCancelled())
|
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
if (event.getPlayer().getInventory().getItemInMainHand().getType() == Material.CARVED_PUMPKIN) {
|
if (event.getPlayer().getInventory().getItemInMainHand().getType() == Material.CARVED_PUMPKIN) {
|
||||||
ItemStack item = event.getPlayer().getInventory().getItemInMainHand();
|
ItemStack item = event.getPlayer().getInventory().getItemInMainHand();
|
||||||
if (item.getItemMeta() != null && item.getItemMeta().hasCustomModelData()) {
|
if (item.getItemMeta() != null && item.getItemMeta().hasCustomModelData()) {
|
||||||
int customModel = item.getItemMeta().getCustomModelData();
|
int customModel = item.getItemMeta().getCustomModelData();
|
||||||
Boolean created = SiegeEngines.placeEquipment(thePlayer, customModel, event.getBlockAgainst().getLocation());
|
SiegeEngine siegeEngine = null;
|
||||||
if (created) {
|
// 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);
|
item.setAmount(item.getAmount() - 1);
|
||||||
thePlayer.getInventory().setItemInMainHand(item);
|
thePlayer.getInventory().setItemInMainHand(item);
|
||||||
thePlayer.sendMessage("§eGunner Equipment spawned!");
|
thePlayer.sendMessage("§eGunner Equipment spawned!");
|
||||||
} else {
|
event.setCancelled(true);
|
||||||
thePlayer.sendMessage("§eGunner Equipment could not be spawned, is it enabled?");
|
|
||||||
}
|
}
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -148,37 +157,36 @@ public class ClickHandler implements Listener {
|
|||||||
|
|
||||||
public void Shoot(Entity player, long delay) {
|
public void Shoot(Entity player, long delay) {
|
||||||
float actualDelay = delay;
|
float actualDelay = delay;
|
||||||
Boolean FirstShot = true;
|
|
||||||
int counter = 0;
|
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)) {
|
for (Entity ent : player.getNearbyEntities(5, 5, 5)) {
|
||||||
if (ent instanceof ArmorStand) {
|
if (ent instanceof ArmorStand) {
|
||||||
TakeControl(player, ent);
|
TakeControl(player, ent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (SiegeEngines.TrackedStands.get(player.getUniqueId()) == null)
|
if (SiegeEngines.trackedStands.get(player.getUniqueId()) == null)
|
||||||
return;
|
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) {
|
for (Entity ent : entities) {
|
||||||
if (ent == null || ent.isDead()) {
|
if (ent == null || ent.isDead()) {
|
||||||
SiegeEngines.TrackedStands.get(player.getUniqueId()).remove(ent);
|
SiegeEngines.trackedStands.get(player.getUniqueId()).remove(ent);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (((LivingEntity) ent).getEquipment().getHelmet().getType() != Material.CARVED_PUMPKIN) {
|
if (((LivingEntity) ent).getEquipment().getHelmet().getType() != Material.CARVED_PUMPKIN) {
|
||||||
SiegeEngines.TrackedStands.get(player.getUniqueId()).remove(ent);
|
SiegeEngines.trackedStands.get(player.getUniqueId()).remove(ent);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
double distance = player.getLocation().distance(ent.getLocation());
|
double distance = player.getLocation().distance(ent.getLocation());
|
||||||
if (distance >= Config.controlDistance) {
|
if (distance >= Config.controlDistance) {
|
||||||
SiegeEngines.TrackedStands.get(player.getUniqueId()).remove(ent);
|
SiegeEngines.trackedStands.get(player.getUniqueId()).remove(ent);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
SiegeEngine siege = SiegeEngines.equipment.get(ent.getUniqueId());
|
SiegeEngine siege = SiegeEngines.activeSiegeEngines.get(ent.getUniqueId());
|
||||||
if (counter > 4)
|
if (counter > 4)
|
||||||
return;
|
return;
|
||||||
if (ent == null || ent.isDead()) {
|
if (ent == null || ent.isDead()) {
|
||||||
SiegeEngines.TrackedStands.get(player.getUniqueId()).remove(ent);
|
SiegeEngines.trackedStands.get(player.getUniqueId()).remove(ent);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (siege.isLoaded()) {
|
if (siege.isLoaded()) {
|
||||||
@@ -218,16 +226,7 @@ public class ClickHandler implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean hasItem(Inventory inv, ItemStack m) {
|
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 inv.containsAtLeast(m,m.getAmount());
|
||||||
//return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
@@ -239,29 +238,19 @@ public class ClickHandler implements Listener {
|
|||||||
return;
|
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 (event.getAction() == Action.RIGHT_CLICK_AIR) {
|
||||||
if (ItemInHand.getType() != Config.controlItem) {
|
if (ItemInHand.getType() != Config.controlItem) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!player.isSneaking()) {
|
if (!player.isSneaking()) {
|
||||||
List<Entity> entities = SiegeEngines.TrackedStands.get(player.getUniqueId());
|
List<Entity> entities = SiegeEngines.trackedStands.get(player.getUniqueId());
|
||||||
if (entities == null) {
|
if (entities == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (Entity entity : entities) {
|
for (Entity entity : entities) {
|
||||||
|
|
||||||
if (SiegeEngines.equipment.containsKey(entity.getUniqueId())) {
|
if (SiegeEngines.activeSiegeEngines.containsKey(entity.getUniqueId())) {
|
||||||
SiegeEngine equip = SiegeEngines.equipment.get(entity.getUniqueId());
|
SiegeEngine equip = SiegeEngines.activeSiegeEngines.get(entity.getUniqueId());
|
||||||
if (equip != null && equip.enabled && !(entity.isDead())) {
|
if (equip != null && equip.enabled && !(entity.isDead())) {
|
||||||
equip.Fire(player,10f,1);
|
equip.Fire(player,10f,1);
|
||||||
}
|
}
|
||||||
@@ -269,8 +258,8 @@ public class ClickHandler implements Listener {
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (SiegeEngines.TrackedStands.containsKey(player.getUniqueId())) {
|
if (SiegeEngines.trackedStands.containsKey(player.getUniqueId())) {
|
||||||
List<Entity> entities = SiegeEngines.TrackedStands.get(player.getUniqueId());
|
List<Entity> entities = SiegeEngines.trackedStands.get(player.getUniqueId());
|
||||||
if (entities == null) {
|
if (entities == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -279,8 +268,8 @@ public class ClickHandler implements Listener {
|
|||||||
for (Entity entity : entities) {
|
for (Entity entity : entities) {
|
||||||
foundAmmo = false;
|
foundAmmo = false;
|
||||||
if ((entity.isDead())) continue;
|
if ((entity.isDead())) continue;
|
||||||
if (SiegeEngines.equipment.containsKey(entity.getUniqueId())) {
|
if (SiegeEngines.activeSiegeEngines.containsKey(entity.getUniqueId())) {
|
||||||
SiegeEngine equip = SiegeEngines.equipment.get(entity.getUniqueId());
|
SiegeEngine equip = SiegeEngines.activeSiegeEngines.get(entity.getUniqueId());
|
||||||
if (equip == null || !equip.enabled) {
|
if (equip == null || !equip.enabled) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -294,8 +283,8 @@ public class ClickHandler implements Listener {
|
|||||||
continue;
|
continue;
|
||||||
state.getInventory().removeItem(stack);//setStorageContents(updateContents(state.getInventory(),stack,1));
|
state.getInventory().removeItem(stack);//setStorageContents(updateContents(state.getInventory(),stack,1));
|
||||||
//state.update(true,true);
|
//state.update(true,true);
|
||||||
equip.ammoHolder.LoadedProjectile = 1;
|
equip.ammoHolder.loadedProjectile = 1;
|
||||||
equip.ammoHolder.MaterialName = stack;
|
equip.ammoHolder.materialName = stack;
|
||||||
foundAmmo = true;
|
foundAmmo = true;
|
||||||
}
|
}
|
||||||
//state.update(true,true);
|
//state.update(true,true);
|
||||||
@@ -312,8 +301,8 @@ public class ClickHandler implements Listener {
|
|||||||
continue;
|
continue;
|
||||||
state.getInventory().removeItem(stack);//setStorageContents(updateContents(state.getInventory(),stack,1));
|
state.getInventory().removeItem(stack);//setStorageContents(updateContents(state.getInventory(),stack,1));
|
||||||
//state.update(true,true);
|
//state.update(true,true);
|
||||||
equip.ammoHolder.LoadedProjectile = 1;
|
equip.ammoHolder.loadedProjectile = 1;
|
||||||
equip.ammoHolder.MaterialName = stack;
|
equip.ammoHolder.materialName = stack;
|
||||||
foundAmmo = true;
|
foundAmmo = true;
|
||||||
}
|
}
|
||||||
//state.update(true,true);
|
//state.update(true,true);
|
||||||
@@ -330,8 +319,8 @@ public class ClickHandler implements Listener {
|
|||||||
continue;
|
continue;
|
||||||
state.getInventory().removeItem(stack);//setStorageContents(updateContents(state.getInventory(),stack,1));
|
state.getInventory().removeItem(stack);//setStorageContents(updateContents(state.getInventory(),stack,1));
|
||||||
//state.update(true,true);
|
//state.update(true,true);
|
||||||
equip.ammoHolder.LoadedProjectile = 1;
|
equip.ammoHolder.loadedProjectile = 1;
|
||||||
equip.ammoHolder.MaterialName = stack;
|
equip.ammoHolder.materialName = stack;
|
||||||
foundAmmo = true;
|
foundAmmo = true;
|
||||||
}
|
}
|
||||||
//state.update(true,true);
|
//state.update(true,true);
|
||||||
@@ -347,9 +336,9 @@ public class ClickHandler implements Listener {
|
|||||||
continue;
|
continue;
|
||||||
if (!hasItem(event.getPlayer().getInventory(),stack))
|
if (!hasItem(event.getPlayer().getInventory(),stack))
|
||||||
continue;
|
continue;
|
||||||
if (stack.isSimilar(inventoryItem) && equip.ammoHolder.LoadedProjectile == 0) {
|
if (stack.isSimilar(inventoryItem) && equip.ammoHolder.loadedProjectile == 0) {
|
||||||
equip.ammoHolder.LoadedProjectile = 1;
|
equip.ammoHolder.loadedProjectile = 1;
|
||||||
equip.ammoHolder.MaterialName = stack;
|
equip.ammoHolder.materialName = stack;
|
||||||
inventoryItem.setAmount(inventoryItem.getAmount() - 1);
|
inventoryItem.setAmount(inventoryItem.getAmount() - 1);
|
||||||
foundAmmo = true;
|
foundAmmo = true;
|
||||||
break;
|
break;
|
||||||
@@ -366,8 +355,8 @@ public class ClickHandler implements Listener {
|
|||||||
for (Entity entity : entities) {
|
for (Entity entity : entities) {
|
||||||
foundAmmo = false;
|
foundAmmo = false;
|
||||||
if ((entity.isDead())) continue;
|
if ((entity.isDead())) continue;
|
||||||
if (SiegeEngines.equipment.containsKey(entity.getUniqueId())) {
|
if (SiegeEngines.activeSiegeEngines.containsKey(entity.getUniqueId())) {
|
||||||
SiegeEngine equip = SiegeEngines.equipment.get(entity.getUniqueId());
|
SiegeEngine equip = SiegeEngines.activeSiegeEngines.get(entity.getUniqueId());
|
||||||
if (equip == null || !equip.enabled) {
|
if (equip == null || !equip.enabled) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -383,7 +372,7 @@ public class ClickHandler implements Listener {
|
|||||||
continue;
|
continue;
|
||||||
state.getInventory().removeItem(stack);//setStorageContents(updateContents(state.getInventory(),stack,1));
|
state.getInventory().removeItem(stack);//setStorageContents(updateContents(state.getInventory(),stack,1));
|
||||||
//state.update(true,true);
|
//state.update(true,true);
|
||||||
equip.ammoHolder.LoadedFuel += 1;
|
equip.ammoHolder.loadedFuel += 1;
|
||||||
foundAmmo = true;
|
foundAmmo = true;
|
||||||
//state.update(true,true);
|
//state.update(true,true);
|
||||||
}
|
}
|
||||||
@@ -400,7 +389,7 @@ public class ClickHandler implements Listener {
|
|||||||
//state.update(true,true);
|
//state.update(true,true);
|
||||||
if (!equip.CanLoadFuel())
|
if (!equip.CanLoadFuel())
|
||||||
continue;
|
continue;
|
||||||
equip.ammoHolder.LoadedFuel += 1;
|
equip.ammoHolder.loadedFuel += 1;
|
||||||
foundAmmo = true;
|
foundAmmo = true;
|
||||||
//state.update(true,true);
|
//state.update(true,true);
|
||||||
}
|
}
|
||||||
@@ -417,7 +406,7 @@ public class ClickHandler implements Listener {
|
|||||||
continue;
|
continue;
|
||||||
state.getInventory().removeItem(stack);//setStorageContents(updateContents(state.getInventory(),stack,1));
|
state.getInventory().removeItem(stack);//setStorageContents(updateContents(state.getInventory(),stack,1));
|
||||||
//state.update(true,true);
|
//state.update(true,true);
|
||||||
equip.ammoHolder.LoadedFuel += 1;
|
equip.ammoHolder.loadedFuel += 1;
|
||||||
foundAmmo = true;
|
foundAmmo = true;
|
||||||
//state.update(true,true);
|
//state.update(true,true);
|
||||||
}
|
}
|
||||||
@@ -431,7 +420,7 @@ public class ClickHandler implements Listener {
|
|||||||
break;
|
break;
|
||||||
if (!equip.CanLoadFuel())
|
if (!equip.CanLoadFuel())
|
||||||
continue;
|
continue;
|
||||||
equip.ammoHolder.LoadedFuel += 1;
|
equip.ammoHolder.loadedFuel += 1;
|
||||||
stack.setAmount(1);
|
stack.setAmount(1);
|
||||||
event.getPlayer().getInventory().removeItem(stack);
|
event.getPlayer().getInventory().removeItem(stack);
|
||||||
foundAmmo = true;
|
foundAmmo = true;
|
||||||
@@ -451,7 +440,8 @@ public class ClickHandler implements Listener {
|
|||||||
|
|
||||||
@EventHandler(priority = EventPriority.NORMAL)
|
@EventHandler(priority = EventPriority.NORMAL)
|
||||||
public void onSignChange(SignChangeEvent event) {
|
public void onSignChange(SignChangeEvent event) {
|
||||||
String topline = event.getLine(0);
|
@SuppressWarnings("deprecation")
|
||||||
|
String topline = event.getLine(0);
|
||||||
if (topline == null) topline = "";
|
if (topline == null) topline = "";
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
String toplinetrimmed = topline.trim();
|
String toplinetrimmed = topline.trim();
|
||||||
@@ -474,8 +464,8 @@ public class ClickHandler implements Listener {
|
|||||||
|
|
||||||
public static void TakeControl(Entity player, Entity entity) {
|
public static void TakeControl(Entity player, Entity entity) {
|
||||||
LivingEntity living = (LivingEntity) entity;
|
LivingEntity living = (LivingEntity) entity;
|
||||||
if (SiegeEngines.TrackedStands.containsKey(player.getUniqueId())) {
|
if (SiegeEngines.trackedStands.containsKey(player.getUniqueId())) {
|
||||||
List<Entity> entities = SiegeEngines.TrackedStands.get(player.getUniqueId());
|
List<Entity> entities = SiegeEngines.trackedStands.get(player.getUniqueId());
|
||||||
if (entities.contains(entity)) {
|
if (entities.contains(entity)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -494,17 +484,17 @@ public class ClickHandler implements Listener {
|
|||||||
stand.addEquipmentLock(EquipmentSlot.FEET, LockType.ADDING_OR_CHANGING);
|
stand.addEquipmentLock(EquipmentSlot.FEET, LockType.ADDING_OR_CHANGING);
|
||||||
stand.setBasePlate(false);
|
stand.setBasePlate(false);
|
||||||
|
|
||||||
if (SiegeEngines.equipment.containsKey(entity.getUniqueId())) {
|
if (SiegeEngines.activeSiegeEngines.containsKey(entity.getUniqueId())) {
|
||||||
equip = SiegeEngines.equipment.get(entity.getUniqueId());
|
equip = SiegeEngines.activeSiegeEngines.get(entity.getUniqueId());
|
||||||
if (equip == null || !equip.enabled) {
|
if (equip == null || !equip.enabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
equip = SiegeEngines.CreateClone(living.getEquipment().getHelmet().getItemMeta().getCustomModelData());
|
equip = SiegeEnginesUtil.createCloneFromCustomModelData(living.getEquipment().getHelmet().getItemMeta().getCustomModelData());
|
||||||
if (equip == null || !equip.enabled) {
|
if (equip == null || !equip.enabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
equip.ammoHolder = new EquipmentMagazine();
|
equip.ammoHolder = new SiegeEngineAmmoHolder();
|
||||||
equip.entity = entity;
|
equip.entity = entity;
|
||||||
equip.entityId = entity.getUniqueId();
|
equip.entityId = entity.getUniqueId();
|
||||||
}
|
}
|
||||||
@@ -513,35 +503,32 @@ public class ClickHandler implements Listener {
|
|||||||
stand.addEquipmentLock(EquipmentSlot.CHEST, LockType.ADDING_OR_CHANGING);
|
stand.addEquipmentLock(EquipmentSlot.CHEST, LockType.ADDING_OR_CHANGING);
|
||||||
stand.addEquipmentLock(EquipmentSlot.FEET, LockType.ADDING_OR_CHANGING);
|
stand.addEquipmentLock(EquipmentSlot.FEET, LockType.ADDING_OR_CHANGING);
|
||||||
stand.setBasePlate(false);
|
stand.setBasePlate(false);
|
||||||
if (SiegeEngines.TrackedStands.containsKey(player.getUniqueId())) {
|
if (SiegeEngines.trackedStands.containsKey(player.getUniqueId())) {
|
||||||
List<Entity> entities = SiegeEngines.TrackedStands.get(player.getUniqueId());
|
List<Entity> entities = SiegeEngines.trackedStands.get(player.getUniqueId());
|
||||||
entities.add(entity);
|
entities.add(entity);
|
||||||
SiegeEngines.TrackedStands.put(player.getUniqueId(), entities);
|
SiegeEngines.trackedStands.put(player.getUniqueId(), entities);
|
||||||
} else {
|
} else {
|
||||||
List<Entity> newList = new ArrayList<Entity>();
|
List<Entity> newList = new ArrayList<Entity>();
|
||||||
newList.add(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.");
|
//player.sendMessage("§eNow controlling the equipment.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SaveCannons(Player player, Block block) {
|
public void SaveCannons(Player player, Block block) {
|
||||||
List<String> Ids = new ArrayList<String>();
|
List<String> Ids = new ArrayList<String>();
|
||||||
if (!SiegeEngines.TrackedStands.containsKey(player.getUniqueId())) {
|
if (!SiegeEngines.trackedStands.containsKey(player.getUniqueId())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (Entity ent : SiegeEngines.TrackedStands.get(player.getUniqueId())) {
|
for (Entity ent : SiegeEngines.trackedStands.get(player.getUniqueId())) {
|
||||||
if (ent.isDead()) {
|
if (ent.isDead()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Ids.add(ent.getUniqueId().toString());
|
Ids.add(ent.getUniqueId().toString());
|
||||||
}
|
}
|
||||||
TileState state = ((TileState) block.getState());
|
for (Entity ent : SiegeEngines.trackedStands.get(player.getUniqueId())) {
|
||||||
NamespacedKey key = new NamespacedKey(SiegeEngines.plugin, "cannons");
|
|
||||||
|
|
||||||
for (Entity ent : SiegeEngines.TrackedStands.get(player.getUniqueId())) {
|
|
||||||
if (ent.isDead()) {
|
if (ent.isDead()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -557,7 +544,7 @@ public class ClickHandler implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
loc.setPitch((float) (loc.getPitch() - amount));
|
loc.setPitch((float) (loc.getPitch() - amount));
|
||||||
SiegeEngine equipment = SiegeEngines.equipment.get(ent.getUniqueId());
|
SiegeEngine equipment = SiegeEngines.activeSiegeEngines.get(ent.getUniqueId());
|
||||||
if (equipment != null) {
|
if (equipment != null) {
|
||||||
if (player instanceof Player)
|
if (player instanceof Player)
|
||||||
equipment.ShowFireLocation(player);
|
equipment.ShowFireLocation(player);
|
||||||
@@ -576,7 +563,7 @@ public class ClickHandler implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
loc.setPitch((float) (loc.getPitch() - amount));
|
loc.setPitch((float) (loc.getPitch() - amount));
|
||||||
SiegeEngine equipment = SiegeEngines.equipment.get(ent.getUniqueId());
|
SiegeEngine equipment = SiegeEngines.activeSiegeEngines.get(ent.getUniqueId());
|
||||||
if (equipment != null) {
|
if (equipment != null) {
|
||||||
if (player instanceof Player)
|
if (player instanceof Player)
|
||||||
equipment.ShowFireLocation(player);
|
equipment.ShowFireLocation(player);
|
||||||
@@ -594,7 +581,7 @@ public class ClickHandler implements Listener {
|
|||||||
if (loc.getPitch() == 85 || loc.getPitch() + amount > 85) {
|
if (loc.getPitch() == 85 || loc.getPitch() + amount > 85) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
SiegeEngine equipment = SiegeEngines.equipment.get(ent.getUniqueId());
|
SiegeEngine equipment = SiegeEngines.activeSiegeEngines.get(ent.getUniqueId());
|
||||||
if (equipment != null) {
|
if (equipment != null) {
|
||||||
if (player instanceof Player) {
|
if (player instanceof Player) {
|
||||||
equipment.ShowFireLocation((Player) player);
|
equipment.ShowFireLocation((Player) player);
|
||||||
@@ -609,7 +596,7 @@ public class ClickHandler implements Listener {
|
|||||||
ent.teleport(loc);
|
ent.teleport(loc);
|
||||||
}
|
}
|
||||||
|
|
||||||
NamespacedKey key = new NamespacedKey(SiegeEngines.plugin, "cannons");
|
NamespacedKey key = new NamespacedKey(SiegeEngines.getInstance(), "cannons");
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void DeathEvent(EntityDeathEvent event) {
|
public void DeathEvent(EntityDeathEvent event) {
|
||||||
@@ -620,12 +607,12 @@ public class ClickHandler implements Listener {
|
|||||||
Entity base = Bukkit.getEntity(UUID.fromString(event.getEntity().getPersistentDataContainer().get(key, PersistentDataType.STRING)));
|
Entity base = Bukkit.getEntity(UUID.fromString(event.getEntity().getPersistentDataContainer().get(key, PersistentDataType.STRING)));
|
||||||
base.remove();
|
base.remove();
|
||||||
}
|
}
|
||||||
if (SiegeEngines.equipment.containsKey(event.getEntity().getUniqueId())) {
|
if (SiegeEngines.activeSiegeEngines.containsKey(event.getEntity().getUniqueId())) {
|
||||||
removeStands = true;
|
removeStands = true;
|
||||||
} else {
|
} else {
|
||||||
for (ItemStack i : items) {
|
for (ItemStack i : items) {
|
||||||
if (i.getType() == Material.CARVED_PUMPKIN && i.hasItemMeta() && i.getItemMeta().hasCustomModelData()) {
|
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;
|
removeStands = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -646,7 +633,7 @@ public class ClickHandler implements Listener {
|
|||||||
|
|
||||||
public void AimUp(Entity player, float amount) {
|
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()) {
|
if (ent.isDead()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -656,7 +643,7 @@ public class ClickHandler implements Listener {
|
|||||||
|
|
||||||
public void AimDown(Entity player, float amount) {
|
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()) {
|
if (ent.isDead()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -665,12 +652,12 @@ public class ClickHandler implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void LoadCannonsWithPowder(Entity player) {
|
public void LoadCannonsWithPowder(Entity player) {
|
||||||
for (Entity ent : SiegeEngines.TrackedStands.get(player.getUniqueId())) {
|
for (Entity ent : SiegeEngines.trackedStands.get(player.getUniqueId())) {
|
||||||
if (ent.isDead()) {
|
if (ent.isDead()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
SiegeEngine equipment = SiegeEngines.equipment.get(ent.getUniqueId());
|
SiegeEngine equipment = SiegeEngines.activeSiegeEngines.get(ent.getUniqueId());
|
||||||
if (equipment != null) {
|
if (equipment != null) {
|
||||||
equipment.LoadFuel(player);
|
equipment.LoadFuel(player);
|
||||||
}
|
}
|
||||||
@@ -678,24 +665,25 @@ public class ClickHandler implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void LoadCannonsWithProjectile(Entity player, ItemStack projectile) {
|
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()) {
|
if (ent.isDead()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
SiegeEngine equipment = SiegeEngines.equipment.get(ent.getUniqueId());
|
SiegeEngine equipment = SiegeEngines.activeSiegeEngines.get(ent.getUniqueId());
|
||||||
if (equipment != null) {
|
if (equipment != null) {
|
||||||
equipment.LoadProjectile(player, projectile);
|
equipment.LoadProjectile(player, projectile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@SuppressWarnings("deprecation")
|
||||||
|
@EventHandler
|
||||||
public void onPlayerClickSign(PlayerInteractEvent event) {
|
public void onPlayerClickSign(PlayerInteractEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
if (event.getClickedBlock() != null && event.getClickedBlock().getType().toString().contains("SIGN")) {
|
if (event.getClickedBlock() != null && event.getClickedBlock().getType().toString().contains("SIGN")) {
|
||||||
Sign sign = (Sign) event.getClickedBlock().getState();
|
Sign sign = (Sign) event.getClickedBlock().getState();
|
||||||
if (sign.getLine(0).equalsIgnoreCase("[Fire]") && event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@@ -728,7 +716,7 @@ public class ClickHandler implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (sign.getLine(0).equalsIgnoreCase("[Aim]")) {
|
if (sign.getLine(0).equalsIgnoreCase("[Aim]")) {
|
||||||
if (!SiegeEngines.TrackedStands.containsKey(player.getUniqueId())) {
|
if (!SiegeEngines.trackedStands.containsKey(player.getUniqueId())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
float amount;
|
float amount;
|
||||||
@@ -749,7 +737,7 @@ public class ClickHandler implements Listener {
|
|||||||
|
|
||||||
if (sign.getLine(0).equalsIgnoreCase("[Cannon]")) {
|
if (sign.getLine(0).equalsIgnoreCase("[Cannon]")) {
|
||||||
if (event.getAction() == Action.LEFT_CLICK_BLOCK) {
|
if (event.getAction() == Action.LEFT_CLICK_BLOCK) {
|
||||||
SiegeEngines.TrackedStands.remove(player.getUniqueId());
|
SiegeEngines.trackedStands.remove(player.getUniqueId());
|
||||||
player.sendMessage("§eReleasing the equipment!");
|
player.sendMessage("§eReleasing the equipment!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -760,9 +748,9 @@ public class ClickHandler implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
NamespacedKey key = new NamespacedKey(SiegeEngines.plugin, "cannons");
|
NamespacedKey key = new NamespacedKey(SiegeEngines.getInstance(), "cannons");
|
||||||
TileState state = (TileState) sign.getBlock().getState();
|
TileState state = (TileState) sign.getBlock().getState();
|
||||||
SiegeEngines.TrackedStands.remove(player.getUniqueId());
|
SiegeEngines.trackedStands.remove(player.getUniqueId());
|
||||||
List<UUID> temp = new ArrayList<UUID>();
|
List<UUID> temp = new ArrayList<UUID>();
|
||||||
if (!state.getPersistentDataContainer().has(key, PersistentDataType.STRING)) {
|
if (!state.getPersistentDataContainer().has(key, PersistentDataType.STRING)) {
|
||||||
return;
|
return;
|
||||||
@@ -772,7 +760,6 @@ public class ClickHandler implements Listener {
|
|||||||
temp.add(UUID.fromString(s.trim()));
|
temp.add(UUID.fromString(s.trim()));
|
||||||
}
|
}
|
||||||
for (UUID Id : temp) {
|
for (UUID Id : temp) {
|
||||||
List<Entity> entities = new ArrayList<Entity>();
|
|
||||||
Entity ent = Bukkit.getEntity(Id);
|
Entity ent = Bukkit.getEntity(Id);
|
||||||
if (ent != null) {
|
if (ent != null) {
|
||||||
TakeControl(player, ent);
|
TakeControl(player, ent);
|
||||||
@@ -797,13 +784,13 @@ public class ClickHandler implements Listener {
|
|||||||
}
|
}
|
||||||
if (entity.getType() == EntityType.ARMOR_STAND) {
|
if (entity.getType() == EntityType.ARMOR_STAND) {
|
||||||
if (itemInHand.getType() != Config.controlItem) {
|
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.");
|
player.sendMessage("§eThis Equipment is no longer commanded by you.");
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
TakeControl(player, entity);
|
TakeControl(player, entity);
|
||||||
}
|
}
|
||||||
if (SiegeEngines.equipment.containsKey(entity.getUniqueId())) {
|
if (SiegeEngines.activeSiegeEngines.containsKey(entity.getUniqueId())) {
|
||||||
if (itemInHand.getType() == Material.CLOCK) {
|
if (itemInHand.getType() == Material.CLOCK) {
|
||||||
if (player.isSneaking()) {
|
if (player.isSneaking()) {
|
||||||
DoAimDown(entity, 1, player);
|
DoAimDown(entity, 1, player);
|
||||||
@@ -813,7 +800,7 @@ public class ClickHandler implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SiegeEngine equipment = SiegeEngines.equipment.get(entity.getUniqueId());
|
SiegeEngine equipment = SiegeEngines.activeSiegeEngines.get(entity.getUniqueId());
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
|
|
||||||
if (itemInHand == null || itemInHand.getType() == Material.AIR) {
|
if (itemInHand == null || itemInHand.getType() == Material.AIR) {
|
||||||
@@ -836,9 +823,9 @@ public class ClickHandler implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (ItemStack stack : equipment.projectiles.keySet()) {
|
for (ItemStack stack : equipment.projectiles.keySet()) {
|
||||||
if (stack.isSimilar(itemInHand) && equipment.ammoHolder.LoadedProjectile == 0) {
|
if (stack.isSimilar(itemInHand) && equipment.ammoHolder.loadedProjectile == 0) {
|
||||||
equipment.ammoHolder.LoadedProjectile = 1;
|
equipment.ammoHolder.loadedProjectile = 1;
|
||||||
equipment.ammoHolder.MaterialName = stack;
|
equipment.ammoHolder.materialName = stack;
|
||||||
player.sendMessage("§eAdding Ammunition to Weapon");
|
player.sendMessage("§eAdding Ammunition to Weapon");
|
||||||
itemInHand.setAmount(itemInHand.getAmount() - 1);
|
itemInHand.setAmount(itemInHand.getAmount() - 1);
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -28,8 +28,8 @@ public class RotationHandler implements Listener {
|
|||||||
@EventHandler
|
@EventHandler
|
||||||
public void playerMove(PlayerMoveEvent event) {
|
public void playerMove(PlayerMoveEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
NamespacedKey key = new NamespacedKey(SiegeEngines.plugin, "cannons");
|
NamespacedKey key = new NamespacedKey(SiegeEngines.getInstance(), "cannons");
|
||||||
if (SiegeEngines.TrackedStands.containsKey(player.getUniqueId())) {
|
if (SiegeEngines.trackedStands.containsKey(player.getUniqueId())) {
|
||||||
ItemStack itemInHand = player.getInventory().getItemInMainHand();
|
ItemStack itemInHand = player.getInventory().getItemInMainHand();
|
||||||
if (itemInHand != null) {
|
if (itemInHand != null) {
|
||||||
if (itemInHand.getType() != Config.controlItem) {
|
if (itemInHand.getType() != Config.controlItem) {
|
||||||
@@ -37,10 +37,10 @@ public class RotationHandler implements Listener {
|
|||||||
|
|
||||||
return;
|
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) {
|
for (Entity ent : list) {
|
||||||
if (ent != null) {
|
if (ent != null) {
|
||||||
SiegeEngine equipment = SiegeEngines.equipment.get(ent.getUniqueId());
|
SiegeEngine equipment = SiegeEngines.activeSiegeEngines.get(ent.getUniqueId());
|
||||||
if (ent.isDead()) {
|
if (ent.isDead()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -85,7 +85,7 @@ public class RotationHandler implements Listener {
|
|||||||
living.teleport(loc);
|
living.teleport(loc);
|
||||||
equipment.ShowFireLocation(player);
|
equipment.ShowFireLocation(player);
|
||||||
} else {
|
} else {
|
||||||
SiegeEngines.TrackedStands.get(player.getUniqueId()).remove(ent);
|
SiegeEngines.trackedStands.get(player.getUniqueId()).remove(ent);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package com.github.alathra.siegeengines.projectile;
|
package com.github.alathra.siegeengines.projectile;
|
||||||
|
|
||||||
import com.github.alathra.siegeengines.SiegeEngines;
|
import com.github.alathra.siegeengines.SiegeEngines;
|
||||||
|
import com.github.alathra.siegeengines.SiegeEnginesUtil;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Particle;
|
import org.bukkit.Particle;
|
||||||
@@ -9,7 +11,6 @@ import org.bukkit.World;
|
|||||||
import org.bukkit.entity.Arrow;
|
import org.bukkit.entity.Arrow;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.LivingEntity;
|
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
public class EntityProjectile implements GunnersProjectile {
|
public class EntityProjectile implements GunnersProjectile {
|
||||||
@@ -31,7 +32,7 @@ public class EntityProjectile implements GunnersProjectile {
|
|||||||
for (int i = 0; i < EntityCount; i++) {
|
for (int i = 0; i < EntityCount; i++) {
|
||||||
if (DelayedFire) {
|
if (DelayedFire) {
|
||||||
baseDelay += DelayTime;
|
baseDelay += DelayTime;
|
||||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(SiegeEngines.plugin, () -> {
|
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(SiegeEngines.getInstance(), () -> {
|
||||||
|
|
||||||
CreateEntity(entity, FireLocation, velocity, player);
|
CreateEntity(entity, FireLocation, velocity, player);
|
||||||
}, (long) baseDelay);
|
}, (long) baseDelay);
|
||||||
@@ -39,8 +40,6 @@ public class EntityProjectile implements GunnersProjectile {
|
|||||||
|
|
||||||
CreateEntity(entity, FireLocation, velocity, player);
|
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) {
|
private void CreateEntity(Entity entity, Location loc, Float velocity, Entity player) {
|
||||||
World world = entity.getLocation().getWorld();
|
World world = entity.getLocation().getWorld();
|
||||||
LivingEntity living = (LivingEntity) entity;
|
|
||||||
|
|
||||||
Entity arrow = world.spawnEntity(loc, EntityTyp);
|
Entity arrow = world.spawnEntity(loc, EntityTyp);
|
||||||
if (Inaccuracy != 0f) {
|
if (Inaccuracy != 0f) {
|
||||||
arrow.setVelocity(loc.getDirection().multiply(velocity).add(Randomise())
|
arrow.setVelocity(loc.getDirection().multiply(velocity).add(Randomise())
|
||||||
@@ -57,7 +55,7 @@ public class EntityProjectile implements GunnersProjectile {
|
|||||||
} else {
|
} else {
|
||||||
arrow.setVelocity(loc.getDirection().multiply(velocity));
|
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));
|
Bukkit.getServer().getPluginManager().callEvent(new org.bukkit.event.entity.ProjectileLaunchEvent(arrow));
|
||||||
|
|
||||||
if (arrow instanceof org.bukkit.entity.Projectile) {
|
if (arrow instanceof org.bukkit.entity.Projectile) {
|
||||||
@@ -69,10 +67,7 @@ public class EntityProjectile implements GunnersProjectile {
|
|||||||
arr.setDamage(8);
|
arr.setDamage(8);
|
||||||
if (player instanceof org.bukkit.projectiles.ProjectileSource)
|
if (player instanceof org.bukkit.projectiles.ProjectileSource)
|
||||||
arr.setShooter((org.bukkit.projectiles.ProjectileSource) player);
|
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) {
|
if (PlaySound) {
|
||||||
world.playSound(loc, this.SoundType, 20, 2);
|
world.playSound(loc, this.SoundType, 20, 2);
|
||||||
world.spawnParticle(this.ParticleType, loc.getX(), loc.getY(), loc.getZ(), 0);
|
world.spawnParticle(this.ParticleType, loc.getX(), loc.getY(), loc.getZ(), 0);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.github.alathra.siegeengines.projectile;
|
package com.github.alathra.siegeengines.projectile;
|
||||||
|
|
||||||
import com.github.alathra.siegeengines.SiegeEngines;
|
import com.github.alathra.siegeengines.SiegeEngines;
|
||||||
|
import com.github.alathra.siegeengines.SiegeEnginesUtil;
|
||||||
import com.github.alathra.siegeengines.listeners.ClickHandler;
|
import com.github.alathra.siegeengines.listeners.ClickHandler;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
@@ -10,11 +11,8 @@ import org.bukkit.Sound;
|
|||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.LivingEntity;
|
|
||||||
import org.bukkit.entity.Snowball;
|
import org.bukkit.entity.Snowball;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
//import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
|
||||||
//import me.libraryaddict.disguise.disguisetypes.MiscDisguise;
|
|
||||||
|
|
||||||
public class ExplosiveProjectile implements GunnersProjectile {
|
public class ExplosiveProjectile implements GunnersProjectile {
|
||||||
|
|
||||||
@@ -39,19 +37,16 @@ public class ExplosiveProjectile implements GunnersProjectile {
|
|||||||
for (int i = 0; i < ProjectilesCount; i++) {
|
for (int i = 0; i < ProjectilesCount; i++) {
|
||||||
if (DelayedFire) {
|
if (DelayedFire) {
|
||||||
baseDelay += DelayTime;
|
baseDelay += DelayTime;
|
||||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(SiegeEngines.plugin, () -> {
|
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(SiegeEngines.getInstance(), () -> {
|
||||||
CreateEntity(entity, loc, velocity, player);
|
CreateEntity(entity, loc, velocity, player);
|
||||||
}, (long) baseDelay);
|
}, (long) baseDelay);
|
||||||
} else {
|
} else {
|
||||||
CreateEntity(entity, loc, velocity, player);
|
CreateEntity(entity, loc, velocity, player);
|
||||||
}
|
}
|
||||||
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CreateEntity(Entity entity, Location loc, Float velocity, Entity player) {
|
private void CreateEntity(Entity entity, Location loc, Float velocity, Entity player) {
|
||||||
LivingEntity living = (LivingEntity) entity;
|
|
||||||
World world = entity.getLocation().getWorld();
|
World world = entity.getLocation().getWorld();
|
||||||
Entity tnt = world.spawnEntity(loc, EntityType.SNOWBALL);
|
Entity tnt = world.spawnEntity(loc, EntityType.SNOWBALL);
|
||||||
Snowball ball = (Snowball) tnt;
|
Snowball ball = (Snowball) tnt;
|
||||||
@@ -65,7 +60,7 @@ public class ExplosiveProjectile implements GunnersProjectile {
|
|||||||
} else {
|
} else {
|
||||||
tnt.setVelocity(loc.getDirection().multiply(velocity));
|
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));
|
Bukkit.getServer().getPluginManager().callEvent(new org.bukkit.event.entity.ProjectileLaunchEvent(tnt));
|
||||||
|
|
||||||
if (PlaySound) {
|
if (PlaySound) {
|
||||||
@@ -75,9 +70,6 @@ public class ExplosiveProjectile implements GunnersProjectile {
|
|||||||
PlaySound = false;
|
PlaySound = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// MiscDisguise miscDisguise = new MiscDisguise(DisguiseType.ARROW);
|
|
||||||
// miscDisguise.setEntity(tnt);
|
|
||||||
// miscDisguise.startDisguise();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package com.github.alathra.siegeengines.projectile;
|
package com.github.alathra.siegeengines.projectile;
|
||||||
|
|
||||||
import com.github.alathra.siegeengines.SiegeEngines;
|
import com.github.alathra.siegeengines.SiegeEngines;
|
||||||
|
import com.github.alathra.siegeengines.SiegeEnginesUtil;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@@ -9,7 +11,6 @@ import org.bukkit.Sound;
|
|||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.LivingEntity;
|
|
||||||
import org.bukkit.entity.ThrownPotion;
|
import org.bukkit.entity.ThrownPotion;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.PotionMeta;
|
import org.bukkit.inventory.meta.PotionMeta;
|
||||||
@@ -33,20 +34,18 @@ public class PotionProjectile implements GunnersProjectile {
|
|||||||
for (int i = 0; i < EntityCount; i++) {
|
for (int i = 0; i < EntityCount; i++) {
|
||||||
if (DelayedFire) {
|
if (DelayedFire) {
|
||||||
baseDelay += DelayTime;
|
baseDelay += DelayTime;
|
||||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(SiegeEngines.plugin, () -> {
|
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(SiegeEngines.getInstance(), () -> {
|
||||||
|
|
||||||
CreateEntity(entity, loc, velocity);
|
CreateEntity(entity, loc, velocity);
|
||||||
}, (long) baseDelay);
|
}, (long) baseDelay);
|
||||||
} else {
|
} else {
|
||||||
CreateEntity(entity, loc, velocity);
|
CreateEntity(entity, loc, velocity);
|
||||||
}
|
}
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CreateEntity(Entity entity, Location loc, Float velocity) {
|
private void CreateEntity(Entity entity, Location loc, Float velocity) {
|
||||||
World world = entity.getLocation().getWorld();
|
World world = entity.getLocation().getWorld();
|
||||||
LivingEntity living = (LivingEntity) entity;
|
|
||||||
|
|
||||||
Entity arrow = world.spawnEntity(loc, EntityType.SPLASH_POTION);
|
Entity arrow = world.spawnEntity(loc, EntityType.SPLASH_POTION);
|
||||||
if (Inaccuracy != 0f) {
|
if (Inaccuracy != 0f) {
|
||||||
@@ -54,7 +53,7 @@ public class PotionProjectile implements GunnersProjectile {
|
|||||||
} else {
|
} else {
|
||||||
arrow.setVelocity(loc.getDirection().multiply(velocity));
|
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));
|
Bukkit.getServer().getPluginManager().callEvent(new org.bukkit.event.entity.ProjectileLaunchEvent(arrow));
|
||||||
ItemStack itemStack = new ItemStack(Material.SPLASH_POTION);
|
ItemStack itemStack = new ItemStack(Material.SPLASH_POTION);
|
||||||
PotionMeta potionMeta = (PotionMeta) itemStack.getItemMeta();
|
PotionMeta potionMeta = (PotionMeta) itemStack.getItemMeta();
|
||||||
@@ -62,8 +61,6 @@ public class PotionProjectile implements GunnersProjectile {
|
|||||||
itemStack.setItemMeta(potionMeta);
|
itemStack.setItemMeta(potionMeta);
|
||||||
ThrownPotion potion = (ThrownPotion) arrow;
|
ThrownPotion potion = (ThrownPotion) arrow;
|
||||||
potion.setItem(itemStack);
|
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.playSound(loc, this.SoundType, 20, 2);
|
||||||
world.spawnParticle(this.ParticleType, loc.getX(), loc.getY(), loc.getZ(), 0);
|
world.spawnParticle(this.ParticleType, loc.getX(), loc.getY(), loc.getZ(), 0);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user