2013-04-05 04:11:11 +02:00
|
|
|
package com.gmail.nossr50.commands;
|
|
|
|
|
2019-01-15 07:11:58 +01:00
|
|
|
import com.gmail.nossr50.datatypes.MobHealthbarType;
|
|
|
|
import com.gmail.nossr50.locale.LocaleLoader;
|
|
|
|
import com.gmail.nossr50.util.commands.CommandUtils;
|
|
|
|
import com.gmail.nossr50.util.player.UserManager;
|
|
|
|
import com.google.common.collect.ImmutableList;
|
2013-04-05 04:11:11 +02:00
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandSender;
|
2013-03-28 17:57:49 +01:00
|
|
|
import org.bukkit.command.TabExecutor;
|
2013-05-28 19:33:20 +02:00
|
|
|
import org.bukkit.entity.Player;
|
2013-03-28 17:57:49 +01:00
|
|
|
import org.bukkit.util.StringUtil;
|
2013-04-05 04:11:11 +02:00
|
|
|
|
2019-01-15 07:11:58 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.List;
|
2013-03-28 17:57:49 +01:00
|
|
|
|
|
|
|
public class MobhealthCommand implements TabExecutor {
|
|
|
|
private static final List<String> MOB_HEALTHBAR_TYPES;
|
|
|
|
|
|
|
|
static {
|
|
|
|
ArrayList<String> types = new ArrayList<String>();
|
|
|
|
|
|
|
|
for (MobHealthbarType type : MobHealthbarType.values()) {
|
|
|
|
types.add(type.toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
Collections.sort(types);
|
|
|
|
MOB_HEALTHBAR_TYPES = ImmutableList.copyOf(types);
|
|
|
|
}
|
2013-04-05 04:11:11 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
|
|
|
if (CommandUtils.noConsoleUsage(sender)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-08-20 06:23:19 +02:00
|
|
|
if (!CommandUtils.hasPlayerDataKey(sender)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-04-05 04:11:11 +02:00
|
|
|
switch (args.length) {
|
|
|
|
case 1:
|
|
|
|
try {
|
|
|
|
MobHealthbarType type = MobHealthbarType.valueOf(args[0].toUpperCase().trim());
|
2013-10-29 16:02:57 +01:00
|
|
|
UserManager.getPlayer((Player) sender).getProfile().setMobHealthbarType(type);
|
2013-10-09 06:12:04 +02:00
|
|
|
sender.sendMessage(LocaleLoader.getString("Commands.Healthbars.Changed." + type.name()));
|
2013-04-05 04:11:11 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
catch (IllegalArgumentException ex) {
|
2013-10-09 06:12:04 +02:00
|
|
|
sender.sendMessage(LocaleLoader.getString("Commands.Healthbars.Invalid"));
|
2013-04-05 04:11:11 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2013-03-28 17:57:49 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
|
|
|
|
switch (args.length) {
|
|
|
|
case 1:
|
|
|
|
return StringUtil.copyPartialMatches(args[0], MOB_HEALTHBAR_TYPES, new ArrayList<String>(MOB_HEALTHBAR_TYPES.size()));
|
|
|
|
default:
|
|
|
|
return ImmutableList.of();
|
|
|
|
}
|
|
|
|
}
|
2013-04-05 04:11:11 +02:00
|
|
|
}
|