From 23354ce04991a0601d3fc211ed8ea0901cb13aaf Mon Sep 17 00:00:00 2001 From: NuclearW Date: Sat, 28 Jan 2012 02:00:18 -0500 Subject: [PATCH] New custom event McMMOPlayerLevelUpEvent --- .../events/McMMOPlayerLevelUpEvent.java | 55 +++++++++++++++++++ .../java/com/gmail/nossr50/skills/Skills.java | 5 ++ 2 files changed, 60 insertions(+) create mode 100644 src/main/java/com/gmail/nossr50/events/McMMOPlayerLevelUpEvent.java diff --git a/src/main/java/com/gmail/nossr50/events/McMMOPlayerLevelUpEvent.java b/src/main/java/com/gmail/nossr50/events/McMMOPlayerLevelUpEvent.java new file mode 100644 index 000000000..222780a17 --- /dev/null +++ b/src/main/java/com/gmail/nossr50/events/McMMOPlayerLevelUpEvent.java @@ -0,0 +1,55 @@ +package com.gmail.nossr50.events; + +import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +import com.gmail.nossr50.datatypes.SkillType; + +/** + * Called when a user levels up in a skill + */ +@SuppressWarnings("serial") +public class McMMOPlayerLevelUpEvent extends Event { + private Player player; + private SkillType skill; + private int levelsGained; + + public McMMOPlayerLevelUpEvent(Player player, SkillType skill) { + this.player = player; + this.skill = skill; + this.levelsGained = 1; // Always 1 for now as we call in the loop where the levelups are calculated, could change later! + } + + /** + * @return Player leveling up + */ + public Player getPlayer() { + return player; + } + + /** + * @return SkillType that is being leveled up + */ + public SkillType getSkill() { + return skill; + } + + /** + * @return The number of levels gained in this event + */ + public int getLevelsGained() { + return levelsGained; + } + + /** Rest of file is required boilerplate for custom events **/ + private static final HandlerList handers = new HandlerList(); + + public HandlerList getHandlers() { + return handers; + } + + public static HandlerList getHandlerList() { + return handers; + } +} diff --git a/src/main/java/com/gmail/nossr50/skills/Skills.java b/src/main/java/com/gmail/nossr50/skills/Skills.java index b8dd5db30..6f0bc2755 100644 --- a/src/main/java/com/gmail/nossr50/skills/Skills.java +++ b/src/main/java/com/gmail/nossr50/skills/Skills.java @@ -18,6 +18,7 @@ package com.gmail.nossr50.skills; import java.util.logging.Logger; +import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; @@ -35,6 +36,7 @@ import com.gmail.nossr50.spout.SpoutStuff; import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.PlayerStat; import com.gmail.nossr50.datatypes.SkillType; +import com.gmail.nossr50.events.McMMOPlayerLevelUpEvent; import com.gmail.nossr50.locale.mcLocale; @@ -326,6 +328,9 @@ public class Skills skillups++; PP.removeXP(skillType, PP.getXpToLevel(skillType)); PP.skillUp(skillType, 1); + + McMMOPlayerLevelUpEvent eventToFire = new McMMOPlayerLevelUpEvent(player, skillType); + Bukkit.getPluginManager().callEvent(eventToFire); } if(!LoadProperties.useMySQL)