Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds #586 #677

Merged
merged 1 commit into from
Aug 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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));
}
Expand All @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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() {
Expand All @@ -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;
Expand All @@ -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
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -449,6 +450,7 @@ public static void registerTypeValidator(Predicate<CraftType> 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -44,4 +46,8 @@ public boolean isCancelled() {
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}

public boolean isIncendiary() {
return incendiary;
}
}