mirror of
https://github.com/hyperdefined/ToolStats.git
synced 2025-12-06 06:41:44 +00:00
@@ -61,8 +61,6 @@ public final class ToolStats extends JavaPlugin {
|
||||
public final NamespacedKey newElytra = new NamespacedKey(this, "new");
|
||||
|
||||
public SimpleDateFormat dateFormat;
|
||||
public final DecimalFormat decimalFormat = new DecimalFormat("#,###.00", new DecimalFormatSymbols(Locale.getDefault()));
|
||||
public final DecimalFormat commaFormat = new DecimalFormat("#,###", new DecimalFormatSymbols(Locale.getDefault()));
|
||||
public BlocksMined blocksMined;
|
||||
public ChunkPopulate chunkPopulate;
|
||||
public CraftItem craftItem;
|
||||
@@ -121,8 +119,6 @@ public final class ToolStats extends JavaPlugin {
|
||||
new Metrics(this, 14110);
|
||||
|
||||
Bukkit.getScheduler().runTaskAsynchronously(this, this::checkForUpdates);
|
||||
|
||||
logger.info("Locale: " + Locale.getDefault());
|
||||
}
|
||||
|
||||
public void loadConfig() {
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
package lol.hyper.toolstats.commands;
|
||||
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import lol.hyper.toolstats.tools.NumberFormat;
|
||||
import lol.hyper.toolstats.tools.UUIDDataType;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
import net.kyori.adventure.text.Component;
|
||||
@@ -215,7 +216,7 @@ public class CommandToolStats implements TabExecutor {
|
||||
if (container.has(toolStats.swordPlayerKills, PersistentDataType.INTEGER)) {
|
||||
Integer kills = container.get(toolStats.swordPlayerKills, PersistentDataType.INTEGER);
|
||||
if (kills != null) {
|
||||
lore.add(toolStats.getLoreFromConfig("kills.player", true).replace("{kills}", toolStats.commaFormat.format(kills)));
|
||||
lore.add(toolStats.getLoreFromConfig("kills.player", true).replace("{kills}", NumberFormat.formatInt(kills)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -223,7 +224,7 @@ public class CommandToolStats implements TabExecutor {
|
||||
if (container.has(toolStats.swordMobKills, PersistentDataType.INTEGER)) {
|
||||
Integer kills = container.get(toolStats.swordMobKills, PersistentDataType.INTEGER);
|
||||
if (kills != null) {
|
||||
lore.add(toolStats.getLoreFromConfig("kills.mob", true).replace("{kills}", toolStats.commaFormat.format(kills)));
|
||||
lore.add(toolStats.getLoreFromConfig("kills.mob", true).replace("{kills}", NumberFormat.formatInt(kills)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -231,7 +232,7 @@ public class CommandToolStats implements TabExecutor {
|
||||
if (container.has(toolStats.genericMined, PersistentDataType.INTEGER)) {
|
||||
Integer blocksMined = container.get(toolStats.genericMined, PersistentDataType.INTEGER);
|
||||
if (blocksMined != null) {
|
||||
lore.add(toolStats.getLoreFromConfig("blocks-mined", true).replace("{blocks}", toolStats.commaFormat.format(blocksMined)));
|
||||
lore.add(toolStats.getLoreFromConfig("blocks-mined", true).replace("{blocks}", NumberFormat.formatInt(blocksMined)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -239,7 +240,7 @@ public class CommandToolStats implements TabExecutor {
|
||||
if (container.has(toolStats.fishingRodCaught, PersistentDataType.INTEGER)) {
|
||||
Integer fish = container.get(toolStats.fishingRodCaught, PersistentDataType.INTEGER);
|
||||
if (fish != null) {
|
||||
lore.add(toolStats.getLoreFromConfig("fished.fish-caught", true).replace("{fish}", toolStats.commaFormat.format(fish)));
|
||||
lore.add(toolStats.getLoreFromConfig("fished.fish-caught", true).replace("{fish}", NumberFormat.formatInt(fish)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -247,7 +248,7 @@ public class CommandToolStats implements TabExecutor {
|
||||
if (container.has(toolStats.shearsSheared, PersistentDataType.INTEGER)) {
|
||||
Integer sheep = container.get(toolStats.shearsSheared, PersistentDataType.INTEGER);
|
||||
if (sheep != null) {
|
||||
lore.add(toolStats.getLoreFromConfig("sheep-sheared", true).replace("{sheep}", toolStats.commaFormat.format(sheep)));
|
||||
lore.add(toolStats.getLoreFromConfig("sheep-sheared", true).replace("{sheep}", NumberFormat.formatInt(sheep)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -255,7 +256,7 @@ public class CommandToolStats implements TabExecutor {
|
||||
if (container.has(toolStats.armorDamage, PersistentDataType.DOUBLE)) {
|
||||
Double damage = container.get(toolStats.armorDamage, PersistentDataType.DOUBLE);
|
||||
if (damage != null) {
|
||||
lore.add(toolStats.getLoreFromConfig("damage-taken", true).replace("{damage}", toolStats.commaFormat.format(damage)));
|
||||
lore.add(toolStats.getLoreFromConfig("damage-taken", true).replace("{damage}", NumberFormat.formatDouble(damage)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ package lol.hyper.toolstats.events;
|
||||
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import lol.hyper.toolstats.tools.ItemChecker;
|
||||
import lol.hyper.toolstats.tools.NumberFormat;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -98,7 +99,7 @@ public class BlocksMined implements Listener {
|
||||
}
|
||||
|
||||
List<String> lore;
|
||||
String newLine = configLoreRaw.replace("{blocks}", toolStats.thousandsFormat.format(blocksMined));
|
||||
String newLine = configLoreRaw.replace("{blocks}", NumberFormat.formatInt(blocksMined));
|
||||
if (meta.hasLore()) {
|
||||
lore = meta.getLore();
|
||||
boolean hasLore = false;
|
||||
|
||||
@@ -19,6 +19,7 @@ package lol.hyper.toolstats.events;
|
||||
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import lol.hyper.toolstats.tools.ItemChecker;
|
||||
import lol.hyper.toolstats.tools.NumberFormat;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.*;
|
||||
@@ -243,7 +244,7 @@ public class EntityDamage implements Listener {
|
||||
}
|
||||
|
||||
List<String> lore;
|
||||
String newLine = playerKillsLoreRaw.replace("{kills}", toolStats.commaFormat.format(playerKills));
|
||||
String newLine = playerKillsLoreRaw.replace("{kills}", NumberFormat.formatInt(playerKills));
|
||||
if (meta.hasLore()) {
|
||||
lore = meta.getLore();
|
||||
boolean hasLore = false;
|
||||
@@ -311,7 +312,7 @@ public class EntityDamage implements Listener {
|
||||
}
|
||||
|
||||
List<String> lore;
|
||||
String newLine = mobKillsLoreRaw.replace("{kills}", toolStats.commaFormat.format(mobKills));
|
||||
String newLine = mobKillsLoreRaw.replace("{kills}", NumberFormat.formatInt(mobKills));
|
||||
if (meta.hasLore()) {
|
||||
lore = meta.getLore();
|
||||
boolean hasLore = false;
|
||||
@@ -378,7 +379,7 @@ public class EntityDamage implements Listener {
|
||||
}
|
||||
|
||||
List<String> lore;
|
||||
String newLine = damageTakenLoreRaw.replace("{damage}", toolStats.decimalFormat.format(damageTaken));
|
||||
String newLine = damageTakenLoreRaw.replace("{damage}", NumberFormat.formatDouble(damageTaken));
|
||||
if (meta.hasLore()) {
|
||||
lore = meta.getLore();
|
||||
boolean hasLore = false;
|
||||
|
||||
@@ -19,6 +19,7 @@ package lol.hyper.toolstats.events;
|
||||
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import lol.hyper.toolstats.tools.ItemChecker;
|
||||
import lol.hyper.toolstats.tools.NumberFormat;
|
||||
import lol.hyper.toolstats.tools.UUIDDataType;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
@@ -115,7 +116,7 @@ public class PlayerFish implements Listener {
|
||||
}
|
||||
|
||||
List<String> lore;
|
||||
String newLine = fishCaughtLoreRaw.replace("{fish}", toolStats.commaFormat.format(fishCaught));
|
||||
String newLine = fishCaughtLoreRaw.replace("{fish}", NumberFormat.formatInt(fishCaught));
|
||||
if (meta.hasLore()) {
|
||||
lore = meta.getLore();
|
||||
boolean hasLore = false;
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
package lol.hyper.toolstats.events;
|
||||
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import lol.hyper.toolstats.tools.NumberFormat;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Entity;
|
||||
@@ -110,7 +111,7 @@ public class SheepShear implements Listener {
|
||||
}
|
||||
|
||||
List<String> lore;
|
||||
String newLine = sheepShearedLoreRaw.replace("{sheep}", toolStats.commaFormat.format(sheepSheared));
|
||||
String newLine = sheepShearedLoreRaw.replace("{sheep}", NumberFormat.formatInt(sheepSheared));
|
||||
if (meta.hasLore()) {
|
||||
lore = meta.getLore();
|
||||
boolean hasLore = false;
|
||||
|
||||
56
src/main/java/lol/hyper/toolstats/tools/NumberFormat.java
Normal file
56
src/main/java/lol/hyper/toolstats/tools/NumberFormat.java
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* This file is part of ToolStats.
|
||||
*
|
||||
* ToolStats is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* ToolStats is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with ToolStats. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package lol.hyper.toolstats.tools;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.DecimalFormatSymbols;
|
||||
import java.util.Locale;
|
||||
|
||||
public class NumberFormat {
|
||||
|
||||
private static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat("#,###.00", new DecimalFormatSymbols(Locale.getDefault()));
|
||||
private static final DecimalFormat COMMA_FORMAT = new DecimalFormat("#,###", new DecimalFormatSymbols(Locale.getDefault()));
|
||||
|
||||
/**
|
||||
* Formats a number to make it pretty. Example: 4322 to 4,322
|
||||
* @param number The number to format.
|
||||
* @return The formatted number.
|
||||
*/
|
||||
public static String formatInt(int number) {
|
||||
String finalNumber = COMMA_FORMAT.format(number);
|
||||
// hardcode French system because Minecraft bad
|
||||
if (Locale.getDefault() == Locale.FRANCE || Locale.getDefault() == Locale.FRENCH) {
|
||||
finalNumber = finalNumber.replaceAll("[\\x{202f}\\x{00A0}]", " ");
|
||||
}
|
||||
return finalNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats a number to make it pretty. Example: 4322.33 to 4,322.33
|
||||
* @param number The number to format.
|
||||
* @return The formatted number.
|
||||
*/
|
||||
public static String formatDouble(double number) {
|
||||
String finalNumber = DECIMAL_FORMAT.format(number);
|
||||
// hardcode French system because Minecraft bad
|
||||
if (Locale.getDefault() == Locale.FRANCE || Locale.getDefault() == Locale.FRENCH) {
|
||||
finalNumber = finalNumber.replaceAll("[\\x{202f}\\x{00A0}]", " ");
|
||||
}
|
||||
return finalNumber;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user