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