mirror of
https://github.com/hyperdefined/ToolStats.git
synced 2025-12-06 06:41:44 +00:00
better formatting for numbers
This commit is contained in:
@@ -34,6 +34,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.DecimalFormat;
|
||||||
|
import java.text.DecimalFormatSymbols;
|
||||||
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;
|
||||||
@@ -60,9 +61,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 decimalFormat = new DecimalFormat("#,###.00", new DecimalFormatSymbols(Locale.getDefault()));
|
||||||
public final DecimalFormat commaFormat = new DecimalFormat("#,###");
|
public final DecimalFormat commaFormat = new DecimalFormat("#,###", new DecimalFormatSymbols(Locale.getDefault()));
|
||||||
|
|
||||||
public BlocksMined blocksMined;
|
public BlocksMined blocksMined;
|
||||||
public ChunkPopulate chunkPopulate;
|
public ChunkPopulate chunkPopulate;
|
||||||
public CraftItem craftItem;
|
public CraftItem craftItem;
|
||||||
@@ -121,6 +121,8 @@ public final class ToolStats extends JavaPlugin {
|
|||||||
new Metrics(this, 14110);
|
new Metrics(this, 14110);
|
||||||
|
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(this, this::checkForUpdates);
|
Bukkit.getScheduler().runTaskAsynchronously(this, this::checkForUpdates);
|
||||||
|
|
||||||
|
logger.info("Locale: " + Locale.getDefault());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadConfig() {
|
public void loadConfig() {
|
||||||
@@ -264,7 +266,7 @@ public final class ToolStats extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public BukkitAudiences getAdventure() {
|
public BukkitAudiences getAdventure() {
|
||||||
if(this.adventure == null) {
|
if (this.adventure == null) {
|
||||||
throw new IllegalStateException("Tried to access Adventure when the plugin was disabled!");
|
throw new IllegalStateException("Tried to access Adventure when the plugin was disabled!");
|
||||||
}
|
}
|
||||||
return this.adventure;
|
return this.adventure;
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ public class BlocksMined implements Listener {
|
|||||||
}
|
}
|
||||||
// read the current stats from the item
|
// read the current stats from the item
|
||||||
// if they don't exist, then start from 0
|
// if they don't exist, then start from 0
|
||||||
Integer blocksMined = 0;
|
Integer blocksMined;
|
||||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||||
if (container.has(toolStats.genericMined, PersistentDataType.INTEGER)) {
|
if (container.has(toolStats.genericMined, PersistentDataType.INTEGER)) {
|
||||||
blocksMined = container.get(toolStats.genericMined, PersistentDataType.INTEGER);
|
blocksMined = container.get(toolStats.genericMined, PersistentDataType.INTEGER);
|
||||||
@@ -98,6 +98,7 @@ public class BlocksMined implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
List<String> lore;
|
List<String> lore;
|
||||||
|
String newLine = configLoreRaw.replace("{blocks}", toolStats.thousandsFormat.format(blocksMined));
|
||||||
if (meta.hasLore()) {
|
if (meta.hasLore()) {
|
||||||
lore = meta.getLore();
|
lore = meta.getLore();
|
||||||
boolean hasLore = false;
|
boolean hasLore = false;
|
||||||
@@ -106,18 +107,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}", toolStats.commaFormat.format(blocksMined)));
|
lore.set(x, newLine);
|
||||||
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}", toolStats.commaFormat.format(blocksMined)));
|
lore.add(newLine);
|
||||||
}
|
}
|
||||||
} 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}", toolStats.commaFormat.format(blocksMined)));
|
lore.add(newLine);
|
||||||
}
|
}
|
||||||
// do we add the lore based on the config?
|
// do we add the lore based on the config?
|
||||||
if (toolStats.checkConfig(playerTool, "blocks-mined")) {
|
if (toolStats.checkConfig(playerTool, "blocks-mined")) {
|
||||||
|
|||||||
@@ -219,7 +219,7 @@ public class EntityDamage implements Listener {
|
|||||||
toolStats.logger.warning(itemStack + " does NOT have any meta! Unable to update stats.");
|
toolStats.logger.warning(itemStack + " does NOT have any meta! Unable to update stats.");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Integer playerKills = null;
|
Integer playerKills;
|
||||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||||
if (container.has(toolStats.swordPlayerKills, PersistentDataType.INTEGER)) {
|
if (container.has(toolStats.swordPlayerKills, PersistentDataType.INTEGER)) {
|
||||||
playerKills = container.get(toolStats.swordPlayerKills, PersistentDataType.INTEGER);
|
playerKills = container.get(toolStats.swordPlayerKills, PersistentDataType.INTEGER);
|
||||||
@@ -243,6 +243,7 @@ public class EntityDamage implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
List<String> lore;
|
List<String> lore;
|
||||||
|
String newLine = playerKillsLoreRaw.replace("{kills}", toolStats.commaFormat.format(playerKills));
|
||||||
if (meta.hasLore()) {
|
if (meta.hasLore()) {
|
||||||
lore = meta.getLore();
|
lore = meta.getLore();
|
||||||
boolean hasLore = false;
|
boolean hasLore = false;
|
||||||
@@ -251,18 +252,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}", toolStats.commaFormat.format(playerKills)));
|
lore.set(x, newLine);
|
||||||
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}", toolStats.commaFormat.format(playerKills)));
|
lore.add(newLine);
|
||||||
}
|
}
|
||||||
} 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}", toolStats.commaFormat.format(playerKills)));
|
lore.add(newLine);
|
||||||
}
|
}
|
||||||
// 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")) {
|
||||||
@@ -285,7 +286,7 @@ public class EntityDamage implements Listener {
|
|||||||
toolStats.logger.warning(itemStack + " does NOT have any meta! Unable to update stats.");
|
toolStats.logger.warning(itemStack + " does NOT have any meta! Unable to update stats.");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Integer mobKills = null;
|
Integer mobKills;
|
||||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||||
if (container.has(toolStats.swordMobKills, PersistentDataType.INTEGER)) {
|
if (container.has(toolStats.swordMobKills, PersistentDataType.INTEGER)) {
|
||||||
mobKills = container.get(toolStats.swordMobKills, PersistentDataType.INTEGER);
|
mobKills = container.get(toolStats.swordMobKills, PersistentDataType.INTEGER);
|
||||||
@@ -310,6 +311,7 @@ public class EntityDamage implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
List<String> lore;
|
List<String> lore;
|
||||||
|
String newLine = mobKillsLoreRaw.replace("{kills}", toolStats.commaFormat.format(mobKills));
|
||||||
if (meta.hasLore()) {
|
if (meta.hasLore()) {
|
||||||
lore = meta.getLore();
|
lore = meta.getLore();
|
||||||
boolean hasLore = false;
|
boolean hasLore = false;
|
||||||
@@ -318,18 +320,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}", toolStats.commaFormat.format(mobKills)));
|
lore.set(x, newLine);
|
||||||
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}", toolStats.commaFormat.format(mobKills)));
|
lore.add(newLine);
|
||||||
}
|
}
|
||||||
} 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}", toolStats.commaFormat.format(mobKills)));
|
lore.add(newLine);
|
||||||
}
|
}
|
||||||
// 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")) {
|
||||||
@@ -376,6 +378,7 @@ public class EntityDamage implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
List<String> lore;
|
List<String> lore;
|
||||||
|
String newLine = damageTakenLoreRaw.replace("{damage}", toolStats.decimalFormat.format(damageTaken));
|
||||||
if (meta.hasLore()) {
|
if (meta.hasLore()) {
|
||||||
lore = meta.getLore();
|
lore = meta.getLore();
|
||||||
boolean hasLore = false;
|
boolean hasLore = false;
|
||||||
@@ -384,18 +387,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}", toolStats.decimalFormat.format(damageTaken)));
|
lore.set(x, newLine);
|
||||||
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}", toolStats.decimalFormat.format(damageTaken)));
|
lore.add(newLine);
|
||||||
}
|
}
|
||||||
} 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}", toolStats.decimalFormat.format(damageTaken)));
|
lore.add(newLine);
|
||||||
}
|
}
|
||||||
if (toolStats.config.getBoolean("enabled.armor-damage")) {
|
if (toolStats.config.getBoolean("enabled.armor-damage")) {
|
||||||
meta.setLore(lore);
|
meta.setLore(lore);
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ package lol.hyper.toolstats.events;
|
|||||||
import lol.hyper.toolstats.ToolStats;
|
import lol.hyper.toolstats.ToolStats;
|
||||||
import lol.hyper.toolstats.tools.ItemChecker;
|
import lol.hyper.toolstats.tools.ItemChecker;
|
||||||
import lol.hyper.toolstats.tools.UUIDDataType;
|
import lol.hyper.toolstats.tools.UUIDDataType;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Item;
|
import org.bukkit.entity.Item;
|
||||||
@@ -37,7 +36,6 @@ import org.bukkit.persistence.PersistentDataType;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.ListIterator;
|
|
||||||
|
|
||||||
public class PlayerFish implements Listener {
|
public class PlayerFish implements Listener {
|
||||||
|
|
||||||
@@ -63,7 +61,6 @@ public class PlayerFish implements Listener {
|
|||||||
}
|
}
|
||||||
// make sure the player is holding a fishing rod
|
// make sure the player is holding a fishing rod
|
||||||
ItemStack heldItem = player.getInventory().getItem(player.getInventory().getHeldItemSlot());
|
ItemStack heldItem = player.getInventory().getItem(player.getInventory().getHeldItemSlot());
|
||||||
int heldItemSlot = player.getInventory().getHeldItemSlot();
|
|
||||||
if (heldItem == null || heldItem.getType() == Material.AIR || heldItem.getType() != Material.FISHING_ROD) {
|
if (heldItem == null || heldItem.getType() == Material.AIR || heldItem.getType() != Material.FISHING_ROD) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -86,7 +83,6 @@ public class PlayerFish implements Listener {
|
|||||||
/**
|
/**
|
||||||
* Update a fishing rod's fish count.
|
* Update a fishing rod's fish count.
|
||||||
* @param fishingRod The fishing rod to update.
|
* @param fishingRod The fishing rod to update.
|
||||||
* @return A new fishing rod with update counts.
|
|
||||||
*/
|
*/
|
||||||
private void updateFishCount(ItemStack fishingRod) {
|
private void updateFishCount(ItemStack fishingRod) {
|
||||||
ItemMeta meta = fishingRod.getItemMeta();
|
ItemMeta meta = fishingRod.getItemMeta();
|
||||||
@@ -119,6 +115,7 @@ public class PlayerFish implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
List<String> lore;
|
List<String> lore;
|
||||||
|
String newLine = fishCaughtLoreRaw.replace("{fish}", toolStats.commaFormat.format(fishCaught));
|
||||||
if (meta.hasLore()) {
|
if (meta.hasLore()) {
|
||||||
lore = meta.getLore();
|
lore = meta.getLore();
|
||||||
boolean hasLore = false;
|
boolean hasLore = false;
|
||||||
@@ -127,18 +124,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}", toolStats.commaFormat.format(fishCaught)));
|
lore.set(x, newLine);
|
||||||
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}", toolStats.commaFormat.format(fishCaught)));
|
lore.add(newLine);
|
||||||
}
|
}
|
||||||
} 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}", toolStats.commaFormat.format(fishCaught)));
|
lore.add(newLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -110,6 +110,7 @@ public class SheepShear implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
List<String> lore;
|
List<String> lore;
|
||||||
|
String newLine = sheepShearedLoreRaw.replace("{sheep}", toolStats.commaFormat.format(sheepSheared));
|
||||||
if (meta.hasLore()) {
|
if (meta.hasLore()) {
|
||||||
lore = meta.getLore();
|
lore = meta.getLore();
|
||||||
boolean hasLore = false;
|
boolean hasLore = false;
|
||||||
@@ -118,18 +119,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}", toolStats.commaFormat.format(sheepSheared)));
|
lore.set(x, newLine);
|
||||||
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}", toolStats.commaFormat.format(sheepSheared)));
|
lore.add(newLine);
|
||||||
}
|
}
|
||||||
} 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}", toolStats.commaFormat.format(sheepSheared)));
|
lore.add(newLine);
|
||||||
}
|
}
|
||||||
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