Allow syntax: /god <player> <on/off>

This commit is contained in:
KHobbits 2012-06-10 19:20:24 +01:00
parent c958bc78dd
commit 23283426e0
6 changed files with 36 additions and 32 deletions

View File

@ -114,7 +114,7 @@ public class EssentialsPlayerListener implements Listener
final User user = ess.getUser(event.getPlayer()); final User user = ess.getUser(event.getPlayer());
if (ess.getSettings().removeGodOnDisconnect() && user.isGodModeEnabled()) if (ess.getSettings().removeGodOnDisconnect() && user.isGodModeEnabled())
{ {
user.toggleGodModeEnabled(); user.setGodModeEnabled(false);
} }
ess.getVanishedPlayers().remove(user.getName()); ess.getVanishedPlayers().remove(user.getName());
user.setLastLocation(); user.setLastLocation();

View File

@ -561,16 +561,6 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
return afkPosition; return afkPosition;
} }
@Override
public boolean toggleGodModeEnabled()
{
if (!isGodModeEnabled())
{
setFoodLevel(20);
}
return super.toggleGodModeEnabled();
}
@Override @Override
public boolean isGodModeEnabled() public boolean isGodModeEnabled()
{ {

View File

@ -494,12 +494,6 @@ public abstract class UserData extends PlayerExtension implements IConf
config.save(); config.save();
} }
public boolean toggleGodModeEnabled()
{
boolean ret = !isGodModeEnabled();
setGodModeEnabled(ret);
return ret;
}
private boolean muted; private boolean muted;
private boolean getMuted() private boolean getMuted()

View File

@ -2,8 +2,6 @@ package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._; import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.User; import com.earth2me.essentials.User;
import java.util.Locale;
import org.bukkit.GameMode;
import org.bukkit.Server; import org.bukkit.Server;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -57,7 +55,7 @@ public class Commandfly extends EssentialsCommand
{ {
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.setAllowFlight(!player.getAllowFlight()); player.setAllowFlight(true);
} }
else else
{ {

View File

@ -22,7 +22,7 @@ public class Commandgod extends EssentialsCommand
throw new NotEnoughArgumentsException(); throw new NotEnoughArgumentsException();
} }
godOtherPlayers(server, sender, args[0]); godOtherPlayers(server, sender, args);
} }
@Override @Override
@ -30,23 +30,45 @@ public class Commandgod extends EssentialsCommand
{ {
if (args.length > 0 && args[0].trim().length() > 2 && user.isAuthorized("essentials.god.others")) if (args.length > 0 && args[0].trim().length() > 2 && user.isAuthorized("essentials.god.others"))
{ {
godOtherPlayers(server, user, args[0]); godOtherPlayers(server, user, args);
return; return;
} }
user.setGodModeEnabled(!user.isGodModeEnabled());
user.sendMessage(_("godMode", (user.toggleGodModeEnabled() ? _("enabled") : _("disabled")))); user.sendMessage(_("godMode", (user.isGodModeEnabled() ? _("enabled") : _("disabled"))));
} }
private void godOtherPlayers(final Server server, final CommandSender sender, final String name) private void godOtherPlayers(final Server server, final CommandSender sender, final String[] args)
{ {
for (Player matchPlayer : server.matchPlayer(name)) for (Player matchPlayer : server.matchPlayer(args[0]))
{ {
final User player = ess.getUser(matchPlayer); final User player = ess.getUser(matchPlayer);
if (player.isHidden()) if (player.isHidden())
{ {
continue; continue;
} }
final boolean enabled = player.toggleGodModeEnabled();
if (args.length > 1)
{
if (args[1].contains("on") || args[1].contains("ena") || args[1].equalsIgnoreCase("1"))
{
player.setGodModeEnabled(true);
}
else
{
player.setGodModeEnabled(false);
}
}
else
{
player.setGodModeEnabled(!player.isGodModeEnabled());
}
final boolean enabled = player.isGodModeEnabled();
if (enabled)
{
player.setFoodLevel(20);
}
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())));
} }

View File

@ -105,7 +105,7 @@ commands:
aliases: [efeed,eat,eeat] aliases: [efeed,eat,eeat]
fly: fly:
description: Take off, and soar! description: Take off, and soar!
usage: /<command> [player] usage: /<command> [player] [on|off]
aliases: [efly] aliases: [efly]
itemdb: itemdb:
description: Searches for an item. description: Searches for an item.
@ -133,7 +133,7 @@ commands:
aliases: [egive] aliases: [egive]
god: god:
description: Enables your godly powers. description: Enables your godly powers.
usage: /<command> [player] usage: /<command> [player] [on|off]
aliases: [tgm,godmode,egod,etgm,egodmode] aliases: [tgm,godmode,egod,etgm,egodmode]
hat: hat:
description: Get some cool new headgear description: Get some cool new headgear