mirror of
https://github.com/hyperdefined/ToolStats.git
synced 2026-01-29 08:46:00 +00:00
add critical strikes
This commit is contained in:
@@ -406,6 +406,14 @@ public class CommandToolStats implements TabExecutor {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (toolStats.config.getBoolean("enabled.critical-strikes")) {
|
||||
if (container.has(toolStats.criticalStrikes, PersistentDataType.INTEGER)) {
|
||||
Integer strikes = container.get(toolStats.criticalStrikes, PersistentDataType.INTEGER);
|
||||
if (strikes != null) {
|
||||
lore.add(toolStats.configTools.formatLore("critical-strikes", "{strikes}", toolStats.numberFormat.formatInt(strikes)));
|
||||
}
|
||||
}
|
||||
}
|
||||
finalMeta.lore(lore);
|
||||
finalItem.setItemMeta(finalMeta);
|
||||
int slot = player.getInventory().getHeldItemSlot();
|
||||
@@ -788,6 +796,35 @@ public class CommandToolStats implements TabExecutor {
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "critical-strikes": {
|
||||
if (!toolStats.config.getBoolean("enabled.critical-strikes")) {
|
||||
player.sendMessage(Component.text("This stat is disabled.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
if (container.has(toolStats.criticalStrikes)) {
|
||||
int value;
|
||||
try {
|
||||
value = Integer.parseInt((String) userValue);
|
||||
} catch (NumberFormatException exception) {
|
||||
player.sendMessage(Component.text("That is not a valid number.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
if (value < 0) {
|
||||
player.sendMessage(Component.text("Number must be positive.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
Integer statValue = container.get(toolStats.criticalStrikes, PersistentDataType.INTEGER);
|
||||
if (statValue == null) {
|
||||
player.sendMessage(Component.text("Unable to get stat from item.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
int difference = value - statValue;
|
||||
editedItemMeta = toolStats.itemLore.updateCriticalStrikes(editedItem, difference);
|
||||
} else {
|
||||
player.sendMessage(Component.text("This item does not have that stat.", NamedTextColor.RED));
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
player.sendMessage(Component.text("That is not a valid stat to update.", NamedTextColor.RED));
|
||||
return;
|
||||
@@ -1122,6 +1159,34 @@ public class CommandToolStats implements TabExecutor {
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "critical-strikes": {
|
||||
if (container.has(toolStats.criticalStrikes)) {
|
||||
Integer statValue = container.get(toolStats.criticalStrikes, PersistentDataType.INTEGER);
|
||||
if (statValue == null) {
|
||||
player.sendMessage(Component.text("Unable to get stat from item.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
String tokens = container.get(toolStats.tokenApplied, PersistentDataType.STRING);
|
||||
if (tokens == null) {
|
||||
player.sendMessage(Component.text("Unable to get tokens from item.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
container.remove(toolStats.criticalStrikes);
|
||||
List<String> newTokens = toolStats.itemChecker.removeToken(tokens, "critical-strikes");
|
||||
if (newTokens.isEmpty()) {
|
||||
container.remove(toolStats.tokenApplied);
|
||||
} else {
|
||||
container.set(toolStats.tokenApplied, PersistentDataType.STRING, String.join(",", newTokens));
|
||||
}
|
||||
|
||||
Component oldLine = toolStats.configTools.formatLore("critical-strikes", "{strikes}", toolStats.numberFormat.formatInt(statValue));
|
||||
List<Component> newLore = toolStats.itemLore.removeLore(editedItemMeta.lore(), oldLine);
|
||||
editedItemMeta.lore(newLore);
|
||||
} else {
|
||||
player.sendMessage(Component.text("This item does not have that stat.", NamedTextColor.RED));
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
player.sendMessage(Component.text("That is not a valid stat to update.", NamedTextColor.RED));
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user