mirror of
https://github.com/hyperdefined/ToolStats.git
synced 2026-04-22 19:11:23 +00:00
add logs stripped
This commit is contained in:
@@ -1299,7 +1299,7 @@ public class ItemLore {
|
||||
|
||||
if (criticalStrikes == null) {
|
||||
criticalStrikes = 0;
|
||||
toolStats.logger.warn("{} does not have valid fish-caught set! Resting to zero. This should NEVER happen.", clone);
|
||||
toolStats.logger.warn("{} does not have valid critical-strikes set! Resting to zero. This should NEVER happen.", clone);
|
||||
}
|
||||
|
||||
container.set(toolStats.toolStatsKeys.getCriticalStrikes(), PersistentDataType.INTEGER, criticalStrikes + add);
|
||||
@@ -1397,7 +1397,7 @@ public class ItemLore {
|
||||
|
||||
if (tridentThrows == null) {
|
||||
tridentThrows = 0;
|
||||
toolStats.logger.warn("{} does not have valid fish-caught set! Resting to zero. This should NEVER happen.", clone);
|
||||
toolStats.logger.warn("{} does not have valid trident-throws set! Resting to zero. This should NEVER happen.", clone);
|
||||
}
|
||||
|
||||
container.set(toolStats.toolStatsKeys.getTridentThrows(), PersistentDataType.INTEGER, tridentThrows + add);
|
||||
@@ -1413,6 +1413,104 @@ public class ItemLore {
|
||||
return meta;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add x to logs stripped.
|
||||
*
|
||||
* @param axe The axe used.
|
||||
*/
|
||||
public ItemMeta updateLogsStripped(ItemStack axe, int add) {
|
||||
ItemStack clone = axe.clone();
|
||||
ItemMeta meta = clone.getItemMeta();
|
||||
if (meta == null) {
|
||||
toolStats.logger.warn("{} does NOT have any meta! Unable to update stats.", clone);
|
||||
return null;
|
||||
}
|
||||
|
||||
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.logs-stripped")) {
|
||||
if (container.has(toolStats.toolStatsKeys.getLogsStripped())) {
|
||||
Integer logsStripped = container.get(toolStats.toolStatsKeys.getLogsStripped(), PersistentDataType.INTEGER);
|
||||
if (logsStripped == null) {
|
||||
return null;
|
||||
}
|
||||
container.remove(toolStats.toolStatsKeys.getLogsStripped());
|
||||
// remove the applied token if this stat is disabled
|
||||
if (container.has(toolStats.toolStatsKeys.getTokenApplied())) {
|
||||
String appliedTokens = container.get(toolStats.toolStatsKeys.getTokenApplied(), PersistentDataType.STRING);
|
||||
if (appliedTokens != null) {
|
||||
// remove the token from the list
|
||||
// if the list is empty, remove the PDC
|
||||
// otherwise set the PDC back with the new list
|
||||
List<String> newTokens = toolStats.itemChecker.removeToken(appliedTokens, "logs-stripped");
|
||||
if (!newTokens.isEmpty()) {
|
||||
container.set(toolStats.toolStatsKeys.getTokenApplied(), PersistentDataType.STRING, String.join(",", newTokens));
|
||||
} else {
|
||||
container.remove(toolStats.toolStatsKeys.getTokenApplied());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (meta.hasLore()) {
|
||||
String oldLogsStripped = toolStats.numberFormat.formatInt(logsStripped);
|
||||
Component lineToRemove = toolStats.configTools.formatLore("logs-stripped", "{logs}", oldLogsStripped);
|
||||
List<Component> newLore = removeLore(meta.lore(), lineToRemove);
|
||||
meta.lore(newLore);
|
||||
}
|
||||
return meta;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// check for tokens
|
||||
boolean validToken = toolStats.itemChecker.checkTokens(container, "logs-stripped");
|
||||
// check for tokens
|
||||
if (toolStats.config.getBoolean("tokens.enabled")) {
|
||||
// if the item has stats but no token, add the token
|
||||
if (container.has(toolStats.toolStatsKeys.getLogsStripped()) && !validToken) {
|
||||
String newTokens = toolStats.itemChecker.addTokensToExisting(clone);
|
||||
if (newTokens != null) {
|
||||
container.set(toolStats.toolStatsKeys.getTokenApplied(), PersistentDataType.STRING, newTokens);
|
||||
}
|
||||
}
|
||||
|
||||
// the item does not have a valid token
|
||||
if (!validToken) {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
if (!validToken) {
|
||||
String newTokens = toolStats.itemChecker.addTokensToExisting(clone);
|
||||
if (newTokens != null) {
|
||||
container.set(toolStats.toolStatsKeys.getTokenApplied(), PersistentDataType.STRING, newTokens);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Integer logsStripped = 0;
|
||||
if (container.has(toolStats.toolStatsKeys.getLogsStripped(), PersistentDataType.INTEGER)) {
|
||||
logsStripped = container.get(toolStats.toolStatsKeys.getLogsStripped(), PersistentDataType.INTEGER);
|
||||
}
|
||||
|
||||
if (logsStripped == null) {
|
||||
logsStripped = 0;
|
||||
toolStats.logger.warn("{} does not have valid logs-stripped set! Resting to zero. This should NEVER happen.", clone);
|
||||
}
|
||||
|
||||
container.set(toolStats.toolStatsKeys.getLogsStripped(), PersistentDataType.INTEGER, logsStripped + add);
|
||||
String oldLogsStrippedFormatted = toolStats.numberFormat.formatInt(logsStripped);
|
||||
String newLogsStrippedFormatted = toolStats.numberFormat.formatInt(logsStripped + add);
|
||||
Component oldLine = toolStats.configTools.formatLore("logs-stripped", "{logs}", oldLogsStrippedFormatted);
|
||||
Component newLine = toolStats.configTools.formatLore("logs-stripped", "{logs}", newLogsStrippedFormatted);
|
||||
if (oldLine == null || newLine == null) {
|
||||
return null;
|
||||
}
|
||||
List<Component> newLore = updateItemLore(meta, oldLine, newLine);
|
||||
meta.lore(newLore);
|
||||
return meta;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the item owner lore.
|
||||
*
|
||||
@@ -1667,6 +1765,26 @@ public class ItemLore {
|
||||
finalItem.setItemMeta(meta);
|
||||
}
|
||||
}
|
||||
if (container.has(toolStats.toolStatsKeys.getTridentThrows())) {
|
||||
Integer tridentThrows = container.get(toolStats.toolStatsKeys.getTridentThrows(), PersistentDataType.INTEGER);
|
||||
if (tridentThrows != null) {
|
||||
container.remove(toolStats.toolStatsKeys.getTridentThrows());
|
||||
String tridentThrowsFormatted = toolStats.numberFormat.formatInt(tridentThrows);
|
||||
Component lineToRemove = toolStats.configTools.formatLore("trident-throws", "{times}", tridentThrowsFormatted);
|
||||
meta.lore(removeLore(meta.lore(), lineToRemove));
|
||||
finalItem.setItemMeta(meta);
|
||||
}
|
||||
}
|
||||
if (container.has(toolStats.toolStatsKeys.getLogsStripped())) {
|
||||
Integer logsStripped = container.get(toolStats.toolStatsKeys.getLogsStripped(), PersistentDataType.INTEGER);
|
||||
if (logsStripped != null) {
|
||||
container.remove(toolStats.toolStatsKeys.getLogsStripped());
|
||||
String logsStrippedFormatted = toolStats.numberFormat.formatInt(logsStripped);
|
||||
Component lineToRemove = toolStats.configTools.formatLore("logs-stripped", "{logs}", logsStrippedFormatted);
|
||||
meta.lore(removeLore(meta.lore(), lineToRemove));
|
||||
finalItem.setItemMeta(meta);
|
||||
}
|
||||
}
|
||||
if (removeMeta) {
|
||||
Integer origin = null;
|
||||
if (container.has(toolStats.toolStatsKeys.getOriginType())) {
|
||||
|
||||
Reference in New Issue
Block a user