2011-12-03 00:00:29 +00:00
|
|
|
package com.earth2me.essentials.commands;
|
|
|
|
|
2011-12-03 20:51:57 +00:00
|
|
|
import static com.earth2me.essentials.I18n._;
|
2011-12-03 00:00:29 +00:00
|
|
|
import com.earth2me.essentials.User;
|
2011-12-03 20:51:57 +00:00
|
|
|
import java.util.List;
|
2011-12-03 00:00:29 +00:00
|
|
|
import org.bukkit.Server;
|
2011-12-03 20:51:57 +00:00
|
|
|
import org.bukkit.command.CommandSender;
|
2011-12-03 00:00:29 +00:00
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
|
|
|
|
|
|
|
public class Commandfeed extends EssentialsCommand
|
|
|
|
{
|
|
|
|
public Commandfeed()
|
|
|
|
{
|
|
|
|
super("feed");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2011-12-03 20:51:57 +00:00
|
|
|
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
|
2011-12-03 00:00:29 +00:00
|
|
|
{
|
2011-12-03 20:51:57 +00:00
|
|
|
if (args.length > 0 && user.isAuthorized("essentials.feed.others"))
|
2011-12-03 00:00:29 +00:00
|
|
|
{
|
2011-12-03 20:51:57 +00:00
|
|
|
feedOtherPlayers(server,user,args[0]);
|
2011-12-03 00:00:29 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
user.setFoodLevel(20);
|
2011-12-03 20:51:57 +00:00
|
|
|
user.setSaturation(10);
|
|
|
|
user.sendMessage(_("feed"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void feedOtherPlayers(final Server server, final CommandSender sender, final String name)
|
|
|
|
{
|
|
|
|
final List<Player> players = server.matchPlayer(name);
|
|
|
|
if (players.isEmpty())
|
|
|
|
{
|
|
|
|
sender.sendMessage(_("playerNotFound"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (Player player : players)
|
|
|
|
{
|
|
|
|
if (ess.getUser(player).isHidden())
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
player.setFoodLevel(20);
|
|
|
|
player.setSaturation(10);
|
|
|
|
sender.sendMessage(_("feedOther", player.getDisplayName()));
|
2011-12-03 00:00:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|