Mson.toPlain now has boolea styled parameter. Txt.getItemName.
This commit is contained in:
parent
e0548bbc60
commit
6a6752fdb6
@ -102,7 +102,7 @@ public class MessageMixinDefault extends MessageMixinAbstract
|
||||
{
|
||||
for (Mson mson : msons)
|
||||
{
|
||||
sender.sendMessage(mson.toPlain());
|
||||
sender.sendMessage(mson.toPlain(true));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -861,26 +861,29 @@ public class Mson implements Serializable
|
||||
return raw;
|
||||
}
|
||||
|
||||
public String toPlain()
|
||||
public String toPlain(boolean styled)
|
||||
{
|
||||
StringBuilder ret = new StringBuilder();
|
||||
this.toPlain0(ret);
|
||||
this.toPlain0(ret, styled);
|
||||
return ret.toString();
|
||||
}
|
||||
|
||||
private void toPlain0(StringBuilder builder)
|
||||
private void toPlain0(StringBuilder builder, boolean styled)
|
||||
{
|
||||
if ( ! this.getText().isEmpty())
|
||||
{
|
||||
// Color must be put in BEFORE formatting.
|
||||
// http://minecraft.gamepedia.com/Formatting_codes#Formatting_codes
|
||||
|
||||
if (this.getEffectiveColor() != null) builder.append(this.getEffectiveColor());
|
||||
if (this.isEffectiveBold()) builder.append(ChatColor.BOLD);
|
||||
if (this.isEffectiveItalic()) builder.append(ChatColor.ITALIC);
|
||||
if (this.isEffectiveUnderlined()) builder.append(ChatColor.UNDERLINE);
|
||||
if (this.isEffectiveStrikethrough()) builder.append(ChatColor.STRIKETHROUGH);
|
||||
if (this.isEffectiveObfuscated()) builder.append(ChatColor.MAGIC);
|
||||
if (styled)
|
||||
{
|
||||
if (this.getEffectiveColor() != null) builder.append(this.getEffectiveColor());
|
||||
if (this.isEffectiveBold()) builder.append(ChatColor.BOLD);
|
||||
if (this.isEffectiveItalic()) builder.append(ChatColor.ITALIC);
|
||||
if (this.isEffectiveUnderlined()) builder.append(ChatColor.UNDERLINE);
|
||||
if (this.isEffectiveStrikethrough()) builder.append(ChatColor.STRIKETHROUGH);
|
||||
if (this.isEffectiveObfuscated()) builder.append(ChatColor.MAGIC);
|
||||
}
|
||||
|
||||
builder.append(this.getText());
|
||||
}
|
||||
|
||||
@ -888,12 +891,17 @@ public class Mson implements Serializable
|
||||
{
|
||||
for (Mson part : this.getExtra())
|
||||
{
|
||||
builder.append(ChatColor.RESET);
|
||||
part.toPlain0(builder);
|
||||
if (styled)
|
||||
{
|
||||
builder.append(ChatColor.RESET);
|
||||
}
|
||||
|
||||
part.toPlain0(builder, styled);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
|
@ -16,6 +16,8 @@ import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.CommandSender;
|
||||
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.PredictateStartsWithIgnoreCase;
|
||||
@ -412,6 +414,24 @@ public class Txt
|
||||
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
|
||||
// -------------------------------------------- //
|
||||
|
Loading…
Reference in New Issue
Block a user