From 8db1fdf308c912de9583b1a1a8c5b05194e3e67e Mon Sep 17 00:00:00 2001 From: Intybyte Date: Wed, 31 Jul 2024 13:50:36 +0200 Subject: [PATCH] Adds #586 --- .../async/translation/TranslationTask.java | 12 ++++++----- .../update/ExplosionUpdateCommand.java | 20 ++++++++++++------- .../movecraft/craft/type/CraftType.java | 2 ++ .../movecraft/events/ExplosionEvent.java | 8 +++++++- 4 files changed, 29 insertions(+), 13 deletions(-) diff --git a/Movecraft/src/main/java/net/countercraft/movecraft/async/translation/TranslationTask.java b/Movecraft/src/main/java/net/countercraft/movecraft/async/translation/TranslationTask.java index 068f5d474..ed5112695 100644 --- a/Movecraft/src/main/java/net/countercraft/movecraft/async/translation/TranslationTask.java +++ b/Movecraft/src/main/java/net/countercraft/movecraft/async/translation/TranslationTask.java @@ -3,7 +3,6 @@ import net.countercraft.movecraft.Movecraft; import net.countercraft.movecraft.MovecraftChunk; import net.countercraft.movecraft.MovecraftLocation; -import net.countercraft.movecraft.TrackedLocation; import net.countercraft.movecraft.async.AsyncTask; import net.countercraft.movecraft.config.Settings; import net.countercraft.movecraft.craft.ChunkManager; @@ -58,7 +57,6 @@ import java.util.Collection; import java.util.EnumSet; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Set; import java.util.concurrent.ExecutionException; @@ -334,14 +332,17 @@ else if (world.equals(craft.getWorld()) } newHitBox.removeAll(air); for (MovecraftLocation location : collisionBox) { - if (craft.getType().getFloatProperty(CraftType.EXPLODE_ON_CRASH) > 0F) { + CraftType type = craft.getType(); + + if (type.getFloatProperty(CraftType.EXPLODE_ON_CRASH) > 0F) { if (System.currentTimeMillis() - craft.getOrigPilotTime() <= 1000) { continue; } Location loc = location.toBukkit(craft.getWorld()); if (!loc.getBlock().getType().isAir() && ThreadLocalRandom.current().nextDouble(1) < .05) { updates.add(new ExplosionUpdateCommand(loc, - craft.getType().getFloatProperty(CraftType.EXPLODE_ON_CRASH))); + type.getFloatProperty(CraftType.EXPLODE_ON_CRASH), + type.getBoolProperty(CraftType.INCENDIARY_ON_CRASH))); collisionExplosion = true; } } @@ -358,6 +359,7 @@ else if (world.equals(craft.getWorld()) && System.currentTimeMillis() - craft.getOrigPilotTime() > craft.getType().getIntProperty(CraftType.EXPLOSION_ARMING_TIME)) { for (MovecraftLocation location : collisionBox) { float explosionForce = craft.getType().getFloatProperty(CraftType.COLLISION_EXPLOSION); + boolean incendiary = craft.getType().getBoolProperty(CraftType.INCENDIARY_ON_CRASH); if (craft.getType().getBoolProperty(CraftType.FOCUSED_EXPLOSION)) { explosionForce *= Math.min(oldHitBox.size(), craft.getType().getIntProperty(CraftType.MAX_SIZE)); } @@ -372,7 +374,7 @@ else if (world.equals(craft.getWorld()) newLocation, craft.getWorld()); Bukkit.getServer().getPluginManager().callEvent(e); if (!e.isCancelled()) { - updates.add(new ExplosionUpdateCommand(newLocation, explosionForce)); + updates.add(new ExplosionUpdateCommand(newLocation, explosionForce, incendiary)); collisionExplosion = true; } } diff --git a/Movecraft/src/main/java/net/countercraft/movecraft/mapUpdater/update/ExplosionUpdateCommand.java b/Movecraft/src/main/java/net/countercraft/movecraft/mapUpdater/update/ExplosionUpdateCommand.java index 92bdb0062..a22bc8226 100644 --- a/Movecraft/src/main/java/net/countercraft/movecraft/mapUpdater/update/ExplosionUpdateCommand.java +++ b/Movecraft/src/main/java/net/countercraft/movecraft/mapUpdater/update/ExplosionUpdateCommand.java @@ -1,6 +1,5 @@ package net.countercraft.movecraft.mapUpdater.update; -import net.countercraft.movecraft.Movecraft; import net.countercraft.movecraft.config.Settings; import net.countercraft.movecraft.events.ExplosionEvent; import org.bukkit.Bukkit; @@ -11,13 +10,15 @@ public class ExplosionUpdateCommand extends UpdateCommand { private final Location explosionLocation; private final float explosionStrength; + private final boolean incendiary; - public ExplosionUpdateCommand(Location explosionLocation, float explosionStrength) throws IllegalArgumentException { + public ExplosionUpdateCommand(Location explosionLocation, float explosionStrength, boolean incendiary) throws IllegalArgumentException { if(explosionStrength < 0){ throw new IllegalArgumentException("Explosion strength cannot be negative"); } this.explosionLocation = explosionLocation; this.explosionStrength = explosionStrength; + this.incendiary = incendiary; } public Location getLocation() { @@ -28,9 +29,13 @@ public float getStrength() { return explosionStrength; } + public boolean isIncendiary() { + return incendiary; + } + @Override public void doUpdate() { - ExplosionEvent e = new ExplosionEvent(explosionLocation, explosionStrength); + ExplosionEvent e = new ExplosionEvent(explosionLocation, explosionStrength, incendiary); Bukkit.getServer().getPluginManager().callEvent(e); if(e.isCancelled()) return; @@ -39,11 +44,11 @@ public void doUpdate() { Bukkit.broadcastMessage("Explosion strength: " + explosionStrength + " at " + explosionLocation.toVector().toString()); } - this.createExplosion(explosionLocation.add(.5,.5,.5), explosionStrength); + this.createExplosion(explosionLocation.add(.5,.5,.5), explosionStrength, incendiary); } - private void createExplosion(Location loc, float explosionPower) { - loc.getWorld().createExplosion(loc.getX(), loc.getY(), loc.getZ(), explosionPower); + private void createExplosion(Location loc, float explosionPower, boolean incendiary) { + loc.getWorld().createExplosion(loc.getX(), loc.getY(), loc.getZ(), explosionPower, incendiary); } @Override @@ -58,6 +63,7 @@ public boolean equals(Object obj) { } ExplosionUpdateCommand other = (ExplosionUpdateCommand) obj; return this.explosionLocation.equals(other.explosionLocation) && - this.explosionStrength == other.explosionStrength; + this.explosionStrength == other.explosionStrength && + this.incendiary == other.incendiary; } } diff --git a/api/src/main/java/net/countercraft/movecraft/craft/type/CraftType.java b/api/src/main/java/net/countercraft/movecraft/craft/type/CraftType.java index 2ed26e40d..53c08d139 100644 --- a/api/src/main/java/net/countercraft/movecraft/craft/type/CraftType.java +++ b/api/src/main/java/net/countercraft/movecraft/craft/type/CraftType.java @@ -127,6 +127,7 @@ final public class CraftType { public static final NamespacedKey KEEP_MOVING_ON_SINK = buildKey("keep_moving_on_sink"); public static final NamespacedKey SMOKE_ON_SINK = buildKey("smoke_on_sink"); public static final NamespacedKey EXPLODE_ON_CRASH = buildKey("explode_on_crash"); + public static final NamespacedKey INCENDIARY_ON_CRASH = buildKey("incendiary_on_crash"); public static final NamespacedKey COLLISION_EXPLOSION = buildKey("collision_explosion"); private static final NamespacedKey MIN_HEIGHT_LIMIT = buildKey("min_height_limit"); // Private key used as default for PER_WORLD_MIN_HEIGHT_LIMIT @@ -449,6 +450,7 @@ public static void registerTypeValidator(Predicate validator, String registerProperty(new BooleanProperty("keepMovingOnSink", KEEP_MOVING_ON_SINK, type -> false)); registerProperty(new IntegerProperty("smokeOnSink", SMOKE_ON_SINK, type -> 0)); registerProperty(new FloatProperty("explodeOnCrash", EXPLODE_ON_CRASH, type -> 0F)); + registerProperty(new BooleanProperty("incendiaryOnCrash", INCENDIARY_ON_CRASH, type -> false)); registerProperty(new FloatProperty("collisionExplosion", COLLISION_EXPLOSION, type -> 0F)); registerProperty(new IntegerProperty("minHeightLimit", MIN_HEIGHT_LIMIT, type -> Integer.MIN_VALUE)); registerProperty(new PerWorldProperty<>("perWorldMinHeightLimit", PER_WORLD_MIN_HEIGHT_LIMIT, diff --git a/api/src/main/java/net/countercraft/movecraft/events/ExplosionEvent.java b/api/src/main/java/net/countercraft/movecraft/events/ExplosionEvent.java index 3edcb0e4f..b11b2e9fe 100644 --- a/api/src/main/java/net/countercraft/movecraft/events/ExplosionEvent.java +++ b/api/src/main/java/net/countercraft/movecraft/events/ExplosionEvent.java @@ -9,11 +9,13 @@ public class ExplosionEvent extends Event implements Cancellable { private static final HandlerList HANDLERS = new HandlerList(); private final Location explosionLocation; private final float explosionStrength; + private final boolean incendiary; private boolean cancelled; - public ExplosionEvent(Location explosionLocation, float explosionStrength) { + public ExplosionEvent(Location explosionLocation, float explosionStrength, boolean incendiary) { this.explosionLocation = explosionLocation; this.explosionStrength = explosionStrength; + this.incendiary = incendiary; cancelled = false; } @@ -44,4 +46,8 @@ public boolean isCancelled() { public void setCancelled(boolean cancelled) { this.cancelled = cancelled; } + + public boolean isIncendiary() { + return incendiary; + } } \ No newline at end of file