From 30aaf8e7c074c5a3fd78be74f31919578a36ab16 Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 6 Sep 2020 11:56:20 +0200 Subject: [PATCH] Fix Shield and Mine destructing Portal --- .../misslewars/listener/ItemListener.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/de/steamwar/misslewars/listener/ItemListener.java b/src/de/steamwar/misslewars/listener/ItemListener.java index 6c4ed1a..14e6ec6 100644 --- a/src/de/steamwar/misslewars/listener/ItemListener.java +++ b/src/de/steamwar/misslewars/listener/ItemListener.java @@ -31,6 +31,7 @@ import com.sk89q.worldedit.world.World; import de.steamwar.misslewars.Config; import de.steamwar.misslewars.FightState; import de.steamwar.misslewars.MissileWars; +import de.steamwar.misslewars.items.Missile; import de.steamwar.misslewars.items.SpecialItem; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -101,6 +102,7 @@ public class ItemListener extends BasicListener { if (e.getEntity() instanceof Snowball) { Bukkit.getScheduler().runTaskLater(MissileWars.getPlugin(), () -> { Location l = e.getEntity().getLocation(); + if (!validSpawn(l)) return; BlockVector3 paste = BlockVector3.at(l.getX(), l.getY(), l.getZ()).subtract(offsetShield); EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, -1); @@ -111,6 +113,7 @@ public class ItemListener extends BasicListener { if (e.getEntity() instanceof Egg) { Bukkit.getScheduler().runTaskLater(MissileWars.getPlugin(), () -> { Location l = e.getEntity().getLocation(); + if (!validSpawn(l)) return; BlockVector3 paste = BlockVector3.at(l.getX(), l.getY(), l.getZ()).subtract(offsetMine); EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, -1); @@ -119,4 +122,27 @@ public class ItemListener extends BasicListener { }, Config.ShieldFlyTime); } } + + private boolean validSpawn(Location location) { + int bz = MissileWars.getBlueTeam().getPortalZ(); + int rz = MissileWars.getRedTeam().getPortalZ(); + + int offset = sign(bz - rz) * 5; + + int blockZ = location.getBlockZ(); + if (offset > 0) { + if (blockZ > bz - offset) return false; + if (blockZ < rz + offset) return false; + } else { + if (blockZ < bz - offset) return false; + if (blockZ > rz + offset) return false; + } + return true; + } + + private int sign(int i) { + if (i < 0) return -1; + return i > 0 ? 1 : 0; + } + }