SteamWar/FightSystem
Archiviert
13
1

Merge pull request 'WaterRemover remove on direct water hit' (#339) from waterRemover into master
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Reviewed-on: #339
Reviewed-by: YoyoNow <jwsteam@nidido.de>
Dieser Commit ist enthalten in:
Lixfel 2022-03-14 11:12:07 +01:00
Commit 3408e2e31e

Datei anzeigen

@ -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<Integer, FightTeam> 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