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

Feature/sink explosion #701

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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 @@ -22,6 +22,7 @@
import net.countercraft.movecraft.craft.type.CraftType;
import net.countercraft.movecraft.events.CraftReleaseEvent;
import net.countercraft.movecraft.events.CraftSinkEvent;
import net.countercraft.movecraft.events.ExplosionEvent;
import net.countercraft.movecraft.events.TypesReloadedEvent;
import net.countercraft.movecraft.exception.NonCancellableReleaseException;
import net.countercraft.movecraft.localisation.I18nSupport;
Expand All @@ -34,6 +35,7 @@
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
Expand Down Expand Up @@ -202,7 +204,27 @@ public void sink(@NotNull Craft craft) {
if (craft instanceof PlayerCraft)
playerCrafts.remove(((PlayerCraft) craft).getPilot());

crafts.add(new SinkingCraftImpl(craft));
SinkingCraftImpl sinkingCraft = new SinkingCraftImpl(craft);
crafts.add(sinkingCraft);

int tickDelay = sinkingCraft.getType().getIntProperty(CraftType.EXPLODE_ON_SINK_DELAY);
new BukkitRunnable() {

@Override
public void run() {
CraftType type = sinkingCraft.getType();
float explosionStrength = type.getFloatProperty(CraftType.EXPLODE_ON_SINK);
boolean incendiary = type.getBoolProperty(CraftType.INCENDIARY_ON_SINK);

Location location = sinkingCraft.getHitBox().getMidPoint().toBukkit(sinkingCraft.getWorld());

ExplosionEvent event = new ExplosionEvent(location, explosionStrength, incendiary);
Bukkit.getServer().getPluginManager().callEvent(event);

if (!event.isCancelled())
location.createExplosion(explosionStrength, incendiary);
}
}.runTaskLater(Movecraft.getInstance(), tickDelay);
Comment on lines +213 to +227
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This implementation does not match the requested feature in #501. The request was that blocks randomly explode as the craft sinks, this triggers a single explosion at the center.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad went by assumption, and didnt finish reading, my idea was that if like when a player dies/craft sinks or a craft sinks it explodes so it can't be used by the enemy or for modern servers that use movecraft and are like OilTrucks or stuff that in general can carry dangerous stuff they explode on sink

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is too different from the feature in #501, if this features isn't needed I will close it, otherwise I will close the PR

}

public void release(@NotNull Craft craft, @NotNull CraftReleaseEvent.Reason reason, boolean force) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ final public class CraftType {
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 EXPLODE_ON_SINK = buildKey("explode_on_sink");
public static final NamespacedKey INCENDIARY_ON_SINK = buildKey("incendiary_on_sink");
public static final NamespacedKey EXPLODE_ON_SINK_DELAY = buildKey("explode_on_sink_delay");
public static final NamespacedKey COLLISION_EXPLOSION = buildKey("collision_explosion");
public static final NamespacedKey UNDERWATER_COLLISION_EXPLOSION = buildKey("underwater_collision_explosion");
private static final NamespacedKey MIN_HEIGHT_LIMIT = buildKey("min_height_limit");
Expand Down Expand Up @@ -456,10 +459,16 @@ public static void registerTypeValidator(Predicate<CraftType> validator, String
type -> (int) Math.ceil(20 / type.getDoubleProperty(SINK_SPEED))));
registerProperty(new BooleanProperty("keepMovingOnSink", KEEP_MOVING_ON_SINK, type -> false));
registerProperty(new IntegerProperty("smokeOnSink", SMOKE_ON_SINK, type -> 0));

/* Craft explosion properties */
registerProperty(new FloatProperty("explodeOnCrash", EXPLODE_ON_CRASH, type -> 0F));
registerProperty(new BooleanProperty("incendiaryOnCrash", INCENDIARY_ON_CRASH, type -> false));
registerProperty(new FloatProperty("explodeOnSink", EXPLODE_ON_SINK, type -> 0F));
registerProperty(new BooleanProperty("incendiaryOnSink", INCENDIARY_ON_SINK, type -> false));
registerProperty(new IntegerProperty("explodeOnSinkDelay", EXPLODE_ON_SINK_DELAY, type -> 0));
registerProperty(new FloatProperty("collisionExplosion", COLLISION_EXPLOSION, type -> 0F));
registerProperty(new FloatProperty("underwaterCollisionExplosion", UNDERWATER_COLLISION_EXPLOSION, type -> type.getFloatProperty(COLLISION_EXPLOSION)));

registerProperty(new IntegerProperty("minHeightLimit", MIN_HEIGHT_LIMIT, type -> Integer.MIN_VALUE));
registerProperty(new PerWorldProperty<>("perWorldMinHeightLimit", PER_WORLD_MIN_HEIGHT_LIMIT,
(type, worldName) -> type.getIntProperty(MIN_HEIGHT_LIMIT)));
Expand Down