mirror of
https://github.com/darksaid98/SiegeEngines.git
synced 2026-12-02 06:28:57 +00:00
.
This commit is contained in:
1 parent
563216cf59
commit
cb4b66a266
12 files changed
+81
-50
No files matched your search
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -18,6 +18,7 @@ import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.block.TileState;
|
||||
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;
|
||||
@@ -33,6 +34,7 @@ import org.bukkit.event.entity.ProjectileHitEvent;
|
||||
import org.bukkit.event.player.PlayerInteractAtEntityEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
@@ -83,15 +85,6 @@ public class ClickHandler implements Listener {
|
||||
}
|
||||
SiegeEquipment siege = CrunchSiegeCore.equipment.get(ent.getUniqueId());
|
||||
|
||||
|
||||
|
||||
if (player.getInventory().containsAtLeast(new ItemStack(Material.COBBLESTONE), 10)) {
|
||||
player.getInventory().remove(new ItemStack(Material.COBBLESTONE, 10));
|
||||
}
|
||||
else {
|
||||
player.sendMessage("Cannot fire, missing cobblestone, requires 10 per shot");
|
||||
continue;
|
||||
}
|
||||
if (siege.isLoaded()) {
|
||||
siege.Fire(player, actualDelay);
|
||||
actualDelay += delay;
|
||||
@@ -126,7 +119,7 @@ public class ClickHandler implements Listener {
|
||||
|
||||
|
||||
if (event.getAction() == Action.LEFT_CLICK_AIR) {
|
||||
if (ItemInHand.getType() != Material.STICK) {
|
||||
if (ItemInHand.getType() != Material.CLOCK) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -152,14 +145,30 @@ public class ClickHandler implements Listener {
|
||||
|
||||
public static void TakeControl(Player player, Entity entity) {
|
||||
LivingEntity living = (LivingEntity) entity;
|
||||
if (CrunchSiegeCore.TrackedStands.containsKey(player.getUniqueId())) {
|
||||
List<Entity> entities = CrunchSiegeCore.TrackedStands.get(player.getUniqueId());
|
||||
if (entities.contains(entity)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (living.getEquipment().getHelmet() != null && living.getEquipment().getHelmet().getType() == Material.CARVED_PUMPKIN) {
|
||||
if (living.getEquipment() == null || living.getEquipment().getHelmet() == null || living.getEquipment().getHelmet().getItemMeta() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
SiegeEquipment equip = CrunchSiegeCore.CreateClone(living.getEquipment().getHelmet().getItemMeta().getCustomModelData());
|
||||
equip.Entity = entity;
|
||||
equip.EntityId = entity.getUniqueId();
|
||||
ArmorStand stand = (ArmorStand) entity;
|
||||
stand.addEquipmentLock(EquipmentSlot.HEAD, LockType.REMOVING_OR_CHANGING);
|
||||
SiegeEquipment equip;
|
||||
if (CrunchSiegeCore.equipment.containsKey(entity.getUniqueId())) {
|
||||
equip = CrunchSiegeCore.equipment.get(entity.getUniqueId());
|
||||
}
|
||||
else {
|
||||
equip = CrunchSiegeCore.CreateClone(living.getEquipment().getHelmet().getItemMeta().getCustomModelData());
|
||||
equip.AmmoHolder = new EquipmentMagazine();
|
||||
equip.Entity = entity;
|
||||
equip.EntityId = entity.getUniqueId();
|
||||
}
|
||||
|
||||
if (CrunchSiegeCore.TrackedStands.containsKey(player.getUniqueId())) {
|
||||
List<Entity> entities = CrunchSiegeCore.TrackedStands.get(player.getUniqueId());
|
||||
@@ -198,7 +207,7 @@ public class ClickHandler implements Listener {
|
||||
Location loc = ent.getLocation();
|
||||
ArmorStand stand = (ArmorStand) ent;
|
||||
// player.sendMessage(String.format("" + loc.getPitch()));
|
||||
if (loc.getPitch() == -90 || loc.getPitch() - amount < -90) {
|
||||
if (loc.getPitch() == -85 || loc.getPitch() - amount < -85) {
|
||||
return;
|
||||
}
|
||||
loc.setPitch((float) (loc.getPitch() - amount));
|
||||
@@ -215,7 +224,7 @@ public class ClickHandler implements Listener {
|
||||
Location loc = ent.getLocation();
|
||||
ArmorStand stand = (ArmorStand) ent;
|
||||
// player.sendMessage(String.format("" + loc.getPitch()));
|
||||
if (loc.getPitch() == 90 || loc.getPitch() + amount > 90) {
|
||||
if (loc.getPitch() == 85 || loc.getPitch() + amount > 85) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -313,12 +322,7 @@ public class ClickHandler implements Listener {
|
||||
return;
|
||||
}
|
||||
if (entity.getType() == EntityType.ARMOR_STAND){
|
||||
if (itemInHand.getType() == Material.CLOCK) {
|
||||
|
||||
TakeControl(player, entity);
|
||||
return;
|
||||
}
|
||||
|
||||
TakeControl(player, entity);
|
||||
if (CrunchSiegeCore.equipment.containsKey(entity.getUniqueId())) {
|
||||
SiegeEquipment equipment = CrunchSiegeCore.equipment.get(entity.getUniqueId());
|
||||
if (itemInHand.getType().equals(equipment.FuelMaterial)) {
|
||||
@@ -330,7 +334,20 @@ public class ClickHandler implements Listener {
|
||||
}
|
||||
}
|
||||
if (itemInHand.getType().equals(Material.FLINT)) {
|
||||
Shoot(player, 6);
|
||||
if (equipment.isLoaded()) {
|
||||
equipment.Fire(player, 6);
|
||||
}
|
||||
else {
|
||||
player.sendMessage("Cannon is not loaded");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (equipment.Projectiles.containsKey(itemInHand.getType()) && !equipment.isLoaded()){
|
||||
equipment.AmmoHolder.LoadedProjectile = 1;
|
||||
equipment.AmmoHolder.MaterialName = (Material) itemInHand.getType();
|
||||
player.sendMessage("Adding projectile to cannon");
|
||||
itemInHand.setAmount(itemInHand.getAmount() - 1);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -114,7 +114,8 @@ public class CrunchSiegeCore extends JavaPlugin {
|
||||
}
|
||||
|
||||
public static void AddDefined() {
|
||||
SiegeEquipment equip = new SiegeEquipment(null);
|
||||
SiegeEquipment equip = new SiegeEquipment();
|
||||
equip.Projectiles.put(Material.COBBLESTONE, new SiegeProjectile(2, false));
|
||||
ItemStack item = new ItemStack(Material.CARVED_PUMPKIN);
|
||||
equip.ReadyModelNumber = 122;
|
||||
equip.ModelNumberToFireAt = 135;
|
||||
@@ -132,7 +133,7 @@ public class CrunchSiegeCore extends JavaPlugin {
|
||||
Location l = player.getLocation();
|
||||
l.setY(l.getY() - 1);
|
||||
Entity entity2 = player.getWorld().spawnEntity(l, EntityType.ARMOR_STAND);
|
||||
SiegeEquipment equip = new SiegeEquipment(entity2.getUniqueId());
|
||||
SiegeEquipment equip = new SiegeEquipment();
|
||||
ItemStack item = new ItemStack(Material.CARVED_PUMPKIN);
|
||||
equip.ReadyModelNumber = 122;
|
||||
equip.ModelNumberToFireAt = 135;
|
||||
@@ -143,6 +144,7 @@ public class CrunchSiegeCore extends JavaPlugin {
|
||||
));
|
||||
equip.CycleThroughModelsBeforeFiring = false;
|
||||
equip.Entity = entity2;
|
||||
equip.EntityId = entity2.getUniqueId();
|
||||
entity2.setCustomName("Weapon");
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package siegeCore;
|
||||
|
||||
import org.bukkit.Material;
|
||||
|
||||
public class EquipmentMagazine {
|
||||
public int LoadedFuel = 0;
|
||||
public int LoadedProjectile = 0;
|
||||
public String MaterialName = "NONE";
|
||||
public Material MaterialName = Material.BEDROCK;
|
||||
}
|
||||
@@ -21,7 +21,7 @@ public class RotationHandler implements Listener {
|
||||
if (CrunchSiegeCore.TrackedStands.containsKey(player.getUniqueId())) {
|
||||
ItemStack itemInHand = player.getInventory().getItemInMainHand();
|
||||
if (itemInHand != null) {
|
||||
if (itemInHand.getType() != Material.STICK) {
|
||||
if (itemInHand.getType() != Material.CLOCK) {
|
||||
// TrackedStands.remove(player.getUniqueId());
|
||||
|
||||
return;
|
||||
@@ -52,8 +52,15 @@ public class RotationHandler implements Listener {
|
||||
ArmorStand stand = (ArmorStand) living;
|
||||
|
||||
if (equipment.RotateUpDown) {
|
||||
stand.setHeadPose(new EulerAngle(player.getLocation().getDirection().getY()*(-1),0,0));
|
||||
loc.setPitch(player.getLocation().getPitch());
|
||||
if (loc.getPitch() < -85) {
|
||||
loc.setPitch(-85);
|
||||
}
|
||||
if (loc.getPitch() > 85) {
|
||||
loc.setPitch(85);
|
||||
}
|
||||
stand.setHeadPose(new EulerAngle(loc.getDirection().getY()*(-1),0,0));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package siegeCore;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
@@ -29,6 +30,8 @@ public class SiegeEquipment implements Cloneable {
|
||||
|
||||
public ItemStack ItemToPlace;
|
||||
|
||||
public HashMap<Material, SiegeProjectile> Projectiles = new HashMap<Material, SiegeProjectile>() ;
|
||||
|
||||
public String ItemToUseForModel;
|
||||
|
||||
public String WorldName;
|
||||
@@ -36,7 +39,7 @@ public class SiegeEquipment implements Cloneable {
|
||||
public int XOffset = 7;
|
||||
public int YOffset = 0;
|
||||
public int MaxFuel = 5;
|
||||
public float VelocityPerFuel = 0.5f;
|
||||
public float VelocityPerFuel = 0.75f;
|
||||
public Material FuelMaterial = Material.GUNPOWDER;
|
||||
public int FuseTime;
|
||||
public long NextShotTime = System.currentTimeMillis();
|
||||
@@ -62,16 +65,10 @@ public class SiegeEquipment implements Cloneable {
|
||||
|
||||
public List<Integer> FiringModelNumbers = new ArrayList<Integer>();
|
||||
|
||||
public SiegeProjectile projectile = new SiegeProjectile(2, false);
|
||||
|
||||
public EquipmentMagazine AmmoHolder = new EquipmentMagazine();
|
||||
|
||||
public SiegeEquipment(UUID id) {
|
||||
EntityId = id;
|
||||
}
|
||||
|
||||
public Boolean isLoaded() {
|
||||
return (AmmoHolder.LoadedFuel > 0 && AmmoHolder.LoadedProjectile > 1);
|
||||
return (AmmoHolder.LoadedFuel > 0 && AmmoHolder.LoadedProjectile >= 1);
|
||||
}
|
||||
|
||||
public Boolean CanLoadFuel() {
|
||||
@@ -110,26 +107,35 @@ public class SiegeEquipment implements Cloneable {
|
||||
return;
|
||||
}
|
||||
float loadedFuel = this.AmmoHolder.LoadedFuel;
|
||||
String LoadedProjectile = this.AmmoHolder.MaterialName;
|
||||
Material LoadedProjectile = this.AmmoHolder.MaterialName;
|
||||
|
||||
this.AmmoHolder.LoadedFuel = 0;
|
||||
this.AmmoHolder.LoadedProjectile = 0;
|
||||
this.AmmoHolder.MaterialName = Material.BEDROCK.toString();
|
||||
this.AmmoHolder.MaterialName = Material.BEDROCK;
|
||||
|
||||
LivingEntity living = (LivingEntity) Entity;
|
||||
if (living.getEquipment() == null || living.getEquipment().getHelmet() == null || living.getEquipment().getHelmet().getItemMeta() == null) {
|
||||
return;
|
||||
}
|
||||
if (living.getEquipment().getHelmet().getItemMeta().getCustomModelData() != this.ReadyModelNumber) {
|
||||
return;
|
||||
}
|
||||
this.WorldName = Entity.getWorld().getName();
|
||||
this.NextShotTime = System.currentTimeMillis() + 6000;
|
||||
if (this.CycleThroughModelsBeforeFiring) {
|
||||
|
||||
|
||||
this.TaskNumber = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(CrunchSiegeCore.plugin, () -> {
|
||||
LivingEntity living = (LivingEntity) Entity;
|
||||
|
||||
Location loc = living.getEyeLocation();
|
||||
Vector direction = Entity.getLocation().getDirection().multiply(XOffset);
|
||||
loc.add(direction);
|
||||
Random random = new Random();
|
||||
float randomVar = random.nextFloat() * (6 - -6) + -6;
|
||||
loc.add(direction.multiply(randomVar));
|
||||
loc.setYaw(loc.getYaw() + randomVar);
|
||||
|
||||
float randomVar = random.nextFloat() * (7 - -7) + -7;
|
||||
|
||||
|
||||
|
||||
this.NextModelNumber = 0;
|
||||
this.location = loc;
|
||||
|
||||
@@ -172,7 +178,7 @@ public class SiegeEquipment implements Cloneable {
|
||||
if (modelData == this.ModelNumberToFireAt) {
|
||||
Entity tnt = Bukkit.getServer().getWorld(this.WorldName).spawnEntity(loc, EntityType.SNOWBALL);
|
||||
|
||||
ClickHandler.projectiles.put(tnt.getUniqueId(), this.projectile);
|
||||
ClickHandler.projectiles.put(tnt.getUniqueId(), Projectiles.get(LoadedProjectile));
|
||||
tnt.setVelocity(loc.getDirection().multiply(loadedFuel * this.VelocityPerFuel));
|
||||
Bukkit.getServer().getWorld(this.WorldName).playSound(this.location, Sound.ENTITY_BAT_DEATH, 20, 2);
|
||||
}
|
||||
@@ -189,20 +195,19 @@ public class SiegeEquipment implements Cloneable {
|
||||
|
||||
this.TaskNumber = Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(CrunchSiegeCore.plugin, () -> {
|
||||
//player.sendMessage("task");
|
||||
LivingEntity living = (LivingEntity) Entity;
|
||||
|
||||
Location loc = living.getEyeLocation();
|
||||
Vector direction = Entity.getLocation().getDirection().multiply(XOffset);
|
||||
loc.add(direction);
|
||||
Random random = new Random();
|
||||
|
||||
float randomVar = random.nextFloat() * (7 - -7) + -7;
|
||||
|
||||
float randomVar = random.nextFloat() * (6 - -6) + -6;
|
||||
loc.add(direction);
|
||||
loc.setYaw(loc.getYaw() + randomVar);
|
||||
this.NextModelNumber = 0;
|
||||
this.location = loc;
|
||||
|
||||
// player.sendMessage("Cannot fire for another " + CrunchSiegeCore.convertTime(this.NextShotTime - System.currentTimeMillis()));
|
||||
Entity tnt = Bukkit.getServer().getWorld(this.WorldName).spawnEntity(loc, EntityType.SNOWBALL);
|
||||
ClickHandler.projectiles.put(tnt.getUniqueId(), this.projectile);
|
||||
ClickHandler.projectiles.put(tnt.getUniqueId(), Projectiles.get(LoadedProjectile));
|
||||
tnt.setVelocity(loc.getDirection().multiply(loadedFuel * this.VelocityPerFuel));
|
||||
Bukkit.getServer().getWorld(this.WorldName).playSound(this.location, Sound.ENTITY_GENERIC_EXPLODE, 20, 2);
|
||||
Bukkit.getServer().getWorld(this.WorldName).spawnParticle(Particle.EXPLOSION_LARGE, loc.getX(), loc.getY(), loc.getZ(), 0);
|
||||
|
||||
@@ -12,6 +12,4 @@ public class SiegeProjectile {
|
||||
Radius = rad;
|
||||
DoFire = fire;
|
||||
}
|
||||
|
||||
public ItemStack AmmoItem = new ItemStack(Material.COBBLESTONE, 1);
|
||||
}
|
||||
Reference in new issue
Block a user