54 lines
1.4 KiB
Java
54 lines
1.4 KiB
Java
package gg.malloc.defense;
|
|
|
|
import gg.malloc.defense.engine.GameRunner;
|
|
|
|
import org.bukkit.event.EventHandler;
|
|
import org.bukkit.event.Listener;
|
|
import org.bukkit.event.entity.EntityDeathEvent;
|
|
import org.bukkit.event.entity.EntityDamageEvent;
|
|
import org.bukkit.event.entity.EntityCombustEvent;
|
|
import org.bukkit.event.entity.EntityTargetEvent;
|
|
import org.bukkit.event.player.PlayerQuitEvent;
|
|
import org.bukkit.entity.Player;
|
|
|
|
public class GameEventHandler implements Listener {
|
|
GameRunner m_runner;
|
|
|
|
public GameEventHandler(GameRunner runner) {
|
|
m_runner = runner;
|
|
}
|
|
|
|
@EventHandler
|
|
public void onEntityDeath(EntityDeathEvent evt) {
|
|
m_runner.handleEntityDeath(evt.getEntity());
|
|
}
|
|
|
|
@EventHandler
|
|
public void onPlayerQuit(PlayerQuitEvent evt) {
|
|
m_runner.removePlayer(evt.getPlayer());
|
|
}
|
|
|
|
@EventHandler
|
|
public void onEntityCombust(EntityCombustEvent evt) {
|
|
evt.setCancelled(true);
|
|
}
|
|
|
|
@EventHandler
|
|
public void onEntityTarget(EntityTargetEvent evt) {
|
|
m_runner.handleEntityRetargeting(evt);
|
|
}
|
|
|
|
@EventHandler
|
|
public void onEntityDamage(EntityDamageEvent evt) {
|
|
if (evt.getEntity() instanceof Player) {
|
|
Player player = (Player)evt.getEntity();
|
|
if (player.getHealth() - evt.getFinalDamage() <= 0) {
|
|
evt.setCancelled(true);
|
|
m_runner.handlePlayerDeath(player);
|
|
}
|
|
} else {
|
|
m_runner.handleEntityDamage(evt);
|
|
}
|
|
}
|
|
}
|