diff options
author | Iaccidentally <coryhuckaby@gmail.com> | 2013-10-10 20:26:39 -0400 |
---|---|---|
committer | KHobbits <rob@khobbits.co.uk> | 2013-10-11 03:14:51 +0100 |
commit | 375caa6f9e5c871770cae3a35e1efb8e60bbdc40 (patch) | |
tree | c482aa473753b66e8f497cc47eee10aabf999239 | |
parent | cc34c0262339ebac2a4a58fb1cf8501c8f0c619f (diff) | |
download | Essentials-375caa6f9e5c871770cae3a35e1efb8e60bbdc40.tar Essentials-375caa6f9e5c871770cae3a35e1efb8e60bbdc40.tar.gz Essentials-375caa6f9e5c871770cae3a35e1efb8e60bbdc40.tar.lz Essentials-375caa6f9e5c871770cae3a35e1efb8e60bbdc40.tar.xz Essentials-375caa6f9e5c871770cae3a35e1efb8e60bbdc40.zip |
implement GodStatusChangeEvent
3 files changed, 24 insertions, 18 deletions
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandgod.java b/Essentials/src/com/earth2me/essentials/commands/Commandgod.java index 1c5352319..8b3dcfe4e 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandgod.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandgod.java @@ -2,8 +2,10 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; +import net.ess3.api.events.GodStatusChangeEvent; import org.bukkit.Server; import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; public class Commandgod extends EssentialsToggleCommand @@ -35,7 +37,7 @@ public class Commandgod extends EssentialsToggleCommand } } else if (args.length == 2 && user.isAuthorized(othersPermission)) - { + { toggleOtherPlayers(server, user.getBase(), args); } else @@ -47,23 +49,29 @@ public class Commandgod extends EssentialsToggleCommand @Override void togglePlayer(CommandSender sender, User user, Boolean enabled) { - if (enabled == null) + final User controller = sender instanceof Player ? ess.getUser(sender) : null; + final GodStatusChangeEvent godEvent = new GodStatusChangeEvent(controller, user, enabled); + ess.getServer().getPluginManager().callEvent(godEvent); + if (!godEvent.isCancelled()) { - enabled = !user.isGodModeEnabled(); - } - - user.setGodModeEnabled(enabled); + if (enabled == null) + { + enabled = !user.isGodModeEnabled(); + } - if (enabled && user.getHealth() != 0) - { - user.setHealth(user.getMaxHealth()); - user.setFoodLevel(20); - } + user.setGodModeEnabled(enabled); - user.sendMessage(_("godMode", enabled ? _("enabled") : _("disabled"))); - if (!sender.equals(user.getBase())) - { - sender.sendMessage(_("godMode", _(enabled ? "godEnabledFor" : "godDisabledFor", user.getDisplayName()))); + if (enabled && user.getHealth() != 0) + { + user.setHealth(user.getMaxHealth()); + user.setFoodLevel(20); + } + + user.sendMessage(_("godMode", enabled ? _("enabled") : _("disabled"))); + if (!sender.equals(user.getBase())) + { + sender.sendMessage(_("godMode", _(enabled ? "godEnabledFor" : "godDisabledFor", user.getDisplayName()))); + } } } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandnick.java b/Essentials/src/com/earth2me/essentials/commands/Commandnick.java index eb5f60ecc..2bdaddc88 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandnick.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandnick.java @@ -4,7 +4,6 @@ import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; import com.earth2me.essentials.utils.FormatUtil; import java.util.Locale; -import net.ess3.api.events.LocalChatSpyEvent; import net.ess3.api.events.NickChangeEvent; import org.bukkit.Server; import org.bukkit.command.CommandSender; @@ -115,7 +114,7 @@ public class Commandnick extends EssentialsLoopCommand || lowerNick.equals(onlinePlayer.getName().toLowerCase(Locale.ENGLISH))) { return true; - } + } } if (ess.getUser(lowerNick) != null && ess.getUser(lowerNick) != target) { return true; diff --git a/Essentials/src/com/earth2me/essentials/commands/EssentialsToggleCommand.java b/Essentials/src/com/earth2me/essentials/commands/EssentialsToggleCommand.java index 6bec3afa6..8bc4cb91e 100644 --- a/Essentials/src/com/earth2me/essentials/commands/EssentialsToggleCommand.java +++ b/Essentials/src/com/earth2me/essentials/commands/EssentialsToggleCommand.java @@ -1,6 +1,5 @@ package com.earth2me.essentials.commands; -import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; import java.util.List; import org.bukkit.Server; |