sequence firing and persistent data

This commit is contained in:
TheCrunchy committed 2023-07-02 13:39:44 +01:00
1 parent 55ce0674db
commit 39c32c4266
8 files changed
+36 -18

No files matched your search

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+12 -8
View File
@@ -65,7 +65,9 @@ public class ClickHandler implements Listener {
public void Shoot(Player player) {
int delay = 6;
for (Entity ent : CrunchSiegeCore.TrackedStands.get(player.getUniqueId())){{
if (ent == null || ent.isDead()) {
continue;
}
@@ -86,9 +88,10 @@ public class ClickHandler implements Listener {
}
else {
player.sendMessage("Cannot fire, missing cobblestone, requires 10 per shot");
return;
continue;
}
siege.Fire(player);
siege.Fire(player, delay);
delay += 6;
}
}
@@ -176,19 +179,16 @@ public class ClickHandler implements Listener {
public void onPlayerClickSign(PlayerInteractEvent event){
Player p = event.getPlayer();
if(event.getClickedBlock() != null && event.getClickedBlock().getType().toString().contains("SIGN")){
Sign sign = (Sign) event.getClickedBlock().getState();
if(sign.getLine(0).equalsIgnoreCase( "[Cannon]")){
if(event.getAction() == Action.RIGHT_CLICK_BLOCK){
Sign sign = (Sign) event.getClickedBlock().getState();
//^^ .getState(); really important
if(sign.getLine(0).equalsIgnoreCase( "[Cannon]")){
NamespacedKey key = new NamespacedKey(CrunchSiegeCore.plugin, "cannons");
TileState state = (TileState) sign.getBlock().getState();
CrunchSiegeCore.TrackedStands.remove(p.getUniqueId());
List<UUID> temp = new ArrayList<UUID>();
event.getPlayer().sendMessage("1");
if (!state.getPersistentDataContainer().has(key, PersistentDataType.STRING)) {
return;
}
event.getPlayer().sendMessage("2");
String[] split = state.getPersistentDataContainer().get(key, PersistentDataType.STRING).replace("[", "").replace("]", "").split(",");
for (String s : split) {
p.sendMessage(s.trim());
@@ -203,6 +203,10 @@ public class ClickHandler implements Listener {
}
}
}
if (event.getAction() == Action.LEFT_CLICK_BLOCK) {
CrunchSiegeCore.TrackedStands.remove(p.getUniqueId());
p.sendMessage("Releasing the cannons!");
}
}
}
+2 -2
View File
@@ -156,8 +156,8 @@ public class CrunchSiegeCore extends JavaPlugin {
stand.addEquipmentLock(EquipmentSlot.CHEST, LockType.ADDING_OR_CHANGING);
stand.addEquipmentLock(EquipmentSlot.FEET, LockType.ADDING_OR_CHANGING);
ent.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 2000000, 1));
// stand.setSmall(true);
// stand.setVisible(true);
stand.setSmall(true);
stand.setVisible(true);
//stand.setSmall(true);
ent.getEquipment().setHelmet(item);
if (TrackedStands.containsKey(player.getUniqueId())) {
+1
View File
@@ -53,6 +53,7 @@ public class RotationHandler implements Listener {
if (equipment.RotateUpDown) {
stand.setHeadPose(new EulerAngle(player.getLocation().getDirection().getY()*(-1),0,0));
loc.setPitch(player.getLocation().getPitch());
}
+21 -8
View File
@@ -7,12 +7,14 @@ import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Particle;
import org.bukkit.Sound;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;
public class SiegeEquipment implements Cloneable {
@@ -30,6 +32,9 @@ public class SiegeEquipment implements Cloneable {
public String WorldName;
public int XOffset = 5;
public int YOffset = 0;
public int FuseTime;
public double Velocity = 3;
public long NextShotTime = System.currentTimeMillis();
@@ -41,7 +46,7 @@ public class SiegeEquipment implements Cloneable {
public Location location;
public int ModelNumberToFireAt;
public Boolean CycleThroughModelsBeforeFiring = false;
public Boolean RotateSideways = true;
public Boolean RotateSideways = false;
public Boolean RotateUpDown = true;
public Boolean HasFired = false;
@@ -61,9 +66,11 @@ public class SiegeEquipment implements Cloneable {
EntityId = id;
}
public void Fire(Player player) {
public void Fire(Player player, int delay) {
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;
@@ -73,7 +80,7 @@ public class SiegeEquipment implements Cloneable {
this.NextShotTime = System.currentTimeMillis() + 6000;
player.sendMessage("Cannot fire for another " + CrunchSiegeCore.convertTime(this.NextShotTime - System.currentTimeMillis()));
this.WorldName = Entity.getWorld().getName();
Bukkit.getServer().getWorld(this.WorldName).playSound(this.location, Sound.ENTITY_BAT_DEATH, 20, 2);
if (this.CycleThroughModelsBeforeFiring) {
@@ -117,7 +124,7 @@ public class SiegeEquipment implements Cloneable {
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.NextModelNumber += 1;
@@ -129,10 +136,16 @@ public class SiegeEquipment implements Cloneable {
}, 0, this.MillisecondsBetweenFiringStages);
}
else {
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));
this.TaskNumber = Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(CrunchSiegeCore.plugin, () -> {
//player.sendMessage("task");
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_GENERIC_EXPLODE, 20, 2);
Bukkit.getServer().getWorld(this.WorldName).spawnParticle(Particle.SMOKE_LARGE, loc.getX(), loc.getY(), loc.getZ(), 0);
}, delay);
}
}