Added new PlayerExpChangeEvent and PlayerLevelChangeEvent events. Thanks to feildmaster for the PR.

By: Nathan Adams <dinnerbone@dinnerbone.com>
This commit is contained in:
Bukkit/Spigot 2012-01-19 16:07:03 +00:00
parent ef6edf9ee2
commit 1a86a7e3f7
5 changed files with 135 additions and 3 deletions

View file

@ -363,6 +363,18 @@ public abstract class Event implements Serializable {
* @see org.bukkit.event.player.PlayerChangedWorldEvent
*/
PLAYER_CHANGED_WORLD(Category.PLAYER, PlayerChangedWorldEvent.class),
/**
* Called when a players level changes
*
* @see org.bukkit.event.player.PlayerLevelChangeEvent
*/
PLAYER_LEVEL_CHANGE(Category.PLAYER, PlayerLevelChangeEvent.class),
/**
* Called when a players experience changes naturally
*
* @see org.bukkit.event.player.PlayerExpChangeEvent
*/
PLAYER_EXP_CHANGE(Category.PLAYER, PlayerExpChangeEvent.class),
/**
* BLOCK EVENTS

View file

@ -0,0 +1,43 @@
package org.bukkit.event.player;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
/**
* Called when a players experience changes naturally
*/
public class PlayerExpChangeEvent extends PlayerEvent {
private static final HandlerList handlers = new HandlerList();
private int exp;
public PlayerExpChangeEvent(Player player, int expAmount) {
super(Type.PLAYER_EXP_CHANGE, player);
exp = expAmount;
}
/**
* Get the amount of experience the player will receive
*
* @return The amount of experience
*/
public int getAmount() {
return exp;
}
/**
* Set the amount of experience the player will receive
*
* @param amount The amount of experience to set
*/
public void setAmount(int amount) {
exp = amount;
}
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}

View file

@ -0,0 +1,45 @@
package org.bukkit.event.player;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
/**
* Called when a players level changes
*/
public class PlayerLevelChangeEvent extends PlayerEvent {
private static final HandlerList handlers = new HandlerList();
private int oldLevel;
private int newLevel;
public PlayerLevelChangeEvent(Player player, int oldLevel, int newLevel) {
super(Type.PLAYER_LEVEL_CHANGE, player);
this.oldLevel = oldLevel;
this.newLevel = newLevel;
}
/**
* Gets the old level of the player
*
* @return The old level of the player
*/
public int getOldLevel() {
return oldLevel;
}
/**
* Gets the new level of the player
*
* @return The new (current) level of the player
*/
public int getNewLevel() {
return newLevel;
}
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}

View file

@ -213,4 +213,18 @@ public class PlayerListener implements Listener {
* @param event Relevant event details
*/
public void onPlayerChangedWorld(PlayerChangedWorldEvent event) {}
/**
* Called when a players level changes
*
* @param event Relevant event details
*/
public void onPlayerLevelChange(PlayerLevelChangeEvent event) {}
/**
* Called when a players experience changes naturally
*
* @param event Relevant event details
*/
public void onPlayerExpChange(PlayerExpChangeEvent event) {}
}

View file

@ -18,9 +18,6 @@ import org.bukkit.Server;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.bukkit.configuration.serialization.ConfigurationSerialization;
import org.bukkit.event.CustomEventListener;
import org.bukkit.event.Event;
import org.bukkit.event.Listener;
import org.bukkit.event.*;
import org.bukkit.event.block.*;
import org.bukkit.event.painting.*;
@ -381,6 +378,13 @@ public class JavaPluginLoader implements PluginLoader {
}
};
case PLAYER_LEVEL_CHANGE:
return new EventExecutor() {
public void execute(Listener listener, Event event) {
((PlayerListener) listener).onPlayerLevelChange((PlayerLevelChangeEvent) event);
}
};
case INVENTORY_OPEN:
return new EventExecutor() {
public void execute(Listener listener, Event event) {
@ -472,6 +476,13 @@ public class JavaPluginLoader implements PluginLoader {
}
};
case PLAYER_EXP_CHANGE:
return new EventExecutor() {
public void execute(Listener listener, Event event) {
((PlayerListener) listener).onPlayerExpChange((PlayerExpChangeEvent) event);
}
};
// Block Events
case BLOCK_PHYSICS:
return new EventExecutor() {
@ -819,6 +830,13 @@ public class JavaPluginLoader implements PluginLoader {
}
};
case ENTITY_SHOOT_BOW:
return new EventExecutor() {
public void execute(Listener listener, Event event) {
((EntityListener) listener).onEntityShootBow((EntityShootBowEvent) event);
}
};
case PROJECTILE_HIT:
return new EventExecutor() {
public void execute(Listener listener, Event event) {