Events cleanup.

This commit is contained in:
GJ 2012-03-31 22:20:35 -04:00
parent a2f23bd056
commit 18a2b686c1
15 changed files with 197 additions and 150 deletions

View File

@ -18,6 +18,7 @@ Version 1.3.05-dev
= Fixed bug where API functions were set to static = Fixed bug where API functions were set to static
! Changed Tree Feller to account for ability durability loss but not leaves. ! Changed Tree Feller to account for ability durability loss but not leaves.
! Changed bypass node for Arcane Forging to not default to true for OPs ! Changed bypass node for Arcane Forging to not default to true for OPs
- Removed McMMOPlayerRepairEvent - was basically a duplicate of McMMOPlayerRepairCheck but couldn't be cancelled.
Version 1.3.04 Version 1.3.04
+ Added McMMOPlayerRepairEvent for API usage - fires after completion of a repair. + Added McMMOPlayerRepairEvent for API usage - fires after completion of a repair.

View File

@ -6,8 +6,10 @@ import org.bukkit.event.player.PlayerEvent;
import com.gmail.nossr50.datatypes.SkillType; import com.gmail.nossr50.datatypes.SkillType;
/**
* Generic event for mcMMO experience events.
*/
public class McMMOPlayerExperienceEvent extends PlayerEvent { public class McMMOPlayerExperienceEvent extends PlayerEvent {
protected SkillType skill; protected SkillType skill;
protected int skillLevel; protected int skillLevel;
@ -17,10 +19,16 @@ public class McMMOPlayerExperienceEvent extends PlayerEvent {
this.skillLevel = skill.getSkillLevel(player); this.skillLevel = skill.getSkillLevel(player);
} }
/**
* @return The skill involved in this event
*/
public SkillType getSkill() { public SkillType getSkill() {
return skill; return skill;
} }
/**
* @return The skill level of the skill involved in this event
*/
public int getSkillLevel() { public int getSkillLevel() {
return skillLevel; return skillLevel;
} }

View File

@ -8,17 +8,17 @@ import com.gmail.nossr50.datatypes.SkillType;
* Called when a user levels up in a skill * Called when a user levels up in a skill
*/ */
public class McMMOPlayerLevelUpEvent extends McMMOPlayerExperienceEvent { public class McMMOPlayerLevelUpEvent extends McMMOPlayerExperienceEvent {
private int levelsGained; private int levelsGained;
public McMMOPlayerLevelUpEvent(Player player, SkillType skill) { public McMMOPlayerLevelUpEvent(Player player, SkillType skill) {
super(player, skill); super(player, skill);
this.levelsGained = 1; // Always 1 for now as we call in the loop where the levelups are calculated, could change later! this.levelsGained = 1; // Always 1 for now as we call in the loop where the levelups are calculated, could change later!
} }
/** /**
* @return The number of levels gained in this event * @return The number of levels gained in this event
*/ */
public int getLevelsGained() { public int getLevelsGained() {
return levelsGained; return levelsGained;
} }
} }

View File

@ -4,18 +4,21 @@ import org.bukkit.entity.Player;
import com.gmail.nossr50.datatypes.SkillType; import com.gmail.nossr50.datatypes.SkillType;
/**
* Called when a player gains XP in a skill
*/
public class McMMOPlayerXpGainEvent extends McMMOPlayerExperienceEvent { public class McMMOPlayerXpGainEvent extends McMMOPlayerExperienceEvent {
private int xpGained; private int xpGained;
public McMMOPlayerXpGainEvent(Player player, SkillType skill, int xpGained) { public McMMOPlayerXpGainEvent(Player player, SkillType skill, int xpGained) {
super(player, skill); super(player, skill);
this.xpGained = xpGained; this.xpGained = xpGained;
} }
/** /**
* @return The number experience gained in this event * @return The amount of experience gained in this event
*/ */
public int getXpGained() { public int getXpGained() {
return xpGained; return xpGained;
} }
} }

View File

@ -1,19 +1,15 @@
package com.gmail.nossr50.events.fake; package com.gmail.nossr50.events.fake;
//import java.util.ArrayList;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockBreakEvent;
//import org.bukkit.inventory.ItemStack;
/**
* Called when mcMMO breaks a block due to a special ability.
*/
public class FakeBlockBreakEvent extends BlockBreakEvent { public class FakeBlockBreakEvent extends BlockBreakEvent {
public FakeBlockBreakEvent(Block theBlock, Player player) { public FakeBlockBreakEvent(Block theBlock, Player player) {
super(theBlock, player); super(theBlock, player);
} }
// public FakeBlockBreakEvent(Block theBlock, Player player) {
// super(theBlock, player, new ArrayList<ItemStack>(theBlock.getDrops()));
// }
} }

View File

@ -3,9 +3,12 @@ package com.gmail.nossr50.events.fake;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;
/**
* Called when mcMMO applies damage from an entity due to special abilities.
*/
public class FakeEntityDamageByEntityEvent extends EntityDamageByEntityEvent { public class FakeEntityDamageByEntityEvent extends EntityDamageByEntityEvent {
public FakeEntityDamageByEntityEvent(Entity damager, Entity damagee, DamageCause cause, int damage) { public FakeEntityDamageByEntityEvent(Entity damager, Entity damagee, DamageCause cause, int damage) {
super(damager, damagee, cause, damage); super(damager, damagee, cause, damage);
} }
} }

View File

@ -3,7 +3,11 @@ package com.gmail.nossr50.events.fake;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent;
public class FakeEntityDamageEvent extends EntityDamageEvent{ /**
* Called when mcMMO applies damage due to special abilities.
*/
public class FakeEntityDamageEvent extends EntityDamageEvent {
public FakeEntityDamageEvent(Entity damagee, DamageCause cause, int damage) { public FakeEntityDamageEvent(Entity damagee, DamageCause cause, int damage) {
super(damagee, cause, damage); super(damagee, cause, damage);
} }

View File

@ -3,10 +3,12 @@ package com.gmail.nossr50.events.fake;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerAnimationEvent; import org.bukkit.event.player.PlayerAnimationEvent;
public class FakePlayerAnimationEvent extends PlayerAnimationEvent{ /**
* Called when handling extra drops to avoid issues with NoCheat.
*/
public class FakePlayerAnimationEvent extends PlayerAnimationEvent {
public FakePlayerAnimationEvent(Player player) { public FakePlayerAnimationEvent(Player player) {
super(player); super(player);
} }
} }

View File

@ -7,66 +7,66 @@ import org.bukkit.event.HandlerList;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
/** /**
* Called when mcMMO is preparing to drop an item * Called when mcMMO is preparing to drop an item.
*/ */
public class McMMOItemSpawnEvent extends Event implements Cancellable { public class McMMOItemSpawnEvent extends Event implements Cancellable {
private Location location; private Location location;
private ItemStack itemStack; private ItemStack itemStack;
private boolean cancelled; private boolean cancelled;
public McMMOItemSpawnEvent(Location location, ItemStack itemStack) { public McMMOItemSpawnEvent(Location location, ItemStack itemStack) {
this.location = location; this.location = location;
this.itemStack = itemStack; this.itemStack = itemStack;
this.cancelled = false; this.cancelled = false;
} }
/** /**
* @return Location where the item will be dropped * @return Location where the item will be dropped
*/ */
public Location getLocation() { public Location getLocation() {
return location; return location;
} }
/** /**
* @param location Location where to drop the item * @param location Location where to drop the item
*/ */
public void setLocation(Location location) { public void setLocation(Location location) {
this.location = location; this.location = location;
} }
/** /**
* @return ItemStack that will be dropped * @return ItemStack that will be dropped
*/ */
public ItemStack getItemStack() { public ItemStack getItemStack() {
return itemStack; return itemStack;
} }
/** /**
* @param itemStack ItemStack to drop * @param itemStack ItemStack to drop
*/ */
public void setItemStack(ItemStack itemStack) { public void setItemStack(ItemStack itemStack) {
this.itemStack = itemStack; this.itemStack = itemStack;
} }
/** Following are required for Cancellable **/ /** Following are required for Cancellable **/
@Override @Override
public boolean isCancelled() { public boolean isCancelled() {
return cancelled; return cancelled;
} }
@Override @Override
public void setCancelled(boolean cancelled) { public void setCancelled(boolean cancelled) {
this.cancelled = cancelled; this.cancelled = cancelled;
} }
/** Rest of file is required boilerplate for custom events **/ /** Rest of file is required boilerplate for custom events **/
private static final HandlerList handlers = new HandlerList(); private static final HandlerList handlers = new HandlerList();
public HandlerList getHandlers() { public HandlerList getHandlers() {
return handlers; return handlers;
} }
public static HandlerList getHandlerList() { public static HandlerList getHandlerList() {
return handlers; return handlers;
} }
} }

View File

@ -5,6 +5,9 @@ import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
import org.bukkit.event.player.PlayerEvent; import org.bukkit.event.player.PlayerEvent;
/**
* Called when a player attempts to join, leave, or change parties.
*/
public class McMMOPartyChangeEvent extends PlayerEvent implements Cancellable{ public class McMMOPartyChangeEvent extends PlayerEvent implements Cancellable{
protected String oldParty; protected String oldParty;
@ -25,18 +28,57 @@ public class McMMOPartyChangeEvent extends PlayerEvent implements Cancellable{
this.cancelled = false; this.cancelled = false;
} }
/**
* @return The party being left, or null if the player was not in a party
*/
public String getOldParty() { public String getOldParty() {
return oldParty; return oldParty;
} }
/**
* @return The party being joined, or null if the player is not joining a new party
*/
public String getNewParty() { public String getNewParty() {
return newParty; return newParty;
} }
/**
* @return The reason for the event being fired
*/
public EventReason getReason() { public EventReason getReason() {
return reason; return reason;
} }
/**
* A list of reasons why the event may have been fired
*/
public enum EventReason{
/**
* Joined a party for the first time.
*/
JOINED_PARTY,
/**
* Left a party and did not join a new one.
*/
LEFT_PARTY,
/**
* Was kicked from a party.
*/
KICKED_FROM_PARTY,
/**
* Left one party to join another.
*/
CHANGED_PARTIES,
/**
* Any reason that doesn't fit elsewhere.
*/
CUSTOM;
}
/** Rest of file is required boilerplate for custom events **/ /** Rest of file is required boilerplate for custom events **/
private static final HandlerList handlers = new HandlerList(); private static final HandlerList handlers = new HandlerList();
@ -59,11 +101,4 @@ public class McMMOPartyChangeEvent extends PlayerEvent implements Cancellable{
public void setCancelled(boolean cancelled) { public void setCancelled(boolean cancelled) {
this.cancelled = cancelled; this.cancelled = cancelled;
} }
public enum EventReason{
JOINED_PARTY,
LEFT_PARTY,
KICKED_FROM_PARTY,
CHANGED_PARTIES;
}
} }

View File

@ -4,8 +4,10 @@ import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.event.player.PlayerTeleportEvent;
/**
* Called just before a player teleports using the /ptp command.
*/
public class McMMOPartyTeleportEvent extends PlayerTeleportEvent{ public class McMMOPartyTeleportEvent extends PlayerTeleportEvent{
private String party; private String party;
private Player target; private Player target;
@ -15,10 +17,16 @@ public class McMMOPartyTeleportEvent extends PlayerTeleportEvent{
this.target = target; this.target = target;
} }
/**
* @return The party the teleporting player is in
*/
public String getParty() { public String getParty() {
return party; return party;
} }
/**
* @return The player being teleported to
*/
public Player getTarget() { public Player getTarget() {
return target; return target;
} }

View File

@ -6,8 +6,10 @@ import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.datatypes.SkillType; import com.gmail.nossr50.datatypes.SkillType;
/**
* Called just before a player repairs an object with mcMMO.
*/
public class McMMOPlayerRepairCheckEvent extends McMMOPlayerSkillEvent implements Cancellable{ public class McMMOPlayerRepairCheckEvent extends McMMOPlayerSkillEvent implements Cancellable{
private short repairAmount; private short repairAmount;
private ItemStack repairMaterial; private ItemStack repairMaterial;
private ItemStack repairedObject; private ItemStack repairedObject;
@ -21,14 +23,23 @@ public class McMMOPlayerRepairCheckEvent extends McMMOPlayerSkillEvent implement
this.cancelled = false; this.cancelled = false;
} }
/**
* @return The amount this item will be repaired.
*/
public short getRepairAmount() { public short getRepairAmount() {
return repairAmount; return repairAmount;
} }
/**
* @return The material used to repair this item
*/
public ItemStack getRepairMaterial() { public ItemStack getRepairMaterial() {
return repairMaterial; return repairMaterial;
} }
/**
* @return The item that was repaired
*/
public ItemStack getRepairedObject() { public ItemStack getRepairedObject() {
return repairedObject; return repairedObject;
} }

View File

@ -1,26 +0,0 @@
package com.gmail.nossr50.events.skills;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.datatypes.SkillType;
public class McMMOPlayerRepairEvent extends McMMOPlayerSkillEvent{
private ItemStack repairedObject;
private short repairAmount;
public McMMOPlayerRepairEvent(Player player, ItemStack repairedObject, short repairAmount) {
super(player, SkillType.REPAIR);
this.repairedObject = repairedObject;
this.repairAmount = repairAmount;
}
public ItemStack getRepairedObject() {
return repairedObject;
}
public short getRepairAmount() {
return repairAmount;
}
}

View File

@ -6,8 +6,10 @@ import org.bukkit.event.player.PlayerEvent;
import com.gmail.nossr50.datatypes.SkillType; import com.gmail.nossr50.datatypes.SkillType;
public class McMMOPlayerSkillEvent extends PlayerEvent{ /**
* Generic event for mcMMO skill handling.
*/
public class McMMOPlayerSkillEvent extends PlayerEvent {
protected SkillType skill; protected SkillType skill;
protected int skillLevel; protected int skillLevel;
@ -17,10 +19,16 @@ public class McMMOPlayerSkillEvent extends PlayerEvent{
this.skillLevel = skill.getSkillLevel(player); this.skillLevel = skill.getSkillLevel(player);
} }
/**
* @return The skill involved in this event
*/
public SkillType getSkill() { public SkillType getSkill() {
return skill; return skill;
} }
/**
* @return The level of the skill involved in this event
*/
public int getSkillLevel() { public int getSkillLevel() {
return skillLevel; return skillLevel;
} }
@ -37,4 +45,3 @@ public class McMMOPlayerSkillEvent extends PlayerEvent{
return handlers; return handlers;
} }
} }

View File

@ -23,7 +23,6 @@ import com.gmail.nossr50.spout.SpoutSounds;
import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.SkillType; import com.gmail.nossr50.datatypes.SkillType;
import com.gmail.nossr50.events.skills.McMMOPlayerRepairCheckEvent; import com.gmail.nossr50.events.skills.McMMOPlayerRepairCheckEvent;
import com.gmail.nossr50.events.skills.McMMOPlayerRepairEvent;
import com.gmail.nossr50.locale.mcLocale; import com.gmail.nossr50.locale.mcLocale;
public class Repair { public class Repair {
@ -448,10 +447,6 @@ public class Repair {
} }
item.setDurability(newDurability); item.setDurability(newDurability);
/* Post-repair Event */
McMMOPlayerRepairEvent postEvent = new McMMOPlayerRepairEvent(player, item, (short) (initialDurability - newDurability));
Bukkit.getPluginManager().callEvent(postEvent);
} }
/** /**