From 24fb7546565c25d08e7a6d11e9b4ae8bb3b3bad2 Mon Sep 17 00:00:00 2001 From: Vaan1310 <61906290+Intybyte@users.noreply.github.com> Date: Sun, 4 Aug 2024 16:17:58 +0200 Subject: [PATCH] Fix #631 (#676) * Fix #631 * Sink ship instead of release --- .../net/countercraft/movecraft/Movecraft.java | 1 + .../movecraft/listener/PlayerListener.java | 15 ++++++--------- Movecraft/src/main/resources/config.yml | 1 + .../countercraft/movecraft/config/Settings.java | 3 +-- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/Movecraft/src/main/java/net/countercraft/movecraft/Movecraft.java b/Movecraft/src/main/java/net/countercraft/movecraft/Movecraft.java index 3614892dd..2f298f1a0 100644 --- a/Movecraft/src/main/java/net/countercraft/movecraft/Movecraft.java +++ b/Movecraft/src/main/java/net/countercraft/movecraft/Movecraft.java @@ -73,6 +73,7 @@ public void onEnable() { Settings.DisableNMSCompatibilityCheck = getConfig().getBoolean("IReallyKnowWhatIAmDoing", false); Settings.DisableSpillProtection = getConfig().getBoolean("DisableSpillProtection", false); Settings.DisableIceForm = getConfig().getBoolean("DisableIceForm", true); + Settings.ReleaseOnDeath = getConfig().getBoolean("ReleaseOnDeath", false); String[] localisations = {"en", "cz", "nl", "fr"}; for (String s : localisations) { diff --git a/Movecraft/src/main/java/net/countercraft/movecraft/listener/PlayerListener.java b/Movecraft/src/main/java/net/countercraft/movecraft/listener/PlayerListener.java index 04099a61a..b9f829be1 100644 --- a/Movecraft/src/main/java/net/countercraft/movecraft/listener/PlayerListener.java +++ b/Movecraft/src/main/java/net/countercraft/movecraft/listener/PlayerListener.java @@ -21,7 +21,6 @@ import net.countercraft.movecraft.config.Settings; import net.countercraft.movecraft.craft.Craft; import net.countercraft.movecraft.craft.CraftManager; -import net.countercraft.movecraft.craft.PlayerCraft; import net.countercraft.movecraft.craft.type.CraftType; import net.countercraft.movecraft.events.CraftReleaseEvent; import net.countercraft.movecraft.localisation.I18nSupport; @@ -32,15 +31,13 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; -import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerQuitEvent; import java.util.EnumSet; import java.util.HashSet; -import java.util.LinkedList; import java.util.Map; -import java.util.Queue; import java.util.Set; import java.util.WeakHashMap; @@ -102,17 +99,17 @@ public void onPlayerLogout(PlayerQuitEvent e) { } @EventHandler - public void onPlayerDeath(EntityDamageByEntityEvent e) { - // changed to death so when you shoot up an airship and hit the pilot, it still sinks - if (!(e instanceof Player)) + public void onPlayerDeath(PlayerDeathEvent e) { + // when you shoot a craft and kill the pilot, it sinks + if (!Settings.ReleaseOnDeath) return; - Player p = (Player) e; + Player p = e.getPlayer(); Craft craft = CraftManager.getInstance().getCraftByPlayer(p); if (craft == null) return; - CraftManager.getInstance().release(craft, CraftReleaseEvent.Reason.DEATH, false); + CraftManager.getInstance().sink(craft); } @EventHandler diff --git a/Movecraft/src/main/resources/config.yml b/Movecraft/src/main/resources/config.yml index 26453e3c1..e450a8707 100644 --- a/Movecraft/src/main/resources/config.yml +++ b/Movecraft/src/main/resources/config.yml @@ -22,6 +22,7 @@ ExtraFadeTimePerBlock: # List of blocks that will take longer time to fade DROPPER: 600 FURNACE: 600 CollisionPrimer: 1000 +ReleaseOnDeath: false ForbiddenRemoteSigns: # These strings will be ignored when searching for signs to trigger from a remote sign - "Mounted" - "Denied" diff --git a/api/src/main/java/net/countercraft/movecraft/config/Settings.java b/api/src/main/java/net/countercraft/movecraft/config/Settings.java index 74c94b49c..122d0b5a5 100644 --- a/api/src/main/java/net/countercraft/movecraft/config/Settings.java +++ b/api/src/main/java/net/countercraft/movecraft/config/Settings.java @@ -19,10 +19,8 @@ import org.bukkit.Material; -import java.util.EnumSet; import java.util.HashMap; import java.util.HashSet; -import java.util.List; import java.util.Map; public class Settings { @@ -48,4 +46,5 @@ public class Settings { public static int MaxRemoteSigns = -1; public static boolean CraftsUseNetherPortals = false; public static HashSet ForbiddenRemoteSigns; + public static boolean ReleaseOnDeath = false; }