2011-12-03 01:00:29 +01:00
|
|
|
package com.earth2me.essentials.commands;
|
|
|
|
|
2013-10-16 21:59:39 +02:00
|
|
|
import com.earth2me.essentials.CommandSource;
|
2011-12-03 21:51:57 +01:00
|
|
|
import static com.earth2me.essentials.I18n._;
|
2011-12-03 01:00:29 +01:00
|
|
|
import com.earth2me.essentials.User;
|
|
|
|
import org.bukkit.Server;
|
|
|
|
import org.bukkit.entity.Player;
|
2013-05-04 17:01:12 +02:00
|
|
|
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
2011-12-03 01:00:29 +01:00
|
|
|
|
|
|
|
|
2013-09-28 18:21:16 +02:00
|
|
|
public class Commandfeed extends EssentialsLoopCommand
|
2011-12-03 01:00:29 +01:00
|
|
|
{
|
|
|
|
public Commandfeed()
|
|
|
|
{
|
|
|
|
super("feed");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2011-12-03 21:51:57 +01:00
|
|
|
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
|
2011-12-03 01:00:29 +01:00
|
|
|
{
|
2013-08-18 22:05:45 +02:00
|
|
|
if (!user.isAuthorized("essentials.feed.cooldown.bypass"))
|
2011-12-03 01:00:29 +01:00
|
|
|
{
|
2013-05-05 08:05:43 +02:00
|
|
|
user.healCooldown();
|
2011-12-03 21:51:57 +01:00
|
|
|
}
|
2013-09-28 18:21:16 +02:00
|
|
|
|
|
|
|
if (args.length > 0 && user.isAuthorized("essentials.feed.others"))
|
2013-05-18 19:20:06 +02:00
|
|
|
{
|
2013-10-16 21:59:39 +02:00
|
|
|
loopOnlinePlayers(server, user.getSource(), true, args[0], null);
|
2013-09-28 18:21:16 +02:00
|
|
|
return;
|
2013-05-18 19:20:06 +02:00
|
|
|
}
|
2013-05-23 23:09:28 +02:00
|
|
|
|
2013-09-28 18:21:16 +02:00
|
|
|
feedPlayer(user.getBase());
|
2013-05-23 23:09:28 +02:00
|
|
|
user.sendMessage(_("feed"));
|
2011-12-03 21:51:57 +01:00
|
|
|
}
|
2013-03-20 00:17:34 +01:00
|
|
|
|
2013-05-04 17:01:12 +02:00
|
|
|
@Override
|
2013-10-16 21:59:39 +02:00
|
|
|
protected void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception
|
2013-05-04 17:01:12 +02:00
|
|
|
{
|
|
|
|
if (args.length < 1)
|
|
|
|
{
|
|
|
|
throw new NotEnoughArgumentsException();
|
|
|
|
}
|
|
|
|
|
2013-09-28 18:21:16 +02:00
|
|
|
loopOnlinePlayers(server, sender, true, args[0], null);
|
2013-05-04 17:01:12 +02:00
|
|
|
}
|
|
|
|
|
2013-09-28 18:21:16 +02:00
|
|
|
@Override
|
2013-10-16 21:59:39 +02:00
|
|
|
protected void updatePlayer(final Server server, final CommandSource sender, final User player, final String[] args) throws PlayerExemptException
|
2011-12-03 21:51:57 +01:00
|
|
|
{
|
2013-09-28 18:21:16 +02:00
|
|
|
try
|
2011-12-03 21:51:57 +01:00
|
|
|
{
|
2013-09-28 18:21:16 +02:00
|
|
|
feedPlayer(player.getBase());
|
|
|
|
sender.sendMessage(_("feedOther", player.getDisplayName()));
|
2013-03-20 00:17:34 +01:00
|
|
|
}
|
2013-09-28 18:21:16 +02:00
|
|
|
catch (QuietAbortException e)
|
2013-03-20 00:17:34 +01:00
|
|
|
{
|
2013-09-28 18:21:16 +02:00
|
|
|
//Handle Quietly
|
2011-12-03 01:00:29 +01:00
|
|
|
}
|
|
|
|
}
|
2013-05-04 17:01:12 +02:00
|
|
|
|
2013-09-28 18:21:16 +02:00
|
|
|
private void feedPlayer(final Player player) throws QuietAbortException
|
2013-05-04 17:01:12 +02:00
|
|
|
{
|
2013-05-26 23:00:35 +02:00
|
|
|
final int amount = 30;
|
2013-05-04 17:01:12 +02:00
|
|
|
|
|
|
|
final FoodLevelChangeEvent flce = new FoodLevelChangeEvent(player, amount);
|
|
|
|
ess.getServer().getPluginManager().callEvent(flce);
|
|
|
|
if (flce.isCancelled())
|
|
|
|
{
|
|
|
|
throw new QuietAbortException();
|
|
|
|
}
|
2013-05-23 23:09:28 +02:00
|
|
|
|
2013-05-18 19:20:06 +02:00
|
|
|
player.setFoodLevel(flce.getFoodLevel() > 20 ? 20 : flce.getFoodLevel());
|
2013-05-04 17:01:12 +02:00
|
|
|
player.setSaturation(10);
|
|
|
|
}
|
2011-12-03 01:00:29 +01:00
|
|
|
}
|