From 68896e0a74ca5c2bddcd03c2d6ec6de0d94bc9b3 Mon Sep 17 00:00:00 2001 From: peaqe Date: Sun, 17 Nov 2024 15:13:12 +0100 Subject: [PATCH] Added a feature to short damage value --- .../plugin/features/DamageDisplayFeature.java | 4 +++- .../holograms/plugin/features/FeatureCommons.java | 10 ++++++++++ src/main/resources/config.yml | 2 ++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/java/eu/decentsoftware/holograms/plugin/features/DamageDisplayFeature.java b/src/main/java/eu/decentsoftware/holograms/plugin/features/DamageDisplayFeature.java index 980c8832..0b1d2b18 100644 --- a/src/main/java/eu/decentsoftware/holograms/plugin/features/DamageDisplayFeature.java +++ b/src/main/java/eu/decentsoftware/holograms/plugin/features/DamageDisplayFeature.java @@ -32,6 +32,7 @@ public class DamageDisplayFeature extends AbstractFeature implements Listener { private boolean displayForMobs = true; private boolean zeroDamage = false; private double heightOffset = 0.0; + private boolean damageShortened = false; public DamageDisplayFeature() { super("damage_display"); @@ -47,6 +48,7 @@ public void reload() { duration = config.getInt("damage-display.duration", duration); appearance = config.getString("damage-display.appearance", appearance); criticalAppearance = config.getString("damage-display.critical-appearance", criticalAppearance); + damageShortened = config.getBoolean("damage-display.critical-appearance.short"); heightOffset = config.getDouble("healing-display.height", heightOffset); @@ -116,7 +118,7 @@ public void onDamage(EntityDamageEvent e) { } else { currentAppearance = this.appearance; } - String text = currentAppearance.replace("{damage}", FeatureCommons.formatNumber(damage)); + String text = currentAppearance.replace("{damage}", (damageShortened ? FeatureCommons.formatNumberShort(damage) : FeatureCommons.formatNumber(damage))); PLUGIN.getHologramManager().spawnTemporaryHologramLine(location, text, duration); } diff --git a/src/main/java/eu/decentsoftware/holograms/plugin/features/FeatureCommons.java b/src/main/java/eu/decentsoftware/holograms/plugin/features/FeatureCommons.java index 561efafb..54c2ddf6 100644 --- a/src/main/java/eu/decentsoftware/holograms/plugin/features/FeatureCommons.java +++ b/src/main/java/eu/decentsoftware/holograms/plugin/features/FeatureCommons.java @@ -13,4 +13,14 @@ public static String formatNumber(double number) { return FORMAT.format(number); } + public static String formatNumberShort(double damage) { + if (damage >= 1000000) { + return formatNumber(damage / 1000000) + "M"; + } else if (damage >= 1000) { + return formatNumber(damage / 1000) + "k"; + } else { + return formatNumber(damage); + } + } + } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 3aedf9f4..4cc23792 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -96,6 +96,8 @@ damage-display: appearance: '&c{damage}' # Appearance of the damage, if the damage is critical critical-appearance: '&4&lCrit!&4 {damage}' + # Do you want to display a shorter number + critical-appearance.short: false # Height offset height: 0