mirror of
https://github.com/hyperdefined/ToolStats.git
synced 2025-12-06 06:41:44 +00:00
better number formatting
This commit is contained in:
@@ -33,6 +33,7 @@ import org.bukkit.plugin.java.JavaPlugin;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.text.DecimalFormat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
@@ -59,6 +60,8 @@ public final class ToolStats extends JavaPlugin {
|
|||||||
public final NamespacedKey newElytra = new NamespacedKey(this, "new");
|
public final NamespacedKey newElytra = new NamespacedKey(this, "new");
|
||||||
|
|
||||||
public final SimpleDateFormat dateFormat = new SimpleDateFormat("M/dd/yyyy", Locale.ENGLISH);
|
public final SimpleDateFormat dateFormat = new SimpleDateFormat("M/dd/yyyy", Locale.ENGLISH);
|
||||||
|
public final DecimalFormat decimalFormat = new DecimalFormat("#,###.00");
|
||||||
|
public final DecimalFormat commaFormat = new DecimalFormat("#,###");
|
||||||
|
|
||||||
public BlocksMined blocksMined;
|
public BlocksMined blocksMined;
|
||||||
public ChunkPopulate chunkPopulate;
|
public ChunkPopulate chunkPopulate;
|
||||||
|
|||||||
@@ -207,7 +207,7 @@ public class CommandToolStats implements TabExecutor {
|
|||||||
if (container.has(toolStats.swordPlayerKills, PersistentDataType.INTEGER)) {
|
if (container.has(toolStats.swordPlayerKills, PersistentDataType.INTEGER)) {
|
||||||
Integer kills = container.get(toolStats.swordPlayerKills, PersistentDataType.INTEGER);
|
Integer kills = container.get(toolStats.swordPlayerKills, PersistentDataType.INTEGER);
|
||||||
if (kills != null) {
|
if (kills != null) {
|
||||||
lore.add(toolStats.getLoreFromConfig("kills.player", true).replace("{kills}", Integer.toString(kills)));
|
lore.add(toolStats.getLoreFromConfig("kills.player", true).replace("{kills}", toolStats.commaFormat.format(kills)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -215,7 +215,7 @@ public class CommandToolStats implements TabExecutor {
|
|||||||
if (container.has(toolStats.swordMobKills, PersistentDataType.INTEGER)) {
|
if (container.has(toolStats.swordMobKills, PersistentDataType.INTEGER)) {
|
||||||
Integer kills = container.get(toolStats.swordMobKills, PersistentDataType.INTEGER);
|
Integer kills = container.get(toolStats.swordMobKills, PersistentDataType.INTEGER);
|
||||||
if (kills != null) {
|
if (kills != null) {
|
||||||
lore.add(toolStats.getLoreFromConfig("kills.mob", true).replace("{kills}", Integer.toString(kills)));
|
lore.add(toolStats.getLoreFromConfig("kills.mob", true).replace("{kills}", toolStats.commaFormat.format(kills)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -223,7 +223,7 @@ public class CommandToolStats implements TabExecutor {
|
|||||||
if (container.has(toolStats.genericMined, PersistentDataType.INTEGER)) {
|
if (container.has(toolStats.genericMined, PersistentDataType.INTEGER)) {
|
||||||
Integer blocksMined = container.get(toolStats.genericMined, PersistentDataType.INTEGER);
|
Integer blocksMined = container.get(toolStats.genericMined, PersistentDataType.INTEGER);
|
||||||
if (blocksMined != null) {
|
if (blocksMined != null) {
|
||||||
lore.add(toolStats.getLoreFromConfig("blocks-mined", true).replace("{blocks}", Integer.toString(blocksMined)));
|
lore.add(toolStats.getLoreFromConfig("blocks-mined", true).replace("{blocks}", toolStats.commaFormat.format(blocksMined)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -231,7 +231,7 @@ public class CommandToolStats implements TabExecutor {
|
|||||||
if (container.has(toolStats.fishingRodCaught, PersistentDataType.INTEGER)) {
|
if (container.has(toolStats.fishingRodCaught, PersistentDataType.INTEGER)) {
|
||||||
Integer fish = container.get(toolStats.fishingRodCaught, PersistentDataType.INTEGER);
|
Integer fish = container.get(toolStats.fishingRodCaught, PersistentDataType.INTEGER);
|
||||||
if (fish != null) {
|
if (fish != null) {
|
||||||
lore.add(toolStats.getLoreFromConfig("fished.fish-caught", true).replace("{fish}", Integer.toString(fish)));
|
lore.add(toolStats.getLoreFromConfig("fished.fish-caught", true).replace("{fish}", toolStats.commaFormat.format(fish)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -239,7 +239,7 @@ public class CommandToolStats implements TabExecutor {
|
|||||||
if (container.has(toolStats.shearsSheared, PersistentDataType.INTEGER)) {
|
if (container.has(toolStats.shearsSheared, PersistentDataType.INTEGER)) {
|
||||||
Integer sheep = container.get(toolStats.shearsSheared, PersistentDataType.INTEGER);
|
Integer sheep = container.get(toolStats.shearsSheared, PersistentDataType.INTEGER);
|
||||||
if (sheep != null) {
|
if (sheep != null) {
|
||||||
lore.add(toolStats.getLoreFromConfig("sheep-sheared", true).replace("{sheep}", Integer.toString(sheep)));
|
lore.add(toolStats.getLoreFromConfig("sheep-sheared", true).replace("{sheep}", toolStats.commaFormat.format(sheep)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -247,7 +247,7 @@ public class CommandToolStats implements TabExecutor {
|
|||||||
if (container.has(toolStats.armorDamage, PersistentDataType.INTEGER)) {
|
if (container.has(toolStats.armorDamage, PersistentDataType.INTEGER)) {
|
||||||
Integer damage = container.get(toolStats.armorDamage, PersistentDataType.INTEGER);
|
Integer damage = container.get(toolStats.armorDamage, PersistentDataType.INTEGER);
|
||||||
if (damage != null) {
|
if (damage != null) {
|
||||||
lore.add(toolStats.getLoreFromConfig("damage-taken", true).replace("{damage}", Integer.toString(damage)));
|
lore.add(toolStats.getLoreFromConfig("damage-taken", true).replace("{damage}", toolStats.commaFormat.format(damage)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,7 +81,6 @@ public class BlocksMined implements Listener {
|
|||||||
blocksMined++;
|
blocksMined++;
|
||||||
}
|
}
|
||||||
container.set(toolStats.genericMined, PersistentDataType.INTEGER, blocksMined);
|
container.set(toolStats.genericMined, PersistentDataType.INTEGER, blocksMined);
|
||||||
|
|
||||||
String configLore = toolStats.getLoreFromConfig("blocks-mined", false);
|
String configLore = toolStats.getLoreFromConfig("blocks-mined", false);
|
||||||
String configLoreRaw = toolStats.getLoreFromConfig("blocks-mined", true);
|
String configLoreRaw = toolStats.getLoreFromConfig("blocks-mined", true);
|
||||||
|
|
||||||
@@ -100,18 +99,18 @@ public class BlocksMined implements Listener {
|
|||||||
for (int x = 0; x < lore.size(); x++) {
|
for (int x = 0; x < lore.size(); x++) {
|
||||||
if (lore.get(x).contains(configLore)) {
|
if (lore.get(x).contains(configLore)) {
|
||||||
hasLore = true;
|
hasLore = true;
|
||||||
lore.set(x, configLoreRaw.replace("{blocks}", Integer.toString(blocksMined)));
|
lore.set(x, configLoreRaw.replace("{blocks}", toolStats.commaFormat.format(blocksMined)));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// if the item has lore but doesn't have the tag, add it
|
// if the item has lore but doesn't have the tag, add it
|
||||||
if (!hasLore) {
|
if (!hasLore) {
|
||||||
lore.add(configLoreRaw.replace("{blocks}", Integer.toString(blocksMined)));
|
lore.add(configLoreRaw.replace("{blocks}", toolStats.commaFormat.format(blocksMined)));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// if the item has no lore, create a new list and add the string
|
// if the item has no lore, create a new list and add the string
|
||||||
lore = new ArrayList<>();
|
lore = new ArrayList<>();
|
||||||
lore.add(configLoreRaw.replace("{blocks}", Integer.toString(blocksMined)));
|
lore.add(configLoreRaw.replace("{blocks}", toolStats.commaFormat.format(blocksMined)));
|
||||||
}
|
}
|
||||||
// do we add the lore based on the config?
|
// do we add the lore based on the config?
|
||||||
if (toolStats.checkConfig(itemStack, "blocks-mined")) {
|
if (toolStats.checkConfig(itemStack, "blocks-mined")) {
|
||||||
|
|||||||
@@ -33,14 +33,11 @@ import org.bukkit.inventory.meta.ItemMeta;
|
|||||||
import org.bukkit.persistence.PersistentDataContainer;
|
import org.bukkit.persistence.PersistentDataContainer;
|
||||||
import org.bukkit.persistence.PersistentDataType;
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
|
|
||||||
import java.math.RoundingMode;
|
|
||||||
import java.text.DecimalFormat;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class EntityDamage implements Listener {
|
public class EntityDamage implements Listener {
|
||||||
|
|
||||||
private final ToolStats toolStats;
|
private final ToolStats toolStats;
|
||||||
private final DecimalFormat decimalFormat = new DecimalFormat("0.00");
|
|
||||||
public final Set<UUID> trackedMobs = new HashSet<>();
|
public final Set<UUID> trackedMobs = new HashSet<>();
|
||||||
|
|
||||||
public EntityDamage(ToolStats toolStats) {
|
public EntityDamage(ToolStats toolStats) {
|
||||||
@@ -227,18 +224,18 @@ public class EntityDamage implements Listener {
|
|||||||
for (int x = 0; x < lore.size(); x++) {
|
for (int x = 0; x < lore.size(); x++) {
|
||||||
if (lore.get(x).contains(playerKillsLore)) {
|
if (lore.get(x).contains(playerKillsLore)) {
|
||||||
hasLore = true;
|
hasLore = true;
|
||||||
lore.set(x, playerKillsLoreRaw.replace("{kills}", Integer.toString(playerKills)));
|
lore.set(x, playerKillsLoreRaw.replace("{kills}", toolStats.commaFormat.format(playerKills)));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// if the item has lore but doesn't have the tag, add it
|
// if the item has lore but doesn't have the tag, add it
|
||||||
if (!hasLore) {
|
if (!hasLore) {
|
||||||
lore.add(playerKillsLoreRaw.replace("{kills}", Integer.toString(playerKills)));
|
lore.add(playerKillsLoreRaw.replace("{kills}", toolStats.commaFormat.format(playerKills)));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// if the item has no lore, create a new list and add the string
|
// if the item has no lore, create a new list and add the string
|
||||||
lore = new ArrayList<>();
|
lore = new ArrayList<>();
|
||||||
lore.add(playerKillsLoreRaw.replace("{kills}", Integer.toString(playerKills)));
|
lore.add(playerKillsLoreRaw.replace("{kills}", toolStats.commaFormat.format(playerKills)));
|
||||||
}
|
}
|
||||||
// do we add the lore based on the config?
|
// do we add the lore based on the config?
|
||||||
if (toolStats.checkConfig(itemStack, "player-kills")) {
|
if (toolStats.checkConfig(itemStack, "player-kills")) {
|
||||||
@@ -290,18 +287,18 @@ public class EntityDamage implements Listener {
|
|||||||
for (int x = 0; x < lore.size(); x++) {
|
for (int x = 0; x < lore.size(); x++) {
|
||||||
if (lore.get(x).contains(mobKillsLore)) {
|
if (lore.get(x).contains(mobKillsLore)) {
|
||||||
hasLore = true;
|
hasLore = true;
|
||||||
lore.set(x, mobKillsLoreRaw.replace("{kills}", Integer.toString(mobKills)));
|
lore.set(x, mobKillsLoreRaw.replace("{kills}", toolStats.commaFormat.format(mobKills)));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// if the item has lore but doesn't have the tag, add it
|
// if the item has lore but doesn't have the tag, add it
|
||||||
if (!hasLore) {
|
if (!hasLore) {
|
||||||
lore.add(mobKillsLoreRaw.replace("{kills}", Integer.toString(mobKills)));
|
lore.add(mobKillsLoreRaw.replace("{kills}", toolStats.commaFormat.format(mobKills)));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// if the item has no lore, create a new list and add the string
|
// if the item has no lore, create a new list and add the string
|
||||||
lore = new ArrayList<>();
|
lore = new ArrayList<>();
|
||||||
lore.add(mobKillsLoreRaw.replace("{kills}", Integer.toString(mobKills)));
|
lore.add(mobKillsLoreRaw.replace("{kills}", toolStats.commaFormat.format(mobKills)));
|
||||||
}
|
}
|
||||||
// do we add the lore based on the config?
|
// do we add the lore based on the config?
|
||||||
if (toolStats.checkConfig(itemStack, "mob-kills")) {
|
if (toolStats.checkConfig(itemStack, "mob-kills")) {
|
||||||
@@ -332,7 +329,6 @@ public class EntityDamage implements Listener {
|
|||||||
} else {
|
} else {
|
||||||
damageTaken = damageTaken + damage;
|
damageTaken = damageTaken + damage;
|
||||||
}
|
}
|
||||||
decimalFormat.setRoundingMode(RoundingMode.DOWN);
|
|
||||||
container.set(toolStats.armorDamage, PersistentDataType.DOUBLE, damageTaken);
|
container.set(toolStats.armorDamage, PersistentDataType.DOUBLE, damageTaken);
|
||||||
|
|
||||||
String damageTakenLore = toolStats.getLoreFromConfig("damage-taken", false);
|
String damageTakenLore = toolStats.getLoreFromConfig("damage-taken", false);
|
||||||
@@ -353,18 +349,18 @@ public class EntityDamage implements Listener {
|
|||||||
for (int x = 0; x < lore.size(); x++) {
|
for (int x = 0; x < lore.size(); x++) {
|
||||||
if (lore.get(x).contains(damageTakenLore)) {
|
if (lore.get(x).contains(damageTakenLore)) {
|
||||||
hasLore = true;
|
hasLore = true;
|
||||||
lore.set(x, damageTakenLoreRaw.replace("{damage}", decimalFormat.format(damageTaken)));
|
lore.set(x, damageTakenLoreRaw.replace("{damage}", toolStats.decimalFormat.format(damageTaken)));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// if the item has lore but doesn't have the tag, add it
|
// if the item has lore but doesn't have the tag, add it
|
||||||
if (!hasLore) {
|
if (!hasLore) {
|
||||||
lore.add(damageTakenLoreRaw.replace("{damage}", decimalFormat.format(damageTaken)));
|
lore.add(damageTakenLoreRaw.replace("{damage}", toolStats.decimalFormat.format(damageTaken)));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// if the item has no lore, create a new list and add the string
|
// if the item has no lore, create a new list and add the string
|
||||||
lore = new ArrayList<>();
|
lore = new ArrayList<>();
|
||||||
lore.add(damageTakenLoreRaw.replace("{damage}", decimalFormat.format(damageTaken)));
|
lore.add(damageTakenLoreRaw.replace("{damage}", toolStats.decimalFormat.format(damageTaken)));
|
||||||
}
|
}
|
||||||
if (toolStats.config.getBoolean("enabled.armor-damage")) {
|
if (toolStats.config.getBoolean("enabled.armor-damage")) {
|
||||||
meta.setLore(lore);
|
meta.setLore(lore);
|
||||||
|
|||||||
@@ -112,18 +112,18 @@ public class PlayerFish implements Listener {
|
|||||||
for (int x = 0; x < lore.size(); x++) {
|
for (int x = 0; x < lore.size(); x++) {
|
||||||
if (lore.get(x).contains(fishCaughtLore)) {
|
if (lore.get(x).contains(fishCaughtLore)) {
|
||||||
hasLore = true;
|
hasLore = true;
|
||||||
lore.set(x, fishCaughtLoreRaw.replace("{fish}", Integer.toString(fishCaught)));
|
lore.set(x, fishCaughtLoreRaw.replace("{fish}", toolStats.commaFormat.format(fishCaught)));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// if the item has lore but doesn't have the tag, add it
|
// if the item has lore but doesn't have the tag, add it
|
||||||
if (!hasLore) {
|
if (!hasLore) {
|
||||||
lore.add(fishCaughtLoreRaw.replace("{fish}", Integer.toString(fishCaught)));
|
lore.add(fishCaughtLoreRaw.replace("{fish}", toolStats.commaFormat.format(fishCaught)));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// if the item has no lore, create a new list and add the string
|
// if the item has no lore, create a new list and add the string
|
||||||
lore = new ArrayList<>();
|
lore = new ArrayList<>();
|
||||||
lore.add(fishCaughtLoreRaw.replace("{fish}", Integer.toString(fishCaught)));
|
lore.add(fishCaughtLoreRaw.replace("{fish}", toolStats.commaFormat.format(fishCaught)));
|
||||||
}
|
}
|
||||||
if (toolStats.config.getBoolean("enabled.fish-caught")) {
|
if (toolStats.config.getBoolean("enabled.fish-caught")) {
|
||||||
meta.setLore(lore);
|
meta.setLore(lore);
|
||||||
|
|||||||
@@ -108,18 +108,18 @@ public class SheepShear implements Listener {
|
|||||||
for (int x = 0; x < lore.size(); x++) {
|
for (int x = 0; x < lore.size(); x++) {
|
||||||
if (lore.get(x).contains(sheepShearedLore)) {
|
if (lore.get(x).contains(sheepShearedLore)) {
|
||||||
hasLore = true;
|
hasLore = true;
|
||||||
lore.set(x, sheepShearedLoreRaw.replace("{sheep}", Integer.toString(sheepSheared)));
|
lore.set(x, sheepShearedLoreRaw.replace("{sheep}", toolStats.commaFormat.format(sheepSheared)));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// if the item has lore but doesn't have the tag, add it
|
// if the item has lore but doesn't have the tag, add it
|
||||||
if (!hasLore) {
|
if (!hasLore) {
|
||||||
lore.add(sheepShearedLoreRaw.replace("{sheep}", Integer.toString(sheepSheared)));
|
lore.add(sheepShearedLoreRaw.replace("{sheep}", toolStats.commaFormat.format(sheepSheared)));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// if the item has no lore, create a new list and add the string
|
// if the item has no lore, create a new list and add the string
|
||||||
lore = new ArrayList<>();
|
lore = new ArrayList<>();
|
||||||
lore.add(sheepShearedLoreRaw.replace("{sheep}", Integer.toString(sheepSheared)));
|
lore.add(sheepShearedLoreRaw.replace("{sheep}", toolStats.commaFormat.format(sheepSheared)));
|
||||||
}
|
}
|
||||||
if (toolStats.config.getBoolean("enabled.sheep-sheared")) {
|
if (toolStats.config.getBoolean("enabled.sheep-sheared")) {
|
||||||
meta.setLore(lore);
|
meta.setLore(lore);
|
||||||
|
|||||||
Reference in New Issue
Block a user