Make /god and /god <player> behave the same.

This commit is contained in:
KHobbits 2013-02-09 19:31:31 +00:00
parent f17485b112
commit d522a4230f

View File

@ -33,10 +33,20 @@ public class Commandgod extends EssentialsCommand
godOtherPlayers(server, user, args); godOtherPlayers(server, user, args);
return; return;
} }
user.setGodModeEnabled(!user.isGodModeEnabled()); godPlayer(user, !user.isGodModeEnabled());
user.sendMessage(_("godMode", (user.isGodModeEnabled() ? _("enabled") : _("disabled")))); user.sendMessage(_("godMode", (user.isGodModeEnabled() ? _("enabled") : _("disabled"))));
} }
private void godPlayer(User player, boolean enabled)
{
player.setGodModeEnabled(enabled);
if (enabled)
{
player.setHealth(player.getMaxHealth());
player.setFoodLevel(20);
}
}
private void godOtherPlayers(final Server server, final CommandSender sender, final String[] args) private void godOtherPlayers(final Server server, final CommandSender sender, final String[] args)
{ {
for (Player matchPlayer : server.matchPlayer(args[0])) for (Player matchPlayer : server.matchPlayer(args[0]))
@ -47,29 +57,24 @@ public class Commandgod extends EssentialsCommand
continue; continue;
} }
boolean enabled;
if (args.length > 1) if (args.length > 1)
{ {
if (args[1].contains("on") || args[1].contains("ena") || args[1].equalsIgnoreCase("1")) if (args[1].contains("on") || args[1].contains("ena") || args[1].equalsIgnoreCase("1"))
{ {
player.setGodModeEnabled(true); enabled = true;
} }
else else
{ {
player.setGodModeEnabled(false); enabled = false;
} }
} }
else else
{ {
player.setGodModeEnabled(!player.isGodModeEnabled()); enabled = !player.isGodModeEnabled();
}
final boolean enabled = player.isGodModeEnabled();
if (enabled)
{
player.setHealth(player.getMaxHealth());
player.setFoodLevel(20);
} }
godPlayer(player, enabled);
player.sendMessage(_("godMode", (enabled ? _("enabled") : _("disabled")))); player.sendMessage(_("godMode", (enabled ? _("enabled") : _("disabled"))));
sender.sendMessage(_("godMode", _(enabled ? "godEnabledFor" : "godDisabledFor", matchPlayer.getDisplayName()))); sender.sendMessage(_("godMode", _(enabled ? "godEnabledFor" : "godDisabledFor", matchPlayer.getDisplayName())));
} }