}
private void player(Player player, String[] args) {
// Give to player
if (args.length == 2) {
Item item = makeItem(args[1], 1);
if (item == null) {
player.notice(Translator.translateAndFormat("give invalid itemtype", args[1]));
return;
}
player.giveItem(item);
player.message(Colors.YELLOW + Translator.translate("give success"));
}
// Give to player or other
else if (args.length == 3) {
if (args[2].matches("\\d+")) {
Item item = makeItem(args[1], Integer.parseInt(args[2]));
if (item == null) {
player.notice(Translator.translateAndFormat("give invalid itemtype", args[1]));
return;
}
player.giveItem(item);
player.message(Colors.YELLOW + Translator.translate("give success"));
}
else {
if (!player.hasPermission("canary.command.give.other")) {
player.notice(Translator.translate("give failed"));
return;
}
Player target = Canary.getServer().matchPlayer(args[2]);
if (target == null) {
player.notice(Translator.translateAndFormat("unknown player", args[2]));
return;
}
Item item = makeItem(args[1], 1);
if (item == null) { // NULL CHECK!
player.notice(Translator.translateAndFormat("give invalid itemtype", args[1]));
return;
}
target.giveItem(item);
target.message(Colors.YELLOW + Translator.translateAndFormat("give received", item.getType().getDisplayName()));
player.notice(Translator.translateAndFormat("give success other", target.getName()));
}
}
// Give to other
else if (args.length == 4) {
if (!player.hasPermission("canary.command.give.other")) {
player.notice(Translator.translate("give failed"));
return;
}
int amount = 1;
if (args[2].matches("\\d+")) {
amount = Integer.parseInt(args[2]);
}
Item item = makeItem(args[1], amount);
if (item == null) {
player.notice(Translator.translateAndFormat("give invalid itemtype", args[1]));
return;
}
Player target = Canary.getServer().matchPlayer(args[3]);
if (target == null) {
player.notice(Translator.translateAndFormat("unknown player", args[3]));
return;
}
target.giveItem(item);
target.message(Colors.YELLOW + Translator.translateAndFormat("give received", item.getType().getDisplayName()));
player.notice(Translator.translateAndFormat("give success other", target.getName()));
}
}