SteamWar/FightSystem
Archiviert
13
1

WaterRemover remove on direct water hit #339

Zusammengeführt
Lixfel hat 1 Commits von waterRemover nach master 2022-03-14 11:12:08 +01:00 zusammengeführt
Nur Änderungen aus Commit fe191a51b5 werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -21,27 +21,61 @@ package de.steamwar.fightsystem.listener;
import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.ArenaMode;
import de.steamwar.fightsystem.Config; 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.FightState;
import de.steamwar.fightsystem.states.StateDependentListener; import de.steamwar.fightsystem.states.StateDependentListener;
import de.steamwar.fightsystem.utils.FlatteningWrapper; import de.steamwar.fightsystem.utils.FlatteningWrapper;
import org.bukkit.Location;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.entity.EntityType;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityExplodeEvent; 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 { public class WaterRemover implements Listener {
private static final int MIN_Y = Config.BluePasteRegion.getMinY() + Config.WaterDepth; private static final int MIN_Y = Config.BluePasteRegion.getMinY() + Config.WaterDepth;
private final Map<Integer, FightTeam> tnt = new HashMap<>();
public WaterRemover() { 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 @EventHandler
public void handleEntityExplode(EntityExplodeEvent event) { public void handleEntityExplode(EntityExplodeEvent event) {
event.setYield(0); //No drops (additionally to world config) 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()){ for(Block b : event.blockList()){
//b cannot be water or air due to current explosion //b cannot be water or air due to current explosion