mirror of
https://github.com/hyperdefined/ToolStats.git
synced 2025-12-06 06:41:44 +00:00
don't add data when config is disabled
previously, this would only not add lore, but add data. this now does not add data. this also removes the data if it's present and disabled
This commit is contained in:
@@ -229,6 +229,26 @@ public class ItemLore {
|
|||||||
// if they don't exist, then start from 0
|
// if they don't exist, then start from 0
|
||||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||||
|
|
||||||
|
// if it's disabled, don't update the stats
|
||||||
|
// check to see if the item has the stats, remove them if it does
|
||||||
|
if (!toolStats.config.getBoolean("enabled.crops-harvested")) {
|
||||||
|
if (container.has(toolStats.cropsHarvested)) {
|
||||||
|
Integer cropsMined = container.get(toolStats.cropsHarvested, PersistentDataType.INTEGER);
|
||||||
|
if (cropsMined == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
container.remove(toolStats.cropsHarvested);
|
||||||
|
if (meta.hasLore()) {
|
||||||
|
String oldCropsMinedFormatted = toolStats.numberFormat.formatInt(cropsMined);
|
||||||
|
Component lineToRemove = toolStats.configTools.formatLore("crops-harvested", "{crops}", oldCropsMinedFormatted);
|
||||||
|
List<Component> newLore = removeLore(meta.lore(), lineToRemove);
|
||||||
|
meta.lore(newLore);
|
||||||
|
}
|
||||||
|
return meta;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// check for tokens
|
// check for tokens
|
||||||
boolean validToken = toolStats.itemChecker.checkTokens(container, "crops-mined");
|
boolean validToken = toolStats.itemChecker.checkTokens(container, "crops-mined");
|
||||||
// check for tokens
|
// check for tokens
|
||||||
@@ -265,9 +285,6 @@ public class ItemLore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
container.set(toolStats.cropsHarvested, PersistentDataType.INTEGER, cropsMined + add);
|
container.set(toolStats.cropsHarvested, PersistentDataType.INTEGER, cropsMined + add);
|
||||||
|
|
||||||
// do we add the lore based on the config?
|
|
||||||
if (toolStats.configTools.checkConfig(clone.getType(), "blocks-mined")) {
|
|
||||||
String oldCropsMinedFormatted = toolStats.numberFormat.formatInt(cropsMined);
|
String oldCropsMinedFormatted = toolStats.numberFormat.formatInt(cropsMined);
|
||||||
String newCropsMinedFormatted = toolStats.numberFormat.formatInt(cropsMined + add);
|
String newCropsMinedFormatted = toolStats.numberFormat.formatInt(cropsMined + add);
|
||||||
Component oldLine = toolStats.configTools.formatLore("crops-harvested", "{crops}", oldCropsMinedFormatted);
|
Component oldLine = toolStats.configTools.formatLore("crops-harvested", "{crops}", oldCropsMinedFormatted);
|
||||||
@@ -277,7 +294,6 @@ public class ItemLore {
|
|||||||
}
|
}
|
||||||
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
||||||
meta.lore(newLore);
|
meta.lore(newLore);
|
||||||
}
|
|
||||||
return meta;
|
return meta;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -295,6 +311,31 @@ public class ItemLore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||||
|
|
||||||
|
// if it's disabled, don't update the stats
|
||||||
|
// check to see if the item has the stats, remove them if it does
|
||||||
|
if (!toolStats.configTools.checkConfig(clone.getType(), "blocks-mined")) {
|
||||||
|
toolStats.logger.info("config is disabled for item");
|
||||||
|
if (container.has(toolStats.blocksMined)) {
|
||||||
|
toolStats.logger.info("however, item has data!");
|
||||||
|
Integer blocksMined = container.get(toolStats.blocksMined, PersistentDataType.INTEGER);
|
||||||
|
if (blocksMined == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
container.remove(toolStats.blocksMined);
|
||||||
|
if (meta.hasLore()) {
|
||||||
|
String oldBlocksMinedFormatted = toolStats.numberFormat.formatInt(blocksMined);
|
||||||
|
Component lineToRemove = toolStats.configTools.formatLore("blocks-mined", "{blocks}", oldBlocksMinedFormatted);
|
||||||
|
List<Component> newLore = removeLore(meta.lore(), lineToRemove);
|
||||||
|
meta.lore(newLore);
|
||||||
|
}
|
||||||
|
toolStats.logger.info("removed lore, returning: " + meta);
|
||||||
|
return meta;
|
||||||
|
}
|
||||||
|
toolStats.logger.info("item did not have data, ignoring adding stats");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
boolean validToken = toolStats.itemChecker.checkTokens(container, "blocks-mined");
|
boolean validToken = toolStats.itemChecker.checkTokens(container, "blocks-mined");
|
||||||
// check for tokens
|
// check for tokens
|
||||||
if (toolStats.config.getBoolean("tokens.enabled")) {
|
if (toolStats.config.getBoolean("tokens.enabled")) {
|
||||||
@@ -332,9 +373,6 @@ public class ItemLore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
container.set(toolStats.blocksMined, PersistentDataType.INTEGER, blocksMined + add);
|
container.set(toolStats.blocksMined, PersistentDataType.INTEGER, blocksMined + add);
|
||||||
|
|
||||||
// do we add the lore based on the config?
|
|
||||||
if (toolStats.configTools.checkConfig(clone.getType(), "blocks-mined")) {
|
|
||||||
String oldBlocksMinedFormatted = toolStats.numberFormat.formatInt(blocksMined);
|
String oldBlocksMinedFormatted = toolStats.numberFormat.formatInt(blocksMined);
|
||||||
String newBlocksMinedFormatted = toolStats.numberFormat.formatInt(blocksMined + add);
|
String newBlocksMinedFormatted = toolStats.numberFormat.formatInt(blocksMined + add);
|
||||||
Component oldLine = toolStats.configTools.formatLore("blocks-mined", "{blocks}", oldBlocksMinedFormatted);
|
Component oldLine = toolStats.configTools.formatLore("blocks-mined", "{blocks}", oldBlocksMinedFormatted);
|
||||||
@@ -344,7 +382,6 @@ public class ItemLore {
|
|||||||
}
|
}
|
||||||
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
||||||
meta.lore(newLore);
|
meta.lore(newLore);
|
||||||
}
|
|
||||||
return meta;
|
return meta;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -362,6 +399,27 @@ public class ItemLore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||||
|
|
||||||
|
// if it's disabled, don't update the stats
|
||||||
|
// check to see if the item has the stats, remove them if it does
|
||||||
|
if (!toolStats.configTools.checkConfig(clone.getType(), "player-kills")) {
|
||||||
|
if (container.has(toolStats.playerKills)) {
|
||||||
|
Integer playerKills = container.get(toolStats.playerKills, PersistentDataType.INTEGER);
|
||||||
|
if (playerKills == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
container.remove(toolStats.playerKills);
|
||||||
|
if (meta.hasLore()) {
|
||||||
|
String oldPlayerKillsFormatted = toolStats.numberFormat.formatInt(playerKills);
|
||||||
|
Component lineToRemove = toolStats.configTools.formatLore("player-kills", "{kills}", oldPlayerKillsFormatted);
|
||||||
|
List<Component> newLore = removeLore(meta.lore(), lineToRemove);
|
||||||
|
meta.lore(newLore);
|
||||||
|
}
|
||||||
|
return meta;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// check for tokens
|
// check for tokens
|
||||||
boolean validToken = toolStats.itemChecker.checkTokens(container, "player-kills");
|
boolean validToken = toolStats.itemChecker.checkTokens(container, "player-kills");
|
||||||
// check for tokens
|
// check for tokens
|
||||||
@@ -398,9 +456,6 @@ public class ItemLore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
container.set(toolStats.playerKills, PersistentDataType.INTEGER, playerKills + add);
|
container.set(toolStats.playerKills, PersistentDataType.INTEGER, playerKills + add);
|
||||||
|
|
||||||
// do we add the lore based on the config?
|
|
||||||
if (toolStats.configTools.checkConfig(clone.getType(), "player-kills")) {
|
|
||||||
String oldPlayerKillsFormatted = toolStats.numberFormat.formatInt(playerKills);
|
String oldPlayerKillsFormatted = toolStats.numberFormat.formatInt(playerKills);
|
||||||
String newPlayerKillsFormatted = toolStats.numberFormat.formatInt(playerKills + add);
|
String newPlayerKillsFormatted = toolStats.numberFormat.formatInt(playerKills + add);
|
||||||
Component oldLine = toolStats.configTools.formatLore("kills.player", "{kills}", oldPlayerKillsFormatted);
|
Component oldLine = toolStats.configTools.formatLore("kills.player", "{kills}", oldPlayerKillsFormatted);
|
||||||
@@ -410,7 +465,6 @@ public class ItemLore {
|
|||||||
}
|
}
|
||||||
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
||||||
meta.lore(newLore);
|
meta.lore(newLore);
|
||||||
}
|
|
||||||
return meta;
|
return meta;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -428,6 +482,27 @@ public class ItemLore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||||
|
|
||||||
|
// if it's disabled, don't update the stats
|
||||||
|
// check to see if the item has the stats, remove them if it does
|
||||||
|
if (!toolStats.configTools.checkConfig(clone.getType(), "mob-kills")) {
|
||||||
|
if (container.has(toolStats.mobKills)) {
|
||||||
|
Integer mobKills = container.get(toolStats.mobKills, PersistentDataType.INTEGER);
|
||||||
|
if (mobKills == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
container.remove(toolStats.mobKills);
|
||||||
|
if (meta.hasLore()) {
|
||||||
|
String oldMobKillsFormatted = toolStats.numberFormat.formatInt(mobKills);
|
||||||
|
Component lineToRemove = toolStats.configTools.formatLore("mob-kills", "{kills}", oldMobKillsFormatted);
|
||||||
|
List<Component> newLore = removeLore(meta.lore(), lineToRemove);
|
||||||
|
meta.lore(newLore);
|
||||||
|
}
|
||||||
|
return meta;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// check for tokens
|
// check for tokens
|
||||||
boolean validToken = toolStats.itemChecker.checkTokens(container, "mob-kills");
|
boolean validToken = toolStats.itemChecker.checkTokens(container, "mob-kills");
|
||||||
// check for tokens
|
// check for tokens
|
||||||
@@ -464,9 +539,6 @@ public class ItemLore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
container.set(toolStats.mobKills, PersistentDataType.INTEGER, mobKills + add);
|
container.set(toolStats.mobKills, PersistentDataType.INTEGER, mobKills + add);
|
||||||
|
|
||||||
// do we add the lore based on the config?
|
|
||||||
if (toolStats.configTools.checkConfig(clone.getType(), "mob-kills")) {
|
|
||||||
String oldMobKillsFormatted = toolStats.numberFormat.formatInt(mobKills);
|
String oldMobKillsFormatted = toolStats.numberFormat.formatInt(mobKills);
|
||||||
String newMobKillsFormatted = toolStats.numberFormat.formatInt(mobKills + add);
|
String newMobKillsFormatted = toolStats.numberFormat.formatInt(mobKills + add);
|
||||||
Component oldLine = toolStats.configTools.formatLore("kills.mob", "{kills}", oldMobKillsFormatted);
|
Component oldLine = toolStats.configTools.formatLore("kills.mob", "{kills}", oldMobKillsFormatted);
|
||||||
@@ -476,7 +548,6 @@ public class ItemLore {
|
|||||||
}
|
}
|
||||||
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
||||||
meta.lore(newLore);
|
meta.lore(newLore);
|
||||||
}
|
|
||||||
return meta;
|
return meta;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -502,6 +573,27 @@ public class ItemLore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||||
|
|
||||||
|
// if it's disabled, don't update the stats
|
||||||
|
// check to see if the item has the stats, remove them if it does
|
||||||
|
if (!toolStats.config.getBoolean("enabled.armor-damage")) {
|
||||||
|
if (container.has(toolStats.armorDamage)) {
|
||||||
|
Double armorDamage = container.get(toolStats.armorDamage, PersistentDataType.DOUBLE);
|
||||||
|
if (armorDamage == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
container.remove(toolStats.armorDamage);
|
||||||
|
if (meta.hasLore()) {
|
||||||
|
String oldDamageTakenFormatted = toolStats.numberFormat.formatDouble(armorDamage);
|
||||||
|
Component lineToRemove = toolStats.configTools.formatLore("damage-taken", "{damage}", oldDamageTakenFormatted);
|
||||||
|
List<Component> newLore = removeLore(meta.lore(), lineToRemove);
|
||||||
|
meta.lore(newLore);
|
||||||
|
}
|
||||||
|
return meta;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// check for tokens
|
// check for tokens
|
||||||
boolean validToken = toolStats.itemChecker.checkTokens(container, "damage-taken");
|
boolean validToken = toolStats.itemChecker.checkTokens(container, "damage-taken");
|
||||||
// check for tokens
|
// check for tokens
|
||||||
@@ -538,8 +630,6 @@ public class ItemLore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
container.set(toolStats.armorDamage, PersistentDataType.DOUBLE, damageTaken + damage);
|
container.set(toolStats.armorDamage, PersistentDataType.DOUBLE, damageTaken + damage);
|
||||||
|
|
||||||
if (toolStats.config.getBoolean("enabled.armor-damage")) {
|
|
||||||
String oldDamageFormatted = toolStats.numberFormat.formatDouble(damageTaken);
|
String oldDamageFormatted = toolStats.numberFormat.formatDouble(damageTaken);
|
||||||
String newDamageFormatted = toolStats.numberFormat.formatDouble(damageTaken + damage);
|
String newDamageFormatted = toolStats.numberFormat.formatDouble(damageTaken + damage);
|
||||||
Component oldLine = toolStats.configTools.formatLore("damage-taken", "{damage}", oldDamageFormatted);
|
Component oldLine = toolStats.configTools.formatLore("damage-taken", "{damage}", oldDamageFormatted);
|
||||||
@@ -549,7 +639,6 @@ public class ItemLore {
|
|||||||
}
|
}
|
||||||
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
||||||
meta.lore(newLore);
|
meta.lore(newLore);
|
||||||
}
|
|
||||||
return meta;
|
return meta;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -567,6 +656,27 @@ public class ItemLore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||||
|
|
||||||
|
// if it's disabled, don't update the stats
|
||||||
|
// check to see if the item has the stats, remove them if it does
|
||||||
|
if (!toolStats.config.getBoolean("enabled.flight-time")) {
|
||||||
|
if (container.has(toolStats.flightTime)) {
|
||||||
|
Long flightTime = container.get(toolStats.flightTime, PersistentDataType.LONG);
|
||||||
|
if (flightTime == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
container.remove(toolStats.flightTime);
|
||||||
|
if (meta.hasLore()) {
|
||||||
|
String oldFlightTimeFormatted = toolStats.numberFormat.formatDouble(flightTime);
|
||||||
|
Component lineToRemove = toolStats.configTools.formatLore("flight-time", "{time}", oldFlightTimeFormatted);
|
||||||
|
List<Component> newLore = removeLore(meta.lore(), lineToRemove);
|
||||||
|
meta.lore(newLore);
|
||||||
|
}
|
||||||
|
return meta;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// check for tokens
|
// check for tokens
|
||||||
boolean validToken = toolStats.itemChecker.checkTokens(container, "flight-time");
|
boolean validToken = toolStats.itemChecker.checkTokens(container, "flight-time");
|
||||||
// check for tokens
|
// check for tokens
|
||||||
@@ -605,9 +715,6 @@ public class ItemLore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
container.set(toolStats.flightTime, PersistentDataType.LONG, flightTime + duration);
|
container.set(toolStats.flightTime, PersistentDataType.LONG, flightTime + duration);
|
||||||
|
|
||||||
// do we add the lore based on the config?
|
|
||||||
if (toolStats.config.getBoolean("enabled.flight-time")) {
|
|
||||||
String oldFlightFormatted = toolStats.numberFormat.formatDouble((double) flightTime / 1000);
|
String oldFlightFormatted = toolStats.numberFormat.formatDouble((double) flightTime / 1000);
|
||||||
String newFlightFormatted = toolStats.numberFormat.formatDouble((double) (flightTime + duration) / 1000);
|
String newFlightFormatted = toolStats.numberFormat.formatDouble((double) (flightTime + duration) / 1000);
|
||||||
Component oldLine = toolStats.configTools.formatLore("flight-time", "{time}", oldFlightFormatted);
|
Component oldLine = toolStats.configTools.formatLore("flight-time", "{time}", oldFlightFormatted);
|
||||||
@@ -617,7 +724,6 @@ public class ItemLore {
|
|||||||
}
|
}
|
||||||
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
||||||
meta.lore(newLore);
|
meta.lore(newLore);
|
||||||
}
|
|
||||||
return meta;
|
return meta;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -635,6 +741,27 @@ public class ItemLore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||||
|
|
||||||
|
// if it's disabled, don't update the stats
|
||||||
|
// check to see if the item has the stats, remove them if it does
|
||||||
|
if (!toolStats.config.getBoolean("enabled.sheep-sheared")) {
|
||||||
|
if (container.has(toolStats.sheepSheared)) {
|
||||||
|
Integer sheepSheared = container.get(toolStats.sheepSheared, PersistentDataType.INTEGER);
|
||||||
|
if (sheepSheared == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
container.remove(toolStats.sheepSheared);
|
||||||
|
if (meta.hasLore()) {
|
||||||
|
String oldSheepShearedFormatted = toolStats.numberFormat.formatDouble(sheepSheared);
|
||||||
|
Component lineToRemove = toolStats.configTools.formatLore("sheep-sheared", "{sheep}", oldSheepShearedFormatted);
|
||||||
|
List<Component> newLore = removeLore(meta.lore(), lineToRemove);
|
||||||
|
meta.lore(newLore);
|
||||||
|
}
|
||||||
|
return meta;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// check for tokens
|
// check for tokens
|
||||||
boolean validToken = toolStats.itemChecker.checkTokens(container, "sheep-sheared");
|
boolean validToken = toolStats.itemChecker.checkTokens(container, "sheep-sheared");
|
||||||
// check for tokens
|
// check for tokens
|
||||||
@@ -671,8 +798,6 @@ public class ItemLore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
container.set(toolStats.sheepSheared, PersistentDataType.INTEGER, sheepSheared + add);
|
container.set(toolStats.sheepSheared, PersistentDataType.INTEGER, sheepSheared + add);
|
||||||
|
|
||||||
if (toolStats.config.getBoolean("enabled.sheep-sheared")) {
|
|
||||||
String oldSheepFormatted = toolStats.numberFormat.formatInt(sheepSheared);
|
String oldSheepFormatted = toolStats.numberFormat.formatInt(sheepSheared);
|
||||||
String newSheepFormatted = toolStats.numberFormat.formatInt(sheepSheared + add);
|
String newSheepFormatted = toolStats.numberFormat.formatInt(sheepSheared + add);
|
||||||
Component oldLine = toolStats.configTools.formatLore("sheep-sheared", "{sheep}", oldSheepFormatted);
|
Component oldLine = toolStats.configTools.formatLore("sheep-sheared", "{sheep}", oldSheepFormatted);
|
||||||
@@ -682,7 +807,6 @@ public class ItemLore {
|
|||||||
}
|
}
|
||||||
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
||||||
meta.lore(newLore);
|
meta.lore(newLore);
|
||||||
}
|
|
||||||
return meta;
|
return meta;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -700,6 +824,27 @@ public class ItemLore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||||
|
|
||||||
|
// if it's disabled, don't update the stats
|
||||||
|
// check to see if the item has the stats, remove them if it does
|
||||||
|
if (!toolStats.config.getBoolean("enabled.arrows-shot")) {
|
||||||
|
if (container.has(toolStats.arrowsShot)) {
|
||||||
|
Integer arrowsShot = container.get(toolStats.arrowsShot, PersistentDataType.INTEGER);
|
||||||
|
if (arrowsShot == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
container.remove(toolStats.arrowsShot);
|
||||||
|
if (meta.hasLore()) {
|
||||||
|
String oldArrowsShotFormatted = toolStats.numberFormat.formatDouble(arrowsShot);
|
||||||
|
Component lineToRemove = toolStats.configTools.formatLore("arrows-shot", "{arrows}", oldArrowsShotFormatted);
|
||||||
|
List<Component> newLore = removeLore(meta.lore(), lineToRemove);
|
||||||
|
meta.lore(newLore);
|
||||||
|
}
|
||||||
|
return meta;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// check for tokens
|
// check for tokens
|
||||||
boolean validToken = toolStats.itemChecker.checkTokens(container, "arrows-shot");
|
boolean validToken = toolStats.itemChecker.checkTokens(container, "arrows-shot");
|
||||||
// check for tokens
|
// check for tokens
|
||||||
@@ -738,9 +883,6 @@ public class ItemLore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
container.set(toolStats.arrowsShot, PersistentDataType.INTEGER, arrowsShot + add);
|
container.set(toolStats.arrowsShot, PersistentDataType.INTEGER, arrowsShot + add);
|
||||||
|
|
||||||
// do we add the lore based on the config?
|
|
||||||
if (toolStats.config.getBoolean("enabled.arrows-shot")) {
|
|
||||||
String oldArrowsFormatted = toolStats.numberFormat.formatInt(arrowsShot);
|
String oldArrowsFormatted = toolStats.numberFormat.formatInt(arrowsShot);
|
||||||
String newArrowsFormatted = toolStats.numberFormat.formatInt(arrowsShot + add);
|
String newArrowsFormatted = toolStats.numberFormat.formatInt(arrowsShot + add);
|
||||||
Component oldLine = toolStats.configTools.formatLore("arrows-shot", "{arrows}", oldArrowsFormatted);
|
Component oldLine = toolStats.configTools.formatLore("arrows-shot", "{arrows}", oldArrowsFormatted);
|
||||||
@@ -750,7 +892,6 @@ public class ItemLore {
|
|||||||
}
|
}
|
||||||
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
||||||
meta.lore(newLore);
|
meta.lore(newLore);
|
||||||
}
|
|
||||||
return meta;
|
return meta;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -768,6 +909,27 @@ public class ItemLore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||||
|
|
||||||
|
// if it's disabled, don't update the stats
|
||||||
|
// check to see if the item has the stats, remove them if it does
|
||||||
|
if (!toolStats.config.getBoolean("enabled.fish-caught")) {
|
||||||
|
if (container.has(toolStats.fishCaught)) {
|
||||||
|
Integer fishCaught = container.get(toolStats.fishCaught, PersistentDataType.INTEGER);
|
||||||
|
if (fishCaught == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
container.remove(toolStats.fishCaught);
|
||||||
|
if (meta.hasLore()) {
|
||||||
|
String oldFishCaught = toolStats.numberFormat.formatDouble(fishCaught);
|
||||||
|
Component lineToRemove = toolStats.configTools.formatLore("fished.fish-caught", "{fish}", oldFishCaught);
|
||||||
|
List<Component> newLore = removeLore(meta.lore(), lineToRemove);
|
||||||
|
meta.lore(newLore);
|
||||||
|
}
|
||||||
|
return meta;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// check for tokens
|
// check for tokens
|
||||||
boolean validToken = toolStats.itemChecker.checkTokens(container, "fish-caught");
|
boolean validToken = toolStats.itemChecker.checkTokens(container, "fish-caught");
|
||||||
// check for tokens
|
// check for tokens
|
||||||
@@ -804,8 +966,6 @@ public class ItemLore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
container.set(toolStats.fishCaught, PersistentDataType.INTEGER, fishCaught + add);
|
container.set(toolStats.fishCaught, PersistentDataType.INTEGER, fishCaught + add);
|
||||||
|
|
||||||
if (toolStats.config.getBoolean("enabled.fish-caught")) {
|
|
||||||
String oldFishFormatted = toolStats.numberFormat.formatInt(fishCaught);
|
String oldFishFormatted = toolStats.numberFormat.formatInt(fishCaught);
|
||||||
String newFishFormatted = toolStats.numberFormat.formatInt(fishCaught + add);
|
String newFishFormatted = toolStats.numberFormat.formatInt(fishCaught + add);
|
||||||
Component oldLine = toolStats.configTools.formatLore("fished.fish-caught", "{fish}", oldFishFormatted);
|
Component oldLine = toolStats.configTools.formatLore("fished.fish-caught", "{fish}", oldFishFormatted);
|
||||||
@@ -815,7 +975,19 @@ public class ItemLore {
|
|||||||
}
|
}
|
||||||
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
||||||
meta.lore(newLore);
|
meta.lore(newLore);
|
||||||
}
|
|
||||||
return meta;
|
return meta;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a given lore from an item.
|
||||||
|
*
|
||||||
|
* @param inputLore The item's lore.
|
||||||
|
* @param toRemove The line to remove.
|
||||||
|
* @return The lore with the line removed.
|
||||||
|
*/
|
||||||
|
public List<Component> removeLore(List<Component> inputLore, Component toRemove) {
|
||||||
|
List<Component> newLore = new ArrayList<>(inputLore);
|
||||||
|
newLore.removeIf(line -> PlainTextComponentSerializer.plainText().serialize(line).equals(PlainTextComponentSerializer.plainText().serialize(toRemove)));
|
||||||
|
return newLore;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user