Compare commits

...

3 Commits

Author SHA1 Message Date
hyperdefined
a0282e67c1 improvements to main command
* fix logic with the edit command
* improved command suggestions
2026-03-06 17:03:29 -05:00
hyperdefined
bb33f4031a 2.0.1 2026-03-06 16:42:19 -05:00
hyperdefined
91331965f1 fix typo on fish-caught edit 2026-03-05 18:10:41 -05:00
2 changed files with 39 additions and 7 deletions

View File

@@ -23,7 +23,7 @@
<groupId>lol.hyper</groupId> <groupId>lol.hyper</groupId>
<artifactId>toolstats</artifactId> <artifactId>toolstats</artifactId>
<version>2.0</version> <version>2.0.1</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>ToolStats</name> <name>ToolStats</name>

View File

@@ -450,6 +450,7 @@ public class CommandToolStats implements BasicCommand {
* @param player The player using the command. * @param player The player using the command.
*/ */
private void handleEdit(String stat, Object userValue, Player player) { private void handleEdit(String stat, Object userValue, Player player) {
boolean updated = false;
ItemStack editedItem = player.getInventory().getItemInMainHand().clone(); ItemStack editedItem = player.getInventory().getItemInMainHand().clone();
if (!toolStats.itemChecker.isValidItem(editedItem.getType())) { if (!toolStats.itemChecker.isValidItem(editedItem.getType())) {
player.sendMessage(Component.text("This is not a valid item.", NamedTextColor.RED)); player.sendMessage(Component.text("This is not a valid item.", NamedTextColor.RED));
@@ -482,6 +483,7 @@ public class CommandToolStats implements BasicCommand {
} }
int difference = value - statValue; int difference = value - statValue;
editedItemMeta = toolStats.itemLore.updateCropsMined(editedItem, difference); editedItemMeta = toolStats.itemLore.updateCropsMined(editedItem, difference);
updated = true;
} else { } else {
player.sendMessage(Component.text("This item does not have that stat.", NamedTextColor.RED)); player.sendMessage(Component.text("This item does not have that stat.", NamedTextColor.RED));
} }
@@ -511,6 +513,7 @@ public class CommandToolStats implements BasicCommand {
} }
int difference = value - statValue; int difference = value - statValue;
editedItemMeta = toolStats.itemLore.updateBlocksMined(editedItem, difference); editedItemMeta = toolStats.itemLore.updateBlocksMined(editedItem, difference);
updated = true;
} else { } else {
player.sendMessage(Component.text("This item does not have that stat.", NamedTextColor.RED)); player.sendMessage(Component.text("This item does not have that stat.", NamedTextColor.RED));
} }
@@ -540,6 +543,7 @@ public class CommandToolStats implements BasicCommand {
} }
double difference = value - statValue; double difference = value - statValue;
editedItemMeta = toolStats.itemLore.updateArmorDamage(editedItem, difference, false); editedItemMeta = toolStats.itemLore.updateArmorDamage(editedItem, difference, false);
updated = true;
} else { } else {
player.sendMessage(Component.text("This item does not have that stat.", NamedTextColor.RED)); player.sendMessage(Component.text("This item does not have that stat.", NamedTextColor.RED));
} }
@@ -569,6 +573,7 @@ public class CommandToolStats implements BasicCommand {
} }
double difference = value - statValue; double difference = value - statValue;
editedItemMeta = toolStats.itemLore.updateWeaponDamage(editedItem, difference, false); editedItemMeta = toolStats.itemLore.updateWeaponDamage(editedItem, difference, false);
updated = true;
} else { } else {
player.sendMessage(Component.text("This item does not have that stat.", NamedTextColor.RED)); player.sendMessage(Component.text("This item does not have that stat.", NamedTextColor.RED));
} }
@@ -598,6 +603,7 @@ public class CommandToolStats implements BasicCommand {
} }
int difference = value - statValue; int difference = value - statValue;
editedItemMeta = toolStats.itemLore.updateMobKills(editedItem, difference); editedItemMeta = toolStats.itemLore.updateMobKills(editedItem, difference);
updated = true;
} else { } else {
player.sendMessage(Component.text("This item does not have that stat.", NamedTextColor.RED)); player.sendMessage(Component.text("This item does not have that stat.", NamedTextColor.RED));
} }
@@ -627,6 +633,7 @@ public class CommandToolStats implements BasicCommand {
} }
int difference = value - statValue; int difference = value - statValue;
editedItemMeta = toolStats.itemLore.updatePlayerKills(editedItem, difference); editedItemMeta = toolStats.itemLore.updatePlayerKills(editedItem, difference);
updated = true;
} else { } else {
player.sendMessage(Component.text("This item does not have that stat.", NamedTextColor.RED)); player.sendMessage(Component.text("This item does not have that stat.", NamedTextColor.RED));
} }
@@ -656,6 +663,7 @@ public class CommandToolStats implements BasicCommand {
} }
int difference = value - statValue; int difference = value - statValue;
editedItemMeta = toolStats.itemLore.updateArrowsShot(editedItem, difference); editedItemMeta = toolStats.itemLore.updateArrowsShot(editedItem, difference);
updated = true;
} else { } else {
player.sendMessage(Component.text("This item does not have that stat.", NamedTextColor.RED)); player.sendMessage(Component.text("This item does not have that stat.", NamedTextColor.RED));
} }
@@ -685,6 +693,7 @@ public class CommandToolStats implements BasicCommand {
} }
int difference = value - statValue; int difference = value - statValue;
editedItemMeta = toolStats.itemLore.updateSheepSheared(editedItem, difference); editedItemMeta = toolStats.itemLore.updateSheepSheared(editedItem, difference);
updated = true;
} else { } else {
player.sendMessage(Component.text("This item does not have that stat.", NamedTextColor.RED)); player.sendMessage(Component.text("This item does not have that stat.", NamedTextColor.RED));
} }
@@ -714,6 +723,7 @@ public class CommandToolStats implements BasicCommand {
} }
long difference = value - statValue; long difference = value - statValue;
editedItemMeta = toolStats.itemLore.updateFlightTime(editedItem, difference); editedItemMeta = toolStats.itemLore.updateFlightTime(editedItem, difference);
updated = true;
} else { } else {
player.sendMessage(Component.text("This item does not have that stat.", NamedTextColor.RED)); player.sendMessage(Component.text("This item does not have that stat.", NamedTextColor.RED));
} }
@@ -743,6 +753,7 @@ public class CommandToolStats implements BasicCommand {
} }
int difference = value - statValue; int difference = value - statValue;
editedItemMeta = toolStats.itemLore.updateFishCaught(editedItem, difference); editedItemMeta = toolStats.itemLore.updateFishCaught(editedItem, difference);
updated = true;
} else { } else {
player.sendMessage(Component.text("This item does not have that stat.", NamedTextColor.RED)); player.sendMessage(Component.text("This item does not have that stat.", NamedTextColor.RED));
} }
@@ -772,6 +783,7 @@ public class CommandToolStats implements BasicCommand {
} }
int difference = value - statValue; int difference = value - statValue;
editedItemMeta = toolStats.itemLore.updateBossesKilled(editedItem, difference, "wither"); editedItemMeta = toolStats.itemLore.updateBossesKilled(editedItem, difference, "wither");
updated = true;
} else { } else {
player.sendMessage(Component.text("This item does not have that stat.", NamedTextColor.RED)); player.sendMessage(Component.text("This item does not have that stat.", NamedTextColor.RED));
} }
@@ -801,6 +813,7 @@ public class CommandToolStats implements BasicCommand {
} }
int difference = value - statValue; int difference = value - statValue;
editedItemMeta = toolStats.itemLore.updateBossesKilled(editedItem, difference, "enderdragon"); editedItemMeta = toolStats.itemLore.updateBossesKilled(editedItem, difference, "enderdragon");
updated = true;
} else { } else {
player.sendMessage(Component.text("This item does not have that stat.", NamedTextColor.RED)); player.sendMessage(Component.text("This item does not have that stat.", NamedTextColor.RED));
} }
@@ -830,6 +843,7 @@ public class CommandToolStats implements BasicCommand {
} }
int difference = value - statValue; int difference = value - statValue;
editedItemMeta = toolStats.itemLore.updateCriticalStrikes(editedItem, difference); editedItemMeta = toolStats.itemLore.updateCriticalStrikes(editedItem, difference);
updated = true;
} else { } else {
player.sendMessage(Component.text("This item does not have that stat.", NamedTextColor.RED)); player.sendMessage(Component.text("This item does not have that stat.", NamedTextColor.RED));
} }
@@ -859,6 +873,7 @@ public class CommandToolStats implements BasicCommand {
} }
int difference = value - statValue; int difference = value - statValue;
editedItemMeta = toolStats.itemLore.updateTridentThrows(editedItem, difference); editedItemMeta = toolStats.itemLore.updateTridentThrows(editedItem, difference);
updated = true;
} else { } else {
player.sendMessage(Component.text("This item does not have that stat.", NamedTextColor.RED)); player.sendMessage(Component.text("This item does not have that stat.", NamedTextColor.RED));
} }
@@ -869,10 +884,13 @@ public class CommandToolStats implements BasicCommand {
return; return;
} }
} }
if (updated) {
editedItem.setItemMeta(editedItemMeta); editedItem.setItemMeta(editedItemMeta);
player.getInventory().setItemInMainHand(editedItem); player.getInventory().setItemInMainHand(editedItem);
player.sendMessage(Component.text("Updated stat " + stat + " for held item!", NamedTextColor.GREEN)); player.sendMessage(Component.text("Updated stat " + stat + " for held item!", NamedTextColor.GREEN));
} }
}
/** /**
* Handle remove subcommand. * Handle remove subcommand.
@@ -1114,7 +1132,7 @@ public class CommandToolStats implements BasicCommand {
} }
break; break;
} }
case "fight-caught": { case "fish-caught": {
if (container.has(toolStats.toolStatsKeys.getFishCaught())) { if (container.has(toolStats.toolStatsKeys.getFishCaught())) {
Integer statValue = container.get(toolStats.toolStatsKeys.getFishCaught(), PersistentDataType.INTEGER); Integer statValue = container.get(toolStats.toolStatsKeys.getFishCaught(), PersistentDataType.INTEGER);
if (statValue == null) { if (statValue == null) {
@@ -1127,7 +1145,7 @@ public class CommandToolStats implements BasicCommand {
return; return;
} }
container.remove(toolStats.toolStatsKeys.getFishCaught()); container.remove(toolStats.toolStatsKeys.getFishCaught());
List<String> newTokens = toolStats.itemChecker.removeToken(tokens, "fight-caught"); List<String> newTokens = toolStats.itemChecker.removeToken(tokens, "fish-caught");
if (newTokens.isEmpty()) { if (newTokens.isEmpty()) {
container.remove(toolStats.toolStatsKeys.getTokenApplied()); container.remove(toolStats.toolStatsKeys.getTokenApplied());
} else { } else {
@@ -1267,7 +1285,8 @@ public class CommandToolStats implements BasicCommand {
@Override @Override
public @NonNull Collection<String> suggest(@NonNull CommandSourceStack source, String[] args) { public @NonNull Collection<String> suggest(@NonNull CommandSourceStack source, String[] args) {
CommandSender sender = source.getSender(); CommandSender sender = source.getSender();
if (args.length == 1) { // suggest basic sub commands
if (args.length == 0) {
List<String> suggestions = new ArrayList<>(); List<String> suggestions = new ArrayList<>();
if (sender.hasPermission("toolstats.reload")) { if (sender.hasPermission("toolstats.reload")) {
suggestions.add("reload"); suggestions.add("reload");
@@ -1290,12 +1309,16 @@ public class CommandToolStats implements BasicCommand {
return suggestions; return suggestions;
} }
// suggest confirm for reset
if (args.length == 2 && args[0].equalsIgnoreCase("reset") && sender.hasPermission("toolstats.reset.confirm")) { if (args.length == 2 && args[0].equalsIgnoreCase("reset") && sender.hasPermission("toolstats.reset.confirm")) {
return Collections.singletonList("confirm"); return Collections.singletonList("confirm");
} }
// suggest confirm for purge
if (args.length == 2 && args[0].equalsIgnoreCase("purge") && sender.hasPermission("toolstats.purge.confirm")) { if (args.length == 2 && args[0].equalsIgnoreCase("purge") && sender.hasPermission("toolstats.purge.confirm")) {
return Collections.singletonList("confirm"); return Collections.singletonList("confirm");
} }
// suggest keys for edit
if (args.length == 2 && args[0].equalsIgnoreCase("edit") && sender.hasPermission("toolstats.edit")) { if (args.length == 2 && args[0].equalsIgnoreCase("edit") && sender.hasPermission("toolstats.edit")) {
// yes I am lazy // yes I am lazy
return toolStats.tokenData.getTokenTypes().stream() return toolStats.tokenData.getTokenTypes().stream()
@@ -1303,6 +1326,8 @@ public class CommandToolStats implements BasicCommand {
.map(s -> s.equals("crops-mined") ? "crops-harvested" : s) .map(s -> s.equals("crops-mined") ? "crops-harvested" : s)
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
// suggest keys for remove
if (args.length == 2 && args[0].equalsIgnoreCase("remove") && sender.hasPermission("toolstats.remove")) { if (args.length == 2 && args[0].equalsIgnoreCase("remove") && sender.hasPermission("toolstats.remove")) {
// yes I am lazy // yes I am lazy
return toolStats.tokenData.getTokenTypes().stream() return toolStats.tokenData.getTokenTypes().stream()
@@ -1310,6 +1335,13 @@ public class CommandToolStats implements BasicCommand {
.map(s -> s.equals("crops-mined") ? "crops-harvested" : s) .map(s -> s.equals("crops-mined") ? "crops-harvested" : s)
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
// suggest players for givetokens
if (args.length == 2 && args[0].equalsIgnoreCase("givetokens") && sender.hasPermission("toolstats.givetokens")) {
return Bukkit.getOnlinePlayers().stream().map(Player::getName).toList();
}
// suggest token types for givetokens
if (args.length == 3 && args[0].equalsIgnoreCase("givetokens") && sender.hasPermission("toolstats.givetokens")) { if (args.length == 3 && args[0].equalsIgnoreCase("givetokens") && sender.hasPermission("toolstats.givetokens")) {
return toolStats.tokenData.getTokenTypes(); return toolStats.tokenData.getTokenTypes();
} }