Skip to content

Commit

Permalink
Feature: implemented /uh feedall.
Browse files Browse the repository at this point in the history
Closes #48.
  • Loading branch information
AmauryCarrade committed Nov 27, 2014
1 parent 8094f2e commit 7c371f8
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/main/java/me/azenet/UHPlugin/UHPluginCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,47 @@ private void doFeed(CommandSender sender, Command command, String label, String[
target.setSaturation(saturation);
}

/**
* This command feeds all player.
* <p>
* Usage: /uh feed &lt;player> [foodLevel=20] [saturation=20]
*
* @param sender
* @param command
* @param label
* @param args
*/
@SuppressWarnings("unused")
private void doFeedall(CommandSender sender, Command command, String label, String[] args) {

int foodLevel = 20;
float saturation = 20f;

if(args.length > 1) { // /uh feedall <foodLevel>
try {
foodLevel = Integer.valueOf(args[1]);
} catch(NumberFormatException e) {
sender.sendMessage(i.t("feed.errorNaN"));
return;
}

if(args.length > 2) { // /uh feedall <foodLevel> <saturation>
try {
// The saturation value cannot be more than the food level.
saturation = Math.min(foodLevel, Float.valueOf(args[2]));
} catch(NumberFormatException e) {
sender.sendMessage(i.t("feed.errorNaN"));
return;
}
}
}

for(Player player : p.getServer().getOnlinePlayers()) {
player.setFoodLevel(foodLevel);
player.setSaturation(saturation);
}
}


/**
* This command resurrects a player.
Expand Down

0 comments on commit 7c371f8

Please sign in to comment.