This commit is contained in:
TheCrunchy committed 2023-07-02 16:42:45 +01:00
1 parent b405f10553
commit 563216cf59
6 files changed
+157 -66

No files matched your search

Binary file not shown.
Binary file not shown.
Binary file not shown.
+48 -11
View File
@@ -44,7 +44,7 @@ import org.bukkit.util.EulerAngle;
public class ClickHandler implements Listener { public class ClickHandler implements Listener {
public float MinDelay = 5; public float MinDelay = 5;
public static HashMap<UUID, SiegeProjectile> projectiles = new HashMap<UUID, SiegeProjectile>(); public static HashMap<UUID, SiegeProjectile> projectiles = new HashMap<UUID, SiegeProjectile>();
@@ -69,7 +69,7 @@ public float MinDelay = 5;
public void Shoot(Player player, long delay) { public void Shoot(Player player, long delay) {
float actualDelay = 0; float actualDelay = delay;
Boolean FirstShot = true; Boolean FirstShot = true;
for (Entity ent : CrunchSiegeCore.TrackedStands.get(player.getUniqueId())){{ for (Entity ent : CrunchSiegeCore.TrackedStands.get(player.getUniqueId())){{
@@ -83,10 +83,7 @@ public float MinDelay = 5;
} }
SiegeEquipment siege = CrunchSiegeCore.equipment.get(ent.getUniqueId()); SiegeEquipment siege = CrunchSiegeCore.equipment.get(ent.getUniqueId());
if (System.currentTimeMillis() < siege.NextShotTime) {
player.sendMessage("Cannot fire for another " + CrunchSiegeCore.convertTime(siege.NextShotTime - System.currentTimeMillis()));
continue;
}
if (player.getInventory().containsAtLeast(new ItemStack(Material.COBBLESTONE), 10)) { if (player.getInventory().containsAtLeast(new ItemStack(Material.COBBLESTONE), 10)) {
player.getInventory().remove(new ItemStack(Material.COBBLESTONE, 10)); player.getInventory().remove(new ItemStack(Material.COBBLESTONE, 10));
@@ -95,9 +92,15 @@ public float MinDelay = 5;
player.sendMessage("Cannot fire, missing cobblestone, requires 10 per shot"); player.sendMessage("Cannot fire, missing cobblestone, requires 10 per shot");
continue; continue;
} }
player.sendMessage(String.format("§e" +actualDelay)); if (siege.isLoaded()) {
siege.Fire(player, actualDelay); siege.Fire(player, actualDelay);
actualDelay += delay; actualDelay += delay;
}
else {
player.sendMessage("Cannon is not loaded");
}
// player.sendMessage(String.format("§e" +actualDelay));
} }
} }
} }
@@ -190,20 +193,31 @@ public float MinDelay = 5;
} }
public void AimUp(Player player, float amount) { public void AimUp(Player player, float amount) {
for (Entity ent : CrunchSiegeCore.TrackedStands.get(player.getUniqueId())) { for (Entity ent : CrunchSiegeCore.TrackedStands.get(player.getUniqueId())) {
Location loc = ent.getLocation(); Location loc = ent.getLocation();
ArmorStand stand = (ArmorStand) ent; ArmorStand stand = (ArmorStand) ent;
// player.sendMessage(String.format("" + loc.getPitch()));
if (loc.getPitch() == -90 || loc.getPitch() - amount < -90) {
return;
}
loc.setPitch((float) (loc.getPitch() - amount)); loc.setPitch((float) (loc.getPitch() - amount));
stand.setHeadPose(new EulerAngle(loc.getDirection().getY()*(-1),0,0)); stand.setHeadPose(new EulerAngle(loc.getDirection().getY()*(-1),0,0));
ent.teleport(loc); ent.teleport(loc);
} }
} }
public void AimDown(Player player, float amount) { public void AimDown(Player player, float amount) {
for (Entity ent : CrunchSiegeCore.TrackedStands.get(player.getUniqueId())) { for (Entity ent : CrunchSiegeCore.TrackedStands.get(player.getUniqueId())) {
Location loc = ent.getLocation(); Location loc = ent.getLocation();
ArmorStand stand = (ArmorStand) ent; ArmorStand stand = (ArmorStand) ent;
// player.sendMessage(String.format("" + loc.getPitch()));
if (loc.getPitch() == 90 || loc.getPitch() + amount > 90) {
return;
}
loc.setPitch((float) (loc.getPitch() + amount)); loc.setPitch((float) (loc.getPitch() + amount));
stand.setHeadPose(new EulerAngle(loc.getDirection().getY()*(-1),0,0)); stand.setHeadPose(new EulerAngle(loc.getDirection().getY()*(-1),0,0));
@@ -217,6 +231,9 @@ public float MinDelay = 5;
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 (!CrunchSiegeCore.TrackedStands.containsKey(player.getUniqueId())) {
return;
}
try { try {
Long delay = Long.parseLong(sign.getLine(1)); Long delay = Long.parseLong(sign.getLine(1));
if (delay < 6){ if (delay < 6){
@@ -230,6 +247,9 @@ public float MinDelay = 5;
} }
if(sign.getLine(0).equalsIgnoreCase( "[Aim]")){ if(sign.getLine(0).equalsIgnoreCase( "[Aim]")){
if (!CrunchSiegeCore.TrackedStands.containsKey(player.getUniqueId())) {
return;
}
float amount; float amount;
try { try {
amount = Float.parseFloat(sign.getLine(1)); amount = Float.parseFloat(sign.getLine(1));
@@ -292,11 +312,28 @@ public float MinDelay = 5;
if (entity == null) { if (entity == null) {
return; return;
} }
if (itemInHand.getType() == Material.CLOCK) { if (entity.getType() == EntityType.ARMOR_STAND){
if (entity.getType() == EntityType.ARMOR_STAND){ if (itemInHand.getType() == Material.CLOCK) {
TakeControl(player, entity); TakeControl(player, entity);
return;
}
if (CrunchSiegeCore.equipment.containsKey(entity.getUniqueId())) {
SiegeEquipment equipment = CrunchSiegeCore.equipment.get(entity.getUniqueId());
if (itemInHand.getType().equals(equipment.FuelMaterial)) {
if (equipment.LoadFuel(player)) {
player.sendMessage("Loaded " + equipment.AmmoHolder.LoadedFuel + "/" + equipment.MaxFuel);
}
else {
player.sendMessage("Could not load powder.");
}
}
if (itemInHand.getType().equals(Material.FLINT)) {
Shoot(player, 6);
}
return;
} }
return;
} }
} }
} }
+7
View File
@@ -0,0 +1,7 @@
package siegeCore;
public class EquipmentMagazine {
public int LoadedFuel = 0;
public int LoadedProjectile = 0;
public String MaterialName = "NONE";
}
+102 -55
View File
@@ -7,6 +7,7 @@ import java.util.UUID;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Particle; import org.bukkit.Particle;
import org.bukkit.Sound; import org.bukkit.Sound;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
@@ -20,7 +21,7 @@ public class SiegeEquipment implements Cloneable {
@Override @Override
public SiegeEquipment clone() throws CloneNotSupportedException { public SiegeEquipment clone() throws CloneNotSupportedException {
return (SiegeEquipment)super.clone(); return (SiegeEquipment)super.clone();
} }
public UUID EntityId; public UUID EntityId;
@@ -34,9 +35,10 @@ public class SiegeEquipment implements Cloneable {
public int XOffset = 7; public int XOffset = 7;
public int YOffset = 0; public int YOffset = 0;
public int MaxFuel = 5;
public float VelocityPerFuel = 0.5f;
public Material FuelMaterial = Material.GUNPOWDER;
public int FuseTime; public int FuseTime;
public double Velocity = 3;
public long NextShotTime = System.currentTimeMillis(); public long NextShotTime = System.currentTimeMillis();
public int MillisecondsBetweenFiringStages; public int MillisecondsBetweenFiringStages;
@@ -47,7 +49,7 @@ public class SiegeEquipment implements Cloneable {
public int ModelNumberToFireAt; public int ModelNumberToFireAt;
public Boolean CycleThroughModelsBeforeFiring = false; public Boolean CycleThroughModelsBeforeFiring = false;
public Boolean RotateSideways = false; public Boolean RotateSideways = false;
public Boolean RotateUpDown = true; public Boolean RotateUpDown = true;
public Boolean HasFired = false; public Boolean HasFired = false;
public Boolean HasReloaded = false; public Boolean HasReloaded = false;
@@ -62,11 +64,57 @@ public class SiegeEquipment implements Cloneable {
public SiegeProjectile projectile = new SiegeProjectile(2, false); public SiegeProjectile projectile = new SiegeProjectile(2, false);
public EquipmentMagazine AmmoHolder = new EquipmentMagazine();
public SiegeEquipment(UUID id) { public SiegeEquipment(UUID id) {
EntityId = id; EntityId = id;
} }
public Boolean isLoaded() {
return (AmmoHolder.LoadedFuel > 0 && AmmoHolder.LoadedProjectile > 1);
}
public Boolean CanLoadFuel() {
return AmmoHolder.LoadedFuel < MaxFuel;
}
public Boolean LoadFuel(Player player) {
ItemStack fuelItem = new ItemStack(this.FuelMaterial, 1);
if (AmmoHolder.LoadedFuel == this.MaxFuel) {
return true;
}
if (player.getInventory().containsAtLeast(fuelItem, 1)) {
if (CanLoadFuel()) {
AmmoHolder.LoadedFuel += 1;
SaveState();
player.getInventory().removeItem(fuelItem);
return true;
}
else {
return false;
}
}
return false;
}
public void SaveState() {
}
public void Fire(Player player, float delay) { public void Fire(Player player, float delay) {
if (System.currentTimeMillis() < this.NextShotTime) {
player.sendMessage("Cannot fire for another " + CrunchSiegeCore.convertTime(this.NextShotTime - System.currentTimeMillis()));
return;
}
float loadedFuel = this.AmmoHolder.LoadedFuel;
String LoadedProjectile = this.AmmoHolder.MaterialName;
this.AmmoHolder.LoadedFuel = 0;
this.AmmoHolder.LoadedProjectile = 0;
this.AmmoHolder.MaterialName = Material.BEDROCK.toString();
this.WorldName = Entity.getWorld().getName(); this.WorldName = Entity.getWorld().getName();
this.NextShotTime = System.currentTimeMillis() + 6000; this.NextShotTime = System.currentTimeMillis() + 6000;
@@ -85,58 +133,57 @@ public class SiegeEquipment implements Cloneable {
this.NextModelNumber = 0; this.NextModelNumber = 0;
this.location = loc; this.location = loc;
// player.sendMessage("Cannot fire for another " + CrunchSiegeCore.convertTime(this.NextShotTime - System.currentTimeMillis())); // player.sendMessage("Cannot fire for another " + CrunchSiegeCore.convertTime(this.NextShotTime - System.currentTimeMillis()));
//player.sendMessage("task"); //player.sendMessage("task");
if (this.HasFired) { if (this.HasFired) {
Bukkit.getServer().getScheduler().cancelTask(this.TaskNumber); Bukkit.getServer().getScheduler().cancelTask(this.TaskNumber);
this.TaskNumber = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(CrunchSiegeCore.plugin, () -> { this.TaskNumber = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(CrunchSiegeCore.plugin, () -> {
// player.sendMessage("task"); // player.sendMessage("task");
if (this.HasReloaded) { if (this.HasReloaded) {
Bukkit.getServer().getScheduler().cancelTask(this.TaskNumber); Bukkit.getServer().getScheduler().cancelTask(this.TaskNumber);
this.HasReloaded = false; this.HasReloaded = false;
this.HasFired = false; this.HasFired = false;
this.NextModelNumber = 0; this.NextModelNumber = 0;
}
else {
//firing stages
if (this.NextModelNumber - 1 <= this.FiringModelNumbers.size() && this.NextModelNumber - 1 >= 0) {
int modelData = this.FiringModelNumbers.get(this.NextModelNumber - 1);
// player.sendMessage("" + modelData);
CrunchSiegeCore.UpdateEntityIdModel(this.Entity, modelData, this.WorldName);
this.NextModelNumber -= 1;
}else {
// plugin.getLogger().log(Level.INFO, "its reloaded");
this.HasReloaded = true;
} }
} else {
}, 0, this.MillisecondsBetweenReloadingStages); //firing stages
if (this.NextModelNumber - 1 <= this.FiringModelNumbers.size() && this.NextModelNumber - 1 >= 0) {
int modelData = this.FiringModelNumbers.get(this.NextModelNumber - 1);
// player.sendMessage("" + modelData);
CrunchSiegeCore.UpdateEntityIdModel(this.Entity, modelData, this.WorldName);
this.NextModelNumber -= 1;
} }else {
else { // plugin.getLogger().log(Level.INFO, "its reloaded");
//firing stages this.HasReloaded = true;
if (this.NextModelNumber < this.FiringModelNumbers.size()) { }
}
int modelData = this.FiringModelNumbers.get(this.NextModelNumber); }, 0, this.MillisecondsBetweenReloadingStages);
// player.sendMessage("" + modelData);
CrunchSiegeCore.UpdateEntityIdModel(this.Entity, modelData, this.WorldName);
if (modelData == this.ModelNumberToFireAt) {
Entity tnt = Bukkit.getServer().getWorld(this.WorldName).spawnEntity(loc, EntityType.SNOWBALL);
ClickHandler.projectiles.put(tnt.getUniqueId(), this.projectile);
tnt.setVelocity(loc.getDirection().multiply(this.Velocity));
Bukkit.getServer().getWorld(this.WorldName).playSound(this.location, Sound.ENTITY_BAT_DEATH, 20, 2);
this.NextShotTime = System.currentTimeMillis() + 6000;
}
this.NextModelNumber += 1;
}else {
this.HasFired = true;
} }
} else {
}, 0, this.MillisecondsBetweenFiringStages); //firing stages
if (this.NextModelNumber < this.FiringModelNumbers.size()) {
int modelData = this.FiringModelNumbers.get(this.NextModelNumber);
// player.sendMessage("" + modelData);
CrunchSiegeCore.UpdateEntityIdModel(this.Entity, modelData, this.WorldName);
if (modelData == this.ModelNumberToFireAt) {
Entity tnt = Bukkit.getServer().getWorld(this.WorldName).spawnEntity(loc, EntityType.SNOWBALL);
ClickHandler.projectiles.put(tnt.getUniqueId(), this.projectile);
tnt.setVelocity(loc.getDirection().multiply(loadedFuel * this.VelocityPerFuel));
Bukkit.getServer().getWorld(this.WorldName).playSound(this.location, Sound.ENTITY_BAT_DEATH, 20, 2);
}
this.NextModelNumber += 1;
}else {
this.HasFired = true;
}
}
}, 0, this.MillisecondsBetweenFiringStages);
} }
else { else {
@@ -153,14 +200,14 @@ public class SiegeEquipment implements Cloneable {
this.NextModelNumber = 0; this.NextModelNumber = 0;
this.location = loc; this.location = loc;
// player.sendMessage("Cannot fire for another " + CrunchSiegeCore.convertTime(this.NextShotTime - System.currentTimeMillis())); // player.sendMessage("Cannot fire for another " + CrunchSiegeCore.convertTime(this.NextShotTime - System.currentTimeMillis()));
Entity tnt = Bukkit.getServer().getWorld(this.WorldName).spawnEntity(loc, EntityType.SNOWBALL); Entity tnt = Bukkit.getServer().getWorld(this.WorldName).spawnEntity(loc, EntityType.SNOWBALL);
ClickHandler.projectiles.put(tnt.getUniqueId(), this.projectile); ClickHandler.projectiles.put(tnt.getUniqueId(), this.projectile);
tnt.setVelocity(loc.getDirection().multiply(this.Velocity)); 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).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); Bukkit.getServer().getWorld(this.WorldName).spawnParticle(Particle.EXPLOSION_LARGE, loc.getX(), loc.getY(), loc.getZ(), 0);
this.NextShotTime = System.currentTimeMillis() + 6000;
}, (long) delay); }, (long) delay);
} }
} }