001 package org.bukkit.event.player; 002 003 import org.bukkit.Material; 004 import org.bukkit.Statistic; 005 import org.bukkit.entity.EntityType; 006 import org.bukkit.entity.Player; 007 import org.bukkit.event.Cancellable; 008 import org.bukkit.event.HandlerList; 009 010 /** 011 * Called when a player statistic is incremented. 012 * <p> 013 * This event is not called for {@link org.bukkit.Statistic#PLAY_ONE_TICK} or 014 * movement based statistics. 015 * 016 */ 017 public class PlayerStatisticIncrementEvent extends PlayerEvent implements Cancellable { 018 private static final HandlerList handlers = new HandlerList(); 019 protected final Statistic statistic; 020 private final int initialValue; 021 private final int newValue; 022 private boolean isCancelled = false; 023 private final EntityType entityType; 024 private final Material material; 025 026 public PlayerStatisticIncrementEvent(Player player, Statistic statistic, int initialValue, int newValue) { 027 super (player); 028 this.statistic = statistic; 029 this.initialValue = initialValue; 030 this.newValue = newValue; 031 this.entityType = null; 032 this.material = null; 033 } 034 035 public PlayerStatisticIncrementEvent(Player player, Statistic statistic, int initialValue, int newValue, EntityType entityType) { 036 super (player); 037 this.statistic = statistic; 038 this.initialValue = initialValue; 039 this.newValue = newValue; 040 this.entityType = entityType; 041 this.material = null; 042 } 043 044 public PlayerStatisticIncrementEvent(Player player, Statistic statistic, int initialValue, int newValue, Material material) { 045 super (player); 046 this.statistic = statistic; 047 this.initialValue = initialValue; 048 this.newValue = newValue; 049 this.entityType = null; 050 this.material = material; 051 } 052 053 /** 054 * Gets the statistic that is being incremented. 055 * 056 * @return the incremented statistic 057 */ 058 public Statistic getStatistic() { 059 return statistic; 060 } 061 062 /** 063 * Gets the previous value of the statistic. 064 * 065 * @return the previous value of the statistic 066 */ 067 public int getPreviousValue() { 068 return initialValue; 069 } 070 071 /** 072 * Gets the new value of the statistic. 073 * 074 * @return the new value of the statistic 075 */ 076 public int getNewValue() { 077 return newValue; 078 } 079 080 /** 081 * Gets the EntityType if {@link #getStatistic() getStatistic()} is an 082 * entity statistic otherwise returns null. 083 * 084 * @return the EntityType of the statistic 085 */ 086 public EntityType getEntityType() { 087 return entityType; 088 } 089 090 /** 091 * Gets the Material if {@link #getStatistic() getStatistic()} is a block 092 * or item statistic otherwise returns null. 093 * 094 * @return the Material of the statistic 095 */ 096 public Material getMaterial() { 097 return material; 098 } 099 100 public boolean isCancelled() { 101 return isCancelled; 102 } 103 104 public void setCancelled(boolean cancel) { 105 this.isCancelled = cancel; 106 } 107 108 @Override 109 public HandlerList getHandlers() { 110 return handlers; 111 } 112 113 public static HandlerList getHandlerList() { 114 return handlers; 115 } 116 }