Commit 3bdded28 authored by kellerkindt's avatar kellerkindt
Browse files

Using custom formatter if formatted text from Balance hook is too long

parent 53e745bd
......@@ -49,6 +49,8 @@ public class SCSConfiguration extends Configuration {
public static final String KEY_HOVER_TEXT_ENABLED = "HoverText.Enabled";
public static final String KEY_HOVER_TEXT_PLAYER_CUSTOM_NAME_ENABLED = "HoverText.PlayerCustomNameEnabled";
public static final String KEY_HOVER_TEXT_PLAYER_CUSTOM_NAME_MAX_LENGTH = "HoverText.PlayerCustomNameMaxLength";
public static final String KEY_HOVER_TEXT_BALANCE_MAX_LENGTH = "HoverText.BalanceMaxLength";
public static final String KEY_HOVER_TEXT_BALANCE_FORMATTER = "HoverText.BalanceFormatter";
public static final String KEY_SAVE_INTERVAL = "Save.Interval";
......@@ -196,6 +198,17 @@ public class SCSConfiguration extends Configuration {
return getForced(KEY_HOVER_TEXT_PLAYER_CUSTOM_NAME_MAX_LENGTH, 32);
}
/**
* @return The maximum allowed length of the hover text if formatted by the balance hook
*/
public int getHoverTextBalanceMaxLength() {
return getForced(KEY_HOVER_TEXT_BALANCE_MAX_LENGTH, 7);
}
public String getHoverTextBalanceFormatter() {
return getForced(KEY_HOVER_TEXT_BALANCE_FORMATTER, ".2f$");
}
public boolean isDebuggingSave() {
return getForced(KEY_DEBUG_SAVE, false);
}
......
......@@ -19,6 +19,7 @@ package com.kellerkindt.scs.shops;
import com.kellerkindt.scs.Properties;
import com.kellerkindt.scs.SCSConfiguration;
import com.kellerkindt.scs.ShowCaseStandalone;
import com.kellerkindt.scs.internals.NamedUUID;
import com.kellerkindt.scs.internals.SimpleChangeable;
......@@ -913,12 +914,22 @@ public abstract class Shop<T extends Shop<?>> extends SimpleChangeable<T> implem
* @return The hover text with default values passed to the given {@link Term}
*/
protected String getHoverText(Term term) {
String formattedPrice = scs.getBalanceHandler().format(getPrice());
SCSConfiguration configuration = scs.getConfiguration();
if (formattedPrice.length() > configuration.getHoverTextPlayerCustomNameMaxLength()) {
formattedPrice = String.format(
configuration.getHoverTextBalanceFormatter(),
getPrice()
);
}
return getHoverText(
term,
new ArrayList<>(
Arrays.asList(
MaterialNames.getItemName(getItemStack()),
scs.getBalanceHandler().format(getPrice()),
formattedPrice,
getOwnerName(),
Integer.toString(getAmount()),
Boolean.toString(isUnlimited())
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment