Fix Wind charges cross middle and interact with Blocks

This commit is contained in:
Sakziea
2026-07-18 12:43:23 +02:00
parent e5cc874834
commit 801678ddd3
@@ -0,0 +1,88 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2026 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.fightsystem.listener;
import de.steamwar.fightsystem.Config;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.fight.FightWorld;
import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.states.StateDependentListener;
import de.steamwar.fightsystem.states.StateDependentTask;
import de.steamwar.linkage.Linked;
import io.papermc.paper.event.entity.EntityMoveEvent;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
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.HashSet;
import java.util.Set;
@Linked
public class Windcharge implements Listener {
private static final int middleLine = Config.SpecSpawn.getBlockZ();
private final Set<Entity> windcharges = new HashSet<>();
public Windcharge() {
new StateDependentListener(true, FightState.Running, this);
new StateDependentTask(true, FightState.Running, this::run, 1, 1);
}
@EventHandler
public void handleEntityExplode(EntityExplodeEvent event) {
if (event.getEntityType() != EntityType.WIND_CHARGE) return;
if (!Config.WindchargesInteractWithBlocks) {
event.blockList().clear();
}
if (!Config.WindchargesCanCrossMiddle) {
windcharges.remove(event.getEntity());
}
}
@EventHandler
public void handleEntitySpawnEvent(EntitySpawnEvent event) {
if (event.getEntityType() != EntityType.WIND_CHARGE) return;
if (!Config.WindchargesCanCrossMiddle) {
windcharges.add(event.getEntity());
}
}
public void run() {
if (!Config.WindchargesCanCrossMiddle) {
windcharges.forEach(entity -> {
Location nextlocation = entity.getLocation().add(entity.getVelocity());
Location location = entity.getLocation();
boolean passedMiddle = nextlocation.getBlockZ() >= middleLine && location.getBlockZ() <= middleLine ||
nextlocation.getBlockZ() <= middleLine && location.getBlockZ() >= middleLine;
if (passedMiddle) {
windcharges.remove(entity);
entity.remove();
}
});
}
}
}