Skip to content

Commit

Permalink
Fixes item text color on signshop reload
Browse files Browse the repository at this point in the history
  • Loading branch information
weaves7 committed Dec 26, 2022
1 parent 3a8e699 commit ad024d8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/wargamer2010/signshop/SignShop.java
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ private void registerSSListeners() {
pm.registerEvents(new SharedMoneyTransaction(), this);
}

/* private void backupOldConfig() {
/* private void backupOldConfig() { TODO reintroduce this
FileConfiguration ymlThing = configUtil.loadYMLFromPluginFolder(SignShopConfig.configFilename);
File configFile = new File(SignShop.getInstance().getDataFolder(), SignShopConfig.configFilename);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,13 @@ public class SignShopItemMeta {
private static final String innerListSeperator = "^";
private static final String filename = "books.db";

private static ChatColor txtColor = ChatColor.YELLOW;
private static ChatColor txtColorTwo = ChatColor.DARK_PURPLE;

private SignShopItemMeta() {

}

public static void init() {
SSDatabase db = new SSDatabase(filename);
txtColor = SignShop.getInstance().getSignShopConfig().getTextColor();
txtColorTwo = SignShop.getInstance().getSignShopConfig().getTextColorTwo();
try {
if (!db.tableExists("ItemMeta"))
db.runStatement("CREATE TABLE ItemMeta ( ItemMetaID INTEGER, ItemMetaHash INT, PRIMARY KEY(ItemMetaID) )", null, false);
Expand All @@ -65,7 +61,11 @@ public static String convertColorsToDisplay(List<Color> colors) {
}

public static ChatColor getTextColor() {
return txtColor;
return SignShop.getInstance().getSignShopConfig().getTextColor();
}

public static ChatColor getTextColorTwo() {
return SignShop.getInstance().getSignShopConfig().getTextColorTwo();
}

private static String convertFireworkTypeToDisplay(FireworkEffect.Type type) {
Expand All @@ -85,13 +85,13 @@ private static boolean hasNoMeta(ItemStack stack) {
}

private static String getDisplayName(ItemStack stack) {
return getDisplayName(stack, txtColor);
return getDisplayName(stack, getTextColor());
}

//May need to implement my own WhatIsIt friendly name yml
private static String getDisplayName(ItemStack stack, ChatColor color) {
String txtcolor = txtColor.toString();
String customcolor = (stack.getEnchantments().isEmpty() ? color.toString() : txtColorTwo.toString());
String txtcolor = getTextColor().toString();
String customcolor = (stack.getEnchantments().isEmpty() ? color.toString() : getTextColorTwo().toString());

String normal = itemUtil.formatMaterialName(stack);
String displayname = "";
Expand Down Expand Up @@ -126,7 +126,7 @@ public static String getName(ItemStack stack) {
if(type == MetaType.EnchantmentStorage) {
EnchantmentStorageMeta enchantmeta = (EnchantmentStorageMeta) meta;
if(enchantmeta.hasStoredEnchants())
return (getDisplayName(stack, txtColorTwo) + " " + itemUtil.enchantmentsToMessageFormat(enchantmeta.getStoredEnchants()));
return (getDisplayName(stack, getTextColorTwo()) + " " + itemUtil.enchantmentsToMessageFormat(enchantmeta.getStoredEnchants()));
} else if(type == MetaType.LeatherArmor) {
LeatherArmorMeta leathermeta = (LeatherArmorMeta) meta;
return (ColorUtil.getColorAsString(leathermeta.getColor()) + " Colored " + getDisplayName(stack));
Expand All @@ -145,14 +145,14 @@ public static String getName(ItemStack stack) {
} else if(type == MetaType.Potion) {
PotionMeta potionMeta = (PotionMeta) meta;
StringBuilder nameBuilder = new StringBuilder();
nameBuilder.append(txtColorTwo);
nameBuilder.append(getTextColorTwo());
nameBuilder.append(itemUtil.stripConstantCase(stack.getType().toString()));
nameBuilder.append(txtColor);
nameBuilder.append(getTextColor());
nameBuilder.append(" (");
if (potionMeta.hasDisplayName()) {
nameBuilder.append("\"");
nameBuilder.append(potionMeta.getDisplayName());
nameBuilder.append(txtColor);
nameBuilder.append(getTextColor());
nameBuilder.append("\" ");
}

Expand Down Expand Up @@ -189,7 +189,7 @@ public static String getName(ItemStack stack) {
FireworkMeta fireworkmeta = (FireworkMeta) meta;

StringBuilder namebuilder = new StringBuilder(256);
namebuilder.append(getDisplayName(stack, txtColorTwo));
namebuilder.append(getDisplayName(stack, getTextColorTwo()));

if(fireworkmeta.hasEffects()) {
namebuilder.append(" (");
Expand Down Expand Up @@ -218,9 +218,9 @@ public static String getName(ItemStack stack) {
if (blockStateMeta.getBlockState() instanceof ShulkerBox){
ShulkerBox shulker = (ShulkerBox) blockStateMeta.getBlockState();
StringBuilder nameBuilder = new StringBuilder();
nameBuilder.append(getDisplayName(stack, txtColorTwo));
nameBuilder.append(getDisplayName(stack, getTextColorTwo()));

nameBuilder.append(txtColor);
nameBuilder.append(getTextColor());
nameBuilder.append(" [");

boolean isEmpty = true;
Expand All @@ -244,7 +244,7 @@ public static String getName(ItemStack stack) {
nameBuilder.append(getName(item));
}
}
nameBuilder.append(txtColor);
nameBuilder.append(getTextColor());
nameBuilder.append("]");

return nameBuilder.toString();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/wargamer2010/signshop/util/itemUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ public static String itemStackToString(ItemStack[] isStacks) {
if (first) first = false;
else sItems.append(signShopConfig.getTextColor()).append(", ");
String newItemMeta = SignShopItemMeta.getName(entry.getKey());
String count = (SignShopItemMeta.getTextColor() + entry.getValue().toString() + " ");
String count = (signShopConfig.getTextColor() + entry.getValue().toString() + " ");
if(newItemMeta.isEmpty())
sItems.append(count).append(formatMaterialName(entry.getKey()));
else
Expand Down

0 comments on commit ad024d8

Please sign in to comment.