Compare commits

...

11 Commits
1.8.2 ... 1.8.3

Author SHA1 Message Date
hyperdefined
50b5823daf remove debug 2024-10-07 21:19:21 -04:00
hyperdefined
c87d0ca3bf Update pom.xml 2024-10-07 21:18:52 -04:00
hyperdefined
d1a16ff2e6 added missing breaks 2024-10-07 21:18:02 -04:00
hyperdefined
9134da31f4 support for mace #82 2024-10-07 21:16:07 -04:00
hyperdefined
0cf85edda6 support for custom mob names
closes #71
2024-10-07 21:05:46 -04:00
hyperdefined
7fe0234785 fix for older MC versions
fixes #81
2024-10-05 18:37:51 -04:00
hyperdefined
6385814b52 Merge pull request #80 from hyperdefined/dependabot/maven/org.bstats-bstats-bukkit-3.1.0
Bump org.bstats:bstats-bukkit from 3.0.3 to 3.1.0
2024-10-05 18:10:25 -04:00
hyperdefined
603e1ac1fd fix #79 2024-09-25 19:50:26 -04:00
dependabot[bot]
86dc5f421a Bump org.bstats:bstats-bukkit from 3.0.3 to 3.1.0
Bumps [org.bstats:bstats-bukkit](https://github.com/Bastian/bStats-Metrics) from 3.0.3 to 3.1.0.
- [Release notes](https://github.com/Bastian/bStats-Metrics/releases)
- [Commits](https://github.com/Bastian/bStats-Metrics/compare/v3.0.3...v3.1.0)

---
updated-dependencies:
- dependency-name: org.bstats:bstats-bukkit
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-09-23 11:36:47 +00:00
hyperdefined
7d9be0cfd1 Update README.md 2024-09-10 17:19:15 -04:00
hyperdefined
f7bacec617 Update README.md 2024-09-10 17:17:51 -04:00
12 changed files with 151 additions and 32 deletions

View File

@@ -6,6 +6,7 @@
<a href="https://github.com/hyperdefined/ToolStats/releases"><img src="https://img.shields.io/github/downloads/hyperdefined/ToolStats/total?logo=github" alt="Downloads"></a> <a href="https://github.com/hyperdefined/ToolStats/releases"><img src="https://img.shields.io/github/downloads/hyperdefined/ToolStats/total?logo=github" alt="Downloads"></a>
<img src="https://img.shields.io/badge/made%20with-love%20&%20fluff-red" alt="Made with love & fluff"> <img src="https://img.shields.io/badge/made%20with-love%20&%20fluff-red" alt="Made with love & fluff">
<a href="https://ko-fi.com/hyperdefined"><img src="https://img.shields.io/badge/Donate-Ko--fi-red" alt="Donate via Ko-fi"></a> <a href="https://ko-fi.com/hyperdefined"><img src="https://img.shields.io/badge/Donate-Ko--fi-red" alt="Donate via Ko-fi"></a>
<img alt="Discord" src="https://img.shields.io/discord/1267600843356639413?style=flat&logo=discord&label=Discord">
<a href="https://www.gnu.org/licenses/gpl-3.0"><img src="https://img.shields.io/badge/License-GPLv3-blue.svg" alt="License: GPL v3"></a> <a href="https://www.gnu.org/licenses/gpl-3.0"><img src="https://img.shields.io/badge/License-GPLv3-blue.svg" alt="License: GPL v3"></a>
<a href="https://wakatime.com/badge/user/992a7647-176a-477c-8086-e1abfba87ff4/project/0200f07a-f303-4103-a5f2-34b38c9c1fa4"><img src="https://wakatime.com/badge/user/992a7647-176a-477c-8086-e1abfba87ff4/project/0200f07a-f303-4103-a5f2-34b38c9c1fa4.svg" alt="wakatime"></a> <a href="https://wakatime.com/badge/user/992a7647-176a-477c-8086-e1abfba87ff4/project/0200f07a-f303-4103-a5f2-34b38c9c1fa4"><img src="https://wakatime.com/badge/user/992a7647-176a-477c-8086-e1abfba87ff4/project/0200f07a-f303-4103-a5f2-34b38c9c1fa4.svg" alt="wakatime"></a>
</p> </p>
@@ -42,5 +43,8 @@ If item lore is ever incorrect/missing, you can run `/toolstats reset`. This com
## Documentation ## Documentation
Visit the [wiki](https://github.com/hyperdefined/ToolStats/wiki) for help. Visit the [wiki](https://github.com/hyperdefined/ToolStats/wiki) for help.
## Support
You can join the [Discord](https://discord.gg/rJuQXVcJz8) for support.
## License ## License
This plugin is released under GNU General Public License v3. See [LICENSE](https://github.com/hyperdefined/ToolStats/blob/master/LICENSE). This plugin is released under GNU General Public License v3. See [LICENSE](https://github.com/hyperdefined/ToolStats/blob/master/LICENSE).

View File

@@ -23,7 +23,7 @@
<groupId>lol.hyper</groupId> <groupId>lol.hyper</groupId>
<artifactId>toolstats</artifactId> <artifactId>toolstats</artifactId>
<version>1.8.2</version> <version>1.8.3</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>ToolStats</name> <name>ToolStats</name>
@@ -123,7 +123,7 @@
<dependency> <dependency>
<groupId>org.bstats</groupId> <groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId> <artifactId>bstats-bukkit</artifactId>
<version>3.0.3</version> <version>3.1.0</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@@ -113,7 +113,7 @@ public final class ToolStats extends JavaPlugin {
*/ */
public final NamespacedKey originType = new NamespacedKey(this, "origin"); public final NamespacedKey originType = new NamespacedKey(this, "origin");
public final int CONFIG_VERSION = 7; public final int CONFIG_VERSION = 8;
public final Logger logger = this.getLogger(); public final Logger logger = this.getLogger();
public final File configFile = new File(this.getDataFolder(), "config.yml"); public final File configFile = new File(this.getDataFolder(), "config.yml");

View File

@@ -39,7 +39,7 @@ public class EntityDamage implements Listener {
private final ToolStats toolStats; private final ToolStats toolStats;
public final Set<UUID> trackedMobs = new HashSet<>(); public final Set<UUID> trackedMobs = new HashSet<>();
private final List<EntityDamageEvent.DamageCause> ignoredCauses = Arrays.asList(EntityDamageEvent.DamageCause.SUICIDE, EntityDamageEvent.DamageCause.VOID, EntityDamageEvent.DamageCause.CUSTOM, EntityDamageEvent.DamageCause.KILL); private final List<String> ignoredDamageCauses = Arrays.asList("SUICIDE", "VOID", "CUSTOM", "KILL");
public EntityDamage(ToolStats toolStats) { public EntityDamage(ToolStats toolStats) {
this.toolStats = toolStats; this.toolStats = toolStats;
@@ -57,8 +57,8 @@ public class EntityDamage implements Listener {
LivingEntity mobBeingAttacked = (LivingEntity) event.getEntity(); LivingEntity mobBeingAttacked = (LivingEntity) event.getEntity();
// ignore void and /kill damage // ignore void and /kill damage
EntityDamageEvent.DamageCause cause = event.getCause(); String cause = event.getCause().toString().toUpperCase();
if (ignoredCauses.contains(cause)) { if (ignoredDamageCauses.contains(cause)) {
return; return;
} }
@@ -166,8 +166,8 @@ public class EntityDamage implements Listener {
} }
// ignore void and /kill damage // ignore void and /kill damage
EntityDamageEvent.DamageCause cause = event.getCause(); String cause = event.getCause().toString().toUpperCase();
if (ignoredCauses.contains(cause)) { if (ignoredDamageCauses.contains(cause)) {
return; return;
} }
@@ -196,8 +196,8 @@ public class EntityDamage implements Listener {
} }
// ignore void and /kill damage // ignore void and /kill damage
EntityDamageEvent.DamageCause cause = event.getCause(); String cause = event.getCause().toString().toUpperCase();
if (ignoredCauses.contains(cause)) { if (ignoredDamageCauses.contains(cause)) {
return; return;
} }

View File

@@ -29,7 +29,8 @@ import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataContainer; import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.persistence.PersistentDataType; import org.bukkit.persistence.PersistentDataType;
import java.util.*; import java.util.List;
import java.util.UUID;
public class EntityDeath implements Listener { public class EntityDeath implements Listener {
@@ -53,13 +54,13 @@ public class EntityDeath implements Listener {
ItemMeta droppedItemMeta = droppedItem.getItemMeta(); ItemMeta droppedItemMeta = droppedItem.getItemMeta();
if (droppedItemMeta != null) { if (droppedItemMeta != null) {
PersistentDataContainer container = droppedItemMeta.getPersistentDataContainer(); PersistentDataContainer container = droppedItemMeta.getPersistentDataContainer();
if (container.has(toolStats.timeCreated, PersistentDataType.LONG)) { if (container.has(toolStats.originType, PersistentDataType.INTEGER)) {
continue; // ignore any items that have our tags continue; // ignore any items that have our tags
} }
} }
if (toolStats.itemChecker.isValidItem(droppedItem.getType())) { if (toolStats.itemChecker.isValidItem(droppedItem.getType())) {
ItemStack newItem = addLore(droppedItem, livingEntity.getName()); ItemStack newItem = addLore(droppedItem, livingEntity);
if (newItem != null) { if (newItem != null) {
event.getDrops().set(i, newItem); event.getDrops().set(i, newItem);
} }
@@ -73,9 +74,9 @@ public class EntityDeath implements Listener {
* Adds "drop by" tag to item. * Adds "drop by" tag to item.
* *
* @param oldItem The item to add lore to. * @param oldItem The item to add lore to.
* @param mob The mob or player name. * @param entity The mob dying.
*/ */
private ItemStack addLore(ItemStack oldItem, String mob) { private ItemStack addLore(ItemStack oldItem, LivingEntity entity) {
ItemStack newItem = oldItem.clone(); ItemStack newItem = oldItem.clone();
ItemMeta meta = newItem.getItemMeta(); ItemMeta meta = newItem.getItemMeta();
if (meta == null) { if (meta == null) {
@@ -86,7 +87,11 @@ public class EntityDeath implements Listener {
container.set(toolStats.originType, PersistentDataType.INTEGER, 1); container.set(toolStats.originType, PersistentDataType.INTEGER, 1);
if (toolStats.config.getBoolean("enabled.dropped-by")) { if (toolStats.config.getBoolean("enabled.dropped-by")) {
String newLine = toolStats.configTools.formatLore("dropped-by", "{name}", mob); String mobName = toolStats.config.getString("messages.mob." + entity.getType());
if (mobName == null) {
mobName = entity.getName();
}
String newLine = toolStats.configTools.formatLore("dropped-by", "{name}", mobName);
List<String> newLore = toolStats.itemLore.addItemLore(meta, newLine); List<String> newLore = toolStats.itemLore.addItemLore(meta, newLine);
meta.setLore(newLore); meta.setLore(newLore);
} }

View File

@@ -64,15 +64,14 @@ public class SheepShear implements Listener {
return; return;
} }
Sheep sheep = (Sheep) entity;
// make sure the sheep is not sheared // make sure the sheep is not sheared
Sheep sheep = (Sheep) entity;
if (sheep.isSheared()) { if (sheep.isSheared()) {
return; return;
} }
// update the stats // update the stats
ItemStack finalShears = shears; addLore(shears);
addLore(finalShears);
} }
private static @Nullable ItemStack getShears(Player player) { private static @Nullable ItemStack getShears(Player player) {

View File

@@ -47,6 +47,9 @@ public class ItemChecker {
if (lowerCase.contains("_helmet") || lowerCase.contains("_chestplate") || lowerCase.contains("_leggings") || lowerCase.contains("_boots")) { if (lowerCase.contains("_helmet") || lowerCase.contains("_chestplate") || lowerCase.contains("_leggings") || lowerCase.contains("_boots")) {
armorItems.add(material); armorItems.add(material);
} }
if (lowerCase.equalsIgnoreCase("mace")) {
meleeItems.add(material);
}
} }
// hardcode these // hardcode these

View File

@@ -99,6 +99,9 @@ public class ConfigTools {
case "fishing-rod": { case "fishing-rod": {
return toolStats.config.getBoolean("enabled." + configName + ".fishing-rod"); return toolStats.config.getBoolean("enabled." + configName + ".fishing-rod");
} }
case "mace": {
return toolStats.config.getBoolean("enabled." + configName + ".mace");
}
case "helmet": case "helmet":
case "chestplate": case "chestplate":
case "leggings": case "leggings":

View File

@@ -37,6 +37,7 @@ package lol.hyper.toolstats.tools.config;
import lol.hyper.toolstats.ToolStats; import lol.hyper.toolstats.ToolStats;
import lol.hyper.toolstats.tools.config.versions.Version6; import lol.hyper.toolstats.tools.config.versions.Version6;
import lol.hyper.toolstats.tools.config.versions.Version7; import lol.hyper.toolstats.tools.config.versions.Version7;
import lol.hyper.toolstats.tools.config.versions.Version8;
public class ConfigUpdater { public class ConfigUpdater {
@@ -49,17 +50,25 @@ public class ConfigUpdater {
public void updateConfig() { public void updateConfig() {
int version = toolStats.config.getInt("config-version"); int version = toolStats.config.getInt("config-version");
// this will be a switch in the future switch(version) {
// Upgrade 5 to 6 case 5: {
if (version == 5) { // Version 5 to 6
Version6 version6 = new Version6(toolStats); Version6 version6 = new Version6(toolStats);
version6.update(); version6.update();
} break;
}
// Upgrade 6 to 7 case 6: {
if (version == 6) { // Version 6 to 7
Version7 version7 = new Version7(toolStats); Version7 version7 = new Version7(toolStats);
version7.update(); version7.update();
break;
}
case 7: {
// Version 7 to 8
Version8 version8 = new Version8(toolStats);
version8.update();
break;
}
} }
} }
} }

View File

@@ -43,7 +43,7 @@ public class Version7 {
try { try {
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config-6.yml"); toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config-6.yml");
} catch (IOException exception) { } catch (IOException exception) {
toolStats.logger.severe("Unable to save config-5.yml!"); toolStats.logger.severe("Unable to save config-6.yml!");
throw new RuntimeException(exception); throw new RuntimeException(exception);
} }
@@ -65,6 +65,6 @@ public class Version7 {
throw new RuntimeException(exception); throw new RuntimeException(exception);
} }
toolStats.loadConfig(); toolStats.loadConfig();
toolStats.logger.info("Config has been updated to version 7. A copy of version 5 has been saved as config-6.yml"); toolStats.logger.info("Config has been updated to version 7. A copy of version 6 has been saved as config-6.yml");
} }
} }

View File

@@ -0,0 +1,88 @@
/*
* This file is part of ToolStats.
*
* ToolStats is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ToolStats is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ToolStats. If not, see <https://www.gnu.org/licenses/>.
*/
package lol.hyper.toolstats.tools.config.versions;
import lol.hyper.toolstats.ToolStats;
import org.bukkit.configuration.ConfigurationSection;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class Version8 {
private final ToolStats toolStats;
/**
* Used for updating from version 7 to 8.
*
* @param toolStats ToolStats instance.
*/
public Version8(ToolStats toolStats) {
this.toolStats = toolStats;
}
/**
* Perform the config update.
*/
public void update() {
// save the old config first
try {
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config-7.yml");
} catch (IOException exception) {
toolStats.logger.severe("Unable to save config-7.yml!");
throw new RuntimeException(exception);
}
// we make this super verbose so that admins can see what's being added
toolStats.logger.info("Updating config.yml to version 8.");
toolStats.config.set("config-version", 8);
// Add example to setting mob names
toolStats.logger.info("Adding example for messages.mob.ZOMBIE");
toolStats.config.set("messages.mob.ZOMBIE", "Zombie");
// Add mace to enabled sections
toolStats.logger.info("Adding entry for enabled.created-by.mace");
toolStats.config.set("enabled.created-by.mace", true);
toolStats.logger.info("Adding entry for enabled.created-date.mace");
toolStats.config.set("enabled.created-date.mace", true);
toolStats.logger.info("Adding entry for enabled.player-kills.mace");
toolStats.config.set("enabled.player-kills.mace", true);
toolStats.logger.info("Adding entry for enabled.mob-kills.mace");
toolStats.config.set("enabled.mob-kills.mace", true);
List<String> mobComments = new ArrayList<>();
mobComments.add("Set display name for mobs. See: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/entity/EntityType.html");
toolStats.config.setComments("messages.mob", mobComments);
// save the config and reload it
try {
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config.yml");
} catch (IOException exception) {
toolStats.logger.severe("Unable to save config.yml!");
throw new RuntimeException(exception);
}
toolStats.loadConfig();
toolStats.logger.info("Config has been updated to version 8. A copy of version 7 has been saved as config-7.yml");
}
}

View File

@@ -9,6 +9,7 @@ enabled:
shears: true shears: true
bow: true bow: true
armor: true armor: true
mace: true
# Will show time the item is created # Will show time the item is created
created-date: created-date:
pickaxe: true pickaxe: true
@@ -19,6 +20,7 @@ enabled:
shears: true shears: true
bow: true bow: true
armor: true armor: true
mace: true
# Will show "Fished by <player>" # Will show "Fished by <player>"
fished-tag: fished-tag:
pickaxe: true pickaxe: true
@@ -54,11 +56,13 @@ enabled:
axe: true axe: true
trident: true trident: true
bow: true bow: true
mace: true
mob-kills: mob-kills:
sword: true sword: true
axe: true axe: true
trident: true trident: true
bow: true bow: true
mace: true
blocks-mined: blocks-mined:
pickaxe: true pickaxe: true
shovel: true shovel: true
@@ -75,6 +79,7 @@ enabled:
shears: true shears: true
bow: true bow: true
armor: true armor: true
mace: true
fish-caught: true fish-caught: true
sheep-sheared: true sheep-sheared: true
armor-damage: true armor-damage: true
@@ -117,6 +122,9 @@ messages:
shift-click-warning: shift-click-warning:
crafting: "&cCrafting items via shift clicking does not fully apply tags to each item. This is a limitation with the Bukkit API." crafting: "&cCrafting items via shift clicking does not fully apply tags to each item. This is a limitation with the Bukkit API."
trading: "&cTrading items via shift clicking does not fully apply tags to each item. This is a limitation with the Bukkit API." trading: "&cTrading items via shift clicking does not fully apply tags to each item. This is a limitation with the Bukkit API."
# Set display name for mobs. See: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/entity/EntityType.html
mobs:
ZOMBIE: "Zombie"
# Change the default formatting for dates. # Change the default formatting for dates.
# See: https://www.digitalocean.com/community/tutorials/java-simpledateformat-java-date-format # See: https://www.digitalocean.com/community/tutorials/java-simpledateformat-java-date-format