From a2f80569e30fdd181a811b1c17d4b221b49bda00 Mon Sep 17 00:00:00 2001 From: GJ Date: Tue, 21 May 2013 09:31:25 -0400 Subject: [PATCH] Fire McMMOPlayerLevelUp events for our experience commands, when applicable. Fixes #921 --- .../nossr50/commands/experience/AddlevelsCommand.java | 6 ++++++ .../gmail/nossr50/commands/experience/MmoeditCommand.java | 6 ++++++ .../nossr50/commands/experience/SkillresetCommand.java | 8 ++++++-- .../events/experience/McMMOPlayerLevelUpEvent.java | 2 +- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/commands/experience/AddlevelsCommand.java b/src/main/java/com/gmail/nossr50/commands/experience/AddlevelsCommand.java index bab887488..e60857303 100644 --- a/src/main/java/com/gmail/nossr50/commands/experience/AddlevelsCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/experience/AddlevelsCommand.java @@ -2,7 +2,9 @@ package com.gmail.nossr50.commands.experience; import org.bukkit.command.CommandSender; +import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.datatypes.skills.SkillType; +import com.gmail.nossr50.events.experience.McMMOPlayerLevelUpEvent; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.skills.SkillUtils; @@ -21,6 +23,10 @@ public class AddlevelsCommand extends ExperienceCommand { @Override protected void handleCommand(SkillType skill) { profile.addLevels(skill, value); + + if (player != null) { + mcMMO.p.getServer().getPluginManager().callEvent(new McMMOPlayerLevelUpEvent(player, skill, value)); + } } @Override diff --git a/src/main/java/com/gmail/nossr50/commands/experience/MmoeditCommand.java b/src/main/java/com/gmail/nossr50/commands/experience/MmoeditCommand.java index 832475316..929c11143 100644 --- a/src/main/java/com/gmail/nossr50/commands/experience/MmoeditCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/experience/MmoeditCommand.java @@ -2,7 +2,9 @@ package com.gmail.nossr50.commands.experience; import org.bukkit.command.CommandSender; +import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.datatypes.skills.SkillType; +import com.gmail.nossr50.events.experience.McMMOPlayerLevelUpEvent; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.skills.SkillUtils; @@ -21,6 +23,10 @@ public class MmoeditCommand extends ExperienceCommand { @Override protected void handleCommand(SkillType skill) { profile.modifySkill(skill, value); + + if (player != null) { + mcMMO.p.getServer().getPluginManager().callEvent(new McMMOPlayerLevelUpEvent(player, skill, value - profile.getSkillLevel(skill))); + } } @Override diff --git a/src/main/java/com/gmail/nossr50/commands/experience/SkillresetCommand.java b/src/main/java/com/gmail/nossr50/commands/experience/SkillresetCommand.java index f3a3a5cfb..a4414b930 100644 --- a/src/main/java/com/gmail/nossr50/commands/experience/SkillresetCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/experience/SkillresetCommand.java @@ -3,8 +3,10 @@ package com.gmail.nossr50.commands.experience; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; +import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.datatypes.player.PlayerProfile; import com.gmail.nossr50.datatypes.skills.SkillType; +import com.gmail.nossr50.events.experience.McMMOPlayerLevelUpEvent; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.commands.CommandUtils; @@ -84,13 +86,11 @@ public class SkillresetCommand extends ExperienceCommand { @Override protected boolean permissionsCheckSelf(CommandSender sender) { - // TODO Auto-generated method stub return false; } @Override protected boolean permissionsCheckOthers(CommandSender sender) { - // TODO Auto-generated method stub return false; } @@ -102,6 +102,10 @@ public class SkillresetCommand extends ExperienceCommand { } profile.modifySkill(skill, 0); + + if (player != null) { + mcMMO.p.getServer().getPluginManager().callEvent(new McMMOPlayerLevelUpEvent(player, skill, 0 - profile.getSkillLevel(skill))); + } } @Override 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 39c0bac48..b1286dc09 100644 --- a/src/main/java/com/gmail/nossr50/events/experience/McMMOPlayerLevelUpEvent.java +++ b/src/main/java/com/gmail/nossr50/events/experience/McMMOPlayerLevelUpEvent.java @@ -17,7 +17,7 @@ public class McMMOPlayerLevelUpEvent extends McMMOPlayerExperienceEvent { public McMMOPlayerLevelUpEvent(Player player, SkillType skill, int levelsGained) { super(player, skill); - this.setLevelsGained(levelsGained); + this.levelsGained = levelsGained; } /**