Add DungeonMob events

This commit is contained in:
Daniel Saukel 2020-04-25 00:38:17 +02:00
parent 725b09e67d
commit cd6e6f045b
6 changed files with 163 additions and 184 deletions

View File

@ -0,0 +1,67 @@
/*
* Copyright (C) 2014-2020 Daniel Saukel
*
* This library is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser 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 GNULesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.erethon.dungeonsxl.api.event.mob;
import de.erethon.dungeonsxl.api.mob.DungeonMob;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
/**
* Fired when a {@link DungeonMob} dies.
*
* @author Daniel Saukel
*/
public class DungeonMobDeathEvent extends DungeonMobEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private boolean cancelled;
public DungeonMobDeathEvent(DungeonMob mob) {
super(mob);
}
/**
* Returns the player who killed the mob or null if the cause of its death was not a player.
*
* @return the player who killed the mob or null if the cause of its death was not a player
*/
public Player getKiller() {
if (mob.getEntity() == null) {
return null;
}
return mob.getEntity().getKiller();
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
}

View File

@ -0,0 +1,52 @@
/*
* Copyright (C) 2014-2020 Daniel Saukel
*
* This library is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser 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 GNULesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.erethon.dungeonsxl.api.event.mob;
import de.erethon.dungeonsxl.api.mob.DungeonMob;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.Event;
/**
* Superclass for events involving DungeonsXL mobs.
*
* @author Daniel Saukel
*/
public abstract class DungeonMobEvent extends Event {
protected DungeonMob mob;
protected DungeonMobEvent(DungeonMob mob) {
this.mob = mob;
}
/**
* Returns the DungeonMob involved in this event.
*
* @return the DungeonMob involved in this event
*/
public DungeonMob getDungeonMob() {
return mob;
}
/**
* Returns the Bukkit LivingEntity involved in this event.
*
* @return the Bukkit LivingEntity involved in this event
*/
public LivingEntity getBukkitEntity() {
return mob.getEntity();
}
}

View File

@ -0,0 +1,44 @@
/*
* Copyright (C) 2014-2020 Daniel Saukel
*
* This library is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser 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 GNULesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.erethon.dungeonsxl.api.event.mob;
import de.erethon.dungeonsxl.api.mob.DungeonMob;
import org.bukkit.event.HandlerList;
/**
* Fired when a spawned entity is registered as a {@link DungeonMob}.
* <p>
* Use {@link org.bukkit.event.entity.CreatureSpawnEvent} if you need to prevent a mob from spawning.
*
* @author Daniel Saukel
*/
public class DungeonMobSpawnEvent extends DungeonMobEvent {
private static final HandlerList handlers = new HandlerList();
public DungeonMobSpawnEvent(DungeonMob mob) {
super(mob);
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}

View File

@ -1,72 +0,0 @@
/*
* Copyright (C) 2012-2020 Frank Baumann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.erethon.dungeonsxl.event.dmob;
import de.erethon.dungeonsxl.mob.DMob;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.bukkit.event.entity.EntityDeathEvent;
/**
* @author Daniel Saukel
*/
public class DMobDeathEvent extends DMobEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private boolean cancelled;
private EntityDeathEvent bukkitEvent;
public DMobDeathEvent(DMob dMob, EntityDeathEvent bukkitEvent) {
super(dMob);
this.bukkitEvent = bukkitEvent;
}
/**
* @return the bukkitEvent
*/
public EntityDeathEvent getBukkitEvent() {
return bukkitEvent;
}
/**
* @param bukkitEvent the bukkitEvent to set
*/
public void setBukkitEvent(EntityDeathEvent bukkitEvent) {
this.bukkitEvent = bukkitEvent;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
}

View File

@ -1,47 +0,0 @@
/*
* Copyright (C) 2012-2020 Frank Baumann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.erethon.dungeonsxl.event.dmob;
import de.erethon.dungeonsxl.mob.DMob;
import org.bukkit.event.Event;
/**
* @author Daniel Saukel
*/
public abstract class DMobEvent extends Event {
protected DMob dMob;
public DMobEvent(DMob dMob) {
this.dMob = dMob;
}
/**
* @return the dMob
*/
public DMob getDMob() {
return dMob;
}
/**
* @param dMob the dMob to set
*/
public void setDMob(DMob dMob) {
this.dMob = dMob;
}
}

View File

@ -1,65 +0,0 @@
/*
* Copyright (C) 2012-2020 Frank Baumann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.erethon.dungeonsxl.event.dmob;
import de.erethon.dungeonsxl.mob.DMob;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
/**
* @author Daniel Saukel
*/
public class DMobSpawnEvent extends DMobEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private boolean cancelled;
private LivingEntity entity;
public DMobSpawnEvent(DMob dMob, LivingEntity entity) {
super(dMob);
this.entity = entity;
}
/**
* @return the mob
*/
public LivingEntity getEntity() {
return entity;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
}