mirror of
https://github.com/hyperdefined/ToolStats.git
synced 2026-04-23 03:21:22 +00:00
add trident throws
This commit is contained in:
@@ -1315,6 +1315,105 @@ public class ItemLore {
|
||||
return meta;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add x to trident throws.
|
||||
*
|
||||
* @param trident The trident used.
|
||||
*/
|
||||
public ItemMeta updateTridentThrows(ItemStack trident, int add) {
|
||||
ItemStack clone = trident.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.trident-throws")) {
|
||||
if (container.has(toolStats.tridentThrows)) {
|
||||
Integer tridentThrows = container.get(toolStats.tridentThrows, PersistentDataType.INTEGER);
|
||||
if (tridentThrows == null) {
|
||||
return null;
|
||||
}
|
||||
container.remove(toolStats.tridentThrows);
|
||||
// remove the applied token if this stat is disabled
|
||||
if (container.has(toolStats.tokenApplied)) {
|
||||
String appliedTokens = container.get(toolStats.tokenApplied, 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, "trident-throws");
|
||||
if (!newTokens.isEmpty()) {
|
||||
container.set(toolStats.tokenApplied, PersistentDataType.STRING, String.join(",", newTokens));
|
||||
} else {
|
||||
container.remove(toolStats.tokenApplied);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (meta.hasLore()) {
|
||||
String oldTridentThrows = toolStats.numberFormat.formatInt(tridentThrows);
|
||||
Component lineToRemove = toolStats.configTools.formatLore("trident-throws", "{times}", oldTridentThrows);
|
||||
List<Component> newLore = removeLore(meta.lore(), lineToRemove);
|
||||
meta.lore(newLore);
|
||||
}
|
||||
return meta;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// check for tokens
|
||||
boolean validToken = toolStats.itemChecker.checkTokens(container, "trident-throws");
|
||||
// check for tokens
|
||||
if (toolStats.config.getBoolean("tokens.enabled")) {
|
||||
// if the item has stats but no token, add the token
|
||||
if (container.has(toolStats.tridentThrows) && !validToken) {
|
||||
String newTokens = toolStats.itemChecker.addTokensToExisting(clone);
|
||||
if (newTokens != null) {
|
||||
container.set(toolStats.tokenApplied, 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.tokenApplied, PersistentDataType.STRING, newTokens);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Integer tridentThrows = 0;
|
||||
if (container.has(toolStats.tridentThrows, PersistentDataType.INTEGER)) {
|
||||
tridentThrows = container.get(toolStats.tridentThrows, PersistentDataType.INTEGER);
|
||||
}
|
||||
|
||||
if (tridentThrows == null) {
|
||||
tridentThrows = 0;
|
||||
toolStats.logger.warn("{} does not have valid fish-caught set! Resting to zero. This should NEVER happen.", clone);
|
||||
}
|
||||
|
||||
container.set(toolStats.tridentThrows, PersistentDataType.INTEGER, tridentThrows + add);
|
||||
String oldTridentThrowsFormatted = toolStats.numberFormat.formatInt(tridentThrows);
|
||||
String newTridentThrowsFormatted = toolStats.numberFormat.formatInt(tridentThrows + add);
|
||||
Component oldLine = toolStats.configTools.formatLore("trident-throws", "{times}", oldTridentThrowsFormatted);
|
||||
Component newLine = toolStats.configTools.formatLore("trident-throws", "{times}", newTridentThrowsFormatted);
|
||||
if (oldLine == null || newLine == null) {
|
||||
return null;
|
||||
}
|
||||
List<Component> newLore = updateItemLore(meta, oldLine, newLine);
|
||||
meta.lore(newLore);
|
||||
toolStats.logger.info(meta.toString());
|
||||
return meta;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the item owner lore.
|
||||
*
|
||||
|
||||
@@ -146,6 +146,13 @@ public class TokenData {
|
||||
criticalStrikesRecipe.setIngredient('S', Material.GOLDEN_SWORD);
|
||||
recipes.add(criticalStrikesRecipe);
|
||||
|
||||
NamespacedKey tridentThrowsKey = new NamespacedKey(toolStats, "trident-throws-token");
|
||||
ShapedRecipe tridentThrowsRecipe = new ShapedRecipe(tridentThrowsKey, createToken("trident-throws"));
|
||||
tridentThrowsRecipe.shape(" P ", "PSP", " P ");
|
||||
tridentThrowsRecipe.setIngredient('P', Material.PAPER);
|
||||
tridentThrowsRecipe.setIngredient('S', Material.PRISMARINE_SHARD);
|
||||
recipes.add(tridentThrowsRecipe);
|
||||
|
||||
tokenTypes.add("crops-mined");
|
||||
tokenTypes.add("blocks-mined");
|
||||
tokenTypes.add("damage-taken");
|
||||
@@ -161,6 +168,7 @@ public class TokenData {
|
||||
tokenTypes.add("wither-kills");
|
||||
tokenTypes.add("enderdragon-kills");
|
||||
tokenTypes.add("critical-strikes");
|
||||
tokenTypes.add("trident-throws");
|
||||
}
|
||||
|
||||
public Set<ShapedRecipe> getRecipes() {
|
||||
|
||||
Reference in New Issue
Block a user