Skip to content

Commit 7639943

Browse files
committed
better formatting for numbers
1 parent 2b75ea0 commit 7639943

File tree

5 files changed

+33
-29
lines changed

5 files changed

+33
-29
lines changed

src/main/java/lol/hyper/toolstats/ToolStats.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import java.io.File;
3535
import java.io.IOException;
3636
import java.text.DecimalFormat;
37+
import java.text.DecimalFormatSymbols;
3738
import java.text.SimpleDateFormat;
3839
import java.util.Locale;
3940
import java.util.logging.Logger;
@@ -60,9 +61,8 @@ public final class ToolStats extends JavaPlugin {
6061
public final NamespacedKey newElytra = new NamespacedKey(this, "new");
6162

6263
public final SimpleDateFormat dateFormat = new SimpleDateFormat("M/dd/yyyy", Locale.ENGLISH);
63-
public final DecimalFormat decimalFormat = new DecimalFormat("#,###.00");
64-
public final DecimalFormat commaFormat = new DecimalFormat("#,###");
65-
64+
public final DecimalFormat decimalFormat = new DecimalFormat("#,###.00", new DecimalFormatSymbols(Locale.getDefault()));
65+
public final DecimalFormat commaFormat = new DecimalFormat("#,###", new DecimalFormatSymbols(Locale.getDefault()));
6666
public BlocksMined blocksMined;
6767
public ChunkPopulate chunkPopulate;
6868
public CraftItem craftItem;
@@ -121,6 +121,8 @@ public void onEnable() {
121121
new Metrics(this, 14110);
122122

123123
Bukkit.getScheduler().runTaskAsynchronously(this, this::checkForUpdates);
124+
125+
logger.info("Locale: " + Locale.getDefault());
124126
}
125127

126128
public void loadConfig() {
@@ -264,7 +266,7 @@ public String getLoreFromConfig(String configName, boolean raw) {
264266
}
265267

266268
public BukkitAudiences getAdventure() {
267-
if(this.adventure == null) {
269+
if (this.adventure == null) {
268270
throw new IllegalStateException("Tried to access Adventure when the plugin was disabled!");
269271
}
270272
return this.adventure;

src/main/java/lol/hyper/toolstats/events/BlocksMined.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ private void updateBlocksMined(ItemStack playerTool) {
7373
}
7474
// read the current stats from the item
7575
// if they don't exist, then start from 0
76-
Integer blocksMined = 0;
76+
Integer blocksMined;
7777
PersistentDataContainer container = meta.getPersistentDataContainer();
7878
if (container.has(toolStats.genericMined, PersistentDataType.INTEGER)) {
7979
blocksMined = container.get(toolStats.genericMined, PersistentDataType.INTEGER);
@@ -98,6 +98,7 @@ private void updateBlocksMined(ItemStack playerTool) {
9898
}
9999

100100
List<String> lore;
101+
String newLine = configLoreRaw.replace("{blocks}", toolStats.thousandsFormat.format(blocksMined));
101102
if (meta.hasLore()) {
102103
lore = meta.getLore();
103104
boolean hasLore = false;
@@ -106,18 +107,18 @@ private void updateBlocksMined(ItemStack playerTool) {
106107
for (int x = 0; x < lore.size(); x++) {
107108
if (lore.get(x).contains(configLore)) {
108109
hasLore = true;
109-
lore.set(x, configLoreRaw.replace("{blocks}", toolStats.commaFormat.format(blocksMined)));
110+
lore.set(x, newLine);
110111
break;
111112
}
112113
}
113114
// if the item has lore but doesn't have the tag, add it
114115
if (!hasLore) {
115-
lore.add(configLoreRaw.replace("{blocks}", toolStats.commaFormat.format(blocksMined)));
116+
lore.add(newLine);
116117
}
117118
} else {
118119
// if the item has no lore, create a new list and add the string
119120
lore = new ArrayList<>();
120-
lore.add(configLoreRaw.replace("{blocks}", toolStats.commaFormat.format(blocksMined)));
121+
lore.add(newLine);
121122
}
122123
// do we add the lore based on the config?
123124
if (toolStats.checkConfig(playerTool, "blocks-mined")) {

src/main/java/lol/hyper/toolstats/events/EntityDamage.java

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ private ItemStack updatePlayerKills(ItemStack itemStack) {
219219
toolStats.logger.warning(itemStack + " does NOT have any meta! Unable to update stats.");
220220
return null;
221221
}
222-
Integer playerKills = null;
222+
Integer playerKills;
223223
PersistentDataContainer container = meta.getPersistentDataContainer();
224224
if (container.has(toolStats.swordPlayerKills, PersistentDataType.INTEGER)) {
225225
playerKills = container.get(toolStats.swordPlayerKills, PersistentDataType.INTEGER);
@@ -243,6 +243,7 @@ private ItemStack updatePlayerKills(ItemStack itemStack) {
243243
}
244244

245245
List<String> lore;
246+
String newLine = playerKillsLoreRaw.replace("{kills}", toolStats.commaFormat.format(playerKills));
246247
if (meta.hasLore()) {
247248
lore = meta.getLore();
248249
boolean hasLore = false;
@@ -251,18 +252,18 @@ private ItemStack updatePlayerKills(ItemStack itemStack) {
251252
for (int x = 0; x < lore.size(); x++) {
252253
if (lore.get(x).contains(playerKillsLore)) {
253254
hasLore = true;
254-
lore.set(x, playerKillsLoreRaw.replace("{kills}", toolStats.commaFormat.format(playerKills)));
255+
lore.set(x, newLine);
255256
break;
256257
}
257258
}
258259
// if the item has lore but doesn't have the tag, add it
259260
if (!hasLore) {
260-
lore.add(playerKillsLoreRaw.replace("{kills}", toolStats.commaFormat.format(playerKills)));
261+
lore.add(newLine);
261262
}
262263
} else {
263264
// if the item has no lore, create a new list and add the string
264265
lore = new ArrayList<>();
265-
lore.add(playerKillsLoreRaw.replace("{kills}", toolStats.commaFormat.format(playerKills)));
266+
lore.add(newLine);
266267
}
267268
// do we add the lore based on the config?
268269
if (toolStats.checkConfig(itemStack, "player-kills")) {
@@ -285,7 +286,7 @@ private ItemStack updateMobKills(ItemStack itemStack) {
285286
toolStats.logger.warning(itemStack + " does NOT have any meta! Unable to update stats.");
286287
return null;
287288
}
288-
Integer mobKills = null;
289+
Integer mobKills;
289290
PersistentDataContainer container = meta.getPersistentDataContainer();
290291
if (container.has(toolStats.swordMobKills, PersistentDataType.INTEGER)) {
291292
mobKills = container.get(toolStats.swordMobKills, PersistentDataType.INTEGER);
@@ -310,6 +311,7 @@ private ItemStack updateMobKills(ItemStack itemStack) {
310311
}
311312

312313
List<String> lore;
314+
String newLine = mobKillsLoreRaw.replace("{kills}", toolStats.commaFormat.format(mobKills));
313315
if (meta.hasLore()) {
314316
lore = meta.getLore();
315317
boolean hasLore = false;
@@ -318,18 +320,18 @@ private ItemStack updateMobKills(ItemStack itemStack) {
318320
for (int x = 0; x < lore.size(); x++) {
319321
if (lore.get(x).contains(mobKillsLore)) {
320322
hasLore = true;
321-
lore.set(x, mobKillsLoreRaw.replace("{kills}", toolStats.commaFormat.format(mobKills)));
323+
lore.set(x, newLine);
322324
break;
323325
}
324326
}
325327
// if the item has lore but doesn't have the tag, add it
326328
if (!hasLore) {
327-
lore.add(mobKillsLoreRaw.replace("{kills}", toolStats.commaFormat.format(mobKills)));
329+
lore.add(newLine);
328330
}
329331
} else {
330332
// if the item has no lore, create a new list and add the string
331333
lore = new ArrayList<>();
332-
lore.add(mobKillsLoreRaw.replace("{kills}", toolStats.commaFormat.format(mobKills)));
334+
lore.add(newLine);
333335
}
334336
// do we add the lore based on the config?
335337
if (toolStats.checkConfig(itemStack, "mob-kills")) {
@@ -376,6 +378,7 @@ private void updateArmorDamage(ItemStack itemStack, double damage) {
376378
}
377379

378380
List<String> lore;
381+
String newLine = damageTakenLoreRaw.replace("{damage}", toolStats.decimalFormat.format(damageTaken));
379382
if (meta.hasLore()) {
380383
lore = meta.getLore();
381384
boolean hasLore = false;
@@ -384,18 +387,18 @@ private void updateArmorDamage(ItemStack itemStack, double damage) {
384387
for (int x = 0; x < lore.size(); x++) {
385388
if (lore.get(x).contains(damageTakenLore)) {
386389
hasLore = true;
387-
lore.set(x, damageTakenLoreRaw.replace("{damage}", toolStats.decimalFormat.format(damageTaken)));
390+
lore.set(x, newLine);
388391
break;
389392
}
390393
}
391394
// if the item has lore but doesn't have the tag, add it
392395
if (!hasLore) {
393-
lore.add(damageTakenLoreRaw.replace("{damage}", toolStats.decimalFormat.format(damageTaken)));
396+
lore.add(newLine);
394397
}
395398
} else {
396399
// if the item has no lore, create a new list and add the string
397400
lore = new ArrayList<>();
398-
lore.add(damageTakenLoreRaw.replace("{damage}", toolStats.decimalFormat.format(damageTaken)));
401+
lore.add(newLine);
399402
}
400403
if (toolStats.config.getBoolean("enabled.armor-damage")) {
401404
meta.setLore(lore);

src/main/java/lol/hyper/toolstats/events/PlayerFish.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import lol.hyper.toolstats.ToolStats;
2121
import lol.hyper.toolstats.tools.ItemChecker;
2222
import lol.hyper.toolstats.tools.UUIDDataType;
23-
import org.bukkit.Bukkit;
2423
import org.bukkit.GameMode;
2524
import org.bukkit.Material;
2625
import org.bukkit.entity.Item;
@@ -37,7 +36,6 @@
3736
import java.util.ArrayList;
3837
import java.util.Date;
3938
import java.util.List;
40-
import java.util.ListIterator;
4139

4240
public class PlayerFish implements Listener {
4341

@@ -63,7 +61,6 @@ public void onFish(PlayerFishEvent event) {
6361
}
6462
// make sure the player is holding a fishing rod
6563
ItemStack heldItem = player.getInventory().getItem(player.getInventory().getHeldItemSlot());
66-
int heldItemSlot = player.getInventory().getHeldItemSlot();
6764
if (heldItem == null || heldItem.getType() == Material.AIR || heldItem.getType() != Material.FISHING_ROD) {
6865
return;
6966
}
@@ -86,7 +83,6 @@ public void onFish(PlayerFishEvent event) {
8683
/**
8784
* Update a fishing rod's fish count.
8885
* @param fishingRod The fishing rod to update.
89-
* @return A new fishing rod with update counts.
9086
*/
9187
private void updateFishCount(ItemStack fishingRod) {
9288
ItemMeta meta = fishingRod.getItemMeta();
@@ -119,6 +115,7 @@ private void updateFishCount(ItemStack fishingRod) {
119115
}
120116

121117
List<String> lore;
118+
String newLine = fishCaughtLoreRaw.replace("{fish}", toolStats.commaFormat.format(fishCaught));
122119
if (meta.hasLore()) {
123120
lore = meta.getLore();
124121
boolean hasLore = false;
@@ -127,18 +124,18 @@ private void updateFishCount(ItemStack fishingRod) {
127124
for (int x = 0; x < lore.size(); x++) {
128125
if (lore.get(x).contains(fishCaughtLore)) {
129126
hasLore = true;
130-
lore.set(x, fishCaughtLoreRaw.replace("{fish}", toolStats.commaFormat.format(fishCaught)));
127+
lore.set(x, newLine);
131128
break;
132129
}
133130
}
134131
// if the item has lore but doesn't have the tag, add it
135132
if (!hasLore) {
136-
lore.add(fishCaughtLoreRaw.replace("{fish}", toolStats.commaFormat.format(fishCaught)));
133+
lore.add(newLine);
137134
}
138135
} else {
139136
// if the item has no lore, create a new list and add the string
140137
lore = new ArrayList<>();
141-
lore.add(fishCaughtLoreRaw.replace("{fish}", toolStats.commaFormat.format(fishCaught)));
138+
lore.add(newLine);
142139
}
143140

144141
/*

src/main/java/lol/hyper/toolstats/events/SheepShear.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ private ItemStack addLore(ItemStack oldShears) {
110110
}
111111

112112
List<String> lore;
113+
String newLine = sheepShearedLoreRaw.replace("{sheep}", toolStats.commaFormat.format(sheepSheared));
113114
if (meta.hasLore()) {
114115
lore = meta.getLore();
115116
boolean hasLore = false;
@@ -118,18 +119,18 @@ private ItemStack addLore(ItemStack oldShears) {
118119
for (int x = 0; x < lore.size(); x++) {
119120
if (lore.get(x).contains(sheepShearedLore)) {
120121
hasLore = true;
121-
lore.set(x, sheepShearedLoreRaw.replace("{sheep}", toolStats.commaFormat.format(sheepSheared)));
122+
lore.set(x, newLine);
122123
break;
123124
}
124125
}
125126
// if the item has lore but doesn't have the tag, add it
126127
if (!hasLore) {
127-
lore.add(sheepShearedLoreRaw.replace("{sheep}", toolStats.commaFormat.format(sheepSheared)));
128+
lore.add(newLine);
128129
}
129130
} else {
130131
// if the item has no lore, create a new list and add the string
131132
lore = new ArrayList<>();
132-
lore.add(sheepShearedLoreRaw.replace("{sheep}", toolStats.commaFormat.format(sheepSheared)));
133+
lore.add(newLine);
133134
}
134135
if (toolStats.config.getBoolean("enabled.sheep-sheared")) {
135136
meta.setLore(lore);

0 commit comments

Comments
 (0)