[Bleeding] Fix Achievement and Statistic API. Fixes BUKKIT-5305

By: t00thpick1 <t00thpick1dirko@gmail.com>
This commit is contained in:
Bukkit/Spigot
2014-01-14 23:16:04 -05:00
parent bac44d80a6
commit 5c0ae695bc
5 changed files with 533 additions and 67 deletions

View File

@@ -0,0 +1,46 @@
package org.bukkit.event.player;
import org.bukkit.Achievement;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
/**
* Called when a player earns an achievement.
*/
public class PlayerAchievementAwardedEvent extends PlayerEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private final Achievement achievement;
private boolean isCancelled = false;
public PlayerAchievementAwardedEvent(Player player, Achievement achievement) {
super(player);
this.achievement = achievement;
}
/**
* Gets the Achievement being awarded.
*
* @return the achievement being awarded
*/
public Achievement getAchievement() {
return achievement;
}
public boolean isCancelled() {
return isCancelled;
}
public void setCancelled(boolean cancel) {
this.isCancelled = cancel;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}

View File

@@ -0,0 +1,116 @@
package org.bukkit.event.player;
import org.bukkit.Material;
import org.bukkit.Statistic;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
/**
* Called when a player statistic is incremented.
* <p>
* This event is not called for {@link org.bukkit.Statistic#PLAY_ONE_MINUTE}
* or movement based statistics.
*
*/
public class PlayerStatisticIncrementEvent extends PlayerEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
protected final Statistic statistic;
private final int initialValue;
private final int newValue;
private boolean isCancelled = false;
private final EntityType entityType;
private final Material material;
public PlayerStatisticIncrementEvent(Player player, Statistic statistic, int initialValue, int newValue) {
super (player);
this.statistic = statistic;
this.initialValue = initialValue;
this.newValue = newValue;
this.entityType = null;
this.material = null;
}
public PlayerStatisticIncrementEvent(Player player, Statistic statistic, int initialValue, int newValue, EntityType entityType) {
super (player);
this.statistic = statistic;
this.initialValue = initialValue;
this.newValue = newValue;
this.entityType = entityType;
this.material = null;
}
public PlayerStatisticIncrementEvent(Player player, Statistic statistic, int initialValue, int newValue, Material material) {
super (player);
this.statistic = statistic;
this.initialValue = initialValue;
this.newValue = newValue;
this.entityType = null;
this.material = material;
}
/**
* Gets the statistic that is being incremented.
*
* @return the incremented statistic
*/
public Statistic getStatistic() {
return statistic;
}
/**
* Gets the previous value of the statistic.
*
* @return the previous value of the statistic
*/
public int getPreviousValue() {
return initialValue;
}
/**
* Gets the new value of the statistic.
*
* @return the new value of the statistic
*/
public int getNewValue() {
return newValue;
}
/**
* Gets the EntityType if {@link #getStatistic() getStatistic()} is an
* entity statistic otherwise returns null.
*
* @return the EntityType of the statistic
*/
public EntityType getEntityType() {
return entityType;
}
/**
* Gets the Material if {@link #getStatistic() getStatistic()} is a block
* or item statistic otherwise returns null.
*
* @return the Material of the statistic
*/
public Material getMaterial() {
return material;
}
public boolean isCancelled() {
return isCancelled;
}
public void setCancelled(boolean cancel) {
this.isCancelled = cancel;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}