Mson.toPlain now has boolea styled parameter. Txt.getItemName.

This commit is contained in:
Olof Larsson 2015-09-01 12:09:45 +02:00
parent e0548bbc60
commit 6a6752fdb6
3 changed files with 41 additions and 13 deletions

View File

@ -102,7 +102,7 @@ public class MessageMixinDefault extends MessageMixinAbstract
{ {
for (Mson mson : msons) for (Mson mson : msons)
{ {
sender.sendMessage(mson.toPlain()); sender.sendMessage(mson.toPlain(true));
} }
} }

View File

@ -861,39 +861,47 @@ public class Mson implements Serializable
return raw; return raw;
} }
public String toPlain() public String toPlain(boolean styled)
{ {
StringBuilder ret = new StringBuilder(); StringBuilder ret = new StringBuilder();
this.toPlain0(ret); this.toPlain0(ret, styled);
return ret.toString(); return ret.toString();
} }
private void toPlain0(StringBuilder builder) private void toPlain0(StringBuilder builder, boolean styled)
{ {
if ( ! this.getText().isEmpty()) if ( ! this.getText().isEmpty())
{ {
// Color must be put in BEFORE formatting. // Color must be put in BEFORE formatting.
// http://minecraft.gamepedia.com/Formatting_codes#Formatting_codes // http://minecraft.gamepedia.com/Formatting_codes#Formatting_codes
if (styled)
{
if (this.getEffectiveColor() != null) builder.append(this.getEffectiveColor()); if (this.getEffectiveColor() != null) builder.append(this.getEffectiveColor());
if (this.isEffectiveBold()) builder.append(ChatColor.BOLD); if (this.isEffectiveBold()) builder.append(ChatColor.BOLD);
if (this.isEffectiveItalic()) builder.append(ChatColor.ITALIC); if (this.isEffectiveItalic()) builder.append(ChatColor.ITALIC);
if (this.isEffectiveUnderlined()) builder.append(ChatColor.UNDERLINE); if (this.isEffectiveUnderlined()) builder.append(ChatColor.UNDERLINE);
if (this.isEffectiveStrikethrough()) builder.append(ChatColor.STRIKETHROUGH); if (this.isEffectiveStrikethrough()) builder.append(ChatColor.STRIKETHROUGH);
if (this.isEffectiveObfuscated()) builder.append(ChatColor.MAGIC); if (this.isEffectiveObfuscated()) builder.append(ChatColor.MAGIC);
}
builder.append(this.getText()); builder.append(this.getText());
} }
if (this.hasExtra()) if (this.hasExtra())
{ {
for (Mson part : this.getExtra()) for (Mson part : this.getExtra())
{
if (styled)
{ {
builder.append(ChatColor.RESET); builder.append(ChatColor.RESET);
part.toPlain0(builder); }
part.toPlain0(builder, styled);
} }
} }
} }
@Override @Override
public String toString() public String toString()
{ {

View File

@ -16,6 +16,8 @@ import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import com.massivecraft.massivecore.Predictate; import com.massivecraft.massivecore.Predictate;
import com.massivecraft.massivecore.PredictateStartsWithIgnoreCase; import com.massivecraft.massivecore.PredictateStartsWithIgnoreCase;
@ -412,6 +414,24 @@ public class Txt
return getNicedEnum(material); return getNicedEnum(material);
} }
public static String getItemName(ItemStack itemStack)
{
if (InventoryUtil.isNothing(itemStack)) return Txt.parse("<silver><em>Nothing");
ChatColor color = (itemStack.getEnchantments().size() > 0) ? ChatColor.AQUA : ChatColor.RESET;
if (itemStack.hasItemMeta())
{
ItemMeta itemMeta = itemStack.getItemMeta();
if (itemMeta.hasDisplayName())
{
return color + itemMeta.getDisplayName();
}
}
return color + Txt.getMaterialName(itemStack.getType());
}
// -------------------------------------------- // // -------------------------------------------- //
// Paging and chrome-tools like titleize // Paging and chrome-tools like titleize
// -------------------------------------------- // // -------------------------------------------- //