TF-EssentialsX/Essentials/src/com/earth2me/essentials/commands/Commandgod.java

70 lines
1.6 KiB
Java
Raw Normal View History

package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.User;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
public class Commandgod extends EssentialsToggleCommand
{
public Commandgod()
{
super("god", "essentials.god.others");
}
@Override
2011-11-18 12:06:59 +00:00
protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
{
toggleOtherPlayers(server, sender, args);
}
@Override
2011-11-18 12:06:59 +00:00
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
{
if (args.length == 1)
{
Boolean toggle = matchToggleArgument(args[0]);
if (toggle == null && user.isAuthorized(othersPermission))
{
2013-07-07 12:02:40 +00:00
toggleOtherPlayers(server, user.getBase(), args);
}
else
{
2013-07-07 12:02:40 +00:00
togglePlayer(user.getBase(), user, toggle);
}
}
else if (args.length == 2 && user.isAuthorized(othersPermission))
{
2013-07-07 12:02:40 +00:00
toggleOtherPlayers(server, user.getBase(), args);
}
else
{
2013-07-07 12:02:40 +00:00
togglePlayer(user.getBase(), user, null);
}
}
@Override
void togglePlayer(CommandSender sender, User user, Boolean enabled)
{
if (enabled == null)
{
enabled = !user.isGodModeEnabled();
}
user.setGodModeEnabled(enabled);
2012-06-10 18:20:24 +00:00
if (enabled && user.getHealth() != 0)
{
user.setHealth(user.getMaxHealth());
user.setFoodLevel(20);
}
user.sendMessage(_("godMode", enabled ? _("enabled") : _("disabled")));
2013-07-09 08:08:26 +00:00
if (!sender.equals(user.getBase()))
{
sender.sendMessage(_("godMode", _(enabled ? "godEnabledFor" : "godDisabledFor", user.getDisplayName())));
}
}
}