From ff24427af840417b0db48d1185f8b9b19c908e03 Mon Sep 17 00:00:00 2001 From: Intybyte Date: Sun, 25 Aug 2024 10:53:52 +0200 Subject: [PATCH 1/2] Added craft tags --- .../net/countercraft/movecraft/craft/type/CraftType.java | 9 +++++++++ 1 file changed, 9 insertions(+) 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 eb01c1f41..a0360a344 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 @@ -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"); @@ -456,10 +459,16 @@ public static void registerTypeValidator(Predicate 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))); From 1d1bf21d244c8c226950d883d2c54df44e47662a Mon Sep 17 00:00:00 2001 From: Intybyte Date: Sun, 25 Aug 2024 11:13:36 +0200 Subject: [PATCH 2/2] Add explosion --- .../movecraft/craft/CraftManager.java | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/Movecraft/src/main/java/net/countercraft/movecraft/craft/CraftManager.java b/Movecraft/src/main/java/net/countercraft/movecraft/craft/CraftManager.java index 1db3db008..a88a1cda8 100644 --- a/Movecraft/src/main/java/net/countercraft/movecraft/craft/CraftManager.java +++ b/Movecraft/src/main/java/net/countercraft/movecraft/craft/CraftManager.java @@ -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; @@ -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; @@ -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); } public void release(@NotNull Craft craft, @NotNull CraftReleaseEvent.Reason reason, boolean force) {