From 18a2b686c140276e1751fdd87fcb4f5021245873 Mon Sep 17 00:00:00 2001 From: GJ Date: Sat, 31 Mar 2012 22:20:35 -0400 Subject: [PATCH] Events cleanup. --- Changelog.txt | 1 + .../McMMOPlayerExperienceEvent.java | 14 ++- .../experience/McMMOPlayerLevelUpEvent.java | 26 ++-- .../experience/McMMOPlayerXpGainEvent.java | 29 +++-- .../events/fake/FakeBlockBreakEvent.java | 18 ++- .../fake/FakeEntityDamageByEntityEvent.java | 11 +- .../events/fake/FakeEntityDamageEvent.java | 8 +- .../events/fake/FakePlayerAnimationEvent.java | 6 +- .../events/items/McMMOItemSpawnEvent.java | 118 +++++++++--------- .../events/party/McMMOPartyChangeEvent.java | 49 ++++++-- .../events/party/McMMOPartyTeleportEvent.java | 10 +- .../skills/McMMOPlayerRepairCheckEvent.java | 13 +- .../events/skills/McMMOPlayerRepairEvent.java | 26 ---- .../events/skills/McMMOPlayerSkillEvent.java | 13 +- .../java/com/gmail/nossr50/skills/Repair.java | 5 - 15 files changed, 197 insertions(+), 150 deletions(-) delete mode 100644 src/main/java/com/gmail/nossr50/events/skills/McMMOPlayerRepairEvent.java diff --git a/Changelog.txt b/Changelog.txt index 0a0d616d8..d7f1c5ce9 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -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. diff --git a/src/main/java/com/gmail/nossr50/events/experience/McMMOPlayerExperienceEvent.java b/src/main/java/com/gmail/nossr50/events/experience/McMMOPlayerExperienceEvent.java index fd594277b..534c493d8 100644 --- a/src/main/java/com/gmail/nossr50/events/experience/McMMOPlayerExperienceEvent.java +++ b/src/main/java/com/gmail/nossr50/events/experience/McMMOPlayerExperienceEvent.java @@ -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,22 +19,28 @@ 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; } /** Rest of file is required boilerplate for custom events **/ private static final HandlerList handlers = new HandlerList(); - + @Override public HandlerList getHandlers() { return handlers; } - + public static HandlerList getHandlerList() { return handlers; } diff --git a/src/main/java/com/gmail/nossr50/events/experience/McMMOPlayerLevelUpEvent.java b/src/main/java/com/gmail/nossr50/events/experience/McMMOPlayerLevelUpEvent.java index 6c5dd19fc..fdbd2d8cf 100644 --- a/src/main/java/com/gmail/nossr50/events/experience/McMMOPlayerLevelUpEvent.java +++ b/src/main/java/com/gmail/nossr50/events/experience/McMMOPlayerLevelUpEvent.java @@ -8,17 +8,17 @@ import com.gmail.nossr50.datatypes.SkillType; * Called when a user levels up in a skill */ public class McMMOPlayerLevelUpEvent extends McMMOPlayerExperienceEvent { - private int levelsGained; - - public McMMOPlayerLevelUpEvent(Player player, SkillType 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! - } - - /** - * @return The number of levels gained in this event - */ - public int getLevelsGained() { - return levelsGained; - } + private int levelsGained; + + public McMMOPlayerLevelUpEvent(Player player, SkillType 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! + } + + /** + * @return The number of levels gained in this event + */ + public int getLevelsGained() { + return levelsGained; + } } diff --git a/src/main/java/com/gmail/nossr50/events/experience/McMMOPlayerXpGainEvent.java b/src/main/java/com/gmail/nossr50/events/experience/McMMOPlayerXpGainEvent.java index 5c4e4745b..4d3ef874a 100644 --- a/src/main/java/com/gmail/nossr50/events/experience/McMMOPlayerXpGainEvent.java +++ b/src/main/java/com/gmail/nossr50/events/experience/McMMOPlayerXpGainEvent.java @@ -4,18 +4,21 @@ 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; - - public McMMOPlayerXpGainEvent(Player player, SkillType skill, int xpGained) { - super(player, skill); - this.xpGained = xpGained; - } - - /** - * @return The number experience gained in this event - */ - public int getXpGained() { - return xpGained; - } + private int xpGained; + + public McMMOPlayerXpGainEvent(Player player, SkillType skill, int xpGained) { + super(player, skill); + this.xpGained = xpGained; + } + + /** + * @return The amount of experience gained in this event + */ + public int getXpGained() { + return xpGained; + } } diff --git a/src/main/java/com/gmail/nossr50/events/fake/FakeBlockBreakEvent.java b/src/main/java/com/gmail/nossr50/events/fake/FakeBlockBreakEvent.java index 48b07914b..cdccfb07e 100644 --- a/src/main/java/com/gmail/nossr50/events/fake/FakeBlockBreakEvent.java +++ b/src/main/java/com/gmail/nossr50/events/fake/FakeBlockBreakEvent.java @@ -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(theBlock.getDrops())); -// } -} \ No newline at end of file + public FakeBlockBreakEvent(Block theBlock, Player player) { + super(theBlock, player); + } +} diff --git a/src/main/java/com/gmail/nossr50/events/fake/FakeEntityDamageByEntityEvent.java b/src/main/java/com/gmail/nossr50/events/fake/FakeEntityDamageByEntityEvent.java index 1bd2f00ee..377436b5d 100644 --- a/src/main/java/com/gmail/nossr50/events/fake/FakeEntityDamageByEntityEvent.java +++ b/src/main/java/com/gmail/nossr50/events/fake/FakeEntityDamageByEntityEvent.java @@ -3,9 +3,12 @@ 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) { - super(damager, damagee, cause, damage); - } + + public FakeEntityDamageByEntityEvent(Entity damager, Entity damagee, DamageCause cause, int damage) { + super(damager, damagee, cause, damage); + } } diff --git a/src/main/java/com/gmail/nossr50/events/fake/FakeEntityDamageEvent.java b/src/main/java/com/gmail/nossr50/events/fake/FakeEntityDamageEvent.java index 1ac79be2d..df531adac 100644 --- a/src/main/java/com/gmail/nossr50/events/fake/FakeEntityDamageEvent.java +++ b/src/main/java/com/gmail/nossr50/events/fake/FakeEntityDamageEvent.java @@ -3,8 +3,12 @@ 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); } -} \ No newline at end of file +} diff --git a/src/main/java/com/gmail/nossr50/events/fake/FakePlayerAnimationEvent.java b/src/main/java/com/gmail/nossr50/events/fake/FakePlayerAnimationEvent.java index 96f13783f..1d884a7bc 100644 --- a/src/main/java/com/gmail/nossr50/events/fake/FakePlayerAnimationEvent.java +++ b/src/main/java/com/gmail/nossr50/events/fake/FakePlayerAnimationEvent.java @@ -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); } - } diff --git a/src/main/java/com/gmail/nossr50/events/items/McMMOItemSpawnEvent.java b/src/main/java/com/gmail/nossr50/events/items/McMMOItemSpawnEvent.java index b3ed0d40d..4da6a0740 100644 --- a/src/main/java/com/gmail/nossr50/events/items/McMMOItemSpawnEvent.java +++ b/src/main/java/com/gmail/nossr50/events/items/McMMOItemSpawnEvent.java @@ -7,66 +7,66 @@ 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; - private ItemStack itemStack; - private boolean cancelled; - - public McMMOItemSpawnEvent(Location location, ItemStack itemStack) { - this.location = location; - this.itemStack = itemStack; - this.cancelled = false; - } - - /** - * @return Location where the item will be dropped - */ - public Location getLocation() { - return location; - } - - /** - * @param location Location where to drop the item - */ - public void setLocation(Location location) { - this.location = location; - } - - /** - * @return ItemStack that will be dropped - */ - public ItemStack getItemStack() { - return itemStack; - } - - /** - * @param itemStack ItemStack to drop - */ - public void setItemStack(ItemStack itemStack) { - this.itemStack = itemStack; - } - - /** Following are required for Cancellable **/ - @Override - public boolean isCancelled() { - return cancelled; - } + private Location location; + private ItemStack itemStack; + private boolean cancelled; - @Override - public void setCancelled(boolean cancelled) { - this.cancelled = cancelled; - } - - /** Rest of file is required boilerplate for custom events **/ - private static final HandlerList handlers = new HandlerList(); - - public HandlerList getHandlers() { - return handlers; - } - - public static HandlerList getHandlerList() { - return handlers; - } + public McMMOItemSpawnEvent(Location location, ItemStack itemStack) { + this.location = location; + this.itemStack = itemStack; + this.cancelled = false; + } + + /** + * @return Location where the item will be dropped + */ + public Location getLocation() { + return location; + } + + /** + * @param location Location where to drop the item + */ + public void setLocation(Location location) { + this.location = location; + } + + /** + * @return ItemStack that will be dropped + */ + public ItemStack getItemStack() { + return itemStack; + } + + /** + * @param itemStack ItemStack to drop + */ + public void setItemStack(ItemStack itemStack) { + this.itemStack = itemStack; + } + + /** Following are required for Cancellable **/ + @Override + public boolean isCancelled() { + return cancelled; + } + + @Override + public void setCancelled(boolean cancelled) { + this.cancelled = cancelled; + } + + /** Rest of file is required boilerplate for custom events **/ + private static final HandlerList handlers = new HandlerList(); + + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } } diff --git a/src/main/java/com/gmail/nossr50/events/party/McMMOPartyChangeEvent.java b/src/main/java/com/gmail/nossr50/events/party/McMMOPartyChangeEvent.java index f3ff383e2..2248176ec 100644 --- a/src/main/java/com/gmail/nossr50/events/party/McMMOPartyChangeEvent.java +++ b/src/main/java/com/gmail/nossr50/events/party/McMMOPartyChangeEvent.java @@ -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; - } } diff --git a/src/main/java/com/gmail/nossr50/events/party/McMMOPartyTeleportEvent.java b/src/main/java/com/gmail/nossr50/events/party/McMMOPartyTeleportEvent.java index 9006609cf..35d647102 100644 --- a/src/main/java/com/gmail/nossr50/events/party/McMMOPartyTeleportEvent.java +++ b/src/main/java/com/gmail/nossr50/events/party/McMMOPartyTeleportEvent.java @@ -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; } diff --git a/src/main/java/com/gmail/nossr50/events/skills/McMMOPlayerRepairCheckEvent.java b/src/main/java/com/gmail/nossr50/events/skills/McMMOPlayerRepairCheckEvent.java index c6bf2cd56..d017c7c80 100644 --- a/src/main/java/com/gmail/nossr50/events/skills/McMMOPlayerRepairCheckEvent.java +++ b/src/main/java/com/gmail/nossr50/events/skills/McMMOPlayerRepairCheckEvent.java @@ -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; } diff --git a/src/main/java/com/gmail/nossr50/events/skills/McMMOPlayerRepairEvent.java b/src/main/java/com/gmail/nossr50/events/skills/McMMOPlayerRepairEvent.java deleted file mode 100644 index 6623dd407..000000000 --- a/src/main/java/com/gmail/nossr50/events/skills/McMMOPlayerRepairEvent.java +++ /dev/null @@ -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; - } -} diff --git a/src/main/java/com/gmail/nossr50/events/skills/McMMOPlayerSkillEvent.java b/src/main/java/com/gmail/nossr50/events/skills/McMMOPlayerSkillEvent.java index 0d09407ac..a844bd19f 100644 --- a/src/main/java/com/gmail/nossr50/events/skills/McMMOPlayerSkillEvent.java +++ b/src/main/java/com/gmail/nossr50/events/skills/McMMOPlayerSkillEvent.java @@ -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; } } - diff --git a/src/main/java/com/gmail/nossr50/skills/Repair.java b/src/main/java/com/gmail/nossr50/skills/Repair.java index 1f4e29fc4..95b117d46 100644 --- a/src/main/java/com/gmail/nossr50/skills/Repair.java +++ b/src/main/java/com/gmail/nossr50/skills/Repair.java @@ -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); } /**