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
|
|
|
{
|
2013-03-19 23:17:34 +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"));
|
|
|
|
}
|
|
|
|
}
|
2013-03-19 23:17:34 +00:00
|
|
|
|
|
|
|
private void feedOtherPlayers(final Server server, final CommandSender sender, final String name) throws NotEnoughArgumentsException
|
2011-12-03 20:51:57 +00:00
|
|
|
{
|
2013-03-19 23:17:34 +00:00
|
|
|
boolean foundUser = false;
|
|
|
|
final List<Player> matchedPlayers = server.matchPlayer(name);
|
|
|
|
for (Player matchPlayer : matchedPlayers)
|
2011-12-03 20:51:57 +00:00
|
|
|
{
|
2013-03-19 23:24:06 +00:00
|
|
|
final User player = ess.getUser(matchPlayer);
|
|
|
|
if (player.isHidden())
|
2011-12-03 20:51:57 +00:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2013-03-19 23:17:34 +00:00
|
|
|
foundUser = true;
|
|
|
|
matchPlayer.setFoodLevel(20);
|
|
|
|
matchPlayer.setSaturation(10);
|
|
|
|
sender.sendMessage(_("feedOther", matchPlayer.getDisplayName()));
|
|
|
|
}
|
|
|
|
if (!foundUser)
|
|
|
|
{
|
|
|
|
throw new NotEnoughArgumentsException(_("playerNotFound"));
|
2011-12-03 00:00:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|