From fe191a51b5d7f5144f4af9f0ada7480e680637f1 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 14 Mar 2022 09:49:51 +0100 Subject: [PATCH] WaterRemover remove on direct water hit Signed-off-by: Lixfel --- .../fightsystem/listener/WaterRemover.java | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/WaterRemover.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/WaterRemover.java index f6fba6b..d555ad0 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/WaterRemover.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/WaterRemover.java @@ -21,27 +21,61 @@ package de.steamwar.fightsystem.listener; import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.fight.Fight; +import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentListener; import de.steamwar.fightsystem.utils.FlatteningWrapper; +import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; +import org.bukkit.entity.EntityType; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityExplodeEvent; +import org.bukkit.event.entity.EntitySpawnEvent; + +import java.util.HashMap; +import java.util.Map; public class WaterRemover implements Listener { private static final int MIN_Y = Config.BluePasteRegion.getMinY() + Config.WaterDepth; + private final Map tnt = new HashMap<>(); + public WaterRemover() { - new StateDependentListener(ArenaMode.AntiReplay, FightState.Running, this); + new StateDependentListener(ArenaMode.AntiReplay, FightState.Running, this){ + @Override + public void enable() { + tnt.clear(); + super.enable(); + } + }; + } + + @EventHandler + public void handleEntitySpawn(EntitySpawnEvent event) { + if(event.getEntityType() != EntityType.PRIMED_TNT) + return; + + Location location = event.getLocation(); + if (Config.BlueExtendRegion.inRegion(location)) { + tnt.put(event.getEntity().getEntityId(), Fight.getBlueTeam()); + } else if (Config.RedExtendRegion.inRegion(location)) { + tnt.put(event.getEntity().getEntityId(), Fight.getRedTeam()); + } } @EventHandler public void handleEntityExplode(EntityExplodeEvent event) { event.setYield(0); //No drops (additionally to world config) + FightTeam spawn = tnt.remove(event.getEntity().getEntityId()); + if(spawn != null && event.blockList().isEmpty() && Fight.getOpposite(spawn).getExtendRegion().inRegion(event.getLocation())) { + checkBlock(event.getLocation().getBlock()); + } + for(Block b : event.blockList()){ //b cannot be water or air due to current explosion