mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-28 07:20:24 +01:00
Entity damage hooks
By: angelsl <angelsl@rpm>
This commit is contained in:
parent
05b2a299c0
commit
b2817db6b7
6 changed files with 196 additions and 2 deletions
|
@ -318,12 +318,12 @@ public abstract class Event {
|
||||||
* Called when a LivingEntity is damaged by the environment (for example,
|
* Called when a LivingEntity is damaged by the environment (for example,
|
||||||
* falling or lava)
|
* falling or lava)
|
||||||
*/
|
*/
|
||||||
ENTITY_DAMAGED_ENVIRONMENT (Category.LIVING_ENTITY),
|
ENTITY_DAMAGEDBY_BLOCK (Category.LIVING_ENTITY),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a LivingEntity is damaged by another LivingEntity
|
* Called when a LivingEntity is damaged by another LivingEntity
|
||||||
*/
|
*/
|
||||||
ENTITY_DAMAGED (Category.LIVING_ENTITY),
|
ENTITY_DAMAGEDBY_ENTITY (Category.LIVING_ENTITY),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a LivingEntity dies
|
* Called when a LivingEntity dies
|
||||||
|
|
|
@ -0,0 +1,67 @@
|
||||||
|
package org.bukkit.event.entity;
|
||||||
|
|
||||||
|
import org.bukkit.Block;
|
||||||
|
import org.bukkit.Entity;
|
||||||
|
import org.bukkit.LivingEntity;
|
||||||
|
import org.bukkit.event.Cancellable;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores details for damage events where the damager is a block
|
||||||
|
*/
|
||||||
|
public class EntityDamagedByBlockEvent extends EntityEvent implements Cancellable {
|
||||||
|
|
||||||
|
private Block damager;
|
||||||
|
private int damage;
|
||||||
|
private boolean cancelled;
|
||||||
|
|
||||||
|
public EntityDamagedByBlockEvent(Block damager, LivingEntity damagee, int damage)
|
||||||
|
{
|
||||||
|
super(Event.Type.ENTITY_DAMAGEDBY_BLOCK, damagee);
|
||||||
|
this.damager = damager;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the cancellation state of this event. A cancelled event will not
|
||||||
|
* be executed in the server, but will still pass to other plugins
|
||||||
|
*
|
||||||
|
* If a damage event is cancelled, the damage will not be deducted from the player's health.
|
||||||
|
* This will not fire an event.
|
||||||
|
*
|
||||||
|
* @return true if this event is cancelled
|
||||||
|
*/
|
||||||
|
public boolean isCancelled() {
|
||||||
|
return cancelled;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the cancellation state of this event. A cancelled event will not
|
||||||
|
* be executed in the server, but will still pass to other plugins
|
||||||
|
*
|
||||||
|
* If a damage event is cancelled, the damage will not be deducted from the player's health.
|
||||||
|
* This will not fire an event.
|
||||||
|
*
|
||||||
|
* @param cancel true if you wish to cancel this event
|
||||||
|
*/
|
||||||
|
public void setCancelled(boolean cancel) {
|
||||||
|
cancelled = cancel;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the block that damaged the player.
|
||||||
|
* @return Block that damaged the player
|
||||||
|
*/
|
||||||
|
public Block getDamager()
|
||||||
|
{
|
||||||
|
return damager;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the amount of damage caused by the Block
|
||||||
|
* @return The amount of damage caused by the Block
|
||||||
|
*/
|
||||||
|
public int getDamage()
|
||||||
|
{
|
||||||
|
return damage;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,67 @@
|
||||||
|
package org.bukkit.event.entity;
|
||||||
|
|
||||||
|
import org.bukkit.Block;
|
||||||
|
import org.bukkit.Entity;
|
||||||
|
import org.bukkit.LivingEntity;
|
||||||
|
import org.bukkit.event.Cancellable;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores details for damage events where the damager is another entity
|
||||||
|
*/
|
||||||
|
public class EntityDamagedByEntityEvent extends EntityEvent implements Cancellable {
|
||||||
|
|
||||||
|
private LivingEntity damager;
|
||||||
|
private int damage;
|
||||||
|
private boolean cancelled;
|
||||||
|
|
||||||
|
public EntityDamagedByEntityEvent(LivingEntity damager, LivingEntity damagee, int damage)
|
||||||
|
{
|
||||||
|
super(Event.Type.ENTITY_DAMAGEDBY_ENTITY, damagee);
|
||||||
|
this.damager = damager;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the cancellation state of this event. A cancelled event will not
|
||||||
|
* be executed in the server, but will still pass to other plugins
|
||||||
|
*
|
||||||
|
* If a damage event is cancelled, the damage will not be deducted from the player's health.
|
||||||
|
* This will not fire an event.
|
||||||
|
*
|
||||||
|
* @return true if this event is cancelled
|
||||||
|
*/
|
||||||
|
public boolean isCancelled() {
|
||||||
|
return cancelled;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the cancellation state of this event. A cancelled event will not
|
||||||
|
* be executed in the server, but will still pass to other plugins
|
||||||
|
*
|
||||||
|
* If a damage event is cancelled, the damage will not be deducted from the player's health.
|
||||||
|
* This will not fire an event.
|
||||||
|
*
|
||||||
|
* @param cancel true if you wish to cancel this event
|
||||||
|
*/
|
||||||
|
public void setCancelled(boolean cancel) {
|
||||||
|
cancelled = cancel;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the entity that damaged the player.
|
||||||
|
* @return LivingEntity that damaged the player
|
||||||
|
*/
|
||||||
|
public LivingEntity getDamager()
|
||||||
|
{
|
||||||
|
return damager;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the amount of damage caused by the Block
|
||||||
|
* @return The amount of damage caused by the Block
|
||||||
|
*/
|
||||||
|
public int getDamage()
|
||||||
|
{
|
||||||
|
return damage;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
package org.bukkit.event.entity;
|
||||||
|
|
||||||
|
import org.bukkit.LivingEntity;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents an LivingEntity-related event
|
||||||
|
*/
|
||||||
|
public class EntityEvent extends Event {
|
||||||
|
protected LivingEntity entity;
|
||||||
|
|
||||||
|
public EntityEvent(final Event.Type type, final LivingEntity what)
|
||||||
|
{
|
||||||
|
super(type);
|
||||||
|
entity = what;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the LivingEntity involved in this event
|
||||||
|
* @return LivingEntity who is involved in this event
|
||||||
|
*/
|
||||||
|
public final LivingEntity getEntity()
|
||||||
|
{
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
package org.bukkit.event.entity;
|
||||||
|
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles all events fired in relation to entities
|
||||||
|
*/
|
||||||
|
public class EntityListener implements Listener {
|
||||||
|
public EntityListener() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onEntityDamagedByBlock(EntityDamagedByBlockEvent event) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onEntityDamagedByEntity(EntityDamagedByEntityEvent event) {
|
||||||
|
}
|
||||||
|
}
|
|
@ -16,6 +16,9 @@ import org.bukkit.event.CustomEventListener;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.block.*;
|
import org.bukkit.event.block.*;
|
||||||
|
import org.bukkit.event.entity.EntityDamagedByBlockEvent;
|
||||||
|
import org.bukkit.event.entity.EntityDamagedByEntityEvent;
|
||||||
|
import org.bukkit.event.entity.EntityListener;
|
||||||
import org.bukkit.event.player.*;
|
import org.bukkit.event.player.*;
|
||||||
import org.bukkit.event.server.PluginEvent;
|
import org.bukkit.event.server.PluginEvent;
|
||||||
import org.bukkit.event.server.ServerListener;
|
import org.bukkit.event.server.ServerListener;
|
||||||
|
@ -133,6 +136,20 @@ public final class JavaPluginLoader implements PluginLoader {
|
||||||
trueListener.onPluginDisabled((PluginEvent)event);
|
trueListener.onPluginDisabled((PluginEvent)event);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
} else if(listener instanceof EntityListener) {
|
||||||
|
EntityListener trueListener = (EntityListener) listener;
|
||||||
|
switch(event.getType())
|
||||||
|
{
|
||||||
|
case ENTITY_DAMAGEDBY_BLOCK:
|
||||||
|
trueListener.onEntityDamagedByBlock((EntityDamagedByBlockEvent)event);
|
||||||
|
break;
|
||||||
|
case ENTITY_DAMAGEDBY_ENTITY:
|
||||||
|
trueListener.onEntityDamagedByEntity((EntityDamagedByEntityEvent)event);
|
||||||
|
break;
|
||||||
|
case ENTITY_DEATH:
|
||||||
|
// TODO: ENTITY_DEATH hook
|
||||||
|
break;
|
||||||
|
}
|
||||||
} else if (listener instanceof VehicleListener) {
|
} else if (listener instanceof VehicleListener) {
|
||||||
VehicleListener trueListener = (VehicleListener)listener;
|
VehicleListener trueListener = (VehicleListener)listener;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue