This commit is contained in:
TheCrunchy committed 2023-07-15 12:06:35 +01:00
1 parent 8f467ba352
commit bd0ad436c8
17 files changed
+139 -64

No files matched your search

+34 -13
View File
@@ -133,14 +133,14 @@ public class ClickHandler implements Listener {
return;
}
// if (ItemInHand.getType() == Material.PAPER) {
// ItemMeta meta = ItemInHand.getItemMeta();
// if (meta.hasCustomModelData() && meta.getCustomModelData() == 505050505) {
// CrunchSiegeCore.CreateTrebuchet(player);
// ItemInHand.setAmount(ItemInHand.getAmount() - 1);
// return;
// }
// }
// if (ItemInHand.getType() == Material.PAPER) {
// ItemMeta meta = ItemInHand.getItemMeta();
// if (meta.hasCustomModelData() && meta.getCustomModelData() == 505050505) {
// CrunchSiegeCore.CreateTrebuchet(player);
// ItemInHand.setAmount(ItemInHand.getAmount() - 1);
// return;
// }
// }
if (event.getAction() == Action.LEFT_CLICK_AIR) {
@@ -183,9 +183,8 @@ public class ClickHandler implements Listener {
}
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());
if (equip == null || !equip.Enabled) {
@@ -201,7 +200,10 @@ public class ClickHandler implements Listener {
equip.Entity = entity;
equip.EntityId = entity.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);
if (CrunchSiegeCore.TrackedStands.containsKey(player.getUniqueId())) {
List<Entity> entities = CrunchSiegeCore.TrackedStands.get(player.getUniqueId());
entities.add(entity);
@@ -246,10 +248,21 @@ public class ClickHandler implements Listener {
return;
}
loc.setPitch((float) (loc.getPitch() - amount));
stand.setHeadPose(new EulerAngle(loc.getDirection().getY()*(-1),0,0));
SiegeEquipment equipment = CrunchSiegeCore.equipment.get(ent.getUniqueId());
if (equipment != null) {
equipment.ShowFireLocation(player);
if (equipment.RotateStandHead) {
stand.setHeadPose(new EulerAngle(loc.getDirection().getY()*(-1),0,0));
}
}
ent.teleport(loc);
}
}
@@ -265,9 +278,17 @@ public class ClickHandler implements Listener {
if (loc.getPitch() == 85 || loc.getPitch() + amount > 85) {
return;
}
SiegeEquipment equipment = CrunchSiegeCore.equipment.get(ent.getUniqueId());
if (equipment != null) {
equipment.ShowFireLocation(player);
if (equipment.RotateStandHead) {
stand.setHeadPose(new EulerAngle(loc.getDirection().getY()*(-1),0,0));
}
}
loc.setPitch((float) (loc.getPitch() + amount));
stand.setHeadPose(new EulerAngle(loc.getDirection().getY()*(-1),0,0));
ent.teleport(loc);
}
}
+38 -23
View File
@@ -61,6 +61,28 @@ public class CrunchSiegeCore extends JavaPlugin {
public static Random random = new Random();
private static String Path;
@SuppressWarnings("deprecation")
@Override
public void onDisable() {
for (SiegeEquipment equip : equipment.values()) {
if (equip.Entity != null) {
ItemStack item = new ItemStack(Material.CARVED_PUMPKIN);
ItemMeta meta = item.getItemMeta();
equip.AmmoHolder = new EquipmentMagazine();
meta.setCustomModelData(equip.ReadyModelNumber);
meta.setDisplayName("§e" + equip.EquipmentName +" spawn item");
List<String> Lore = new ArrayList<String>();
Lore.add("§ePlace as a block to spawn a " + equip.EquipmentName + " or put on an armour stand.");
meta.setLore(Lore);
item.setItemMeta(meta);
((LivingEntity) equip.Entity).getEquipment().setHelmet(item);
}
}
}
@SuppressWarnings("deprecation")
@Override
public void onEnable() {
@@ -206,15 +228,15 @@ public class CrunchSiegeCore extends JavaPlugin {
fireProj.SoundType = Sound.ENTITY_BLAZE_SHOOT;
equip.Projectiles.put(Material.DIAMOND, fireProj);
EntityProjectile pig = new EntityProjectile();
pig.EntityCount = 100;
pig.DelayedFire = true;
pig.DelayTime = 3;
pig.EntityTyp = EntityType.ARROW;
pig.SoundType = Sound.ITEM_CROSSBOW_SHOOT;
pig.ParticleType = Particle.GLOW;
equip.Projectiles.put(Material.PORKCHOP, pig);
equip.Projectiles.put(Material.BONE, new PotionProjectile());
// EntityProjectile pig = new EntityProjectile();
// pig.EntityCount = 100;
// pig.DelayedFire = true;
// pig.DelayTime = 3;
// pig.EntityTyp = EntityType.ARROW;
// pig.SoundType = Sound.ITEM_CROSSBOW_SHOOT;
// pig.ParticleType = Particle.GLOW;
// equip.Projectiles.put(Material.PORKCHOP, pig);
// equip.Projectiles.put(Material.BONE, new PotionProjectile());
ItemStack item = new ItemStack(Material.CARVED_PUMPKIN);
equip.ReadyModelNumber = 122;
equip.ModelNumberToFireAt = 135;
@@ -227,18 +249,7 @@ public class CrunchSiegeCore extends JavaPlugin {
DefinedEquipment.put(equip.ReadyModelNumber, equip);
}
public static Location getCenter(Location loc) {
return new Location(loc.getWorld(),
getRelativeCoord(loc.getBlockX()),
getRelativeCoord(loc.getBlockY()),
getRelativeCoord(loc.getBlockZ()));
}
private static double getRelativeCoord(int i) {
double d = i;
d = d < 0 ? d - .5 : d + .5;
return d;
}
public static Boolean CreateTrebuchet(Player player, int CustomModelData, Location l) {
//l.setY(l.getY() - 1);
l.add(0.5, 0, 0.5);
@@ -253,10 +264,14 @@ public class CrunchSiegeCore extends JavaPlugin {
ItemMeta meta = item.getItemMeta();
equip.AmmoHolder = new EquipmentMagazine();
meta.setCustomModelData(CustomModelData);
meta.setCustomModelData(equip.ReadyModelNumber);
meta.setDisplayName("§e" + equip.EquipmentName +" spawn item");
List<String> Lore = new ArrayList<String>();
Lore.add("§ePlace as a block to spawn a " + equip.EquipmentName + " or put on an armour stand.");
meta.setLore(Lore);
item.setItemMeta(meta);
LivingEntity ent = (LivingEntity) entity2;
ArmorStand stand = (ArmorStand) ent;
equip.Entity = entity2;
+14 -1
View File
@@ -1,7 +1,11 @@
package siegeCore;
import java.awt.Color;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Particle;
import org.bukkit.block.Block;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
@@ -10,6 +14,7 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.BlockIterator;
import org.bukkit.util.EulerAngle;
import org.bukkit.util.Vector;
@@ -59,16 +64,24 @@ public class RotationHandler implements Listener {
if (loc.getPitch() > 85) {
loc.setPitch(85);
}
if (equipment.RotateStandHead) {
stand.setHeadPose(new EulerAngle(loc.getDirection().getY()*(-1),0,0));
}
}
living.teleport(loc);
equipment.ShowFireLocation(player);
}
}
}
}
}
}
Vector getDirectionBetweenLocations(Location Start, Location End) {
Vector from = Start.toVector();
Vector to = End.toVector();
return to.subtract(from);
}
}
+39 -5
View File
@@ -35,7 +35,7 @@ public class SiegeEquipment implements Cloneable {
public Boolean Enabled = false;
public UUID EntityId;
public Entity Entity;
public Boolean RotateStandHead = true;
public HashMap<Material, CrunchProjectile> Projectiles = new HashMap<Material, CrunchProjectile>() ;
public String WorldName;
@@ -103,6 +103,38 @@ public class SiegeEquipment implements Cloneable {
}
public Location GetFireLocation(LivingEntity living) {
Location loc = living.getEyeLocation();
Vector direction = living.getLocation().getDirection().multiply(XOffset);
loc.add(direction);
if (this.YOffset > 0) {
loc.setY(loc.getY() + this.YOffset);
}
else {
loc.setY(loc.getY() - this.YOffset);
}
return loc;
}
public void ShowFireLocation(Player player) {
LivingEntity living = (LivingEntity) this.Entity;
if (living != null) {
Location origin = this.GetFireLocation(living);
Vector direction = origin.getDirection();
direction.multiply(5 /* the range */);
Location destination = origin.clone().add(direction);
direction.normalize();
for (int i = 0; i < 3 /* range */; i+= 1) {
Location spawn = origin.add(direction);
player.spawnParticle(Particle.CLOUD, spawn, 1, 0,0,0,0);
}
}
}
public void Fire(Player player, float delay) {
if (System.currentTimeMillis() < this.NextShotTime) {
player.sendMessage("Cannot fire for another " + CrunchSiegeCore.convertTime(this.NextShotTime - System.currentTimeMillis()));
@@ -129,10 +161,12 @@ public class SiegeEquipment implements Cloneable {
this.TaskNumber = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(CrunchSiegeCore.plugin, () -> {
Location loc = living.getEyeLocation();
Vector direction = Entity.getLocation().getDirection().multiply(XOffset);
Random random = new Random();
float randomVar = random.nextFloat() * (6 - -6) + -6;
Location loc = living.getEyeLocation();
Vector direction = Entity.getLocation().getDirection().multiply(XOffset);
loc.add(direction.multiply(randomVar));
loc.setYaw(loc.getYaw() + randomVar);
@@ -177,7 +211,7 @@ public class SiegeEquipment implements Cloneable {
// player.sendMessage("" + modelData);
CrunchSiegeCore.UpdateEntityIdModel(this.Entity, modelData, this.WorldName);
if (modelData == this.ModelNumberToFireAt) {
Projectiles.get(LoadedProjectile).Shoot(player, this.Entity, XOffset, YOffset, loadedFuel * this.VelocityPerFuel);
Projectiles.get(LoadedProjectile).Shoot(player, this.Entity, this.GetFireLocation(living), loadedFuel * this.VelocityPerFuel);
}
this.NextModelNumber += 1;
@@ -200,7 +234,7 @@ public class SiegeEquipment implements Cloneable {
this.NextModelNumber = 0;
Projectiles.get(LoadedProjectile).Shoot(player, this.Entity, XOffset, YOffset, loadedFuel * this.VelocityPerFuel);
Projectiles.get(LoadedProjectile).Shoot(player, this.Entity, this.GetFireLocation(living), loadedFuel * this.VelocityPerFuel);
}, (long) delay);
}