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
! 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
- Removed McMMOPlayerRepairEvent - was basically a duplicate of McMMOPlayerRepairCheck but couldn't be cancelled.
Version 1.3.04
+ 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;
/**
* Generic event for mcMMO experience events.
*/
public class McMMOPlayerExperienceEvent extends PlayerEvent {
protected SkillType skill;
protected int skillLevel;
@ -17,10 +19,16 @@ public class McMMOPlayerExperienceEvent extends PlayerEvent {
this.skillLevel = skill.getSkillLevel(player);
}
/**
* @return The skill involved in this event
*/
public SkillType getSkill() {
return skill;
}
/**
* @return The skill level of the skill involved in this event
*/
public int getSkillLevel() {
return skillLevel;
}

View File

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

View File

@ -1,19 +1,15 @@
package com.gmail.nossr50.events.fake;
//import java.util.ArrayList;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
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 FakeBlockBreakEvent(Block theBlock, Player player) {
super(theBlock, player);
}
// public FakeBlockBreakEvent(Block theBlock, Player player) {
// super(theBlock, player, new ArrayList<ItemStack>(theBlock.getDrops()));
// }
}

View File

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

View File

@ -3,7 +3,11 @@ package com.gmail.nossr50.events.fake;
import org.bukkit.entity.Entity;
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) {
super(damagee, cause, damage);
}

View File

@ -3,10 +3,12 @@ package com.gmail.nossr50.events.fake;
import org.bukkit.entity.Player;
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) {
super(player);
}
}

View File

@ -7,7 +7,7 @@ import org.bukkit.event.HandlerList;
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 {
private Location location;

View File

@ -5,6 +5,9 @@ import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.bukkit.event.player.PlayerEvent;
/**
* Called when a player attempts to join, leave, or change parties.
*/
public class McMMOPartyChangeEvent extends PlayerEvent implements Cancellable{
protected String oldParty;
@ -25,18 +28,57 @@ public class McMMOPartyChangeEvent extends PlayerEvent implements Cancellable{
this.cancelled = false;
}
/**
* @return The party being left, or null if the player was not in a party
*/
public String getOldParty() {
return oldParty;
}
/**
* @return The party being joined, or null if the player is not joining a new party
*/
public String getNewParty() {
return newParty;
}
/**
* @return The reason for the event being fired
*/
public EventReason getReason() {
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 **/
private static final HandlerList handlers = new HandlerList();
@ -59,11 +101,4 @@ public class McMMOPartyChangeEvent extends PlayerEvent implements Cancellable{
public void setCancelled(boolean 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.player.PlayerTeleportEvent;
/**
* Called just before a player teleports using the /ptp command.
*/
public class McMMOPartyTeleportEvent extends PlayerTeleportEvent{
private String party;
private Player target;
@ -15,10 +17,16 @@ public class McMMOPartyTeleportEvent extends PlayerTeleportEvent{
this.target = target;
}
/**
* @return The party the teleporting player is in
*/
public String getParty() {
return party;
}
/**
* @return The player being teleported to
*/
public Player getTarget() {
return target;
}

View File

@ -6,8 +6,10 @@ import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.datatypes.SkillType;
/**
* Called just before a player repairs an object with mcMMO.
*/
public class McMMOPlayerRepairCheckEvent extends McMMOPlayerSkillEvent implements Cancellable{
private short repairAmount;
private ItemStack repairMaterial;
private ItemStack repairedObject;
@ -21,14 +23,23 @@ public class McMMOPlayerRepairCheckEvent extends McMMOPlayerSkillEvent implement
this.cancelled = false;
}
/**
* @return The amount this item will be repaired.
*/
public short getRepairAmount() {
return repairAmount;
}
/**
* @return The material used to repair this item
*/
public ItemStack getRepairMaterial() {
return repairMaterial;
}
/**
* @return The item that was repaired
*/
public ItemStack getRepairedObject() {
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;
public class McMMOPlayerSkillEvent extends PlayerEvent{
/**
* Generic event for mcMMO skill handling.
*/
public class McMMOPlayerSkillEvent extends PlayerEvent {
protected SkillType skill;
protected int skillLevel;
@ -17,10 +19,16 @@ public class McMMOPlayerSkillEvent extends PlayerEvent{
this.skillLevel = skill.getSkillLevel(player);
}
/**
* @return The skill involved in this event
*/
public SkillType getSkill() {
return skill;
}
/**
* @return The level of the skill involved in this event
*/
public int getSkillLevel() {
return skillLevel;
}
@ -37,4 +45,3 @@ public class McMMOPlayerSkillEvent extends PlayerEvent{
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.SkillType;
import com.gmail.nossr50.events.skills.McMMOPlayerRepairCheckEvent;
import com.gmail.nossr50.events.skills.McMMOPlayerRepairEvent;
import com.gmail.nossr50.locale.mcLocale;
public class Repair {
@ -448,10 +447,6 @@ public class Repair {
}
item.setDurability(newDurability);
/* Post-repair Event */
McMMOPlayerRepairEvent postEvent = new McMMOPlayerRepairEvent(player, item, (short) (initialDurability - newDurability));
Bukkit.getPluginManager().callEvent(postEvent);
}
/**