import net.minecraft.util.text.Style; //导入方法依赖的package包/类
@Override
public String execute(String commandName, CommandSender sender, String[] params) throws CommandException {
boolean global = commandName.endsWith("global");
if (params.length > (global ? 0 : 1)) {
String type = global ? null : params[0];
if (!global) params = Arrays.copyOfRange(params, 1, params.length);
Style style = new Style();
if (params[0].equalsIgnoreCase("reset")) style = null;
else {
for (String formatting : params) {
String[] split = formatting.split(":");
if (split.length != 2) throw new CommandException("command.chatstyle.invalidArg", sender, formatting);
if (formatting.startsWith("color")) {
TextFormatting color = TextFormatting.getValueByName(split[1]);
if (color == null || !color.isColor()) throw new CommandException("command.chatstyle.noColor", sender, split[1]);
style.setColor(color);
}
else if (split[0].equalsIgnoreCase("bold")) style.setBold(split[1].equalsIgnoreCase("true") || split[1].equals("1"));
else if (split[0].equalsIgnoreCase("italic")) style.setItalic(split[1].equalsIgnoreCase("true") || split[1].equals("1"));
else if (split[0].equalsIgnoreCase("underlined")) style.setUnderlined(split[1].equalsIgnoreCase("true") || split[1].equals("1"));
else if (split[0].equalsIgnoreCase("strikethrough")) style.setStrikethrough(split[1].equalsIgnoreCase("true") || split[1].equals("1"));
else if (split[0].equalsIgnoreCase("obfuscated")) style.setObfuscated(split[1].equalsIgnoreCase("true") || split[1].equals("1"));
else throw new CommandException("command.chatstyle.invalidArg", sender, formatting);
}
}
if (global) ReflectionHelper.set(ObfuscatedField.Style_defaultStyle, null, style);
else {
ServerPlayerSettings settings = getPlayerSettings(getSenderAsEntity(sender.getMinecraftISender(), EntityPlayerMP.class));
if (type.equals("name")) settings.nameStyle = style;
else if (type.equals("text")) settings.textStyle = style;
else if (type.equals("both")) settings.nameStyle = settings.textStyle = style;
}
}
return null;
}