Compare commits

...

21 Commits
1.3.3 ... 1.4

Author SHA1 Message Date
hyperdefined
d9ad7ebcad shade stuff 2022-06-07 17:58:46 -04:00
hyperdefined
995f80e159 Update plugin.yml 2022-06-06 13:26:05 -04:00
hyperdefined
56850c40d1 Merge pull request #11 from hyperdefined/dependabot/maven/net.kyori-adventure-text-minimessage-4.11.0
Bump adventure-text-minimessage from 4.10.1 to 4.11.0
2022-06-06 13:25:15 -04:00
dependabot[bot]
b9e4bbd1e8 Bump adventure-text-minimessage from 4.10.1 to 4.11.0
Bumps [adventure-text-minimessage](https://github.com/KyoriPowered/adventure) from 4.10.1 to 4.11.0.
- [Release notes](https://github.com/KyoriPowered/adventure/releases)
- [Commits](https://github.com/KyoriPowered/adventure/compare/v4.10.1...v4.11.0)

---
updated-dependencies:
- dependency-name: net.kyori:adventure-text-minimessage
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-06-02 11:28:36 +00:00
hyperdefined
6a23c7a724 version bump 2022-05-10 15:31:52 -04:00
hyperdefined
cd6cb999c0 handle item pickup better 2022-05-10 15:29:53 -04:00
hyperdefined
f9cff275b5 fixed trident lore not being added 2022-05-10 15:27:51 -04:00
hyperdefined
ba1ae01801 use minimessage for various messages 2022-05-10 14:41:01 -04:00
hyperdefined
fd35cf6e9c Update README.md 2022-04-19 18:55:48 -04:00
hyperdefined
5971ecc919 Merge pull request #10 from hyperdefined/dependabot/maven/org.apache.maven.plugins-maven-clean-plugin-3.2.0
Bump maven-clean-plugin from 3.1.0 to 3.2.0
2022-04-06 11:38:22 -04:00
dependabot[bot]
4c4ca0c31e Bump maven-clean-plugin from 3.1.0 to 3.2.0
Bumps [maven-clean-plugin](https://github.com/apache/maven-clean-plugin) from 3.1.0 to 3.2.0.
- [Release notes](https://github.com/apache/maven-clean-plugin/releases)
- [Commits](https://github.com/apache/maven-clean-plugin/compare/maven-clean-plugin-3.1.0...maven-clean-plugin-3.2.0)

---
updated-dependencies:
- dependency-name: org.apache.maven.plugins:maven-clean-plugin
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-04-05 11:24:12 +00:00
hyperdefined
294b753430 Merge pull request #9 from hyperdefined/dependabot/maven/org.apache.maven.plugins-maven-shade-plugin-3.3.0
Bump maven-shade-plugin from 3.2.4 to 3.3.0
2022-03-30 15:11:18 -04:00
dependabot[bot]
adf6a3149b Bump maven-shade-plugin from 3.2.4 to 3.3.0
Bumps [maven-shade-plugin](https://github.com/apache/maven-shade-plugin) from 3.2.4 to 3.3.0.
- [Release notes](https://github.com/apache/maven-shade-plugin/releases)
- [Commits](https://github.com/apache/maven-shade-plugin/compare/maven-shade-plugin-3.2.4...maven-shade-plugin-3.3.0)

---
updated-dependencies:
- dependency-name: org.apache.maven.plugins:maven-shade-plugin
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-03-30 11:32:46 +00:00
hyperdefined
ea68650038 Merge pull request #8 from hyperdefined/dependabot/maven/org.apache.maven.plugins-maven-compiler-plugin-3.10.1
Bump maven-compiler-plugin from 3.10.0 to 3.10.1
2022-03-11 16:47:40 -05:00
dependabot[bot]
114a27e9b5 Bump maven-compiler-plugin from 3.10.0 to 3.10.1
Bumps [maven-compiler-plugin](https://github.com/apache/maven-compiler-plugin) from 3.10.0 to 3.10.1.
- [Release notes](https://github.com/apache/maven-compiler-plugin/releases)
- [Commits](https://github.com/apache/maven-compiler-plugin/compare/maven-compiler-plugin-3.10.0...maven-compiler-plugin-3.10.1)

---
updated-dependencies:
- dependency-name: org.apache.maven.plugins:maven-compiler-plugin
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-03-11 11:26:04 +00:00
hyperdefined
7cdb71df50 cleanup 2022-03-01 23:33:55 -05:00
hyperdefined
bd80d6718c Update CommandToolStats.java 2022-03-01 23:33:26 -05:00
hyperdefined
b9907eedec unify item arrays & date formats 2022-03-01 23:32:30 -05:00
hyperdefined
61cf44a407 handle finding who opens a newly spawned chest better 2022-03-01 23:21:09 -05:00
hyperdefined
337f88ce36 Update pom.xml 2022-02-24 11:46:50 -05:00
hyperdefined
42f100f0b0 added missing return (fixes #7) 2022-02-24 11:46:08 -05:00
14 changed files with 227 additions and 98 deletions

View File

@@ -36,5 +36,8 @@ If item lore is ever incorrect, you can run `/toolstats reset` to reset the item
![Image](https://raw.githubusercontent.com/hyperdefined/ToolStats/master/images/image9.png)
![Image](https://raw.githubusercontent.com/hyperdefined/ToolStats/master/images/image10.png)
## Documentation
Visit the [wiki](https://github.com/hyperdefined/ToolStats/wiki) for help.
## License
This plugin is released under GNU General Public License v3. See [LICENSE](https://github.com/hyperdefined/ToolStats/blob/master/LICENSE).

45
pom.xml
View File

@@ -23,7 +23,7 @@
<groupId>lol.hyper</groupId>
<artifactId>toolstats</artifactId>
<version>1.3.3</version>
<version>1.4</version>
<packaging>jar</packaging>
<name>ToolStats</name>
@@ -37,7 +37,7 @@
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
<version>3.2.0</version>
<executions>
<execution>
<id>auto-clean</id>
@@ -51,7 +51,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.0</version>
<version>3.10.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
@@ -60,13 +60,21 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<version>3.3.0</version>
<configuration>
<relocations>
<relocation>
<pattern>org.bstats</pattern>
<shadedPattern>lol.hyper.toolstats.bstats</shadedPattern>
</relocation>
<relocation>
<pattern>net.kyori.adventure</pattern>
<shadedPattern>lol.hyper.toolstats.adventure</shadedPattern>
</relocation>
<relocation>
<pattern>lol.hyper.githubreleaseapi</pattern>
<shadedPattern>lol.hyper.toolstats.updater</shadedPattern>
</relocation>
</relocations>
</configuration>
<executions>
@@ -101,15 +109,9 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.18.1-R0.1-SNAPSHOT</version>
<version>1.19-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>23.0.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
@@ -119,7 +121,26 @@
<dependency>
<groupId>lol.hyper</groupId>
<artifactId>github-release-api</artifactId>
<version>1.0.1</version>
<version>1.0.2</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-text-minimessage</artifactId>
<version>4.11.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-platform-bukkit</artifactId>
<version>4.1.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>

View File

@@ -21,6 +21,7 @@ import lol.hyper.githubreleaseapi.GitHubRelease;
import lol.hyper.githubreleaseapi.GitHubReleaseAPI;
import lol.hyper.toolstats.commands.CommandToolStats;
import lol.hyper.toolstats.events.*;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@@ -32,8 +33,8 @@ import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
import java.text.SimpleDateFormat;
import java.util.Locale;
import java.util.logging.Logger;
public final class ToolStats extends JavaPlugin {
@@ -57,6 +58,13 @@ public final class ToolStats extends JavaPlugin {
// used for tracking new elytras
public final NamespacedKey newElytra = new NamespacedKey(this, "new");
public final String[] allValidItems = {
"pickaxe", "sword", "shovel", "axe", "hoe", "bow", "helmet", "chestplate", "leggings", "boots", "fishing"
};
public final String[] meleeItems = {"sword", "trident", "axe"};
public final String[] mineItems = {"pickaxe", "axe", "hoe", "shovel", "shear"};
public final SimpleDateFormat dateFormat = new SimpleDateFormat("M/dd/yyyy", Locale.ENGLISH);
public BlocksMined blocksMined;
public ChunkPopulate chunkPopulate;
public CraftItem craftItem;
@@ -65,6 +73,7 @@ public final class ToolStats extends JavaPlugin {
public PickupItem pickupItem;
public EntityDamage mobKill;
public PlayerFish playerFish;
public PlayerInteract playerInteract;
public SheepShear sheepShear;
public VillagerTrade villagerTrade;
public CommandToolStats commandToolStats;
@@ -74,8 +83,11 @@ public final class ToolStats extends JavaPlugin {
public FileConfiguration config;
public final int CONFIG_VERSION = 3;
private BukkitAudiences adventure;
@Override
public void onEnable() {
this.adventure = BukkitAudiences.create(this);
if (!configFile.exists()) {
this.saveResource("config.yml", true);
logger.info("Copying default config!");
@@ -89,6 +101,7 @@ public final class ToolStats extends JavaPlugin {
pickupItem = new PickupItem(this);
mobKill = new EntityDamage(this);
playerFish = new PlayerFish(this);
playerInteract = new PlayerInteract(this);
sheepShear = new SheepShear(this);
villagerTrade = new VillagerTrade(this);
commandToolStats = new CommandToolStats(this);
@@ -101,6 +114,7 @@ public final class ToolStats extends JavaPlugin {
Bukkit.getServer().getPluginManager().registerEvents(pickupItem, this);
Bukkit.getServer().getPluginManager().registerEvents(mobKill, this);
Bukkit.getServer().getPluginManager().registerEvents(playerFish, this);
Bukkit.getServer().getPluginManager().registerEvents(playerInteract, this);
Bukkit.getServer().getPluginManager().registerEvents(sheepShear, this);
Bukkit.getServer().getPluginManager().registerEvents(villagerTrade, this);
@@ -143,20 +157,24 @@ public final class ToolStats extends JavaPlugin {
/**
* Checks the config to see if we want to show lore on certain items.
* @param itemStack The item to check.
*
* @param itemStack The item to check.
* @param configName The config we are checking under.
* @return If we want to allow lore or not.
*/
public boolean checkConfig(ItemStack itemStack, String configName) {
String itemName = itemStack.getType().toString().toLowerCase();
String itemType = null;
if (itemName.contains("bow") || itemName.contains("shears")) {
if (itemName.contains("bow") || itemName.contains("shears") || itemName.contains("trident")) {
if (itemName.contains("bow")) {
itemType = "bow";
}
if (itemName.contains("shears")) {
itemType = "shears";
}
if (itemName.contains("trident")) {
itemType = "trident";
}
} else {
itemType = itemName.substring(itemName.indexOf("_") + 1);
}
@@ -187,6 +205,9 @@ public final class ToolStats extends JavaPlugin {
case "bow": {
return config.getBoolean("enabled." + configName + ".bow");
}
case "trident": {
return config.getBoolean("enabled." + configName + ".trident");
}
case "helmet":
case "chestplate":
case "leggings":
@@ -199,8 +220,9 @@ public final class ToolStats extends JavaPlugin {
/**
* Gets the lore message from the config.
*
* @param configName The config name, "messages." is already in front.
* @param raw If you want the raw message with the formatting codes and placeholders.
* @param raw If you want the raw message with the formatting codes and placeholders.
* @return The lore message.
*/
public String getLoreFromConfig(String configName, boolean raw) {
@@ -242,4 +264,11 @@ public final class ToolStats extends JavaPlugin {
}
return lore;
}
public BukkitAudiences getAdventure() {
if(this.adventure == null) {
throw new IllegalStateException("Tried to access Adventure when the plugin was disabled!");
}
return this.adventure;
}
}

View File

@@ -19,7 +19,10 @@ package lol.hyper.toolstats.commands;
import lol.hyper.toolstats.ToolStats;
import lol.hyper.toolstats.UUIDDataType;
import org.bukkit.*;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
@@ -31,34 +34,35 @@ import org.bukkit.persistence.PersistentDataType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.text.SimpleDateFormat;
import java.util.*;
public class CommandToolStats implements TabExecutor {
private final ToolStats toolStats;
private final BukkitAudiences audiences;
public CommandToolStats(ToolStats toolStats) {
this.toolStats = toolStats;
this.audiences = toolStats.getAdventure();
}
private final SimpleDateFormat format = new SimpleDateFormat("M/dd/yyyy", Locale.ENGLISH);
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if (!sender.hasPermission("toolstats.use")) {
sender.sendMessage(ChatColor.RED + "You do not have permission for this command.");
audiences.sender(sender).sendMessage(Component.text("You do not have permission for this command.").color(NamedTextColor.RED));
return true;
}
if (args.length == 0) {
sender.sendMessage(ChatColor.GREEN + "ToolStats version " + toolStats.getDescription().getVersion() + ". Created by hyperdefined.");
audiences.sender(sender).sendMessage(Component.text("ToolStats version " + toolStats.getDescription().getVersion() + ". Created by hyperdefined.").color(NamedTextColor.GREEN));
return true;
}
switch (args[0]) {
case "reload": {
if (sender.isOp() || sender.hasPermission("toolstats.reload")) {
toolStats.loadConfig();
sender.sendMessage(ChatColor.GREEN + "Configuration reloaded!");
audiences.sender(sender).sendMessage(Component.text("Configuration reloaded!").color(NamedTextColor.GREEN));
} else {
sender.sendMessage(ChatColor.RED + "You do not have permission for this command.");
audiences.sender(sender).sendMessage(Component.text("You do not have permission for this command.").color(NamedTextColor.RED));
}
return true;
}
@@ -67,21 +71,21 @@ public class CommandToolStats implements TabExecutor {
Player player = (Player) sender;
ItemStack heldItem = player.getInventory().getItemInMainHand();
if (heldItem.getType() == Material.AIR) {
sender.sendMessage(ChatColor.RED + "You must hold an item!");
audiences.sender(sender).sendMessage(Component.text("You must hold an item!").color(NamedTextColor.RED));
return true;
}
fixItemLore(heldItem, player);
sender.sendMessage(ChatColor.GREEN + "The lore was reset!");
audiences.sender(sender).sendMessage(Component.text("The lore was reset!").color(NamedTextColor.GREEN));
return true;
}
sender.sendMessage(ChatColor.GREEN + "This will remove ALL current lore from the held item and replace it with the correct lore.");
sender.sendMessage(ChatColor.GREEN + "The item owner will be who ever is currently running this command.");
sender.sendMessage(ChatColor.GREEN + "Only use this if the tags on the tool are incorrect.");
sender.sendMessage(ChatColor.GREEN + "Type /toolstats reset confirm to confirm this.");
audiences.sender(sender).sendMessage(Component.text("This will remove ALL current lore from the held item and replace it with the correct lore.").color(NamedTextColor.GREEN));
audiences.sender(sender).sendMessage(Component.text("The item owner will be who ever is currently running this command.").color(NamedTextColor.GREEN));
audiences.sender(sender).sendMessage(Component.text("Only use this if the tags on the tool are incorrect.").color(NamedTextColor.GREEN));
audiences.sender(sender).sendMessage(Component.text("Type /toolstats reset confirm to confirm this.").color(NamedTextColor.GREEN));
return true;
}
default: {
sender.sendMessage(ChatColor.RED + "Invalid sub-command.");
audiences.sender(sender).sendMessage(Component.text("Invalid sub-command.").color(NamedTextColor.RED));
}
}
return true;
@@ -89,8 +93,9 @@ public class CommandToolStats implements TabExecutor {
/**
* Fixes lore on a given item. This will wipe all lore and reapply our custom ones.
*
* @param original The item we are fixing.
* @param player The player running the command.
* @param player The player running the command.
*/
private void fixItemLore(ItemStack original, Player player) {
ItemStack finalItem = original.clone();
@@ -137,7 +142,7 @@ public class CommandToolStats implements TabExecutor {
if (container.has(toolStats.timeCreated, PersistentDataType.LONG)) {
Long time = container.get(toolStats.timeCreated, PersistentDataType.LONG);
if (time != null) {
lore.add(toolStats.getLoreFromConfig("looted.found-on", true).replace("{date}", format.format(new Date(time))));
lore.add(toolStats.getLoreFromConfig("looted.found-on", true).replace("{date}", toolStats.dateFormat.format(new Date(time))));
}
}
finalMeta.setLore(lore);
@@ -179,19 +184,19 @@ public class CommandToolStats implements TabExecutor {
// show how when the item was created based on the previous lore
switch (type) {
case "DEFAULT": {
lore.add(toolStats.getLoreFromConfig("created.created-on", true).replace("{date}", format.format(new Date(time))));
lore.add(toolStats.getLoreFromConfig("created.created-on", true).replace("{date}", toolStats.dateFormat.format(new Date(time))));
break;
}
case "CAUGHT": {
lore.add(toolStats.getLoreFromConfig("fished.caught-on", true).replace("{date}", format.format(new Date(time))));
lore.add(toolStats.getLoreFromConfig("fished.caught-on", true).replace("{date}", toolStats.dateFormat.format(new Date(time))));
break;
}
case "LOOTED": {
lore.add(toolStats.getLoreFromConfig("looted.foundon", true).replace("{date}", format.format(new Date(time))));
lore.add(toolStats.getLoreFromConfig("looted.foundon", true).replace("{date}", toolStats.dateFormat.format(new Date(time))));
break;
}
case "TRADED": {
lore.add(toolStats.getLoreFromConfig("traded.traded-on", true).replace("{date}", format.format(new Date(time))));
lore.add(toolStats.getLoreFromConfig("traded.traded-on", true).replace("{date}", toolStats.dateFormat.format(new Date(time))));
break;
}
}

View File

@@ -36,7 +36,6 @@ import java.util.List;
public class BlocksMined implements Listener {
private final ToolStats toolStats;
private final String[] validTools = {"pickaxe", "axe", "hoe", "shovel", "shear"};
public BlocksMined(ToolStats toolStats) {
this.toolStats = toolStats;
@@ -59,7 +58,7 @@ public class BlocksMined implements Listener {
}
// only check certain items
String itemName = heldItem.getType().toString().toLowerCase();
if (Arrays.stream(validTools).noneMatch(itemName::contains)) {
if (Arrays.stream(toolStats.mineItems).noneMatch(itemName::contains)) {
return;
}
// if it's an item we want, update the stats

View File

@@ -30,16 +30,11 @@ import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.persistence.PersistentDataType;
import java.text.SimpleDateFormat;
import java.util.*;
public class CraftItem implements Listener {
private final ToolStats toolStats;
public final String[] validItems = {
"pickaxe", "sword", "shovel", "axe", "hoe", "bow", "helmet", "chestplate", "leggings", "boots", "fishing"
};
private final SimpleDateFormat format = new SimpleDateFormat("M/dd/yyyy", Locale.ENGLISH);
public CraftItem(ToolStats toolStats) {
this.toolStats = toolStats;
@@ -57,7 +52,7 @@ public class CraftItem implements Listener {
}
String name = itemStack.getType().toString().toLowerCase(Locale.ROOT);
// only check for items we want
for (String x : validItems) {
for (String x : toolStats.allValidItems) {
if (name.contains(x)) {
// if the player shift clicks, send them this warning
if (event.isShiftClick()) {
@@ -69,19 +64,21 @@ public class CraftItem implements Listener {
}
}
// test the item before setting it
if (addLore(itemStack, player) == null) {
ItemStack newItem = addLore(itemStack, player);
if (newItem == null) {
return;
}
// set the result
event.setCurrentItem(addLore(itemStack, player));
event.setCurrentItem(newItem);
}
}
}
/**
* Adds crafted tags to item.
*
* @param itemStack The item add item to.
* @param owner The player crafting.
* @param owner The player crafting.
* @return A copy of the item with the tags + lore.
*/
private ItemStack addLore(ItemStack itemStack, Player owner) {
@@ -127,7 +124,7 @@ public class CraftItem implements Listener {
}
// do we add the lore based on the config?
if (toolStats.checkConfig(itemStack, "created-date")) {
lore.add(createdOnRaw.replace("{date}", format.format(finalDate)));
lore.add(createdOnRaw.replace("{date}", toolStats.dateFormat.format(finalDate)));
}
if (toolStats.checkConfig(itemStack, "created-by")) {
lore.add(createdByRaw.replace("{player}", owner.getName()));

View File

@@ -39,7 +39,6 @@ import java.util.*;
public class EntityDamage implements Listener {
private final ToolStats toolStats;
private final String[] validTools = {"sword", "trident", "axe"};
private final DecimalFormat decimalFormat = new DecimalFormat("0.00");
public final Set<UUID> trackedMobs = new HashSet<>();
@@ -71,7 +70,7 @@ public class EntityDamage implements Listener {
}
// check items we want
String itemName = heldItem.getType().toString().toLowerCase();
if (Arrays.stream(validTools).noneMatch(itemName::contains)) {
if (Arrays.stream(toolStats.meleeItems).noneMatch(itemName::contains)) {
return;
}
// a player is killing another player
@@ -176,6 +175,7 @@ public class EntityDamage implements Listener {
/**
* Updates a weapon's player kills.
*
* @param itemStack The item to update.
* @return A copy of the item.
*/
@@ -238,6 +238,7 @@ public class EntityDamage implements Listener {
/**
* Updates a weapon's mob kills.
*
* @param itemStack The item to update.
* @return A copy of the item.
*/
@@ -300,8 +301,9 @@ public class EntityDamage implements Listener {
/**
* Updates a player's armor damage stats.
*
* @param itemStack The armor piece.
* @param damage How much damage is being added.
* @param damage How much damage is being added.
*/
private void updateArmorDamage(ItemStack itemStack, double damage) {
ItemMeta meta = itemStack.getItemMeta();
@@ -360,6 +362,7 @@ public class EntityDamage implements Listener {
/**
* Check if item is an armor piece.
*
* @param itemType The item type, not name.
* @return If the item is an armor piece.
*/

View File

@@ -47,7 +47,7 @@ public class EntityDeath implements Listener {
if (toolStats.mobKill.trackedMobs.contains(livingEntityUUID)) {
for (ItemStack current : event.getDrops()) {
String name = current.getType().toString().toLowerCase(Locale.ROOT);
for (String item : toolStats.craftItem.validItems) {
for (String item : toolStats.allValidItems) {
if (name.contains(item)) {
addLore(current, livingEntity.getName());
}
@@ -59,8 +59,9 @@ public class EntityDeath implements Listener {
/**
* Adds "drop by" tag to item.
*
* @param itemStack The item to add lore to.
* @param mob The mob or player name.
* @param mob The mob or player name.
*/
private void addLore(ItemStack itemStack, String mob) {
ItemMeta meta = itemStack.getItemMeta();

View File

@@ -20,7 +20,9 @@ package lol.hyper.toolstats.events;
import lol.hyper.toolstats.ToolStats;
import lol.hyper.toolstats.UUIDDataType;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
@@ -32,7 +34,6 @@ import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.persistence.PersistentDataType;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@@ -41,10 +42,6 @@ import java.util.Locale;
public class GenerateLoot implements Listener {
private final ToolStats toolStats;
public final String[] validItems = {
"pickaxe", "sword", "shovel", "axe", "hoe", "bow", "helmet", "chestplate", "leggings", "boots", "fishing"
};
private final SimpleDateFormat format = new SimpleDateFormat("M/dd/yyyy", Locale.ENGLISH);
public GenerateLoot(ToolStats toolStats) {
this.toolStats = toolStats;
@@ -56,32 +53,51 @@ public class GenerateLoot implements Listener {
if (inventoryHolder == null) {
return;
}
Inventory chest = inventoryHolder.getInventory();
Location lootLocation = event.getLootContext().getLocation();
Inventory chestInv = inventoryHolder.getInventory();
Block openedChest = null;
// look at the current list of opened chest and get the distance
// between the lootcontext location and chest location
// if the distance is less than 1, it's the same chest
for (Block chest : toolStats.playerInteract.openedChests.keySet()) {
Location chestLocation = chest.getLocation();
double distance = lootLocation.distance(chestLocation);
if (distance <= 1.0) {
openedChest = chest;
}
}
// ignore if the chest is not in the same location
if (openedChest == null) {
return;
}
// run task later since if it runs on the same tick it breaks idk
Block finalOpenedChest = openedChest;
Bukkit.getScheduler().runTaskLater(toolStats, () -> {
Player player = (Player) chest.getViewers().get(0);
// do a classic for loot so we keep track of chest index of item
for (int i = 0; i < chest.getContents().length; i++) {
ItemStack itemStack = chest.getItem(i);
Player player = toolStats.playerInteract.openedChests.get(finalOpenedChest);
// do a classic for loop, so we keep track of chest index of item
for (int i = 0; i < chestInv.getContents().length; i++) {
ItemStack itemStack = chestInv.getItem(i);
// ignore air
if (itemStack == null || itemStack.getType() == Material.AIR) {
continue;
}
String name = itemStack.getType().toString().toLowerCase(Locale.ROOT);
for (String x : validItems) {
for (String x : toolStats.allValidItems) {
if (name.contains(x)) {
chest.setItem(i, addLore(itemStack, player));
chestInv.setItem(i, addLore(itemStack, player));
}
}
}
},1);
}, 1);
}
/**
* Adds lore to newly generated items.
*
* @param itemStack The item to add lore to.
* @param owner The player that found the item.
* @param owner The player that found the item.
* @return The item with the lore.
*/
private ItemStack addLore(ItemStack itemStack, Player owner) {
@@ -117,7 +133,7 @@ public class GenerateLoot implements Listener {
lore = new ArrayList<>();
}
if (toolStats.checkConfig(newItem, "looted-tag")) {
lore.add(foundOnLoreRaw.replace("{date}", format.format(finalDate)));
lore.add(foundOnLoreRaw.replace("{date}", toolStats.dateFormat.format(finalDate)));
lore.add(foundByLoreRaw.replace("{player}", owner.getName()));
}
meta.setLore(lore);

View File

@@ -20,8 +20,7 @@ package lol.hyper.toolstats.events;
import lol.hyper.toolstats.ToolStats;
import lol.hyper.toolstats.UUIDDataType;
import org.bukkit.Material;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.entity.*;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityPickupItemEvent;
@@ -30,16 +29,13 @@ import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.persistence.PersistentDataType;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;
public class PickupItem implements Listener {
private final ToolStats toolStats;
private final SimpleDateFormat format = new SimpleDateFormat("M/dd/yyyy", Locale.ENGLISH);
public PickupItem(ToolStats toolStats) {
this.toolStats = toolStats;
@@ -52,16 +48,20 @@ public class PickupItem implements Listener {
}
Entity entity = event.getEntity();
if (entity instanceof Player) {
ItemStack itemStack = event.getItem().getItemStack();
if (itemStack.getType() == Material.ELYTRA) {
Item item = event.getItem();
if (item.getType() == EntityType.DROPPED_ITEM) {
ItemStack itemStack = event.getItem().getItemStack();
ItemMeta meta = itemStack.getItemMeta();
if (meta == null) {
toolStats.logger.info("null");
return;
}
PersistentDataContainer container = meta.getPersistentDataContainer();
// the elytra has the new key, set the lore to it
if (container.has(toolStats.newElytra, PersistentDataType.INTEGER)) {
addLore(itemStack, (Player) event.getEntity());
if (itemStack.getType() == Material.ELYTRA) {
// the elytra has the new key, set the lore to it
if (container.has(toolStats.newElytra, PersistentDataType.INTEGER)) {
addLore(itemStack, (Player) event.getEntity());
}
}
}
}
@@ -69,8 +69,9 @@ public class PickupItem implements Listener {
/**
* Adds "looted by" tags for elytras.
*
* @param itemStack The elytra to add lore to.
* @param owner The player who found it.
* @param owner The player who found it.
*/
private void addLore(ItemStack itemStack, Player owner) {
ItemMeta meta = itemStack.getItemMeta();
@@ -100,7 +101,7 @@ public class PickupItem implements Listener {
lore = new ArrayList<>();
}
if (toolStats.config.getBoolean("enabled.elytra-tag")) {
lore.add(foundOnLoreRaw.replace("{date}", format.format(finalDate)));
lore.add(foundOnLoreRaw.replace("{date}", toolStats.dateFormat.format(finalDate)));
lore.add(foundByLoreRaw.replace("{player}", owner.getName()));
}
meta.setLore(lore);

View File

@@ -30,7 +30,6 @@ import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.persistence.PersistentDataType;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@@ -39,10 +38,6 @@ import java.util.Locale;
public class PlayerFish implements Listener {
private final ToolStats toolStats;
public final String[] validItems = {
"pickaxe", "sword", "shovel", "axe", "hoe", "bow", "helmet", "chestplate", "leggings", "boots", "fishing"
};
private final SimpleDateFormat format = new SimpleDateFormat("M/dd/yyyy", Locale.ENGLISH);
public PlayerFish(ToolStats toolStats) {
this.toolStats = toolStats;
@@ -68,7 +63,7 @@ public class PlayerFish implements Listener {
return;
}
ItemStack caughtItem = ((Item) event.getCaught()).getItemStack();
for (String x : validItems) {
for (String x : toolStats.allValidItems) {
if (caughtItem.getType().toString().toLowerCase(Locale.ROOT).contains(x)) {
addNewLore(caughtItem, player);
}
@@ -77,6 +72,7 @@ public class PlayerFish implements Listener {
/**
* Updates a fishing rod's count.
*
* @param itemStack The fishing rod to update.
*/
private void updateFishCount(ItemStack itemStack) {
@@ -135,8 +131,9 @@ public class PlayerFish implements Listener {
/**
* Adds "caught by" tags to newly fished items.
*
* @param itemStack The item to add lore to.
* @param owner The player who caught the item.
* @param owner The player who caught the item.
*/
private void addNewLore(ItemStack itemStack, Player owner) {
ItemMeta meta = itemStack.getItemMeta();
@@ -170,7 +167,7 @@ public class PlayerFish implements Listener {
lore = new ArrayList<>();
}
if (toolStats.checkConfig(itemStack, "fished-tag")) {
lore.add(caughtOnLoreRaw.replace("{date}", format.format(finalDate)));
lore.add(caughtOnLoreRaw.replace("{date}", toolStats.dateFormat.format(finalDate)));
lore.add(caughtByLoreRaw.replace("{player}", owner.getName()));
}
meta.setLore(lore);

View File

@@ -0,0 +1,60 @@
/*
* 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.events;
import lol.hyper.toolstats.ToolStats;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import java.util.HashMap;
public class PlayerInteract implements Listener {
private final ToolStats toolStats;
public final HashMap<Block, Player> openedChests = new HashMap<>();
public PlayerInteract(ToolStats toolStats) {
this.toolStats = toolStats;
}
@EventHandler
public void onInteract(PlayerInteractEvent event) {
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) {
return;
}
Block block = event.getClickedBlock();
if (block == null) {
return;
}
// store when a player opens a chest
// this is used to detect who opens a newly spawned chest
// since that is not really tracked on the lootevent
if (block.getType() != Material.AIR && block.getType() == Material.CHEST) {
openedChests.put(block, event.getPlayer());
Bukkit.getScheduler().runTaskLater(toolStats, () -> openedChests.remove(block), 20);
}
}
}

View File

@@ -66,6 +66,7 @@ public class SheepShear implements Listener {
/**
* Adds tags to shears.
*
* @param itemStack The shears.
*/
private void addLore(ItemStack itemStack) {

View File

@@ -33,7 +33,6 @@ import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.persistence.PersistentDataType;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@@ -42,10 +41,6 @@ import java.util.Locale;
public class VillagerTrade implements Listener {
private final ToolStats toolStats;
public final String[] validItems = {
"pickaxe", "sword", "shovel", "axe", "hoe", "bow", "helmet", "chestplate", "leggings", "boots", "fishing"
};
private final SimpleDateFormat format = new SimpleDateFormat("M/dd/yyyy", Locale.ENGLISH);
public VillagerTrade(ToolStats toolStats) {
this.toolStats = toolStats;
@@ -63,7 +58,7 @@ public class VillagerTrade implements Listener {
if (event.getSlotType() == InventoryType.SlotType.RESULT) {
ItemStack item = event.getCurrentItem();
// only check items we want
for (String x : validItems) {
for (String x : toolStats.allValidItems) {
if (item.getType().toString().toLowerCase(Locale.ROOT).contains(x)) {
// if the player shift clicks show the warning
if (event.isShiftClick()) {
@@ -78,7 +73,7 @@ public class VillagerTrade implements Listener {
}
// this gets delayed since villager inventories suck for no reason
// if you don't delay this it doesn't work idk
Bukkit.getScheduler().runTaskLater(toolStats, ()-> event.setCurrentItem(newItem), 5);
Bukkit.getScheduler().runTaskLater(toolStats, () -> event.setCurrentItem(newItem), 5);
}
}
}
@@ -87,8 +82,9 @@ public class VillagerTrade implements Listener {
/**
* Adds "traded by" tags to item.
*
* @param itemStack The item to add lore.
* @param owner The player who traded.
* @param owner The player who traded.
* @return The item with lore.
*/
private ItemStack addLore(ItemStack itemStack, Player owner) {
@@ -123,7 +119,7 @@ public class VillagerTrade implements Listener {
lore = new ArrayList<>();
}
if (toolStats.checkConfig(itemStack, "traded-tag")) {
lore.add(tradedOnLoreRaw.replace("{date}", format.format(finalDate)));
lore.add(tradedOnLoreRaw.replace("{date}", toolStats.dateFormat.format(finalDate)));
lore.add(tradedByLoreRaw.replace("{player}", owner.getName()));
}
meta.setLore(lore);