mirror of
https://github.com/hyperdefined/ToolStats.git
synced 2025-12-06 06:41:44 +00:00
Compare commits
228 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6b263be041 | ||
|
|
aeaeee680b | ||
|
|
d8c7425a5a | ||
|
|
86c92c9706 | ||
|
|
cd62f7309e | ||
|
|
e2b18cb5f1 | ||
|
|
150956b2c9 | ||
|
|
585e020baf | ||
|
|
50b5823daf | ||
|
|
c87d0ca3bf | ||
|
|
d1a16ff2e6 | ||
|
|
9134da31f4 | ||
|
|
0cf85edda6 | ||
|
|
7fe0234785 | ||
|
|
6385814b52 | ||
|
|
603e1ac1fd | ||
|
|
86dc5f421a | ||
|
|
7d9be0cfd1 | ||
|
|
f7bacec617 | ||
|
|
227723fe10 | ||
|
|
785333e8d1 | ||
|
|
bc784b8d46 | ||
|
|
f5ddada892 | ||
|
|
a43155b0c5 | ||
|
|
e327d132e2 | ||
|
|
f09f2d3703 | ||
|
|
e9782c2985 | ||
|
|
b596310bfe | ||
|
|
6d1f0fe561 | ||
|
|
fb0d179d37 | ||
|
|
e8ab578eef | ||
|
|
57be2371e1 | ||
|
|
f3732a4eea | ||
|
|
7e13159056 | ||
|
|
7cdb8d55b5 | ||
|
|
368e59b1e1 | ||
|
|
9412dc02d7 | ||
|
|
0765c49622 | ||
|
|
91959c223e | ||
|
|
a53cebc589 | ||
|
|
7f7c1d4656 | ||
|
|
1e99fa5076 | ||
|
|
d50ee82a98 | ||
|
|
2a2c9a7376 | ||
|
|
813648e330 | ||
|
|
330001e6de | ||
|
|
75b1a95cb5 | ||
|
|
ca37021e5a | ||
|
|
f72ea3dbfa | ||
|
|
03077d5e2f | ||
|
|
608c870667 | ||
|
|
ea27e4f4ab | ||
|
|
8a7c6c720a | ||
|
|
12e2758ffd | ||
|
|
5939b8f944 | ||
|
|
021d67e505 | ||
|
|
c0ee457c4d | ||
|
|
4f4e4a961a | ||
|
|
3412094f93 | ||
|
|
cdc46a1f5f | ||
|
|
d4c7770352 | ||
|
|
85db07877d | ||
|
|
1e37fcd3cb | ||
|
|
10f9b9404e | ||
|
|
c350536ab6 | ||
|
|
e12a0a80f5 | ||
|
|
44a3fc7d63 | ||
|
|
6a5bb994cc | ||
|
|
1c52664935 | ||
|
|
4d18020065 | ||
|
|
ee5ebff614 | ||
|
|
fa7b19e3fc | ||
|
|
cc4176cfbe | ||
|
|
bd30b05246 | ||
|
|
2ace1c4f16 | ||
|
|
c3f47707c4 | ||
|
|
ee1c197d72 | ||
|
|
74b529ba4f | ||
|
|
c328b9e019 | ||
|
|
38c37ea601 | ||
|
|
700e7bca2c | ||
|
|
59bfdf69ca | ||
|
|
68aed25834 | ||
|
|
0968497fc0 | ||
|
|
c7a5aef9ee | ||
|
|
e40e16c273 | ||
|
|
fc9ef05afd | ||
|
|
26ae28dcd8 | ||
|
|
02a7920ad2 | ||
|
|
68c9685477 | ||
|
|
9f81cb1f74 | ||
|
|
e068aeb9f4 | ||
|
|
b0733935ae | ||
|
|
664eddeab0 | ||
|
|
cda8d94199 | ||
|
|
5551c24202 | ||
|
|
951106177b | ||
|
|
0a3f46fc6e | ||
|
|
2894e2021a | ||
|
|
2e34cb812a | ||
|
|
a38c148b80 | ||
|
|
a55cea4b5d | ||
|
|
d0fcd4fc61 | ||
|
|
f14b9bc474 | ||
|
|
366a54052a | ||
|
|
fe96235ed1 | ||
|
|
fe8052f9d6 | ||
|
|
884bdef444 | ||
|
|
be31202f65 | ||
|
|
39d8a42110 | ||
|
|
91090dd6cc | ||
|
|
29a2a5150c | ||
|
|
b38d2825cb | ||
|
|
fd6c120a58 | ||
|
|
459569a1dc | ||
|
|
9ba6200415 | ||
|
|
b94e0e8c36 | ||
|
|
a42c526198 | ||
|
|
851a494935 | ||
|
|
72e869d5e2 | ||
|
|
300fe56c5a | ||
|
|
fe5e55d746 | ||
|
|
0574fb61a6 | ||
|
|
433ab547cb | ||
|
|
9746789f2b | ||
|
|
fd3c3ca8ed | ||
|
|
c6dc2c3368 | ||
|
|
d11211b1c7 | ||
|
|
e8c2296bd7 | ||
|
|
d8f296a085 | ||
|
|
58dee809f3 | ||
|
|
590cf6e8b0 | ||
|
|
a7cc8671bd | ||
|
|
37a7c642d3 | ||
|
|
31acdd9527 | ||
|
|
9b0ac2d912 | ||
|
|
4ea9e1600b | ||
|
|
72b8b31779 | ||
|
|
fce135f2f8 | ||
|
|
425b315104 | ||
|
|
50a0bc800c | ||
|
|
583cd824f4 | ||
|
|
d63f00166d | ||
|
|
0bcb0c7370 | ||
|
|
e4859de614 | ||
|
|
f7c1af153f | ||
|
|
946dc591f5 | ||
|
|
d279569199 | ||
|
|
f2739cf433 | ||
|
|
bef854be14 | ||
|
|
2c971da1b9 | ||
|
|
2e0ee18594 | ||
|
|
98a5f20a86 | ||
|
|
dd8a0db3b6 | ||
|
|
fee7d5cd99 | ||
|
|
70ebf49958 | ||
|
|
50d2ec0507 | ||
|
|
6428925e40 | ||
|
|
1d4faa89a1 | ||
|
|
1ad650f42b | ||
|
|
fdb6626c42 | ||
|
|
cd80e6a675 | ||
|
|
03d45ea8f7 | ||
|
|
91a98cf664 | ||
|
|
72b00e96f6 | ||
|
|
07458bfc11 | ||
|
|
24d30f6059 | ||
|
|
bea7e52347 | ||
|
|
1b1b45ef6d | ||
|
|
2de2ae82a7 | ||
|
|
7639943fea | ||
|
|
2b75ea094d | ||
|
|
bc8496fad4 | ||
|
|
1cef74311e | ||
|
|
cbbdb4e9c4 | ||
|
|
f6d35c459c | ||
|
|
4624d7a847 | ||
|
|
3766db3454 | ||
|
|
5a5e29c5e2 | ||
|
|
d188877f18 | ||
|
|
05200f075b | ||
|
|
9973d743a5 | ||
|
|
a89b9d6f6a | ||
|
|
082f529c32 | ||
|
|
05f940026f | ||
|
|
59d0295b18 | ||
|
|
af908f2eb6 | ||
|
|
c86e96e200 | ||
|
|
8061293810 | ||
|
|
656e265006 | ||
|
|
507813f106 | ||
|
|
e3e1c6a690 | ||
|
|
5eebcb9ff4 | ||
|
|
63d508fded | ||
|
|
59a8079ba2 | ||
|
|
3767ee2f63 | ||
|
|
7d5f73ae96 | ||
|
|
b581d9d178 | ||
|
|
d355b7a429 | ||
|
|
d06a1c4a40 | ||
|
|
e22fc7b530 | ||
|
|
8478411b8f | ||
|
|
85d072667a | ||
|
|
010ca54144 | ||
|
|
6af49d6c30 | ||
|
|
c4e4ce01fd | ||
|
|
983a35bd0b | ||
|
|
d9ad7ebcad | ||
|
|
995f80e159 | ||
|
|
56850c40d1 | ||
|
|
b9e4bbd1e8 | ||
|
|
6a23c7a724 | ||
|
|
cd6cb999c0 | ||
|
|
f9cff275b5 | ||
|
|
ba1ae01801 | ||
|
|
fd35cf6e9c | ||
|
|
5971ecc919 | ||
|
|
4c4ca0c31e | ||
|
|
294b753430 | ||
|
|
adf6a3149b | ||
|
|
ea68650038 | ||
|
|
114a27e9b5 | ||
|
|
7cdb71df50 | ||
|
|
bd80d6718c | ||
|
|
b9907eedec | ||
|
|
61cf44a407 | ||
|
|
337f88ce36 | ||
|
|
42f100f0b0 |
15
.github/workflows/maven.yml
vendored
15
.github/workflows/maven.yml
vendored
@@ -15,10 +15,11 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Set up JDK 1.8
|
||||
uses: actions/setup-java@v1
|
||||
with:
|
||||
java-version: 1.8
|
||||
- name: Build with Maven
|
||||
run: mvn -B package --file pom.xml
|
||||
- uses: actions/checkout@v4
|
||||
- name: Set up JDK 21
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
distribution: temurin
|
||||
java-version: 21
|
||||
- name: Build with Maven
|
||||
run: mvn -B package --file pom.xml
|
||||
|
||||
12
.github/workflows/modrinth.yml
vendored
Normal file
12
.github/workflows/modrinth.yml
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
jobs:
|
||||
modrinth-desc:
|
||||
runs-on: 'ubuntu-latest'
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: funnyboy-roks/modrinth-auto-desc@v1.6
|
||||
with:
|
||||
auth-token: ${{ secrets.MODRINTH }}
|
||||
slug: 'oBZj9E15'
|
||||
24
README.md
24
README.md
@@ -1,29 +1,31 @@
|
||||
<h1 align="center">ToolStats</h1>
|
||||
|
||||
<p align="center">
|
||||
<img src="https://img.shields.io/badge/Minecraft-1.15+-orange" alt="Minecraft versions">
|
||||
<img src="https://img.shields.io/badge/Minecraft-1.21--1.21.4-orange" alt="Minecraft versions">
|
||||
<img src="https://img.shields.io/github/v/release/hyperdefined/ToolStats" alt="GitHub release (latest by date)">
|
||||
<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://en.cryptobadges.io/donate/1F29aNKQzci3ga5LDcHHawYzFPXvELTFoL"><img src="https://en.cryptobadges.io/badge/micro/1F29aNKQzci3ga5LDcHHawYzFPXvELTFoL" alt="Donate with Bitcoin"></a>
|
||||
<a href="https://en.cryptobadges.io/donate/0xF3b4e87E4c11f586949ca8740eD33A1e473F924c"><img src="https://en.cryptobadges.io/badge/micro/0xF3b4e87E4c11f586949ca8740eD33A1e473F924c" alt="Donate with Ethereum"></a>
|
||||
<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>
|
||||
<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://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>
|
||||
|
||||
ToolStats is a small plugin that display various stats about tools. This plugin is inspired off of [GearStats](https://www.spigotmc.org/resources/gearstats.12960/). You can disable/enable which stats are shown on which tools via the config. Note: stats are tracked regardless of config setting. The config is to disable the lore on the item.
|
||||
ToolStats is a Paper plugin that display various stats about tools. This plugin is inspired off of [GearStats](https://www.spigotmc.org/resources/gearstats.12960/). You can disable/enable which stats are shown on which tools via the config. Note: stats are tracked regardless of config setting. The config is to disable the lore on the item.
|
||||
|
||||
Here is everything it tracks:
|
||||
* Blocks mined (pickaxes, shovels, axes, hoes, shears)
|
||||
* Player/mob kills (swords, axes, tridents, bows/crossbows)
|
||||
* Ownership of items when crafted, looted (from chests), traded, and caught from fishing.
|
||||
* Crops mined (hoes)
|
||||
* Player/mob kills (swords, axes, tridents, bows/crossbows, mace)
|
||||
* Ownership of items when crafted, looted (from chests), traded, spawned via creative, and caught from fishing.
|
||||
* Armor damage taken.
|
||||
* Fish caught.
|
||||
* Sheep sheared.
|
||||
* Arrows shot (bows/crossbows)
|
||||
|
||||
The best part is, this data is stored on the item itself. You can also change how the lore is displayed on the items!
|
||||
|
||||
If item lore is ever incorrect, you can run `/toolstats reset` to reset the item lore so it's correct.
|
||||
If item lore is ever incorrect/missing, you can run `/toolstats reset`. This command fixes the lore on whatever item you are holding.
|
||||
|
||||

|
||||

|
||||
@@ -35,6 +37,14 @@ If item lore is ever incorrect, you can run `/toolstats reset` to reset the item
|
||||

|
||||

|
||||

|
||||

|
||||

|
||||
|
||||
## Documentation
|
||||
Visit the [wiki](https://github.com/hyperdefined/ToolStats/wiki) for help.
|
||||
|
||||
## Support
|
||||
You can join the [Discord](https://discord.gg/rJuQXVcJz8) for support.
|
||||
|
||||
## License
|
||||
This plugin is released under GNU General Public License v3. See [LICENSE](https://github.com/hyperdefined/ToolStats/blob/master/LICENSE).
|
||||
|
||||
BIN
images/image11.png
Normal file
BIN
images/image11.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 26 KiB |
BIN
images/image12.png
Normal file
BIN
images/image12.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 94 KiB |
35
pom.xml
35
pom.xml
@@ -23,13 +23,13 @@
|
||||
|
||||
<groupId>lol.hyper</groupId>
|
||||
<artifactId>toolstats</artifactId>
|
||||
<version>1.3.3</version>
|
||||
<version>1.8.4</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>ToolStats</name>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<java.version>21</java.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-clean-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<version>3.4.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.13.0</version>
|
||||
<configuration>
|
||||
<source>${java.version}</source>
|
||||
<target>${java.version}</target>
|
||||
@@ -60,13 +60,17 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.2.4</version>
|
||||
<version>3.6.0</version>
|
||||
<configuration>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>org.bstats</pattern>
|
||||
<shadedPattern>lol.hyper.toolstats.bstats</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>lol.hyper.githubreleaseapi</pattern>
|
||||
<shadedPattern>lol.hyper.toolstats.updater</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
<executions>
|
||||
@@ -92,34 +96,29 @@
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spigotmc-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
<id>papermc</id>
|
||||
<url>https://repo.papermc.io/repository/maven-public/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.18.1-R0.1-SNAPSHOT</version>
|
||||
<groupId>io.papermc.paper</groupId>
|
||||
<artifactId>paper-api</artifactId>
|
||||
<version>1.21.4-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>
|
||||
<version>3.0.0</version>
|
||||
<version>3.1.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>lol.hyper</groupId>
|
||||
<artifactId>github-release-api</artifactId>
|
||||
<version>1.0.1</version>
|
||||
<version>1.0.5</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
@@ -21,41 +21,93 @@ import lol.hyper.githubreleaseapi.GitHubRelease;
|
||||
import lol.hyper.githubreleaseapi.GitHubReleaseAPI;
|
||||
import lol.hyper.toolstats.commands.CommandToolStats;
|
||||
import lol.hyper.toolstats.events.*;
|
||||
import lol.hyper.toolstats.tools.HashMaker;
|
||||
import lol.hyper.toolstats.tools.ItemChecker;
|
||||
import lol.hyper.toolstats.tools.ItemLore;
|
||||
import lol.hyper.toolstats.tools.NumberFormat;
|
||||
import lol.hyper.toolstats.tools.config.ConfigTools;
|
||||
import lol.hyper.toolstats.tools.config.ConfigUpdater;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public final class ToolStats extends JavaPlugin {
|
||||
|
||||
// stores who created an item
|
||||
/**
|
||||
* Stores who created an item.
|
||||
*/
|
||||
public final NamespacedKey genericOwner = new NamespacedKey(this, "owner");
|
||||
// stores when an item was created
|
||||
/**
|
||||
* Stores when the item was created.
|
||||
*/
|
||||
public final NamespacedKey timeCreated = new NamespacedKey(this, "time-created");
|
||||
// stores how many player kills by sword
|
||||
/**
|
||||
* Stores how many player kills.
|
||||
*/
|
||||
public final NamespacedKey swordPlayerKills = new NamespacedKey(this, "player-kills");
|
||||
// stores how many mob kills by sword
|
||||
/**
|
||||
* Stores how many mob kills.
|
||||
*/
|
||||
public final NamespacedKey swordMobKills = new NamespacedKey(this, "mob-kills");
|
||||
// stores how blocks mined (used for all tools)
|
||||
/**
|
||||
* Stores how many blocks were mined.
|
||||
*/
|
||||
public final NamespacedKey genericMined = new NamespacedKey(this, "generic-mined");
|
||||
// stores how many fish were caught
|
||||
/**
|
||||
* Stores how many crops were harvested.
|
||||
*/
|
||||
public final NamespacedKey cropsHarvested = new NamespacedKey(this, "crops-mined");
|
||||
/**
|
||||
* Stores how many fish were caught.
|
||||
*/
|
||||
public final NamespacedKey fishingRodCaught = new NamespacedKey(this, "fish-caught");
|
||||
// stores how many times sheep were sheared
|
||||
/**
|
||||
* Stores how many sheep were sheared.
|
||||
*/
|
||||
public final NamespacedKey shearsSheared = new NamespacedKey(this, "sheared");
|
||||
// stores how much damage armor has taken
|
||||
/**
|
||||
* Stores how much damage an armor piece has taken.
|
||||
*/
|
||||
public final NamespacedKey armorDamage = new NamespacedKey(this, "damage-taken");
|
||||
// used for tracking new elytras
|
||||
/**
|
||||
* Key for tracking new elytras that spawn.
|
||||
*/
|
||||
public final NamespacedKey newElytra = new NamespacedKey(this, "new");
|
||||
/**
|
||||
* Key for item has.
|
||||
*/
|
||||
public final NamespacedKey hash = new NamespacedKey(this, "hash");
|
||||
/**
|
||||
* Key for arrows shot.
|
||||
*/
|
||||
public final NamespacedKey arrowsShot = new NamespacedKey(this, "arrows-shot");
|
||||
/**
|
||||
* Key for tracking flight time.
|
||||
*/
|
||||
public final NamespacedKey flightTime = new NamespacedKey(this, "flightTime");
|
||||
/**
|
||||
* Stores how an item was created.
|
||||
* 0 = crafted.
|
||||
* 1 = dropped.
|
||||
* 2 = looted.
|
||||
* 3 = traded.
|
||||
* 4 = founded (for elytras).
|
||||
* 5 = fished.
|
||||
* 6 = spawned in (creative).
|
||||
*/
|
||||
public final NamespacedKey originType = new NamespacedKey(this, "origin");
|
||||
|
||||
public final int CONFIG_VERSION = 8;
|
||||
public final Logger logger = this.getLogger();
|
||||
public final File configFile = new File(this.getDataFolder(), "config.yml");
|
||||
|
||||
public BlocksMined blocksMined;
|
||||
public ChunkPopulate chunkPopulate;
|
||||
@@ -65,14 +117,21 @@ 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;
|
||||
|
||||
public final Logger logger = this.getLogger();
|
||||
public final File configFile = new File(this.getDataFolder(), "config.yml");
|
||||
public FileConfiguration config;
|
||||
public final int CONFIG_VERSION = 3;
|
||||
public ItemLore itemLore;
|
||||
public InventoryOpen inventoryOpen;
|
||||
public PlayerJoin playerJoin;
|
||||
public NumberFormat numberFormat;
|
||||
public YamlConfiguration config;
|
||||
public HashMaker hashMaker;
|
||||
public CreativeEvent creativeEvent;
|
||||
public PlayerMove playerMove;
|
||||
public ItemChecker itemChecker;
|
||||
public ShootBow shootBow;
|
||||
public ConfigTools configTools;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
@@ -81,6 +140,7 @@ public final class ToolStats extends JavaPlugin {
|
||||
logger.info("Copying default config!");
|
||||
}
|
||||
loadConfig();
|
||||
hashMaker = new HashMaker(this);
|
||||
blocksMined = new BlocksMined(this);
|
||||
craftItem = new CraftItem(this);
|
||||
chunkPopulate = new ChunkPopulate(this);
|
||||
@@ -89,9 +149,18 @@ 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);
|
||||
itemLore = new ItemLore(this);
|
||||
inventoryOpen = new InventoryOpen(this);
|
||||
playerJoin = new PlayerJoin(this);
|
||||
creativeEvent = new CreativeEvent(this);
|
||||
playerMove = new PlayerMove(this);
|
||||
itemChecker = new ItemChecker();
|
||||
shootBow = new ShootBow(this);
|
||||
configTools = new ConfigTools(this);
|
||||
|
||||
Bukkit.getServer().getPluginManager().registerEvents(blocksMined, this);
|
||||
Bukkit.getServer().getPluginManager().registerEvents(chunkPopulate, this);
|
||||
@@ -101,21 +170,30 @@ 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);
|
||||
Bukkit.getServer().getPluginManager().registerEvents(inventoryOpen, this);
|
||||
Bukkit.getServer().getPluginManager().registerEvents(playerJoin, this);
|
||||
Bukkit.getServer().getPluginManager().registerEvents(creativeEvent, this);
|
||||
Bukkit.getServer().getPluginManager().registerEvents(shootBow, this);
|
||||
Bukkit.getServer().getPluginManager().registerEvents(playerMove, this);
|
||||
|
||||
this.getCommand("toolstats").setExecutor(commandToolStats);
|
||||
|
||||
new Metrics(this, 14110);
|
||||
|
||||
Bukkit.getScheduler().runTaskAsynchronously(this, this::checkForUpdates);
|
||||
Bukkit.getAsyncScheduler().runNow(this, scheduledTask -> checkForUpdates());
|
||||
}
|
||||
|
||||
public void loadConfig() {
|
||||
config = YamlConfiguration.loadConfiguration(configFile);
|
||||
if (config.getInt("config-version") != CONFIG_VERSION) {
|
||||
logger.warning("Your config file is outdated! Please regenerate the config.");
|
||||
logger.warning("Your config file is outdated! We will try to update it, but you should regenerate it!");
|
||||
ConfigUpdater configUpdater = new ConfigUpdater(this);
|
||||
configUpdater.updateConfig();
|
||||
}
|
||||
|
||||
numberFormat = new NumberFormat(this);
|
||||
}
|
||||
|
||||
public void checkForUpdates() {
|
||||
@@ -140,106 +218,4 @@ public final class ToolStats extends JavaPlugin {
|
||||
logger.warning("A new version is available (" + latest.getTagVersion() + ")! You are running version " + current.getTagVersion() + ". You are " + buildsBehind + " version(s) behind.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the config to see if we want to show lore on certain items.
|
||||
* @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")) {
|
||||
itemType = "bow";
|
||||
}
|
||||
if (itemName.contains("shears")) {
|
||||
itemType = "shears";
|
||||
}
|
||||
} else {
|
||||
itemType = itemName.substring(itemName.indexOf("_") + 1);
|
||||
}
|
||||
|
||||
if (itemType == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (itemType) {
|
||||
case "pickaxe": {
|
||||
return config.getBoolean("enabled." + configName + ".pickaxe");
|
||||
}
|
||||
case "sword": {
|
||||
return config.getBoolean("enabled." + configName + ".sword");
|
||||
}
|
||||
case "shovel": {
|
||||
return config.getBoolean("enabled." + configName + ".shovel");
|
||||
}
|
||||
case "axe": {
|
||||
return config.getBoolean("enabled." + configName + ".axe");
|
||||
}
|
||||
case "hoe": {
|
||||
return config.getBoolean("enabled." + configName + ".hoe");
|
||||
}
|
||||
case "shears": {
|
||||
return config.getBoolean("enabled." + configName + ".shears");
|
||||
}
|
||||
case "bow": {
|
||||
return config.getBoolean("enabled." + configName + ".bow");
|
||||
}
|
||||
case "helmet":
|
||||
case "chestplate":
|
||||
case "leggings":
|
||||
case "boots": {
|
||||
return config.getBoolean("enabled." + configName + ".armor");
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* @return The lore message.
|
||||
*/
|
||||
public String getLoreFromConfig(String configName, boolean raw) {
|
||||
String lore = config.getString("messages." + configName);
|
||||
if (lore == null) {
|
||||
return null;
|
||||
}
|
||||
if (raw) {
|
||||
return ChatColor.translateAlternateColorCodes('&', lore);
|
||||
} else {
|
||||
// we basically add the color codes then remove them
|
||||
// this is a dirty trick to remove color codes
|
||||
lore = ChatColor.translateAlternateColorCodes('&', lore);
|
||||
lore = ChatColor.stripColor(lore);
|
||||
if (lore.contains("{player}")) {
|
||||
lore = lore.replace("{player}", "");
|
||||
}
|
||||
if (lore.contains("{date}")) {
|
||||
lore = lore.replace("{date}", "");
|
||||
}
|
||||
if (lore.contains("{name}")) {
|
||||
lore = lore.replace("{name}", "");
|
||||
}
|
||||
if (lore.contains("{kills}")) {
|
||||
lore = lore.replace("{kills}", "");
|
||||
}
|
||||
if (lore.contains("{blocks}")) {
|
||||
lore = lore.replace("{blocks}", "");
|
||||
}
|
||||
if (lore.contains("{sheep}")) {
|
||||
lore = lore.replace("{sheep}", "");
|
||||
}
|
||||
if (lore.contains("{damage}")) {
|
||||
lore = lore.replace("{damage}", "");
|
||||
}
|
||||
if (lore.contains("{fish}")) {
|
||||
lore = lore.replace("{fish}", "");
|
||||
}
|
||||
}
|
||||
return lore;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,10 +18,15 @@
|
||||
package lol.hyper.toolstats.commands;
|
||||
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import lol.hyper.toolstats.UUIDDataType;
|
||||
import org.bukkit.*;
|
||||
import lol.hyper.toolstats.tools.UUIDDataType;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@@ -31,7 +36,6 @@ 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 {
|
||||
@@ -41,47 +45,59 @@ public class CommandToolStats implements TabExecutor {
|
||||
public CommandToolStats(ToolStats toolStats) {
|
||||
this.toolStats = toolStats;
|
||||
}
|
||||
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.");
|
||||
if (!sender.hasPermission("toolstats.command")) {
|
||||
sender.sendMessage(Component.text("You do not have permission for this command.", NamedTextColor.RED));
|
||||
return true;
|
||||
}
|
||||
if (args.length == 0) {
|
||||
sender.sendMessage(ChatColor.GREEN + "ToolStats version " + toolStats.getDescription().getVersion() + ". Created by hyperdefined.");
|
||||
sender.sendMessage(Component.text("ToolStats version " + toolStats.getPluginMeta().getVersion() + ". Created by hyperdefined.", NamedTextColor.GREEN));
|
||||
return true;
|
||||
}
|
||||
switch (args[0]) {
|
||||
case "reload": {
|
||||
if (sender.isOp() || sender.hasPermission("toolstats.reload")) {
|
||||
if (sender.hasPermission("toolstats.reload")) {
|
||||
toolStats.loadConfig();
|
||||
sender.sendMessage(ChatColor.GREEN + "Configuration reloaded!");
|
||||
sender.sendMessage(Component.text("Configuration reloaded!", NamedTextColor.GREEN));
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "You do not have permission for this command.");
|
||||
sender.sendMessage(Component.text("You do not have permission for this command.", NamedTextColor.RED));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case "reset": {
|
||||
if (!sender.hasPermission("toolstats.reset")) {
|
||||
sender.sendMessage(Component.text("You do not have permission for this command.", NamedTextColor.RED));
|
||||
return true;
|
||||
}
|
||||
if (sender instanceof ConsoleCommandSender) {
|
||||
sender.sendMessage(Component.text("You must be a player for this command.", NamedTextColor.RED));
|
||||
return true;
|
||||
}
|
||||
if (args.length == 2 && args[1].equalsIgnoreCase("confirm")) {
|
||||
if (!sender.hasPermission("toolstats.reset.confirm")) {
|
||||
sender.sendMessage(Component.text("You do not have permission for this command.", NamedTextColor.RED));
|
||||
return true;
|
||||
}
|
||||
Player player = (Player) sender;
|
||||
ItemStack heldItem = player.getInventory().getItemInMainHand();
|
||||
if (heldItem.getType() == Material.AIR) {
|
||||
sender.sendMessage(ChatColor.RED + "You must hold an item!");
|
||||
if (!toolStats.itemChecker.isValidItem(heldItem.getType())) {
|
||||
sender.sendMessage(Component.text("You must hold a valid item.", NamedTextColor.RED));
|
||||
return true;
|
||||
}
|
||||
fixItemLore(heldItem, player);
|
||||
sender.sendMessage(ChatColor.GREEN + "The lore was reset!");
|
||||
sender.sendMessage(Component.text("The lore was reset!", 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.");
|
||||
sender.sendMessage(Component.text("This will remove ALL current lore from the held item and replace it with the correct lore.", NamedTextColor.GREEN));
|
||||
sender.sendMessage(Component.text("If the owner of the item is broken, it will reset to the person holding it.", NamedTextColor.GREEN));
|
||||
sender.sendMessage(Component.text("Only use this if the tags on the tool are incorrect.", NamedTextColor.GREEN));
|
||||
sender.sendMessage(Component.text("Type /toolstats reset confirm to confirm this.", NamedTextColor.GREEN));
|
||||
return true;
|
||||
}
|
||||
default: {
|
||||
sender.sendMessage(ChatColor.RED + "Invalid sub-command.");
|
||||
sender.sendMessage(Component.text("Invalid sub-command.", NamedTextColor.RED));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
@@ -89,8 +105,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();
|
||||
@@ -99,126 +116,161 @@ public class CommandToolStats implements TabExecutor {
|
||||
return;
|
||||
}
|
||||
PersistentDataContainer container = finalMeta.getPersistentDataContainer();
|
||||
List<String> lore = new ArrayList<>();
|
||||
List<Component> lore = new ArrayList<>();
|
||||
|
||||
String caughtByLore = toolStats.getLoreFromConfig("fished.caught-by", false);
|
||||
String lootedByLore = toolStats.getLoreFromConfig("looted.found-by", false);
|
||||
String tradedByLore = toolStats.getLoreFromConfig("traded.traded-by", false);
|
||||
|
||||
// make sure the config messages are not null
|
||||
if (caughtByLore == null || lootedByLore == null || tradedByLore == null) {
|
||||
return;
|
||||
// set how the item was obtained
|
||||
Integer origin = -1;
|
||||
if (container.has(toolStats.originType, PersistentDataType.INTEGER)) {
|
||||
origin = container.get(toolStats.originType, PersistentDataType.INTEGER);
|
||||
}
|
||||
|
||||
// determine how the item was originally created
|
||||
// this doesn't get saved, so we just rely on the lore
|
||||
// if there isn't a tag, default to crafted
|
||||
String type = "DEFAULT";
|
||||
if (finalMeta.hasLore()) {
|
||||
if (finalMeta.getLore() != null) {
|
||||
for (String line : finalMeta.getLore()) {
|
||||
if (line.contains(caughtByLore)) {
|
||||
type = "CAUGHT";
|
||||
}
|
||||
if (line.contains(lootedByLore)) {
|
||||
type = "LOOTED";
|
||||
}
|
||||
if (line.contains(tradedByLore)) {
|
||||
type = "TRADED";
|
||||
}
|
||||
}
|
||||
}
|
||||
// set to -1 if it's invalid
|
||||
if (origin == null) {
|
||||
origin = -1;
|
||||
}
|
||||
|
||||
// hard code elytras
|
||||
if (finalItem.getType() == Material.ELYTRA) {
|
||||
if (toolStats.config.getBoolean("enabled.elytra-tag")) {
|
||||
lore.add(toolStats.getLoreFromConfig("looted.found-by", true).replace("{player}", player.getName()));
|
||||
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))));
|
||||
}
|
||||
}
|
||||
finalMeta.setLore(lore);
|
||||
finalItem.setItemMeta(finalMeta);
|
||||
int slot = player.getInventory().getHeldItemSlot();
|
||||
player.getInventory().setItem(slot, finalItem);
|
||||
return;
|
||||
Long flightTime = null;
|
||||
Long timeCreated = null;
|
||||
if (container.has(toolStats.timeCreated, PersistentDataType.LONG)) {
|
||||
timeCreated = container.get(toolStats.timeCreated, PersistentDataType.LONG);
|
||||
}
|
||||
if (container.has(toolStats.flightTime, PersistentDataType.LONG)) {
|
||||
flightTime = container.get(toolStats.flightTime, PersistentDataType.LONG);
|
||||
}
|
||||
|
||||
if (flightTime != null) {
|
||||
if (toolStats.config.getBoolean("enabled.flight-time")) {
|
||||
Component line = toolStats.configTools.formatLore("flight-time", "{time}", toolStats.numberFormat.formatDouble((double) flightTime / 1000));
|
||||
lore.add(line);
|
||||
}
|
||||
}
|
||||
|
||||
if (timeCreated != null) {
|
||||
Component timeCreatedLine = toolStats.configTools.formatLore("looted.found-by", "{player}", player.getName());
|
||||
Component playerOwnerLine = toolStats.configTools.formatLore("looted.found-on", "{date}", toolStats.numberFormat.formatDate(new Date(timeCreated)));
|
||||
lore.add(timeCreatedLine);
|
||||
lore.add(playerOwnerLine);
|
||||
}
|
||||
|
||||
finalMeta.lore(lore);
|
||||
finalItem.setItemMeta(finalMeta);
|
||||
int slot = player.getInventory().getHeldItemSlot();
|
||||
player.getInventory().setItem(slot, finalItem);
|
||||
}
|
||||
|
||||
if (toolStats.checkConfig(original, "created-by")) {
|
||||
if (toolStats.configTools.checkConfig(original.getType(), "created-by")) {
|
||||
if (container.has(toolStats.genericOwner, new UUIDDataType())) {
|
||||
container.set(toolStats.genericOwner, new UUIDDataType(), player.getUniqueId());
|
||||
UUID owner = container.get(toolStats.genericOwner, new UUIDDataType());
|
||||
String ownerName = null;
|
||||
// if we can read the current owner
|
||||
if (owner != null) {
|
||||
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(owner);
|
||||
ownerName = offlinePlayer.getName();
|
||||
}
|
||||
|
||||
// if the owner's name is null for whatever reason, set the new owner
|
||||
// to the current player running the command
|
||||
if (ownerName == null) {
|
||||
player.sendMessage(Component.text("The owner of this item is null. Setting to " + player.getName() + ".", NamedTextColor.RED));
|
||||
ownerName = player.getName();
|
||||
container.set(toolStats.genericOwner, new UUIDDataType(), player.getUniqueId());
|
||||
}
|
||||
|
||||
// show how the item was created based on the previous lore
|
||||
switch (type) {
|
||||
case "DEFAULT": {
|
||||
lore.add(toolStats.getLoreFromConfig("created.created-by", true).replace("{player}", player.getName()));
|
||||
switch (origin) {
|
||||
case 0: {
|
||||
lore.add(toolStats.configTools.formatLore("created.created-by", "{player}", ownerName));
|
||||
break;
|
||||
}
|
||||
case "CAUGHT": {
|
||||
lore.add(toolStats.getLoreFromConfig("fished.caught-by", true).replace("{player}", player.getName()));
|
||||
case 2: {
|
||||
lore.add(toolStats.configTools.formatLore("looted.looted-by", "{player}", ownerName));
|
||||
break;
|
||||
}
|
||||
case "LOOTED": {
|
||||
lore.add(toolStats.getLoreFromConfig("looted.found-by", true).replace("{player}", player.getName()));
|
||||
case 3: {
|
||||
lore.add(toolStats.configTools.formatLore("traded.traded-by", "{player}", ownerName));
|
||||
break;
|
||||
}
|
||||
case "TRADED": {
|
||||
lore.add(toolStats.getLoreFromConfig("traded.traded-by", true).replace("{player}", player.getName()));
|
||||
case 4: {
|
||||
lore.add(toolStats.configTools.formatLore("looted.found-by", "{player}", ownerName));
|
||||
break;
|
||||
}
|
||||
case 5: {
|
||||
lore.add(toolStats.configTools.formatLore("fished.caught-by", "{player}", ownerName));
|
||||
break;
|
||||
}
|
||||
case 6: {
|
||||
lore.add(toolStats.configTools.formatLore("spawned-in.spawned-by", "{player}", ownerName));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (toolStats.checkConfig(original, "created-date")) {
|
||||
if (toolStats.configTools.checkConfig(original.getType(), "created-date")) {
|
||||
if (container.has(toolStats.timeCreated, PersistentDataType.LONG)) {
|
||||
Long time = container.get(toolStats.timeCreated, PersistentDataType.LONG);
|
||||
if (time != null) {
|
||||
String date = toolStats.numberFormat.formatDate(new Date(time));
|
||||
// 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))));
|
||||
switch (origin) {
|
||||
case 0: {
|
||||
lore.add(toolStats.configTools.formatLore("created.created-on", "{date}", date));
|
||||
break;
|
||||
}
|
||||
case "CAUGHT": {
|
||||
lore.add(toolStats.getLoreFromConfig("fished.caught-on", true).replace("{date}", format.format(new Date(time))));
|
||||
case 2: {
|
||||
lore.add(toolStats.configTools.formatLore("looted.looted-on", "{date}", date));
|
||||
break;
|
||||
}
|
||||
case "LOOTED": {
|
||||
lore.add(toolStats.getLoreFromConfig("looted.foundon", true).replace("{date}", format.format(new Date(time))));
|
||||
case 3: {
|
||||
lore.add(toolStats.configTools.formatLore("traded.traded-on", "{date}", date));
|
||||
break;
|
||||
}
|
||||
case "TRADED": {
|
||||
lore.add(toolStats.getLoreFromConfig("traded.traded-on", true).replace("{date}", format.format(new Date(time))));
|
||||
case 4: {
|
||||
lore.add(toolStats.configTools.formatLore("looted.found-on", "{date}", date));
|
||||
break;
|
||||
}
|
||||
case 5: {
|
||||
lore.add(toolStats.configTools.formatLore("fished.caught-on", "{date}", date));
|
||||
break;
|
||||
}
|
||||
case 6: {
|
||||
lore.add(toolStats.configTools.formatLore("spawned-in.spawned-on", "{date}", date));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (toolStats.checkConfig(original, "player-kills")) {
|
||||
if (toolStats.configTools.checkConfig(original.getType(), "player-kills")) {
|
||||
if (container.has(toolStats.swordPlayerKills, PersistentDataType.INTEGER)) {
|
||||
Integer kills = container.get(toolStats.swordPlayerKills, PersistentDataType.INTEGER);
|
||||
if (kills != null) {
|
||||
lore.add(toolStats.getLoreFromConfig("kills.player", true).replace("{kills}", Integer.toString(kills)));
|
||||
lore.add(toolStats.configTools.formatLore("kills.player", "{kills}", toolStats.numberFormat.formatInt(kills)));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (toolStats.checkConfig(original, "mob-kills")) {
|
||||
if (toolStats.configTools.checkConfig(original.getType(), "mob-kills")) {
|
||||
if (container.has(toolStats.swordMobKills, PersistentDataType.INTEGER)) {
|
||||
Integer kills = container.get(toolStats.swordMobKills, PersistentDataType.INTEGER);
|
||||
if (kills != null) {
|
||||
lore.add(toolStats.getLoreFromConfig("kills.mob", true).replace("{kills}", Integer.toString(kills)));
|
||||
lore.add(toolStats.configTools.formatLore("kills.mob", "{kills}", toolStats.numberFormat.formatInt(kills)));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (toolStats.checkConfig(original, "blocks-mined")) {
|
||||
if (toolStats.configTools.checkConfig(original.getType(), "blocks-mined")) {
|
||||
if (original.getType().toString().toLowerCase(Locale.ROOT).contains("hoe")) {
|
||||
if (container.has(toolStats.cropsHarvested, PersistentDataType.INTEGER)) {
|
||||
Integer crops = container.get(toolStats.cropsHarvested, PersistentDataType.INTEGER);
|
||||
if (crops != null) {
|
||||
lore.add(toolStats.configTools.formatLore("crops-harvested", "{crops}", toolStats.numberFormat.formatInt(crops)));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (container.has(toolStats.genericMined, PersistentDataType.INTEGER)) {
|
||||
Integer blocksMined = container.get(toolStats.genericMined, PersistentDataType.INTEGER);
|
||||
if (blocksMined != null) {
|
||||
lore.add(toolStats.getLoreFromConfig("blocks-mined", true).replace("{blocks}", Integer.toString(blocksMined)));
|
||||
lore.add(toolStats.configTools.formatLore("blocks-mined", "{blocks}", toolStats.numberFormat.formatInt(blocksMined)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -226,7 +278,7 @@ public class CommandToolStats implements TabExecutor {
|
||||
if (container.has(toolStats.fishingRodCaught, PersistentDataType.INTEGER)) {
|
||||
Integer fish = container.get(toolStats.fishingRodCaught, PersistentDataType.INTEGER);
|
||||
if (fish != null) {
|
||||
lore.add(toolStats.getLoreFromConfig("fished.fish-caught", true).replace("{fish}", Integer.toString(fish)));
|
||||
lore.add(toolStats.configTools.formatLore("fished.fish-caught", "{fish}", toolStats.numberFormat.formatInt(fish)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -234,19 +286,27 @@ public class CommandToolStats implements TabExecutor {
|
||||
if (container.has(toolStats.shearsSheared, PersistentDataType.INTEGER)) {
|
||||
Integer sheep = container.get(toolStats.shearsSheared, PersistentDataType.INTEGER);
|
||||
if (sheep != null) {
|
||||
lore.add(toolStats.getLoreFromConfig("sheep-sheared", true).replace("{sheep}", Integer.toString(sheep)));
|
||||
lore.add(toolStats.configTools.formatLore("sheep-sheared", "{sheep}", toolStats.numberFormat.formatInt(sheep)));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (toolStats.config.getBoolean("enabled.armor-damage")) {
|
||||
if (container.has(toolStats.armorDamage, PersistentDataType.INTEGER)) {
|
||||
Integer damage = container.get(toolStats.armorDamage, PersistentDataType.INTEGER);
|
||||
if (container.has(toolStats.armorDamage, PersistentDataType.DOUBLE)) {
|
||||
Double damage = container.get(toolStats.armorDamage, PersistentDataType.DOUBLE);
|
||||
if (damage != null) {
|
||||
lore.add(toolStats.getLoreFromConfig("damage-taken", true).replace("{damage}", Integer.toString(damage)));
|
||||
lore.add(toolStats.configTools.formatLore("damage-taken", "{damage}", toolStats.numberFormat.formatDouble(damage)));
|
||||
}
|
||||
}
|
||||
}
|
||||
finalMeta.setLore(lore);
|
||||
if (toolStats.config.getBoolean("enabled.arrows-shot")) {
|
||||
if (container.has(toolStats.arrowsShot, PersistentDataType.INTEGER)) {
|
||||
Integer arrows = container.get(toolStats.arrowsShot, PersistentDataType.INTEGER);
|
||||
if (arrows != null) {
|
||||
lore.add(toolStats.configTools.formatLore("arrows-shot", "{arrows}", toolStats.numberFormat.formatInt(arrows)));
|
||||
}
|
||||
}
|
||||
}
|
||||
finalMeta.lore(lore);
|
||||
finalItem.setItemMeta(finalMeta);
|
||||
int slot = player.getInventory().getHeldItemSlot();
|
||||
player.getInventory().setItem(slot, finalItem);
|
||||
@@ -258,13 +318,16 @@ public class CommandToolStats implements TabExecutor {
|
||||
if (args.length == 1) {
|
||||
if (sender.hasPermission("toolstats.reload")) {
|
||||
return Arrays.asList("reset", "reload");
|
||||
} else {
|
||||
}
|
||||
if (sender.hasPermission("toolstats.reset")) {
|
||||
return Collections.singletonList("reset");
|
||||
}
|
||||
}
|
||||
if (args.length == 2) {
|
||||
if (args[0].equalsIgnoreCase("reset")) {
|
||||
return Collections.singletonList("confirm");
|
||||
if (sender.hasPermission("toolstats.reset.confirm")) {
|
||||
return Collections.singletonList("confirm");
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -17,58 +17,76 @@
|
||||
|
||||
package lol.hyper.toolstats.events;
|
||||
|
||||
import io.papermc.paper.threadedregions.scheduler.ScheduledTask;
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.Ageable;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onBreak(BlockBreakEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
Player player = event.getPlayer();
|
||||
// ignore creative mode
|
||||
if (player.getGameMode() != GameMode.SURVIVAL) {
|
||||
if (player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.SPECTATOR) {
|
||||
return;
|
||||
}
|
||||
// if the player mines something with their fist
|
||||
ItemStack heldItem = player.getInventory().getItem(player.getInventory().getHeldItemSlot());
|
||||
if (heldItem == null || heldItem.getType() == Material.AIR) {
|
||||
return;
|
||||
PlayerInventory inventory = player.getInventory();
|
||||
ItemStack heldItem = inventory.getItemInMainHand();
|
||||
Block block = event.getBlock();
|
||||
|
||||
if (block.getType() == Material.CHEST) {
|
||||
toolStats.playerInteract.openedChests.put(block, player);
|
||||
Bukkit.getGlobalRegionScheduler().runDelayed(toolStats, scheduledTask -> toolStats.playerInteract.openedChests.remove(block), 20);
|
||||
}
|
||||
|
||||
// only check certain items
|
||||
String itemName = heldItem.getType().toString().toLowerCase();
|
||||
if (Arrays.stream(validTools).noneMatch(itemName::contains)) {
|
||||
if (!toolStats.itemChecker.isMineTool(heldItem.getType())) {
|
||||
return;
|
||||
}
|
||||
// if it's an item we want, update the stats
|
||||
updateBlocksMined(heldItem);
|
||||
|
||||
if (heldItem.getType().toString().toLowerCase(Locale.ROOT).contains("hoe")) {
|
||||
// player is breaking crops with a hoe
|
||||
if (block.getBlockData() instanceof Ageable) {
|
||||
updateCropsMined(heldItem, (Ageable) block.getBlockData());
|
||||
}
|
||||
} else {
|
||||
// update the blocks mined
|
||||
updateBlocksMined(heldItem);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateBlocksMined(ItemStack itemStack) {
|
||||
ItemMeta meta = itemStack.getItemMeta();
|
||||
private void updateBlocksMined(ItemStack playerTool) {
|
||||
ItemMeta meta = playerTool.getItemMeta();
|
||||
if (meta == null) {
|
||||
toolStats.logger.warning(playerTool + " does NOT have any meta! Unable to update stats.");
|
||||
return;
|
||||
}
|
||||
// read the current stats from the item
|
||||
@@ -78,48 +96,67 @@ public class BlocksMined implements Listener {
|
||||
if (container.has(toolStats.genericMined, PersistentDataType.INTEGER)) {
|
||||
blocksMined = container.get(toolStats.genericMined, PersistentDataType.INTEGER);
|
||||
}
|
||||
|
||||
if (blocksMined == null) {
|
||||
return;
|
||||
} else {
|
||||
blocksMined++;
|
||||
}
|
||||
container.set(toolStats.genericMined, PersistentDataType.INTEGER, blocksMined);
|
||||
|
||||
String configLore = toolStats.getLoreFromConfig("blocks-mined", false);
|
||||
String configLoreRaw = toolStats.getLoreFromConfig("blocks-mined", true);
|
||||
|
||||
if (configLore == null || configLoreRaw == null) {
|
||||
toolStats.logger.warning("There is no lore message for messages.blocks-mined!");
|
||||
return;
|
||||
blocksMined = 0;
|
||||
toolStats.logger.warning(playerTool + " does not have valid generic-mined set! Resting to zero. This should NEVER happen.");
|
||||
}
|
||||
|
||||
List<String> lore;
|
||||
if (meta.hasLore()) {
|
||||
lore = meta.getLore();
|
||||
assert lore != null;
|
||||
boolean hasLore = false;
|
||||
// we do a for loop like this, we can keep track of index
|
||||
// this doesn't mess the lore up of existing items
|
||||
for (int x = 0; x < lore.size(); x++) {
|
||||
if (lore.get(x).contains(configLore)) {
|
||||
hasLore = true;
|
||||
lore.set(x, configLoreRaw.replace("{blocks}", Integer.toString(blocksMined)));
|
||||
break;
|
||||
}
|
||||
}
|
||||
// if the item has lore but doesn't have the tag, add it
|
||||
if (!hasLore) {
|
||||
lore.add(configLoreRaw.replace("{blocks}", Integer.toString(blocksMined)));
|
||||
}
|
||||
} else {
|
||||
// if the item has no lore, create a new list and add the string
|
||||
lore = new ArrayList<>();
|
||||
lore.add(configLoreRaw.replace("{blocks}", Integer.toString(blocksMined)));
|
||||
}
|
||||
container.set(toolStats.genericMined, PersistentDataType.INTEGER, blocksMined + 1);
|
||||
|
||||
// do we add the lore based on the config?
|
||||
if (toolStats.checkConfig(itemStack, "blocks-mined")) {
|
||||
meta.setLore(lore);
|
||||
if (toolStats.configTools.checkConfig(playerTool.getType(), "blocks-mined")) {
|
||||
String oldBlocksMinedFormatted = toolStats.numberFormat.formatInt(blocksMined);
|
||||
String newBlocksMinedFormatted = toolStats.numberFormat.formatInt(blocksMined + 1);
|
||||
Component oldLine = toolStats.configTools.formatLore("blocks-mined", "{blocks}", oldBlocksMinedFormatted);
|
||||
Component newLine = toolStats.configTools.formatLore("blocks-mined", "{blocks}", newBlocksMinedFormatted);
|
||||
if (oldLine == null || newLine == null) {
|
||||
return;
|
||||
}
|
||||
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
||||
meta.lore(newLore);
|
||||
}
|
||||
itemStack.setItemMeta(meta);
|
||||
playerTool.setItemMeta(meta);
|
||||
}
|
||||
|
||||
private void updateCropsMined(ItemStack playerTool, Ageable block) {
|
||||
// ignore crops that are not fully grown
|
||||
if (block.getAge() != block.getMaximumAge()) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemMeta meta = playerTool.getItemMeta();
|
||||
if (meta == null) {
|
||||
toolStats.logger.warning(playerTool + " does NOT have any meta! Unable to update stats.");
|
||||
return;
|
||||
}
|
||||
// read the current stats from the item
|
||||
// if they don't exist, then start from 0
|
||||
Integer cropsMined = 0;
|
||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||
if (container.has(toolStats.cropsHarvested, PersistentDataType.INTEGER)) {
|
||||
cropsMined = container.get(toolStats.cropsHarvested, PersistentDataType.INTEGER);
|
||||
}
|
||||
|
||||
if (cropsMined == null) {
|
||||
cropsMined = 0;
|
||||
toolStats.logger.warning(playerTool + " does not have valid crops-mined set! Resting to zero. This should NEVER happen.");
|
||||
}
|
||||
|
||||
container.set(toolStats.cropsHarvested, PersistentDataType.INTEGER, cropsMined + 1);
|
||||
|
||||
// do we add the lore based on the config?
|
||||
if (toolStats.configTools.checkConfig(playerTool.getType(), "blocks-mined")) {
|
||||
String oldCropsMinedFormatted = toolStats.numberFormat.formatInt(cropsMined);
|
||||
String newCropsMinedFormatted = toolStats.numberFormat.formatInt(cropsMined + 1);
|
||||
Component oldLine = toolStats.configTools.formatLore("crops-harvested", "{crops}", oldCropsMinedFormatted);
|
||||
Component newLine = toolStats.configTools.formatLore("crops-harvested", "{crops}", newCropsMinedFormatted);
|
||||
if (oldLine == null || newLine == null) {
|
||||
return;
|
||||
}
|
||||
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
||||
meta.lore(newLore);
|
||||
}
|
||||
playerTool.setItemMeta(meta);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.ItemFrame;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.world.ChunkPopulateEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@@ -35,7 +36,7 @@ import org.bukkit.persistence.PersistentDataType;
|
||||
public class ChunkPopulate implements Listener {
|
||||
|
||||
// this tags all elytras with a "new" tag
|
||||
// this let's use tag any new elytras player loot
|
||||
// this lets us track any new elytras player loot
|
||||
|
||||
private final ToolStats toolStats;
|
||||
|
||||
@@ -43,32 +44,33 @@ public class ChunkPopulate implements Listener {
|
||||
this.toolStats = toolStats;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onPopulate(ChunkPopulateEvent event) {
|
||||
if (event.getChunk().getWorld().getEnvironment() != World.Environment.THE_END) {
|
||||
return;
|
||||
}
|
||||
World world = event.getChunk().getWorld();
|
||||
// this is delayed because entities are not loaded instantly
|
||||
// we just check 1 second later
|
||||
Bukkit.getScheduler().runTaskLater(toolStats, () -> {
|
||||
Chunk chunk = event.getChunk();
|
||||
Chunk chunk = event.getChunk();
|
||||
Bukkit.getRegionScheduler().runDelayed(toolStats, world, chunk.getX(), chunk.getZ(), scheduledTask -> {
|
||||
for (Entity entity : chunk.getEntities()) {
|
||||
// if there is a new item frame
|
||||
if (entity instanceof ItemFrame) {
|
||||
ItemFrame itemFrame = (ItemFrame) entity;
|
||||
// if the item frame has an elytra
|
||||
if (itemFrame.getItem().getType() == Material.ELYTRA) {
|
||||
ItemStack elytraCopy = itemFrame.getItem();
|
||||
ItemMeta meta = elytraCopy.getItemMeta();
|
||||
if (meta == null) {
|
||||
return;
|
||||
}
|
||||
// add the new tag so we know it's new
|
||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||
container.set(toolStats.newElytra, PersistentDataType.INTEGER, 1);
|
||||
elytraCopy.setItemMeta(meta);
|
||||
itemFrame.setItem(elytraCopy);
|
||||
if (!(entity instanceof ItemFrame itemFrame)) {
|
||||
continue;
|
||||
}
|
||||
// if the item frame has an elytra
|
||||
if (itemFrame.getItem().getType() == Material.ELYTRA) {
|
||||
ItemStack elytraCopy = itemFrame.getItem();
|
||||
ItemMeta meta = elytraCopy.getItemMeta();
|
||||
if (meta == null) {
|
||||
continue;
|
||||
}
|
||||
// add the new tag so we know it's new
|
||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||
container.set(toolStats.newElytra, PersistentDataType.INTEGER, 1);
|
||||
elytraCopy.setItemMeta(meta);
|
||||
itemFrame.setItem(elytraCopy);
|
||||
}
|
||||
}
|
||||
}, 20);
|
||||
|
||||
@@ -18,11 +18,13 @@
|
||||
package lol.hyper.toolstats.events;
|
||||
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import lol.hyper.toolstats.UUIDDataType;
|
||||
import org.bukkit.ChatColor;
|
||||
import lol.hyper.toolstats.tools.UUIDDataType;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.CraftItemEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@@ -30,58 +32,55 @@ import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onCraft(CraftItemEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
if (player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.SPECTATOR) {
|
||||
return;
|
||||
}
|
||||
ItemStack itemStack = event.getCurrentItem();
|
||||
if (itemStack == null || itemStack.getType() == Material.AIR) {
|
||||
return;
|
||||
}
|
||||
String name = itemStack.getType().toString().toLowerCase(Locale.ROOT);
|
||||
// only check for items we want
|
||||
for (String x : validItems) {
|
||||
if (name.contains(x)) {
|
||||
// if the player shift clicks, send them this warning
|
||||
if (event.isShiftClick()) {
|
||||
String configMessage = toolStats.config.getString("messages.shift-click-warning.crafting");
|
||||
if (configMessage != null) {
|
||||
if (configMessage.length() != 0) {
|
||||
event.getWhoClicked().sendMessage(ChatColor.translateAlternateColorCodes('&', configMessage));
|
||||
}
|
||||
}
|
||||
}
|
||||
// test the item before setting it
|
||||
if (addLore(itemStack, player) == null) {
|
||||
return;
|
||||
}
|
||||
// set the result
|
||||
event.setCurrentItem(addLore(itemStack, player));
|
||||
}
|
||||
// only check certain items
|
||||
if (!toolStats.itemChecker.isValidItem(itemStack.getType())) {
|
||||
return;
|
||||
}
|
||||
|
||||
// if the player shift clicks, send them this warning
|
||||
if (event.isShiftClick()) {
|
||||
Component component = toolStats.configTools.formatLore("shift-click-warning", null, null);
|
||||
event.getWhoClicked().sendMessage(component);
|
||||
}
|
||||
|
||||
// test the item before setting it
|
||||
ItemStack newItem = addLore(itemStack, player);
|
||||
if (newItem != null) {
|
||||
// set the result
|
||||
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) {
|
||||
@@ -89,6 +88,7 @@ public class CraftItem implements Listener {
|
||||
ItemStack newItem = itemStack.clone();
|
||||
ItemMeta meta = newItem.getItemMeta();
|
||||
if (meta == null) {
|
||||
toolStats.logger.warning(itemStack + " does NOT have any meta! Unable to update stats.");
|
||||
return null;
|
||||
}
|
||||
// get the current time
|
||||
@@ -102,37 +102,41 @@ public class CraftItem implements Listener {
|
||||
return null;
|
||||
}
|
||||
|
||||
// only make the hash if it's enabled
|
||||
if (toolStats.config.getBoolean("generate-hash-for-items")) {
|
||||
String hash = toolStats.hashMaker.makeHash(newItem.getType(), owner.getUniqueId(), timeCreated);
|
||||
container.set(toolStats.hash, PersistentDataType.STRING, hash);
|
||||
}
|
||||
|
||||
container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated);
|
||||
container.set(toolStats.genericOwner, new UUIDDataType(), owner.getUniqueId());
|
||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 0);
|
||||
|
||||
String createdByRaw = toolStats.getLoreFromConfig("created.created-by", true);
|
||||
String createdOnRaw = toolStats.getLoreFromConfig("created.created-on", true);
|
||||
|
||||
if (createdOnRaw == null) {
|
||||
toolStats.logger.warning("There is no lore message for messages.created.created-on!");
|
||||
return null;
|
||||
}
|
||||
if (createdByRaw == null) {
|
||||
toolStats.logger.warning("There is no lore message for messages.created.created-by!");
|
||||
return null;
|
||||
}
|
||||
|
||||
List<String> lore;
|
||||
List<Component> lore;
|
||||
// get the current lore the item
|
||||
if (meta.hasLore()) {
|
||||
lore = meta.getLore();
|
||||
assert lore != null;
|
||||
lore = meta.lore();
|
||||
} else {
|
||||
lore = new ArrayList<>();
|
||||
}
|
||||
// do we add the lore based on the config?
|
||||
if (toolStats.checkConfig(itemStack, "created-date")) {
|
||||
lore.add(createdOnRaw.replace("{date}", format.format(finalDate)));
|
||||
if (toolStats.configTools.checkConfig(itemStack.getType(), "created-date")) {
|
||||
String date = toolStats.numberFormat.formatDate(finalDate);
|
||||
Component newLine = toolStats.configTools.formatLore("created.created-on", "{date}", date);
|
||||
if (newLine == null) {
|
||||
return null;
|
||||
}
|
||||
lore.add(newLine);
|
||||
meta.lore(lore);
|
||||
}
|
||||
if (toolStats.checkConfig(itemStack, "created-by")) {
|
||||
lore.add(createdByRaw.replace("{player}", owner.getName()));
|
||||
if (toolStats.configTools.checkConfig(itemStack.getType(), "created-by")) {
|
||||
Component newLine = toolStats.configTools.formatLore("created.created-by", "{player}", owner.getName());
|
||||
if (newLine == null) {
|
||||
return null;
|
||||
}
|
||||
lore.add(newLine);
|
||||
meta.lore(lore);
|
||||
}
|
||||
meta.setLore(lore);
|
||||
newItem.setItemMeta(meta);
|
||||
return newItem;
|
||||
}
|
||||
|
||||
115
src/main/java/lol/hyper/toolstats/events/CreativeEvent.java
Normal file
115
src/main/java/lol/hyper/toolstats/events/CreativeEvent.java
Normal file
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* 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 lol.hyper.toolstats.tools.UUIDDataType;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryCreativeEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class CreativeEvent implements Listener {
|
||||
|
||||
private final ToolStats toolStats;
|
||||
|
||||
public CreativeEvent(ToolStats toolStats) {
|
||||
this.toolStats = toolStats;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onCreativeEvent(InventoryCreativeEvent event) {
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
// make sure they are in creative mode
|
||||
if (player.getGameMode() != GameMode.CREATIVE) {
|
||||
return;
|
||||
}
|
||||
ItemStack spawnedItem = event.getCursor();
|
||||
if (!toolStats.itemChecker.isValidItem(spawnedItem.getType())) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemMeta spawnedItemMeta = spawnedItem.getItemMeta();
|
||||
if (spawnedItemMeta == null) {
|
||||
return;
|
||||
}
|
||||
// if the item already has an origin set, don't add it again
|
||||
// this is needed since you can spam click an item and the event will fire again
|
||||
PersistentDataContainer container = spawnedItemMeta.getPersistentDataContainer();
|
||||
if (container.has(toolStats.originType, PersistentDataType.INTEGER)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// add the tags to the item
|
||||
ItemStack newItem = addLore(spawnedItem, player);
|
||||
if (newItem != null) {
|
||||
event.setCursor(newItem);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds tags to newly spawned items in creative.
|
||||
*
|
||||
* @param spawnedItem The item.
|
||||
*/
|
||||
private ItemStack addLore(ItemStack spawnedItem, Player owner) {
|
||||
ItemStack newSpawnedItem = spawnedItem.clone();
|
||||
ItemMeta meta = newSpawnedItem.getItemMeta();
|
||||
if (meta == null) {
|
||||
toolStats.logger.warning(newSpawnedItem + " does NOT have any meta! Unable to update stats.");
|
||||
return null;
|
||||
}
|
||||
|
||||
long timeCreated = System.currentTimeMillis();
|
||||
Date finalDate = new Date(timeCreated);
|
||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||
|
||||
// if the item already has an origin set, don't add it again
|
||||
if (container.has(toolStats.originType, PersistentDataType.INTEGER)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// only make the hash if it's enabled
|
||||
if (toolStats.config.getBoolean("generate-hash-for-items")) {
|
||||
String hash = toolStats.hashMaker.makeHash(spawnedItem.getType(), owner.getUniqueId(), timeCreated);
|
||||
container.set(toolStats.hash, PersistentDataType.STRING, hash);
|
||||
}
|
||||
|
||||
container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated);
|
||||
container.set(toolStats.genericOwner, new UUIDDataType(), owner.getUniqueId());
|
||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 6);
|
||||
|
||||
if (toolStats.configTools.checkConfig(newSpawnedItem.getType(), "spawned-in")) {
|
||||
String formattedDate = toolStats.numberFormat.formatDate(finalDate);
|
||||
List<Component> newLore = toolStats.itemLore.addNewOwner(meta, owner.getName(), formattedDate);
|
||||
meta.lore(newLore);
|
||||
}
|
||||
|
||||
newSpawnedItem.setItemMeta(meta);
|
||||
return newSpawnedItem;
|
||||
}
|
||||
}
|
||||
@@ -18,10 +18,12 @@
|
||||
package lol.hyper.toolstats.events;
|
||||
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDamageByBlockEvent;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
@@ -32,142 +34,176 @@ import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
import java.math.RoundingMode;
|
||||
import java.text.DecimalFormat;
|
||||
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<>();
|
||||
private final List<EntityDamageEvent.DamageCause> ignoredCauses = Arrays.asList(EntityDamageEvent.DamageCause.SUICIDE, EntityDamageEvent.DamageCause.VOID, EntityDamageEvent.DamageCause.CUSTOM, EntityDamageEvent.DamageCause.KILL);
|
||||
|
||||
public EntityDamage(ToolStats toolStats) {
|
||||
this.toolStats = toolStats;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onDamage(EntityDamageByEntityEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
if (!(event.getEntity() instanceof LivingEntity)) {
|
||||
|
||||
if (!(event.getEntity() instanceof LivingEntity mobBeingAttacked)) {
|
||||
return;
|
||||
}
|
||||
LivingEntity livingEntity = (LivingEntity) event.getEntity();
|
||||
|
||||
// ignore void and /kill damage
|
||||
EntityDamageEvent.DamageCause cause = event.getCause();
|
||||
if (ignoredCauses.contains(cause)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// mob is going to die
|
||||
if (livingEntity.getHealth() - event.getFinalDamage() <= 0) {
|
||||
if (mobBeingAttacked.getHealth() - event.getFinalDamage() <= 0) {
|
||||
// a player is killing something
|
||||
if (event.getDamager() instanceof Player) {
|
||||
Player player = (Player) event.getDamager();
|
||||
if (player.getGameMode() != GameMode.SURVIVAL) {
|
||||
if (event.getDamager() instanceof Player attackingPlayer) {
|
||||
if (attackingPlayer.getGameMode() == GameMode.CREATIVE || attackingPlayer.getGameMode() == GameMode.SPECTATOR) {
|
||||
return;
|
||||
}
|
||||
// a player killed something with their fist
|
||||
ItemStack heldItem = player.getInventory().getItem(player.getInventory().getHeldItemSlot());
|
||||
if (heldItem == null || heldItem.getType() == Material.AIR) {
|
||||
return;
|
||||
}
|
||||
// check items we want
|
||||
String itemName = heldItem.getType().toString().toLowerCase();
|
||||
if (Arrays.stream(validTools).noneMatch(itemName::contains)) {
|
||||
PlayerInventory attackingPlayerInventory = attackingPlayer.getInventory();
|
||||
ItemStack heldItem = attackingPlayerInventory.getItemInMainHand();
|
||||
// only check certain items
|
||||
if (!toolStats.itemChecker.isMeleeWeapon(heldItem.getType())) {
|
||||
return;
|
||||
}
|
||||
// a player is killing another player
|
||||
if (livingEntity instanceof Player) {
|
||||
player.getInventory().setItem(player.getInventory().getHeldItemSlot(), updatePlayerKills(heldItem));
|
||||
if (mobBeingAttacked instanceof Player) {
|
||||
updatePlayerKills(heldItem);
|
||||
return;
|
||||
}
|
||||
// player is killing regular mob
|
||||
player.getInventory().setItem(player.getInventory().getHeldItemSlot(), updateMobKills(heldItem));
|
||||
trackedMobs.add(livingEntity.getUniqueId());
|
||||
updateMobKills(heldItem);
|
||||
trackedMobs.add(mobBeingAttacked.getUniqueId());
|
||||
}
|
||||
// trident is being thrown at something
|
||||
if (event.getDamager() instanceof Trident) {
|
||||
Trident trident = (Trident) event.getDamager();
|
||||
ItemStack clone;
|
||||
if (event.getDamager() instanceof Trident trident) {
|
||||
ItemStack newTrident;
|
||||
// trident is killing player
|
||||
if (livingEntity instanceof Player) {
|
||||
clone = updatePlayerKills(trident.getItem());
|
||||
if (mobBeingAttacked instanceof Player) {
|
||||
newTrident = tridentPlayerKills(trident.getItemStack());
|
||||
} else {
|
||||
clone = updateMobKills(trident.getItem());
|
||||
// trident is killing a mob
|
||||
newTrident = tridentMobKills(trident.getItemStack());
|
||||
trackedMobs.add(mobBeingAttacked.getUniqueId());
|
||||
}
|
||||
if (clone == null) {
|
||||
return;
|
||||
if (newTrident != null) {
|
||||
trident.setItemStack(newTrident);
|
||||
}
|
||||
trident.setItem(clone);
|
||||
}
|
||||
// arrow is being shot
|
||||
if (event.getDamager() instanceof Arrow) {
|
||||
Arrow arrow = (Arrow) event.getDamager();
|
||||
if (event.getDamager() instanceof Arrow arrow) {
|
||||
// if the shooter is a player
|
||||
if (arrow.getShooter() instanceof Player) {
|
||||
Player player = (Player) arrow.getShooter();
|
||||
ItemStack heldItem = player.getInventory().getItem(player.getInventory().getHeldItemSlot());
|
||||
if (heldItem == null) {
|
||||
if (arrow.getShooter() instanceof Player shootingPlayer) {
|
||||
if (shootingPlayer.getGameMode() == GameMode.CREATIVE || shootingPlayer.getGameMode() == GameMode.SPECTATOR) {
|
||||
return;
|
||||
}
|
||||
// if the player is holding the bow/crossbow
|
||||
// if they switch then oh well
|
||||
if (heldItem.getType() == Material.BOW || heldItem.getType() == Material.CROSSBOW) {
|
||||
if (livingEntity instanceof Player) {
|
||||
player.getInventory().setItem(player.getInventory().getHeldItemSlot(), updatePlayerKills(heldItem));
|
||||
} else {
|
||||
player.getInventory().setItem(player.getInventory().getHeldItemSlot(), updateMobKills(heldItem));
|
||||
}
|
||||
PlayerInventory inventory = shootingPlayer.getInventory();
|
||||
boolean isMainHand = inventory.getItemInMainHand().getType() == Material.BOW || inventory.getItemInMainHand().getType() == Material.CROSSBOW;
|
||||
boolean isOffHand = inventory.getItemInOffHand().getType() == Material.BOW || inventory.getItemInMainHand().getType() == Material.CROSSBOW;
|
||||
ItemStack heldBow = null;
|
||||
if (isMainHand) {
|
||||
heldBow = inventory.getItemInMainHand();
|
||||
}
|
||||
if (isOffHand) {
|
||||
heldBow = inventory.getItemInOffHand();
|
||||
}
|
||||
|
||||
// if the player is holding a bow in both hands
|
||||
// default to main hand since that takes priority
|
||||
if (isMainHand && isOffHand) {
|
||||
heldBow = inventory.getItemInMainHand();
|
||||
}
|
||||
|
||||
// player swapped
|
||||
if (heldBow == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// player is shooting another player
|
||||
if (mobBeingAttacked instanceof Player) {
|
||||
updatePlayerKills(heldBow);
|
||||
} else {
|
||||
updateMobKills(heldBow);
|
||||
trackedMobs.add(mobBeingAttacked.getUniqueId());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// player is taken damage but not being killed
|
||||
if (livingEntity instanceof Player) {
|
||||
Player player = (Player) livingEntity;
|
||||
PlayerInventory inventory = player.getInventory();
|
||||
for (ItemStack armor : inventory.getArmorContents()) {
|
||||
if (armor != null) {
|
||||
if (isArmor(armor.getType().toString().toLowerCase(Locale.ROOT))) {
|
||||
updateArmorDamage(armor, event.getFinalDamage());
|
||||
if (mobBeingAttacked instanceof Player playerTakingDamage) {
|
||||
if (playerTakingDamage.getGameMode() == GameMode.CREATIVE || playerTakingDamage.getGameMode() == GameMode.SPECTATOR) {
|
||||
return;
|
||||
}
|
||||
PlayerInventory playerInventory = playerTakingDamage.getInventory();
|
||||
for (ItemStack armorPiece : playerInventory.getArmorContents()) {
|
||||
if (armorPiece != null) {
|
||||
if (toolStats.itemChecker.isArmor(armorPiece.getType())) {
|
||||
updateDamage(armorPiece, event.getFinalDamage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onDamage(EntityDamageEvent event) {
|
||||
if (!(event.getEntity() instanceof LivingEntity)) {
|
||||
if (!(event.getEntity() instanceof LivingEntity mobBeingAttacked)) {
|
||||
return;
|
||||
}
|
||||
LivingEntity livingEntity = (LivingEntity) event.getEntity();
|
||||
|
||||
// ignore void and /kill damage
|
||||
EntityDamageEvent.DamageCause cause = event.getCause();
|
||||
if (ignoredCauses.contains(cause)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// player is taken damage but not being killed
|
||||
if (livingEntity instanceof Player) {
|
||||
Player player = (Player) livingEntity;
|
||||
PlayerInventory inventory = player.getInventory();
|
||||
for (ItemStack armor : inventory.getArmorContents()) {
|
||||
if (armor != null) {
|
||||
if (isArmor(armor.getType().toString().toLowerCase(Locale.ROOT))) {
|
||||
updateArmorDamage(armor, event.getFinalDamage());
|
||||
if (mobBeingAttacked instanceof Player playerTakingDamage) {
|
||||
if (playerTakingDamage.getGameMode() == GameMode.CREATIVE || playerTakingDamage.getGameMode() == GameMode.SPECTATOR) {
|
||||
return;
|
||||
}
|
||||
PlayerInventory playerInventory = playerTakingDamage.getInventory();
|
||||
for (ItemStack armorPiece : playerInventory.getArmorContents()) {
|
||||
if (armorPiece != null) {
|
||||
if (toolStats.itemChecker.isArmor(armorPiece.getType())) {
|
||||
updateDamage(armorPiece, event.getFinalDamage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onDamage(EntityDamageByBlockEvent event) {
|
||||
if (!(event.getEntity() instanceof LivingEntity)) {
|
||||
if (!(event.getEntity() instanceof LivingEntity mobBeingAttacked)) {
|
||||
return;
|
||||
}
|
||||
LivingEntity livingEntity = (LivingEntity) event.getEntity();
|
||||
|
||||
// ignore void and /kill damage
|
||||
EntityDamageEvent.DamageCause cause = event.getCause();
|
||||
if (ignoredCauses.contains(cause)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// player is taken damage but not being killed
|
||||
if (livingEntity instanceof Player) {
|
||||
Player player = (Player) livingEntity;
|
||||
PlayerInventory inventory = player.getInventory();
|
||||
for (ItemStack armor : inventory.getArmorContents()) {
|
||||
if (armor != null) {
|
||||
if (isArmor(armor.getType().toString().toLowerCase(Locale.ROOT))) {
|
||||
updateArmorDamage(armor, event.getFinalDamage());
|
||||
if (mobBeingAttacked instanceof Player playerTakingDamage) {
|
||||
if (playerTakingDamage.getGameMode() == GameMode.CREATIVE || playerTakingDamage.getGameMode() == GameMode.SPECTATOR) {
|
||||
return;
|
||||
}
|
||||
PlayerInventory playerInventory = playerTakingDamage.getInventory();
|
||||
for (ItemStack armorPiece : playerInventory.getArmorContents()) {
|
||||
if (armorPiece != null) {
|
||||
if (toolStats.itemChecker.isArmor(armorPiece.getType())) {
|
||||
updateDamage(armorPiece, event.getFinalDamage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -176,136 +212,96 @@ public class EntityDamage implements Listener {
|
||||
|
||||
/**
|
||||
* Updates a weapon's player kills.
|
||||
*
|
||||
* @param itemStack The item to update.
|
||||
* @return A copy of the item.
|
||||
*/
|
||||
private ItemStack updatePlayerKills(ItemStack itemStack) {
|
||||
ItemStack finalItem = itemStack.clone();
|
||||
ItemMeta meta = finalItem.getItemMeta();
|
||||
private void updatePlayerKills(ItemStack itemStack) {
|
||||
ItemMeta meta = itemStack.getItemMeta();
|
||||
if (meta == null) {
|
||||
return null;
|
||||
toolStats.logger.warning(itemStack + " does NOT have any meta! Unable to update stats.");
|
||||
return;
|
||||
}
|
||||
Integer playerKills = 0;
|
||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||
if (container.has(toolStats.swordPlayerKills, PersistentDataType.INTEGER)) {
|
||||
playerKills = container.get(toolStats.swordPlayerKills, PersistentDataType.INTEGER);
|
||||
}
|
||||
|
||||
if (playerKills == null) {
|
||||
return null;
|
||||
} else {
|
||||
playerKills++;
|
||||
}
|
||||
container.set(toolStats.swordPlayerKills, PersistentDataType.INTEGER, playerKills);
|
||||
|
||||
String playerKillsLore = toolStats.getLoreFromConfig("kills.player", false);
|
||||
String playerKillsLoreRaw = toolStats.getLoreFromConfig("kills.player", true);
|
||||
|
||||
if (playerKillsLore == null || playerKillsLoreRaw == null) {
|
||||
toolStats.logger.warning("There is no lore message for messages.kills.player!");
|
||||
return null;
|
||||
playerKills = 0;
|
||||
toolStats.logger.warning(itemStack + " does not have valid player-kills set! Resting to zero. This should NEVER happen.");
|
||||
}
|
||||
|
||||
List<String> lore;
|
||||
if (meta.hasLore()) {
|
||||
lore = meta.getLore();
|
||||
assert lore != null;
|
||||
boolean hasLore = false;
|
||||
// we do a for loop like this, we can keep track of index
|
||||
// this doesn't mess the lore up of existing items
|
||||
for (int x = 0; x < lore.size(); x++) {
|
||||
if (lore.get(x).contains(playerKillsLore)) {
|
||||
hasLore = true;
|
||||
lore.set(x, playerKillsLoreRaw.replace("{kills}", Integer.toString(playerKills)));
|
||||
break;
|
||||
}
|
||||
}
|
||||
// if the item has lore but doesn't have the tag, add it
|
||||
if (!hasLore) {
|
||||
lore.add(playerKillsLoreRaw.replace("{kills}", Integer.toString(playerKills)));
|
||||
}
|
||||
} else {
|
||||
// if the item has no lore, create a new list and add the string
|
||||
lore = new ArrayList<>();
|
||||
lore.add(playerKillsLoreRaw.replace("{kills}", Integer.toString(playerKills)));
|
||||
}
|
||||
container.set(toolStats.swordPlayerKills, PersistentDataType.INTEGER, playerKills + 1);
|
||||
|
||||
// do we add the lore based on the config?
|
||||
if (toolStats.checkConfig(itemStack, "player-kills")) {
|
||||
meta.setLore(lore);
|
||||
if (toolStats.configTools.checkConfig(itemStack.getType(), "player-kills")) {
|
||||
String oldPlayerKillsFormatted = toolStats.numberFormat.formatInt(playerKills);
|
||||
String newPlayerKillsFormatted = toolStats.numberFormat.formatInt(playerKills + 1);
|
||||
Component oldLine = toolStats.configTools.formatLore("kills.player", "{kills}", oldPlayerKillsFormatted);
|
||||
Component newLine = toolStats.configTools.formatLore("kills.player", "{kills}", newPlayerKillsFormatted);
|
||||
if (oldLine == null || newLine == null) {
|
||||
return;
|
||||
}
|
||||
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
||||
meta.lore(newLore);
|
||||
}
|
||||
finalItem.setItemMeta(meta);
|
||||
return finalItem;
|
||||
itemStack.setItemMeta(meta);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a weapon's mob kills.
|
||||
*
|
||||
* @param itemStack The item to update.
|
||||
* @return A copy of the item.
|
||||
*/
|
||||
private ItemStack updateMobKills(ItemStack itemStack) {
|
||||
ItemStack finalItem = itemStack.clone();
|
||||
ItemMeta meta = finalItem.getItemMeta();
|
||||
private void updateMobKills(ItemStack itemStack) {
|
||||
ItemMeta meta = itemStack.getItemMeta();
|
||||
if (meta == null) {
|
||||
return null;
|
||||
toolStats.logger.warning(itemStack + " does NOT have any meta! Unable to update stats.");
|
||||
return;
|
||||
}
|
||||
Integer mobKills = 0;
|
||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||
if (container.has(toolStats.swordMobKills, PersistentDataType.INTEGER)) {
|
||||
mobKills = container.get(toolStats.swordMobKills, PersistentDataType.INTEGER);
|
||||
}
|
||||
|
||||
if (mobKills == null) {
|
||||
return null;
|
||||
} else {
|
||||
mobKills++;
|
||||
}
|
||||
container.set(toolStats.swordMobKills, PersistentDataType.INTEGER, mobKills);
|
||||
|
||||
String mobKillsLore = toolStats.getLoreFromConfig("kills.mob", false);
|
||||
String mobKillsLoreRaw = toolStats.getLoreFromConfig("kills.mob", true);
|
||||
|
||||
if (mobKillsLore == null || mobKillsLoreRaw == null) {
|
||||
toolStats.logger.warning("There is no lore message for messages.kills.mob!");
|
||||
return null;
|
||||
mobKills = 0;
|
||||
toolStats.logger.warning(itemStack + " does not have valid mob-kills set! Resting to zero. This should NEVER happen.");
|
||||
}
|
||||
|
||||
List<String> lore;
|
||||
if (meta.hasLore()) {
|
||||
lore = meta.getLore();
|
||||
assert lore != null;
|
||||
boolean hasLore = false;
|
||||
// we do a for loop like this, we can keep track of index
|
||||
// this doesn't mess the lore up of existing items
|
||||
for (int x = 0; x < lore.size(); x++) {
|
||||
if (lore.get(x).contains(mobKillsLore)) {
|
||||
hasLore = true;
|
||||
lore.set(x, mobKillsLoreRaw.replace("{kills}", Integer.toString(mobKills)));
|
||||
break;
|
||||
}
|
||||
}
|
||||
// if the item has lore but doesn't have the tag, add it
|
||||
if (!hasLore) {
|
||||
lore.add(mobKillsLoreRaw.replace("{kills}", Integer.toString(mobKills)));
|
||||
}
|
||||
} else {
|
||||
// if the item has no lore, create a new list and add the string
|
||||
lore = new ArrayList<>();
|
||||
lore.add(mobKillsLoreRaw.replace("{kills}", Integer.toString(mobKills)));
|
||||
}
|
||||
container.set(toolStats.swordMobKills, PersistentDataType.INTEGER, mobKills + 1);
|
||||
|
||||
// do we add the lore based on the config?
|
||||
if (toolStats.checkConfig(itemStack, "mob-kills")) {
|
||||
meta.setLore(lore);
|
||||
if (toolStats.configTools.checkConfig(itemStack.getType(), "mob-kills")) {
|
||||
String oldMobKillsFormatted = toolStats.numberFormat.formatInt(mobKills);
|
||||
String newMobKillsFormatted = toolStats.numberFormat.formatInt(mobKills + 1);
|
||||
Component oldLine = toolStats.configTools.formatLore("kills.mob", "{kills}", oldMobKillsFormatted);
|
||||
Component newLine = toolStats.configTools.formatLore("kills.mob", "{kills}", newMobKillsFormatted);
|
||||
if (oldLine == null || newLine == null) {
|
||||
return;
|
||||
}
|
||||
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
||||
meta.lore(newLore);
|
||||
}
|
||||
finalItem.setItemMeta(meta);
|
||||
return finalItem;
|
||||
itemStack.setItemMeta(meta);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
private void updateDamage(ItemStack itemStack, double damage) {
|
||||
// ignore if the damage is zero or negative
|
||||
if (damage < 0) {
|
||||
return;
|
||||
}
|
||||
ItemMeta meta = itemStack.getItemMeta();
|
||||
if (meta == null) {
|
||||
toolStats.logger.warning(itemStack + " does NOT have any meta! Unable to update stats.");
|
||||
return;
|
||||
}
|
||||
Double damageTaken = 0.0;
|
||||
@@ -313,57 +309,107 @@ public class EntityDamage implements Listener {
|
||||
if (container.has(toolStats.armorDamage, PersistentDataType.DOUBLE)) {
|
||||
damageTaken = container.get(toolStats.armorDamage, PersistentDataType.DOUBLE);
|
||||
}
|
||||
|
||||
if (damageTaken == null) {
|
||||
return;
|
||||
} else {
|
||||
damageTaken = damageTaken + damage;
|
||||
}
|
||||
decimalFormat.setRoundingMode(RoundingMode.DOWN);
|
||||
container.set(toolStats.armorDamage, PersistentDataType.DOUBLE, damageTaken);
|
||||
|
||||
String damageTakenLore = toolStats.getLoreFromConfig("damage-taken", false);
|
||||
String damageTakenLoreRaw = toolStats.getLoreFromConfig("damage-taken", true);
|
||||
|
||||
if (damageTakenLore == null || damageTakenLoreRaw == null) {
|
||||
toolStats.logger.warning("There is no lore message for messages.damage-taken!");
|
||||
return;
|
||||
damageTaken = 0.0;
|
||||
toolStats.logger.warning(itemStack + " does not have valid damage-taken set! Resting to zero. This should NEVER happen.");
|
||||
}
|
||||
|
||||
List<String> lore;
|
||||
if (meta.hasLore()) {
|
||||
lore = meta.getLore();
|
||||
assert lore != null;
|
||||
boolean hasLore = false;
|
||||
// we do a for loop like this, we can keep track of index
|
||||
// this doesn't mess the lore up of existing items
|
||||
for (int x = 0; x < lore.size(); x++) {
|
||||
if (lore.get(x).contains(damageTakenLore)) {
|
||||
hasLore = true;
|
||||
lore.set(x, damageTakenLoreRaw.replace("{damage}", decimalFormat.format(damageTaken)));
|
||||
break;
|
||||
}
|
||||
}
|
||||
// if the item has lore but doesn't have the tag, add it
|
||||
if (!hasLore) {
|
||||
lore.add(damageTakenLoreRaw.replace("{damage}", decimalFormat.format(damageTaken)));
|
||||
}
|
||||
} else {
|
||||
// if the item has no lore, create a new list and add the string
|
||||
lore = new ArrayList<>();
|
||||
lore.add(damageTakenLoreRaw.replace("{damage}", decimalFormat.format(damageTaken)));
|
||||
}
|
||||
container.set(toolStats.armorDamage, PersistentDataType.DOUBLE, damageTaken + damage);
|
||||
|
||||
if (toolStats.config.getBoolean("enabled.armor-damage")) {
|
||||
meta.setLore(lore);
|
||||
String oldDamageFormatted = toolStats.numberFormat.formatDouble(damageTaken);
|
||||
String newDamageFormatted = toolStats.numberFormat.formatDouble(damageTaken + damage);
|
||||
Component oldLine = toolStats.configTools.formatLore("damage-taken", "{damage}", oldDamageFormatted);
|
||||
Component newLine = toolStats.configTools.formatLore("damage-taken", "{damage}", newDamageFormatted);
|
||||
if (oldLine == null || newLine == null) {
|
||||
return;
|
||||
}
|
||||
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
||||
meta.lore(newLore);
|
||||
}
|
||||
itemStack.setItemMeta(meta);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if item is an armor piece.
|
||||
* @param itemType The item type, not name.
|
||||
* @return If the item is an armor piece.
|
||||
* Updates a trident's mob kills.
|
||||
*
|
||||
* @param trident The item to update.
|
||||
*/
|
||||
private boolean isArmor(String itemType) {
|
||||
return itemType.endsWith("_helmet") || itemType.endsWith("_chestplate") || itemType.endsWith("_leggings") || itemType.endsWith("_boots");
|
||||
private ItemStack tridentMobKills(ItemStack trident) {
|
||||
ItemStack newTrident = trident.clone();
|
||||
ItemMeta meta = newTrident.getItemMeta();
|
||||
if (meta == null) {
|
||||
toolStats.logger.warning(newTrident + " does NOT have any meta! Unable to update stats.");
|
||||
return null;
|
||||
}
|
||||
Integer mobKills = 0;
|
||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||
if (container.has(toolStats.swordMobKills, PersistentDataType.INTEGER)) {
|
||||
mobKills = container.get(toolStats.swordMobKills, PersistentDataType.INTEGER);
|
||||
}
|
||||
|
||||
if (mobKills == null) {
|
||||
mobKills = 0;
|
||||
toolStats.logger.warning(newTrident + " does not have valid mob-kills set! Resting to zero. This should NEVER happen.");
|
||||
}
|
||||
|
||||
container.set(toolStats.swordMobKills, PersistentDataType.INTEGER, mobKills + 1);
|
||||
|
||||
// do we add the lore based on the config?
|
||||
if (toolStats.configTools.checkConfig(newTrident.getType(), "mob-kills")) {
|
||||
String oldMobKillsFormatted = toolStats.numberFormat.formatInt(mobKills);
|
||||
String newMobKillsFormatted = toolStats.numberFormat.formatInt(mobKills + 1);
|
||||
Component oldLine = toolStats.configTools.formatLore("kills.mob", "{kills}", oldMobKillsFormatted);
|
||||
Component newLine = toolStats.configTools.formatLore("kills.mob", "{kills}", newMobKillsFormatted);
|
||||
if (oldLine == null || newLine == null) {
|
||||
return null;
|
||||
}
|
||||
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
||||
meta.lore(newLore);
|
||||
}
|
||||
newTrident.setItemMeta(meta);
|
||||
return newTrident;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a trident's player kills.
|
||||
*
|
||||
* @param trident The item to update.
|
||||
*/
|
||||
private ItemStack tridentPlayerKills(ItemStack trident) {
|
||||
ItemStack newTrident = trident.clone();
|
||||
ItemMeta meta = newTrident.getItemMeta();
|
||||
if (meta == null) {
|
||||
toolStats.logger.warning(newTrident + " does NOT have any meta! Unable to update stats.");
|
||||
return null;
|
||||
}
|
||||
Integer playerKills = 0;
|
||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||
if (container.has(toolStats.swordPlayerKills, PersistentDataType.INTEGER)) {
|
||||
playerKills = container.get(toolStats.swordPlayerKills, PersistentDataType.INTEGER);
|
||||
}
|
||||
|
||||
if (playerKills == null) {
|
||||
playerKills = 0;
|
||||
toolStats.logger.warning(newTrident + " does not have valid player-kills set! Resting to zero. This should NEVER happen.");
|
||||
}
|
||||
|
||||
container.set(toolStats.swordPlayerKills, PersistentDataType.INTEGER, playerKills + 1);
|
||||
|
||||
// do we add the lore based on the config?
|
||||
if (toolStats.configTools.checkConfig(newTrident.getType(), "player-kills")) {
|
||||
String oldPlayerKillsFormatted = toolStats.numberFormat.formatInt(playerKills);
|
||||
String newPlayerKillsFormatted = toolStats.numberFormat.formatInt(playerKills + 1);
|
||||
Component oldLine = toolStats.configTools.formatLore("kills.player", "{kills}", oldPlayerKillsFormatted);
|
||||
Component newLine = toolStats.configTools.formatLore("kills.player", "{kills}", newPlayerKillsFormatted);
|
||||
if (oldLine == null || newLine == null) {
|
||||
return null;
|
||||
}
|
||||
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
||||
meta.lore(newLore);
|
||||
}
|
||||
newTrident.setItemMeta(meta);
|
||||
return newTrident;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,15 +18,20 @@
|
||||
package lol.hyper.toolstats.events;
|
||||
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDeathEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class EntityDeath implements Listener {
|
||||
|
||||
@@ -36,7 +41,7 @@ public class EntityDeath implements Listener {
|
||||
this.toolStats = toolStats;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onDeath(EntityDeathEvent event) {
|
||||
LivingEntity livingEntity = event.getEntity();
|
||||
if (livingEntity instanceof Player) {
|
||||
@@ -45,11 +50,20 @@ public class EntityDeath implements Listener {
|
||||
UUID livingEntityUUID = event.getEntity().getUniqueId();
|
||||
// if it's a mob we are tracking that matters
|
||||
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) {
|
||||
if (name.contains(item)) {
|
||||
addLore(current, livingEntity.getName());
|
||||
for (int i = 0; i < event.getDrops().size(); i++) {
|
||||
ItemStack droppedItem = event.getDrops().get(i);
|
||||
ItemMeta droppedItemMeta = droppedItem.getItemMeta();
|
||||
if (droppedItemMeta != null) {
|
||||
PersistentDataContainer container = droppedItemMeta.getPersistentDataContainer();
|
||||
if (container.has(toolStats.originType, PersistentDataType.INTEGER)) {
|
||||
continue; // ignore any items that have our tags
|
||||
}
|
||||
|
||||
}
|
||||
if (toolStats.itemChecker.isValidItem(droppedItem.getType())) {
|
||||
ItemStack newItem = addLore(droppedItem, livingEntity);
|
||||
if (newItem != null) {
|
||||
event.getDrops().set(i, newItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -59,45 +73,30 @@ 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 oldItem The item to add lore to.
|
||||
* @param entity The mob dying.
|
||||
*/
|
||||
private void addLore(ItemStack itemStack, String mob) {
|
||||
ItemMeta meta = itemStack.getItemMeta();
|
||||
private ItemStack addLore(ItemStack oldItem, LivingEntity entity) {
|
||||
ItemStack newItem = oldItem.clone();
|
||||
ItemMeta meta = newItem.getItemMeta();
|
||||
if (meta == null) {
|
||||
return;
|
||||
}
|
||||
boolean hasTag = false;
|
||||
|
||||
String droppedByLore = toolStats.getLoreFromConfig("dropped-by", false);
|
||||
String droppedByLoreRaw = toolStats.getLoreFromConfig("dropped-by", true);
|
||||
|
||||
if (droppedByLore == null || droppedByLoreRaw == null) {
|
||||
toolStats.logger.warning("There is no lore message for messages.dropped-by!");
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
List<String> lore;
|
||||
if (meta.hasLore()) {
|
||||
lore = meta.getLore();
|
||||
assert lore != null;
|
||||
for (int x = 0; x < lore.size(); x++) {
|
||||
if (lore.get(x).contains(droppedByLore)) {
|
||||
// replace existing tag
|
||||
lore.set(x, droppedByLoreRaw.replace("{name}", mob));
|
||||
hasTag = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// if the item has no lore, create a new list and add the string
|
||||
lore = new ArrayList<>();
|
||||
}
|
||||
if (!hasTag) {
|
||||
lore.add(droppedByLoreRaw.replace("{name}", mob));
|
||||
}
|
||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 1);
|
||||
|
||||
if (toolStats.config.getBoolean("enabled.dropped-by")) {
|
||||
meta.setLore(lore);
|
||||
String mobName = toolStats.config.getString("messages.mob." + entity.getType());
|
||||
if (mobName == null) {
|
||||
mobName = entity.getName();
|
||||
}
|
||||
Component newLine = toolStats.configTools.formatLore("dropped-by", "{name}", mobName);
|
||||
List<Component> newLore = toolStats.itemLore.addItemLore(meta, newLine);
|
||||
meta.lore(newLore);
|
||||
}
|
||||
itemStack.setItemMeta(meta);
|
||||
newItem.setItemMeta(meta);
|
||||
return newItem;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,70 +18,78 @@
|
||||
package lol.hyper.toolstats.events;
|
||||
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import lol.hyper.toolstats.UUIDDataType;
|
||||
import org.bukkit.Bukkit;
|
||||
import lol.hyper.toolstats.tools.UUIDDataType;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Chest;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.minecart.StorageMinecart;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.world.LootGenerateEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
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 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;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onGenerateLoot(LootGenerateEvent event) {
|
||||
InventoryHolder inventoryHolder = event.getInventoryHolder();
|
||||
if (inventoryHolder == null) {
|
||||
return;
|
||||
}
|
||||
Inventory chest = inventoryHolder.getInventory();
|
||||
// run task later since if it runs on the same tick it breaks idk
|
||||
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);
|
||||
// ignore air
|
||||
if (itemStack == null || itemStack.getType() == Material.AIR) {
|
||||
continue;
|
||||
}
|
||||
String name = itemStack.getType().toString().toLowerCase(Locale.ROOT);
|
||||
for (String x : validItems) {
|
||||
if (name.contains(x)) {
|
||||
chest.setItem(i, addLore(itemStack, player));
|
||||
Location lootLocation = event.getLootContext().getLocation();
|
||||
|
||||
if (inventoryHolder instanceof Chest) {
|
||||
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();
|
||||
if (chest.getWorld() == lootLocation.getWorld()) {
|
||||
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;
|
||||
}
|
||||
|
||||
},1);
|
||||
Player player = toolStats.playerInteract.openedChests.get(openedChest);
|
||||
setLoot(event.getLoot(), player);
|
||||
}
|
||||
if (inventoryHolder instanceof StorageMinecart mineCart) {
|
||||
if (toolStats.playerInteract.openedMineCarts.containsKey(mineCart)) {
|
||||
Player player = toolStats.playerInteract.openedMineCarts.get(mineCart);
|
||||
setLoot(event.getLoot(), player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
@@ -98,30 +106,44 @@ public class GenerateLoot implements Listener {
|
||||
return null;
|
||||
}
|
||||
|
||||
// only make the hash if it's enabled
|
||||
if (toolStats.config.getBoolean("generate-hash-for-items")) {
|
||||
String hash = toolStats.hashMaker.makeHash(newItem.getType(), owner.getUniqueId(), timeCreated);
|
||||
container.set(toolStats.hash, PersistentDataType.STRING, hash);
|
||||
}
|
||||
|
||||
container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated);
|
||||
container.set(toolStats.genericOwner, new UUIDDataType(), owner.getUniqueId());
|
||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 2);
|
||||
|
||||
String foundByLoreRaw = toolStats.getLoreFromConfig("looted.found-by", true);
|
||||
String foundOnLoreRaw = toolStats.getLoreFromConfig("looted.found-on", true);
|
||||
|
||||
if (foundByLoreRaw == null || foundOnLoreRaw == null) {
|
||||
toolStats.logger.warning("There is no lore message for messages.looted!");
|
||||
return null;
|
||||
if (toolStats.configTools.checkConfig(newItem.getType(), "looted-tag")) {
|
||||
String formattedDate = toolStats.numberFormat.formatDate(finalDate);
|
||||
List<Component> newLore = toolStats.itemLore.addNewOwner(meta, owner.getName(), formattedDate);
|
||||
meta.lore(newLore);
|
||||
}
|
||||
|
||||
List<String> lore;
|
||||
if (meta.hasLore()) {
|
||||
lore = meta.getLore();
|
||||
assert lore != null;
|
||||
} else {
|
||||
lore = new ArrayList<>();
|
||||
}
|
||||
if (toolStats.checkConfig(newItem, "looted-tag")) {
|
||||
lore.add(foundOnLoreRaw.replace("{date}", format.format(finalDate)));
|
||||
lore.add(foundByLoreRaw.replace("{player}", owner.getName()));
|
||||
}
|
||||
meta.setLore(lore);
|
||||
newItem.setItemMeta(meta);
|
||||
return newItem;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add tags to the generated loot.
|
||||
*
|
||||
* @param loot The loot from the event.
|
||||
* @param player The player triggering the event.
|
||||
*/
|
||||
private void setLoot(List<ItemStack> loot, Player player) {
|
||||
for (int i = 0; i < loot.size(); i++) {
|
||||
ItemStack itemStack = loot.get(i);
|
||||
// ignore air
|
||||
if (itemStack == null || itemStack.getType() == Material.AIR) {
|
||||
continue;
|
||||
}
|
||||
if (toolStats.itemChecker.isValidItem(itemStack.getType())) {
|
||||
ItemStack newItem = addLore(itemStack, player);
|
||||
if (newItem != null) {
|
||||
loot.set(i, newItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
94
src/main/java/lol/hyper/toolstats/events/InventoryOpen.java
Normal file
94
src/main/java/lol/hyper/toolstats/events/InventoryOpen.java
Normal file
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* 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 io.papermc.paper.threadedregions.scheduler.ScheduledTask;
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import lol.hyper.toolstats.tools.UUIDDataType;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryOpenEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class InventoryOpen implements Listener {
|
||||
|
||||
private final ToolStats toolStats;
|
||||
|
||||
public InventoryOpen(ToolStats toolStats) {
|
||||
this.toolStats = toolStats;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onOpen(InventoryOpenEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Inventory inventory = event.getInventory();
|
||||
Location location = event.getInventory().getLocation();
|
||||
for (ItemStack itemStack : inventory) {
|
||||
if (itemStack == null) {
|
||||
continue;
|
||||
}
|
||||
// ignore items that are not the right type
|
||||
if (!toolStats.itemChecker.isValidItem(itemStack.getType())) {
|
||||
continue;
|
||||
}
|
||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
if (itemMeta == null) {
|
||||
continue;
|
||||
}
|
||||
PersistentDataContainer container = itemMeta.getPersistentDataContainer();
|
||||
|
||||
// generate a hash if the item doesn't have one (if it's enabled in the config)
|
||||
if (toolStats.config.getBoolean("generate-hash-for-items")) {
|
||||
if (!container.has(toolStats.hash, PersistentDataType.STRING)) {
|
||||
// make sure the item has an owner
|
||||
if (!container.has(toolStats.genericOwner, new UUIDDataType())) {
|
||||
continue;
|
||||
}
|
||||
UUID owner = container.get(toolStats.genericOwner, new UUIDDataType());
|
||||
if (owner == null) {
|
||||
continue;
|
||||
}
|
||||
Long timestamp = container.get(toolStats.timeCreated, PersistentDataType.LONG);
|
||||
if (timestamp == null) {
|
||||
continue;
|
||||
}
|
||||
String hash = toolStats.hashMaker.makeHash(itemStack.getType(), owner, timestamp);
|
||||
toolStats.logger.info(hash);
|
||||
container.set(toolStats.hash, PersistentDataType.STRING, hash);
|
||||
}
|
||||
}
|
||||
ItemMeta clone = itemMeta.clone();
|
||||
if (location != null) {
|
||||
Bukkit.getRegionScheduler().runDelayed(toolStats, location, scheduledTask -> itemStack.setItemMeta(clone), 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,11 +18,13 @@
|
||||
package lol.hyper.toolstats.events;
|
||||
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import lol.hyper.toolstats.UUIDDataType;
|
||||
import lol.hyper.toolstats.tools.UUIDDataType;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.GameMode;
|
||||
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.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityPickupItemEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@@ -30,38 +32,43 @@ 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;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onPickup(EntityPickupItemEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
Entity entity = event.getEntity();
|
||||
if (entity instanceof Player) {
|
||||
ItemStack itemStack = event.getItem().getItemStack();
|
||||
if (itemStack.getType() == Material.ELYTRA) {
|
||||
if (entity instanceof Player player) {
|
||||
if (player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.SPECTATOR) {
|
||||
return;
|
||||
}
|
||||
Item item = event.getItem();
|
||||
if (item.getType() == EntityType.ITEM) {
|
||||
ItemStack itemStack = event.getItem().getItemStack();
|
||||
ItemMeta meta = itemStack.getItemMeta();
|
||||
if (meta == 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)) {
|
||||
ItemStack newElytra = addLore(itemStack, (Player) event.getEntity());
|
||||
if (newElytra != null) {
|
||||
item.setItemStack(newElytra);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -69,41 +76,37 @@ 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();
|
||||
private ItemStack addLore(ItemStack itemStack, Player owner) {
|
||||
ItemStack finalItem = itemStack.clone();
|
||||
ItemMeta meta = finalItem.getItemMeta();
|
||||
if (meta == null) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
long timeCreated = System.currentTimeMillis();
|
||||
Date finalDate = new Date(timeCreated);
|
||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||
|
||||
// only make the hash if it's enabled
|
||||
if (toolStats.config.getBoolean("generate-hash-for-items")) {
|
||||
String hash = toolStats.hashMaker.makeHash(finalItem.getType(), owner.getUniqueId(), timeCreated);
|
||||
container.set(toolStats.hash, PersistentDataType.STRING, hash);
|
||||
}
|
||||
|
||||
container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated);
|
||||
container.set(toolStats.genericOwner, new UUIDDataType(), owner.getUniqueId());
|
||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 4);
|
||||
container.remove(toolStats.newElytra);
|
||||
|
||||
String foundByLoreRaw = toolStats.getLoreFromConfig("looted.found-by", true);
|
||||
String foundOnLoreRaw = toolStats.getLoreFromConfig("looted.found-on", true);
|
||||
|
||||
if (foundByLoreRaw == null || foundOnLoreRaw == null) {
|
||||
toolStats.logger.warning("There is no lore message for messages.looted!");
|
||||
return;
|
||||
}
|
||||
|
||||
List<String> lore;
|
||||
if (meta.hasLore()) {
|
||||
lore = meta.getLore();
|
||||
assert lore != null;
|
||||
} else {
|
||||
lore = new ArrayList<>();
|
||||
}
|
||||
if (toolStats.config.getBoolean("enabled.elytra-tag")) {
|
||||
lore.add(foundOnLoreRaw.replace("{date}", format.format(finalDate)));
|
||||
lore.add(foundByLoreRaw.replace("{player}", owner.getName()));
|
||||
String formattedDate = toolStats.numberFormat.formatDate(finalDate);
|
||||
List<Component> newLore = toolStats.itemLore.addNewOwner(meta, owner.getName(), formattedDate);
|
||||
meta.lore(newLore);
|
||||
}
|
||||
meta.setLore(lore);
|
||||
itemStack.setItemMeta(meta);
|
||||
finalItem.setItemMeta(meta);
|
||||
return finalItem;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,37 +18,35 @@
|
||||
package lol.hyper.toolstats.events;
|
||||
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import lol.hyper.toolstats.UUIDDataType;
|
||||
import lol.hyper.toolstats.tools.UUIDDataType;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerFishEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
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;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onFish(PlayerFishEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
@@ -59,29 +57,62 @@ public class PlayerFish implements Listener {
|
||||
}
|
||||
|
||||
Player player = event.getPlayer();
|
||||
ItemStack heldItem = player.getInventory().getItem(player.getInventory().getHeldItemSlot());
|
||||
if (heldItem == null || heldItem.getType() == Material.AIR || heldItem.getType() != Material.FISHING_ROD) {
|
||||
if (player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.SPECTATOR) {
|
||||
return;
|
||||
}
|
||||
updateFishCount(heldItem);
|
||||
|
||||
ItemStack fishingRod = getItemStack(player);
|
||||
// player swapped items?
|
||||
if (fishingRod == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// update the fishing rod!
|
||||
updateFishCount(fishingRod);
|
||||
|
||||
// check if the player caught an item
|
||||
if (event.getCaught() == null) {
|
||||
return;
|
||||
}
|
||||
ItemStack caughtItem = ((Item) event.getCaught()).getItemStack();
|
||||
for (String x : validItems) {
|
||||
if (caughtItem.getType().toString().toLowerCase(Locale.ROOT).contains(x)) {
|
||||
addNewLore(caughtItem, player);
|
||||
Item caughtItemEntity = (Item) event.getCaught();
|
||||
if (toolStats.itemChecker.isValidItem(caughtItem.getType())) {
|
||||
ItemStack newItem = addNewLore(caughtItem, player);
|
||||
if (newItem != null) {
|
||||
caughtItemEntity.setItemStack(newItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static @Nullable ItemStack getItemStack(Player player) {
|
||||
PlayerInventory inventory = player.getInventory();
|
||||
boolean isMainHand = inventory.getItemInMainHand().getType() == Material.FISHING_ROD;
|
||||
boolean isOffHand = inventory.getItemInOffHand().getType() == Material.FISHING_ROD;
|
||||
ItemStack fishingRod = null;
|
||||
if (isMainHand) {
|
||||
fishingRod = inventory.getItemInMainHand();
|
||||
}
|
||||
if (isOffHand) {
|
||||
fishingRod = inventory.getItemInOffHand();
|
||||
}
|
||||
|
||||
// if the player is hold fishing rods in both hands
|
||||
// default to main hand since that takes priority
|
||||
if (isMainHand && isOffHand) {
|
||||
fishingRod = inventory.getItemInMainHand();
|
||||
}
|
||||
return fishingRod;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a fishing rod's count.
|
||||
* @param itemStack The fishing rod to update.
|
||||
* Update a fishing rod's fish count.
|
||||
*
|
||||
* @param fishingRod The fishing rod to update.
|
||||
*/
|
||||
private void updateFishCount(ItemStack itemStack) {
|
||||
ItemMeta meta = itemStack.getItemMeta();
|
||||
private void updateFishCount(ItemStack fishingRod) {
|
||||
ItemMeta meta = fishingRod.getItemMeta();
|
||||
if (meta == null) {
|
||||
toolStats.logger.warning(fishingRod + " does NOT have any meta! Unable to update stats.");
|
||||
return;
|
||||
}
|
||||
Integer fishCaught = 0;
|
||||
@@ -89,91 +120,62 @@ public class PlayerFish implements Listener {
|
||||
if (container.has(toolStats.fishingRodCaught, PersistentDataType.INTEGER)) {
|
||||
fishCaught = container.get(toolStats.fishingRodCaught, PersistentDataType.INTEGER);
|
||||
}
|
||||
|
||||
if (fishCaught == null) {
|
||||
return;
|
||||
} else {
|
||||
fishCaught++;
|
||||
}
|
||||
container.set(toolStats.fishingRodCaught, PersistentDataType.INTEGER, fishCaught);
|
||||
|
||||
String fishCaughtLore = toolStats.getLoreFromConfig("fished.fish-caught", false);
|
||||
String fishCaughtLoreRaw = toolStats.getLoreFromConfig("fished.fish-caught", true);
|
||||
|
||||
if (fishCaughtLore == null || fishCaughtLoreRaw == null) {
|
||||
toolStats.logger.warning("There is no lore message for messages.fish-caught!");
|
||||
return;
|
||||
fishCaught = 0;
|
||||
toolStats.logger.warning(fishingRod + " does not have valid fish-caught set! Resting to zero. This should NEVER happen.");
|
||||
}
|
||||
|
||||
List<String> lore;
|
||||
if (meta.hasLore()) {
|
||||
lore = meta.getLore();
|
||||
assert lore != null;
|
||||
boolean hasLore = false;
|
||||
// we do a for loop like this, we can keep track of index
|
||||
// this doesn't mess the lore up of existing items
|
||||
for (int x = 0; x < lore.size(); x++) {
|
||||
if (lore.get(x).contains(fishCaughtLore)) {
|
||||
hasLore = true;
|
||||
lore.set(x, fishCaughtLoreRaw.replace("{fish}", Integer.toString(fishCaught)));
|
||||
break;
|
||||
}
|
||||
}
|
||||
// if the item has lore but doesn't have the tag, add it
|
||||
if (!hasLore) {
|
||||
lore.add(fishCaughtLoreRaw.replace("{fish}", Integer.toString(fishCaught)));
|
||||
}
|
||||
} else {
|
||||
// if the item has no lore, create a new list and add the string
|
||||
lore = new ArrayList<>();
|
||||
lore.add(fishCaughtLoreRaw.replace("{fish}", Integer.toString(fishCaught)));
|
||||
}
|
||||
container.set(toolStats.fishingRodCaught, PersistentDataType.INTEGER, fishCaught + 1);
|
||||
|
||||
if (toolStats.config.getBoolean("enabled.fish-caught")) {
|
||||
meta.setLore(lore);
|
||||
String oldFishFormatted = toolStats.numberFormat.formatInt(fishCaught);
|
||||
String newFishFormatted = toolStats.numberFormat.formatInt(fishCaught + 1);
|
||||
Component oldLine = toolStats.configTools.formatLore("fished.fish-caught", "{fish}", oldFishFormatted);
|
||||
Component newLine = toolStats.configTools.formatLore("fished.fish-caught", "{fish}", newFishFormatted);
|
||||
if (oldLine == null || newLine == null) {
|
||||
return;
|
||||
}
|
||||
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
||||
meta.lore(newLore);
|
||||
}
|
||||
itemStack.setItemMeta(meta);
|
||||
fishingRod.setItemMeta(meta);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds "caught by" tags to newly fished items.
|
||||
* @param itemStack The item to add lore to.
|
||||
* @param owner The player who caught the item.
|
||||
* Add lore to newly caught item.
|
||||
*
|
||||
* @param originalItem The original item to add lore.
|
||||
* @param owner The player who caught it.
|
||||
* @return A copy of the new item with lore.
|
||||
*/
|
||||
private void addNewLore(ItemStack itemStack, Player owner) {
|
||||
ItemMeta meta = itemStack.getItemMeta();
|
||||
private ItemStack addNewLore(ItemStack originalItem, Player owner) {
|
||||
ItemStack newItem = originalItem.clone();
|
||||
ItemMeta meta = originalItem.getItemMeta();
|
||||
if (meta == null) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
long timeCreated = System.currentTimeMillis();
|
||||
Date finalDate = new Date(timeCreated);
|
||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||
|
||||
if (container.has(toolStats.timeCreated, PersistentDataType.LONG) || container.has(toolStats.genericOwner, PersistentDataType.LONG)) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
String hash = toolStats.hashMaker.makeHash(newItem.getType(), owner.getUniqueId(), timeCreated);
|
||||
|
||||
container.set(toolStats.hash, PersistentDataType.STRING, hash);
|
||||
container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated);
|
||||
container.set(toolStats.genericOwner, new UUIDDataType(), owner.getUniqueId());
|
||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 5);
|
||||
|
||||
String caughtByLoreRaw = toolStats.getLoreFromConfig("fished.caught-by", true);
|
||||
String caughtOnLoreRaw = toolStats.getLoreFromConfig("fished.caught-on", true);
|
||||
|
||||
if (caughtByLoreRaw == null || caughtOnLoreRaw == null) {
|
||||
toolStats.logger.warning("There is no lore message for messages.fished!");
|
||||
return;
|
||||
if (toolStats.configTools.checkConfig(newItem.getType(), "fished-tag")) {
|
||||
String formattedDate = toolStats.numberFormat.formatDate(finalDate);
|
||||
List<Component> newLore = toolStats.itemLore.addNewOwner(meta, owner.getName(), formattedDate);
|
||||
meta.lore(newLore);
|
||||
}
|
||||
|
||||
List<String> lore;
|
||||
if (meta.hasLore()) {
|
||||
lore = meta.getLore();
|
||||
assert lore != null;
|
||||
} else {
|
||||
lore = new ArrayList<>();
|
||||
}
|
||||
if (toolStats.checkConfig(itemStack, "fished-tag")) {
|
||||
lore.add(caughtOnLoreRaw.replace("{date}", format.format(finalDate)));
|
||||
lore.add(caughtByLoreRaw.replace("{player}", owner.getName()));
|
||||
}
|
||||
meta.setLore(lore);
|
||||
itemStack.setItemMeta(meta);
|
||||
newItem.setItemMeta(meta);
|
||||
return newItem;
|
||||
}
|
||||
}
|
||||
|
||||
88
src/main/java/lol/hyper/toolstats/events/PlayerInteract.java
Normal file
88
src/main/java/lol/hyper/toolstats/events/PlayerInteract.java
Normal 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.events;
|
||||
|
||||
import io.papermc.paper.threadedregions.scheduler.ScheduledTask;
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.minecart.StorageMinecart;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class PlayerInteract implements Listener {
|
||||
|
||||
private final ToolStats toolStats;
|
||||
|
||||
public final Map<Block, Player> openedChests = new HashMap<>();
|
||||
public final Map<StorageMinecart, Player> openedMineCarts = 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;
|
||||
}
|
||||
|
||||
Player player = event.getPlayer();
|
||||
if (player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.SPECTATOR) {
|
||||
return;
|
||||
}
|
||||
// store when a player opens a chest
|
||||
if (block.getType() != Material.AIR && block.getType() == Material.CHEST) {
|
||||
openedChests.put(block, player);
|
||||
Bukkit.getGlobalRegionScheduler().runDelayed(toolStats, scheduledTask -> openedChests.remove(block), 20);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInteract(PlayerInteractEntityEvent event) {
|
||||
Entity clicked = event.getRightClicked();
|
||||
Player player = event.getPlayer();
|
||||
if (player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.SPECTATOR) {
|
||||
return;
|
||||
}
|
||||
// store when a player opens a minecart
|
||||
if (clicked.getType() == EntityType.CHEST_MINECART) {
|
||||
StorageMinecart storageMinecart = (StorageMinecart) clicked;
|
||||
openedMineCarts.put(storageMinecart, player);
|
||||
Bukkit.getGlobalRegionScheduler().runDelayed(toolStats, scheduledTask -> openedMineCarts.remove(storageMinecart), 20);
|
||||
}
|
||||
}
|
||||
}
|
||||
85
src/main/java/lol/hyper/toolstats/events/PlayerJoin.java
Normal file
85
src/main/java/lol/hyper/toolstats/events/PlayerJoin.java
Normal file
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* 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 io.papermc.paper.threadedregions.scheduler.ScheduledTask;
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import lol.hyper.toolstats.tools.UUIDDataType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class PlayerJoin implements Listener {
|
||||
|
||||
private final ToolStats toolStats;
|
||||
|
||||
public PlayerJoin(ToolStats toolStats) {
|
||||
this.toolStats = toolStats;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
Inventory inventory = player.getInventory();
|
||||
for (ItemStack itemStack : inventory) {
|
||||
if (itemStack == null) {
|
||||
continue;
|
||||
}
|
||||
// ignore items that are not the right type
|
||||
if (!toolStats.itemChecker.isValidItem(itemStack.getType())) {
|
||||
continue;
|
||||
}
|
||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
if (itemMeta == null) {
|
||||
continue;
|
||||
}
|
||||
PersistentDataContainer container = itemMeta.getPersistentDataContainer();
|
||||
|
||||
// generate a hash if the item doesn't have one
|
||||
if (!container.has(toolStats.hash, PersistentDataType.STRING)) {
|
||||
// make sure the item has an owner
|
||||
if (!container.has(toolStats.genericOwner, new UUIDDataType())) {
|
||||
continue;
|
||||
}
|
||||
UUID owner = container.get(toolStats.genericOwner, new UUIDDataType());
|
||||
if (owner == null) {
|
||||
continue;
|
||||
}
|
||||
Long timestamp = container.get(toolStats.timeCreated, PersistentDataType.LONG);
|
||||
if (timestamp == null) {
|
||||
continue;
|
||||
}
|
||||
String hash = toolStats.hashMaker.makeHash(itemStack.getType(), owner, timestamp);
|
||||
container.set(toolStats.hash, PersistentDataType.STRING, hash);
|
||||
}
|
||||
ItemMeta clone = itemMeta.clone();
|
||||
player.getScheduler().runDelayed(toolStats, scheduledTask -> itemStack.setItemMeta(clone), null, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
108
src/main/java/lol/hyper/toolstats/events/PlayerMove.java
Normal file
108
src/main/java/lol/hyper/toolstats/events/PlayerMove.java
Normal file
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* 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 net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class PlayerMove implements Listener {
|
||||
|
||||
private final ToolStats toolStats;
|
||||
private final Map<Player, Long> playerStartFlight = new HashMap<>();
|
||||
|
||||
public PlayerMove(ToolStats toolStats) {
|
||||
this.toolStats = toolStats;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onCraft(PlayerMoveEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
// player starts to fly
|
||||
if (player.isGliding()) {
|
||||
// if they are flying, and we don't have them tracked, add them
|
||||
if (!playerStartFlight.containsKey(player)) {
|
||||
playerStartFlight.put(player, System.currentTimeMillis());
|
||||
}
|
||||
} else {
|
||||
// player is not flying
|
||||
if (playerStartFlight.containsKey(player)) {
|
||||
trackFlight(player, playerStartFlight.get(player));
|
||||
playerStartFlight.remove(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void trackFlight(Player player, long startTime) {
|
||||
ItemStack chest = player.getInventory().getChestplate();
|
||||
// make sure their chest piece is an elytra
|
||||
if (chest == null || chest.getType() != Material.ELYTRA) {
|
||||
return;
|
||||
}
|
||||
ItemMeta meta = chest.getItemMeta();
|
||||
if (meta == null) {
|
||||
toolStats.logger.warning(chest + " does NOT have any meta! Unable to update stats.");
|
||||
return;
|
||||
}
|
||||
|
||||
// read the current stats from the item
|
||||
// if they don't exist, then start from 0
|
||||
Long flightTime = 0L;
|
||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||
if (container.has(toolStats.flightTime, PersistentDataType.LONG)) {
|
||||
flightTime = container.get(toolStats.flightTime, PersistentDataType.LONG);
|
||||
}
|
||||
|
||||
if (flightTime == null) {
|
||||
flightTime = 0L;
|
||||
toolStats.logger.warning(flightTime + " does not have valid flight-time set! Resting to zero. This should NEVER happen.");
|
||||
}
|
||||
|
||||
// get the duration of the flight
|
||||
long duration = (System.currentTimeMillis() - startTime);
|
||||
double newDuration = flightTime + duration;
|
||||
container.set(toolStats.flightTime, PersistentDataType.LONG, flightTime + duration);
|
||||
|
||||
// do we add the lore based on the config?
|
||||
if (toolStats.config.getBoolean("enabled.flight-time")) {
|
||||
String oldFlightFormatted = toolStats.numberFormat.formatDouble((double) flightTime / 1000);
|
||||
String newFlightFormatted = toolStats.numberFormat.formatDouble(newDuration / 1000);
|
||||
Component oldLine = toolStats.configTools.formatLore("flight-time", "{time}", oldFlightFormatted);
|
||||
Component newLine = toolStats.configTools.formatLore("flight-time", "{time}", newFlightFormatted);
|
||||
if (oldLine == null || newLine == null) {
|
||||
return;
|
||||
}
|
||||
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
||||
meta.lore(newLore);
|
||||
}
|
||||
chest.setItemMeta(meta);
|
||||
}
|
||||
}
|
||||
@@ -18,19 +18,23 @@
|
||||
package lol.hyper.toolstats.events;
|
||||
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Sheep;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SheepShear implements Listener {
|
||||
@@ -41,36 +45,64 @@ public class SheepShear implements Listener {
|
||||
this.toolStats = toolStats;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onShear(PlayerInteractEntityEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
Player player = event.getPlayer();
|
||||
Entity entity = event.getRightClicked();
|
||||
if (!(entity instanceof Sheep)) {
|
||||
if (player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.SPECTATOR) {
|
||||
return;
|
||||
}
|
||||
// check if the player is right-clicking with shears only
|
||||
ItemStack heldItem = player.getInventory().getItem(player.getInventory().getHeldItemSlot());
|
||||
if (heldItem == null || heldItem.getType() == Material.AIR || heldItem.getType() != Material.SHEARS) {
|
||||
Entity entity = event.getRightClicked();
|
||||
if (!(entity instanceof Sheep sheep)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Sheep sheep = (Sheep) entity;
|
||||
// make sure the sheep is not sheared
|
||||
if (!sheep.isSheared()) {
|
||||
addLore(heldItem);
|
||||
ItemStack shears = getShears(player);
|
||||
// player swapped items?
|
||||
if (shears == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// make sure the sheep is not sheared
|
||||
if (sheep.isSheared()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// update the stats
|
||||
addLore(shears);
|
||||
}
|
||||
|
||||
private static @Nullable ItemStack getShears(Player player) {
|
||||
PlayerInventory inventory = player.getInventory();
|
||||
boolean isMainHand = inventory.getItemInMainHand().getType() == Material.SHEARS;
|
||||
boolean isOffHand = inventory.getItemInOffHand().getType() == Material.SHEARS;
|
||||
ItemStack shears = null;
|
||||
if (isMainHand) {
|
||||
shears = inventory.getItemInMainHand();
|
||||
}
|
||||
if (isOffHand) {
|
||||
shears = inventory.getItemInOffHand();
|
||||
}
|
||||
|
||||
// if the player is hold shears in both hands
|
||||
// default to main hand since that takes priority
|
||||
if (isMainHand && isOffHand) {
|
||||
shears = inventory.getItemInMainHand();
|
||||
}
|
||||
return shears;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds tags to shears.
|
||||
* @param itemStack The shears.
|
||||
*
|
||||
* @param newShears The shears.
|
||||
*/
|
||||
private void addLore(ItemStack itemStack) {
|
||||
ItemMeta meta = itemStack.getItemMeta();
|
||||
private void addLore(ItemStack newShears) {
|
||||
ItemMeta meta = newShears.getItemMeta();
|
||||
if (meta == null) {
|
||||
toolStats.logger.warning(newShears + " does NOT have any meta! Unable to update stats.");
|
||||
return;
|
||||
}
|
||||
Integer sheepSheared = 0;
|
||||
@@ -78,47 +110,25 @@ public class SheepShear implements Listener {
|
||||
if (container.has(toolStats.shearsSheared, PersistentDataType.INTEGER)) {
|
||||
sheepSheared = container.get(toolStats.shearsSheared, PersistentDataType.INTEGER);
|
||||
}
|
||||
|
||||
if (sheepSheared == null) {
|
||||
return;
|
||||
} else {
|
||||
sheepSheared++;
|
||||
}
|
||||
container.set(toolStats.shearsSheared, PersistentDataType.INTEGER, sheepSheared);
|
||||
|
||||
String sheepShearedLore = toolStats.getLoreFromConfig("sheep-sheared", false);
|
||||
String sheepShearedLoreRaw = toolStats.getLoreFromConfig("sheep-sheared", true);
|
||||
|
||||
if (sheepShearedLore == null || sheepShearedLoreRaw == null) {
|
||||
toolStats.logger.warning("There is no lore message for messages.sheep-sheared!");
|
||||
return;
|
||||
sheepSheared = 0;
|
||||
toolStats.logger.warning(newShears + " does not have valid sheared set! Resting to zero. This should NEVER happen.");
|
||||
}
|
||||
|
||||
List<String> lore;
|
||||
if (meta.hasLore()) {
|
||||
lore = meta.getLore();
|
||||
assert lore != null;
|
||||
boolean hasLore = false;
|
||||
// we do a for loop like this, we can keep track of index
|
||||
// this doesn't mess the lore up of existing items
|
||||
for (int x = 0; x < lore.size(); x++) {
|
||||
if (lore.get(x).contains(sheepShearedLore)) {
|
||||
hasLore = true;
|
||||
lore.set(x, sheepShearedLoreRaw.replace("{sheep}", Integer.toString(sheepSheared)));
|
||||
break;
|
||||
}
|
||||
}
|
||||
// if the item has lore but doesn't have the tag, add it
|
||||
if (!hasLore) {
|
||||
lore.add(sheepShearedLoreRaw.replace("{sheep}", Integer.toString(sheepSheared)));
|
||||
}
|
||||
} else {
|
||||
// if the item has no lore, create a new list and add the string
|
||||
lore = new ArrayList<>();
|
||||
lore.add(sheepShearedLoreRaw.replace("{sheep}", Integer.toString(sheepSheared)));
|
||||
}
|
||||
container.set(toolStats.shearsSheared, PersistentDataType.INTEGER, sheepSheared + 1);
|
||||
|
||||
if (toolStats.config.getBoolean("enabled.sheep-sheared")) {
|
||||
meta.setLore(lore);
|
||||
String oldSheepFormatted = toolStats.numberFormat.formatInt(sheepSheared);
|
||||
String newSheepFormatted = toolStats.numberFormat.formatInt(sheepSheared + 1);
|
||||
Component oldLine = toolStats.configTools.formatLore("sheep-sheared", "{sheep}", oldSheepFormatted);
|
||||
Component newLine = toolStats.configTools.formatLore("sheep-sheared", "{sheep}", newSheepFormatted);
|
||||
if (oldLine == null || newLine == null) {
|
||||
return;
|
||||
}
|
||||
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
||||
meta.lore(newLore);
|
||||
}
|
||||
itemStack.setItemMeta(meta);
|
||||
newShears.setItemMeta(meta);
|
||||
}
|
||||
}
|
||||
|
||||
124
src/main/java/lol/hyper/toolstats/events/ShootBow.java
Normal file
124
src/main/java/lol/hyper/toolstats/events/ShootBow.java
Normal file
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* 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 net.kyori.adventure.text.Component;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityShootBowEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ShootBow implements Listener {
|
||||
|
||||
private final ToolStats toolStats;
|
||||
|
||||
public ShootBow(ToolStats toolStats) {
|
||||
this.toolStats = toolStats;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onShoot(EntityShootBowEvent event) {
|
||||
Entity shooter = event.getEntity();
|
||||
// only listen for players
|
||||
if (!(shooter instanceof Player player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.ADVENTURE) {
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerInventory inventory = player.getInventory();
|
||||
ItemStack heldBow = getBow(inventory);
|
||||
|
||||
// player swapped
|
||||
if (heldBow == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
updateArrowsShot(heldBow);
|
||||
}
|
||||
|
||||
private static @Nullable ItemStack getBow(PlayerInventory inventory) {
|
||||
boolean isMainHand = inventory.getItemInMainHand().getType() == Material.BOW || inventory.getItemInMainHand().getType() == Material.CROSSBOW;
|
||||
boolean isOffHand = inventory.getItemInOffHand().getType() == Material.BOW || inventory.getItemInMainHand().getType() == Material.CROSSBOW;
|
||||
ItemStack heldBow = null;
|
||||
if (isMainHand) {
|
||||
heldBow = inventory.getItemInMainHand();
|
||||
}
|
||||
if (isOffHand) {
|
||||
heldBow = inventory.getItemInOffHand();
|
||||
}
|
||||
|
||||
// if the player is holding a bow in both hands
|
||||
// default to main hand since that takes priority
|
||||
if (isMainHand && isOffHand) {
|
||||
heldBow = inventory.getItemInMainHand();
|
||||
}
|
||||
return heldBow;
|
||||
}
|
||||
|
||||
private void updateArrowsShot(ItemStack bow) {
|
||||
ItemMeta meta = bow.getItemMeta();
|
||||
if (meta == null) {
|
||||
toolStats.logger.warning(bow + " does NOT have any meta! Unable to update stats.");
|
||||
return;
|
||||
}
|
||||
// read the current stats from the item
|
||||
// if they don't exist, then start from 0
|
||||
Integer arrowsShot = 0;
|
||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||
if (container.has(toolStats.arrowsShot, PersistentDataType.INTEGER)) {
|
||||
arrowsShot = container.get(toolStats.arrowsShot, PersistentDataType.INTEGER);
|
||||
}
|
||||
|
||||
if (arrowsShot == null) {
|
||||
arrowsShot = 0;
|
||||
toolStats.logger.warning(arrowsShot + " does not have valid arrows-shot set! Resting to zero. This should NEVER happen.");
|
||||
}
|
||||
|
||||
container.set(toolStats.arrowsShot, PersistentDataType.INTEGER, arrowsShot + 1);
|
||||
|
||||
// do we add the lore based on the config?
|
||||
if (toolStats.config.getBoolean("enabled.arrows-shot")) {
|
||||
String oldArrowsFormatted = toolStats.numberFormat.formatInt(arrowsShot);
|
||||
String newArrowsFormatted = toolStats.numberFormat.formatInt(arrowsShot + 1);
|
||||
Component oldLine = toolStats.configTools.formatLore("arrows-shot", "{arrows}", oldArrowsFormatted);
|
||||
Component newLine = toolStats.configTools.formatLore("arrows-shot", "{arrows}", newArrowsFormatted);
|
||||
if (oldLine == null || newLine == null) {
|
||||
return;
|
||||
}
|
||||
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
||||
meta.lore(newLore);
|
||||
}
|
||||
bow.setItemMeta(meta);
|
||||
}
|
||||
}
|
||||
@@ -18,11 +18,13 @@
|
||||
package lol.hyper.toolstats.events;
|
||||
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import lol.hyper.toolstats.UUIDDataType;
|
||||
import org.bukkit.Bukkit;
|
||||
import lol.hyper.toolstats.tools.UUIDDataType;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
@@ -33,67 +35,66 @@ 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 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;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onTrade(InventoryClickEvent event) {
|
||||
if (event.isCancelled() || event.getCurrentItem() == null) {
|
||||
return;
|
||||
}
|
||||
Inventory inventory = event.getClickedInventory();
|
||||
if (!(event.getWhoClicked() instanceof Player player)) {
|
||||
return;
|
||||
}
|
||||
if (player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.SPECTATOR) {
|
||||
return;
|
||||
}
|
||||
// only check villager inventories
|
||||
if (inventory instanceof MerchantInventory) {
|
||||
// only check the result slot (the item you receive)
|
||||
if (event.getSlotType() == InventoryType.SlotType.RESULT) {
|
||||
ItemStack item = event.getCurrentItem();
|
||||
// only check items we want
|
||||
for (String x : validItems) {
|
||||
if (item.getType().toString().toLowerCase(Locale.ROOT).contains(x)) {
|
||||
// if the player shift clicks show the warning
|
||||
if (event.isShiftClick()) {
|
||||
String configMessage = toolStats.config.getString("messages.shift-click-warning.trading");
|
||||
if (configMessage != null) {
|
||||
event.getWhoClicked().sendMessage(ChatColor.translateAlternateColorCodes('&', configMessage));
|
||||
}
|
||||
}
|
||||
ItemStack newItem = addLore(item, (Player) event.getWhoClicked());
|
||||
if (newItem == null) {
|
||||
return;
|
||||
}
|
||||
// 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);
|
||||
if (!toolStats.itemChecker.isValidItem(item.getType())) {
|
||||
return;
|
||||
}
|
||||
// if the player shift clicks, show the warning
|
||||
if (event.isShiftClick()) {
|
||||
String configMessage = toolStats.config.getString("messages.shift-click-warning.trading");
|
||||
if (configMessage != null) {
|
||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', configMessage));
|
||||
}
|
||||
}
|
||||
ItemStack newItem = addLore(item, player);
|
||||
if (newItem != null) {
|
||||
// set the new item
|
||||
inventory.setItem(event.getSlot(), newItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds "traded by" tags to item.
|
||||
* @param itemStack The item to add lore.
|
||||
* @param owner The player who traded.
|
||||
*
|
||||
* @param oldItem The item to add lore.
|
||||
* @param owner The player who traded.
|
||||
* @return The item with lore.
|
||||
*/
|
||||
private ItemStack addLore(ItemStack itemStack, Player owner) {
|
||||
ItemMeta meta = itemStack.getItemMeta();
|
||||
private ItemStack addLore(ItemStack oldItem, Player owner) {
|
||||
ItemStack newItem = oldItem.clone();
|
||||
ItemMeta meta = newItem.getItemMeta();
|
||||
if (meta == null) {
|
||||
toolStats.logger.warning(newItem + " does NOT have any meta! Unable to update stats.");
|
||||
return null;
|
||||
}
|
||||
long timeCreated = System.currentTimeMillis();
|
||||
@@ -104,30 +105,22 @@ public class VillagerTrade implements Listener {
|
||||
return null;
|
||||
}
|
||||
|
||||
// only make the hash if it's enabled
|
||||
if (toolStats.config.getBoolean("generate-hash-for-items")) {
|
||||
String hash = toolStats.hashMaker.makeHash(newItem.getType(), owner.getUniqueId(), timeCreated);
|
||||
container.set(toolStats.hash, PersistentDataType.STRING, hash);
|
||||
}
|
||||
|
||||
container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated);
|
||||
container.set(toolStats.genericOwner, new UUIDDataType(), owner.getUniqueId());
|
||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 3);
|
||||
|
||||
String tradedByLoreRaw = toolStats.getLoreFromConfig("traded.traded-by", true);
|
||||
String tradedOnLoreRaw = toolStats.getLoreFromConfig("traded.traded-on", true);
|
||||
|
||||
if (tradedByLoreRaw == null || tradedOnLoreRaw == null) {
|
||||
toolStats.logger.warning("There is no lore message for messages.traded!");
|
||||
return null;
|
||||
if (toolStats.configTools.checkConfig(newItem.getType(), "traded-tag")) {
|
||||
String formattedDate = toolStats.numberFormat.formatDate(finalDate);
|
||||
List<Component> newLore = toolStats.itemLore.addNewOwner(meta, owner.getName(), formattedDate);
|
||||
meta.lore(newLore);
|
||||
}
|
||||
|
||||
List<String> lore;
|
||||
if (meta.hasLore()) {
|
||||
lore = meta.getLore();
|
||||
assert lore != null;
|
||||
} else {
|
||||
lore = new ArrayList<>();
|
||||
}
|
||||
if (toolStats.checkConfig(itemStack, "traded-tag")) {
|
||||
lore.add(tradedOnLoreRaw.replace("{date}", format.format(finalDate)));
|
||||
lore.add(tradedByLoreRaw.replace("{player}", owner.getName()));
|
||||
}
|
||||
meta.setLore(lore);
|
||||
itemStack.setItemMeta(meta);
|
||||
return itemStack;
|
||||
newItem.setItemMeta(meta);
|
||||
return newItem;
|
||||
}
|
||||
}
|
||||
|
||||
60
src/main/java/lol/hyper/toolstats/tools/HashMaker.java
Normal file
60
src/main/java/lol/hyper/toolstats/tools/HashMaker.java
Normal 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.tools;
|
||||
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import org.bukkit.Material;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.UUID;
|
||||
|
||||
public class HashMaker {
|
||||
|
||||
private final ToolStats toolStats;
|
||||
|
||||
public HashMaker(ToolStats toolStats) {
|
||||
this.toolStats = toolStats;
|
||||
}
|
||||
|
||||
public String makeHash(Material itemType, UUID player, long timestamp) {
|
||||
String input = itemType.toString() + player.toString() + timestamp;
|
||||
|
||||
try {
|
||||
MessageDigest md = MessageDigest.getInstance("SHA-256");
|
||||
byte[] hashBytes = md.digest(input.getBytes(StandardCharsets.UTF_8));
|
||||
|
||||
StringBuilder hexString = new StringBuilder();
|
||||
for (byte b : hashBytes) {
|
||||
String hex = Integer.toHexString(0xff & b);
|
||||
if (hex.length() == 1) {
|
||||
hexString.append('0');
|
||||
}
|
||||
hexString.append(hex);
|
||||
}
|
||||
|
||||
return hexString.toString();
|
||||
} catch (NoSuchAlgorithmException exception) {
|
||||
toolStats.logger.warning("Unable to generate hash for " + player + "!");
|
||||
toolStats.logger.warning("Generating a random UUID instead.");
|
||||
exception.printStackTrace();
|
||||
return java.util.UUID.randomUUID().toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
108
src/main/java/lol/hyper/toolstats/tools/ItemChecker.java
Normal file
108
src/main/java/lol/hyper/toolstats/tools/ItemChecker.java
Normal file
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import org.bukkit.Material;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public class ItemChecker {
|
||||
|
||||
private final List<Material> validItems = new ArrayList<>();
|
||||
private final List<Material> armorItems = new ArrayList<>();
|
||||
private final List<Material> meleeItems = new ArrayList<>();
|
||||
private final List<Material> mineItems = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Creates an item checker and saves all valid items we want.
|
||||
*/
|
||||
public ItemChecker() {
|
||||
for (Material material : Material.values()) {
|
||||
String lowerCase = material.toString().toLowerCase(Locale.ROOT);
|
||||
if (lowerCase.contains("_pickaxe") || lowerCase.contains("_axe") || lowerCase.contains("_hoe") || lowerCase.contains("_shovel")) {
|
||||
mineItems.add(material);
|
||||
}
|
||||
|
||||
if (lowerCase.contains("_sword") || lowerCase.contains("_axe")) {
|
||||
meleeItems.add(material);
|
||||
}
|
||||
|
||||
if (lowerCase.contains("_helmet") || lowerCase.contains("_chestplate") || lowerCase.contains("_leggings") || lowerCase.contains("_boots")) {
|
||||
armorItems.add(material);
|
||||
}
|
||||
if (lowerCase.equalsIgnoreCase("mace")) {
|
||||
meleeItems.add(material);
|
||||
}
|
||||
}
|
||||
|
||||
// hardcode these
|
||||
mineItems.add(Material.SHEARS);
|
||||
meleeItems.add(Material.TRIDENT);
|
||||
validItems.add(Material.BOW);
|
||||
validItems.add(Material.FISHING_ROD);
|
||||
validItems.add(Material.CROSSBOW);
|
||||
validItems.add(Material.ELYTRA);
|
||||
|
||||
// combine the lists
|
||||
validItems.addAll(armorItems);
|
||||
validItems.addAll(meleeItems);
|
||||
validItems.addAll(mineItems);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if item is an armor piece.
|
||||
*
|
||||
* @param itemType The item type, not name.
|
||||
* @return If the item is an armor piece.
|
||||
*/
|
||||
public boolean isArmor(Material itemType) {
|
||||
return armorItems.contains(itemType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if item is a tool or armor piece we want to track.
|
||||
*
|
||||
* @param itemType The item type, not name.
|
||||
* @return If the item something we want to track.
|
||||
*/
|
||||
public boolean isValidItem(Material itemType) {
|
||||
return validItems.contains(itemType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if item is a melee weapon.
|
||||
*
|
||||
* @param itemType The item type, not name.
|
||||
* @return If the item is a melee weapon.
|
||||
*/
|
||||
public boolean isMeleeWeapon(Material itemType) {
|
||||
return meleeItems.contains(itemType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if item is a mining tool.
|
||||
*
|
||||
* @param itemType The item type, not name.
|
||||
* @return If the item is a mining tool.
|
||||
*/
|
||||
public boolean isMineTool(Material itemType) {
|
||||
return mineItems.contains(itemType);
|
||||
}
|
||||
}
|
||||
207
src/main/java/lol/hyper/toolstats/tools/ItemLore.java
Normal file
207
src/main/java/lol/hyper/toolstats/tools/ItemLore.java
Normal file
@@ -0,0 +1,207 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ItemLore {
|
||||
|
||||
private final ToolStats toolStats;
|
||||
|
||||
public ItemLore(ToolStats toolStats) {
|
||||
this.toolStats = toolStats;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates existing lore on an item.
|
||||
*
|
||||
* @param itemMeta The item's meta.
|
||||
* @param oldLine The old line to replace.
|
||||
* @param newLine The new line to replace oldLine.
|
||||
* @return The item's new lore.
|
||||
*/
|
||||
public List<Component> updateItemLore(ItemMeta itemMeta, Component oldLine, Component newLine) {
|
||||
List<Component> itemLore;
|
||||
if (itemMeta.hasLore()) {
|
||||
itemLore = itemMeta.lore();
|
||||
// keep track of line index
|
||||
// this doesn't mess the lore of existing items
|
||||
for (int x = 0; x < itemLore.size(); x++) {
|
||||
Component line = itemLore.get(x);
|
||||
// find the old line to update, keeping index
|
||||
// this means we update this line only!
|
||||
if (line.equals(oldLine)) {
|
||||
itemLore.set(x, newLine);
|
||||
return itemLore;
|
||||
}
|
||||
}
|
||||
// if the item has lore, but we didn't find the line
|
||||
itemLore.add(newLine);
|
||||
} else {
|
||||
// if the item has no lore, create a new list and add the line
|
||||
itemLore = new ArrayList<>();
|
||||
itemLore.add(newLine);
|
||||
}
|
||||
return itemLore;
|
||||
}
|
||||
|
||||
public List<Component> addItemLore(ItemMeta itemMeta, Component newLine) {
|
||||
List<Component> itemLore;
|
||||
if (itemMeta.hasLore()) {
|
||||
itemLore = itemMeta.lore();
|
||||
itemLore.add(newLine);
|
||||
} else {
|
||||
itemLore = new ArrayList<>();
|
||||
itemLore.add(newLine);
|
||||
}
|
||||
return itemLore;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds new ownership to an item.
|
||||
*
|
||||
* @param itemMeta The item meta.
|
||||
* @param playerName The new owner of item.
|
||||
* @param formattedDate The date of the ownership.
|
||||
* @return The item's new lore.
|
||||
*/
|
||||
public List<Component> addNewOwner(ItemMeta itemMeta, String playerName, String formattedDate) {
|
||||
Component dateCreatedLore;
|
||||
Component itemOwnerLore;
|
||||
Integer origin = null;
|
||||
PersistentDataContainer container = itemMeta.getPersistentDataContainer();
|
||||
if (container.has(toolStats.originType, PersistentDataType.INTEGER)) {
|
||||
origin = container.get(toolStats.originType, PersistentDataType.INTEGER);
|
||||
}
|
||||
|
||||
// if the origin is broken, don't try to set the lore
|
||||
if (origin == null) {
|
||||
toolStats.logger.info("Unable to determine origin for item " + itemMeta.getAsString());
|
||||
toolStats.logger.info("This IS a bug, please report this to the GitHub.");
|
||||
return itemMeta.lore();
|
||||
}
|
||||
|
||||
// set the lore based on the origin
|
||||
switch (origin) {
|
||||
case 2: {
|
||||
dateCreatedLore = toolStats.configTools.formatLore("looted.looted-on", "{date}", formattedDate);
|
||||
itemOwnerLore = toolStats.configTools.formatLore("looted.looted-by", "{player}", playerName);
|
||||
|
||||
if (dateCreatedLore == null) {
|
||||
toolStats.logger.warning("messages.looted.looted-on is not set in your config!");
|
||||
toolStats.logger.warning("Unable to update lore for item.");
|
||||
return itemMeta.lore();
|
||||
}
|
||||
if (itemOwnerLore == null) {
|
||||
toolStats.logger.warning("messages.looted.looted-by is not set in your config!");
|
||||
toolStats.logger.warning("Unable to update lore for item.");
|
||||
return itemMeta.lore();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
dateCreatedLore = toolStats.configTools.formatLore("traded.traded-on", "{date}", formattedDate);
|
||||
itemOwnerLore = toolStats.configTools.formatLore("traded.traded-by", "{player}", playerName);
|
||||
|
||||
if (dateCreatedLore == null) {
|
||||
toolStats.logger.warning("messages.traded.traded-on is not set in your config!");
|
||||
toolStats.logger.warning("Unable to update lore for item.");
|
||||
return itemMeta.lore();
|
||||
}
|
||||
if (itemOwnerLore == null) {
|
||||
toolStats.logger.warning("messages.traded.traded-by is not set in your config!");
|
||||
toolStats.logger.warning("Unable to update lore for item.");
|
||||
return itemMeta.lore();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 4: {
|
||||
dateCreatedLore = toolStats.configTools.formatLore("looted.found-on", "{date}", formattedDate);
|
||||
itemOwnerLore = toolStats.configTools.formatLore("looted.found-by", "{player}", playerName);
|
||||
|
||||
if (dateCreatedLore == null) {
|
||||
toolStats.logger.warning("messages.looted.found-on is not set in your config!");
|
||||
toolStats.logger.warning("Unable to update lore for item.");
|
||||
return itemMeta.lore();
|
||||
}
|
||||
if (itemOwnerLore == null) {
|
||||
toolStats.logger.warning("messages.looted.found-by is not set in your config!");
|
||||
toolStats.logger.warning("Unable to update lore for item.");
|
||||
return itemMeta.lore();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 5: {
|
||||
dateCreatedLore = toolStats.configTools.formatLore("fished.caught-on", "{date}", formattedDate);
|
||||
itemOwnerLore = toolStats.configTools.formatLore("fished.caught-by", "{player}", playerName);
|
||||
|
||||
if (dateCreatedLore == null) {
|
||||
toolStats.logger.warning("messages.fished.caught-on is not set in your config!");
|
||||
toolStats.logger.warning("Unable to update lore for item.");
|
||||
return itemMeta.lore();
|
||||
}
|
||||
if (itemOwnerLore == null) {
|
||||
toolStats.logger.warning("messages.fished.caught-by is not set in your config!");
|
||||
toolStats.logger.warning("Unable to update lore for item.");
|
||||
return itemMeta.lore();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 6: {
|
||||
dateCreatedLore = toolStats.configTools.formatLore("spawned-in.spawned-on", "{date}", formattedDate);
|
||||
itemOwnerLore = toolStats.configTools.formatLore("spawned-in.spawned-by", "{player}", playerName);
|
||||
|
||||
if (dateCreatedLore == null) {
|
||||
toolStats.logger.warning("messages.spawned-in.spawned-on is not set in your config!");
|
||||
toolStats.logger.warning("Unable to update lore for item.");
|
||||
return itemMeta.lore();
|
||||
}
|
||||
if (itemOwnerLore == null) {
|
||||
toolStats.logger.warning("messages.spawned-in.spawned-by is not set in your config!");
|
||||
toolStats.logger.warning("Unable to update lore for item.");
|
||||
return itemMeta.lore();
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
toolStats.logger.warning("Origin " + origin + " was found. Data was modified OR something REALLY broke.");
|
||||
toolStats.logger.warning(itemMeta.getAsString());
|
||||
return itemMeta.lore();
|
||||
}
|
||||
}
|
||||
|
||||
List<Component> newLore;
|
||||
if (itemMeta.hasLore()) {
|
||||
newLore = itemMeta.lore();
|
||||
} else {
|
||||
newLore = new ArrayList<>();
|
||||
}
|
||||
|
||||
newLore.add(dateCreatedLore);
|
||||
newLore.add(itemOwnerLore);
|
||||
return newLore;
|
||||
}
|
||||
}
|
||||
139
src/main/java/lol/hyper/toolstats/tools/NumberFormat.java
Normal file
139
src/main/java/lol/hyper/toolstats/tools/NumberFormat.java
Normal file
@@ -0,0 +1,139 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.DecimalFormatSymbols;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
public class NumberFormat {
|
||||
|
||||
private DecimalFormat DECIMAL_FORMAT;
|
||||
private DecimalFormat COMMA_FORMAT;
|
||||
private SimpleDateFormat DATE_FORMAT;
|
||||
|
||||
/**
|
||||
* Utility class to format different numbers
|
||||
* @param toolStats Plugin instance.
|
||||
*/
|
||||
public NumberFormat(ToolStats toolStats) {
|
||||
|
||||
String dateFormat = toolStats.config.getString("date-format");
|
||||
String decimalSeparator = toolStats.config.getString("number-formats.decimal-separator");
|
||||
String commaSeparator = toolStats.config.getString("number-formats.comma-separator");
|
||||
String commaFormat = toolStats.config.getString("number-formats.comma-format");
|
||||
String decimalFormat = toolStats.config.getString("number-formats.decimal-format");
|
||||
|
||||
// if these config values are missing, use the default ones
|
||||
if (dateFormat == null) {
|
||||
dateFormat = "M/dd/yyyy";
|
||||
toolStats.logger.warning("date-format is missing! Using default American English format.");
|
||||
}
|
||||
|
||||
if (decimalSeparator == null) {
|
||||
decimalSeparator = ".";
|
||||
toolStats.logger.warning("number-formats.decimal-separator is missing! Using default \".\" instead.");
|
||||
}
|
||||
|
||||
if (commaSeparator == null) {
|
||||
commaSeparator = ",";
|
||||
toolStats.logger.warning("number-formats.comma-separator is missing! Using default \",\" instead.");
|
||||
}
|
||||
|
||||
if (commaFormat == null) {
|
||||
commaFormat = "#,###";
|
||||
toolStats.logger.warning("number-formats.comma-format is missing! Using default #,### instead.");
|
||||
}
|
||||
|
||||
if (decimalFormat == null) {
|
||||
decimalFormat = "#,###.00";
|
||||
toolStats.logger.warning("number-formats.comma-separator is missing! Using default #,###.00 instead.");
|
||||
}
|
||||
|
||||
// test the date format
|
||||
try {
|
||||
DATE_FORMAT = new SimpleDateFormat(dateFormat, Locale.getDefault());
|
||||
} catch (NullPointerException | IllegalArgumentException exception) {
|
||||
toolStats.logger.warning("date-format is NOT a valid format! Using default American English format.");
|
||||
exception.printStackTrace();
|
||||
DATE_FORMAT = new SimpleDateFormat("M/dd/yyyy", Locale.ENGLISH);
|
||||
}
|
||||
|
||||
// set the separators
|
||||
DecimalFormatSymbols formatSymbols = new DecimalFormatSymbols(Locale.getDefault());
|
||||
formatSymbols.setDecimalSeparator(decimalSeparator.charAt(0));
|
||||
formatSymbols.setGroupingSeparator(commaSeparator.charAt(0));
|
||||
|
||||
|
||||
// test the comma format
|
||||
try {
|
||||
COMMA_FORMAT = new DecimalFormat(commaFormat, formatSymbols);
|
||||
} catch (NullPointerException | IllegalArgumentException exception) {
|
||||
toolStats.logger.warning("number-formats.comma-format is NOT a valid format! Using default #,### instead.");
|
||||
exception.printStackTrace();
|
||||
COMMA_FORMAT = new DecimalFormat("#,###", formatSymbols);
|
||||
}
|
||||
|
||||
// test the decimal format
|
||||
try {
|
||||
DECIMAL_FORMAT = new DecimalFormat(decimalFormat, formatSymbols);
|
||||
} catch (NullPointerException | IllegalArgumentException exception) {
|
||||
toolStats.logger.warning("number-formats.decimal-format is NOT a valid format! Using default #,###.00 instead.");
|
||||
exception.printStackTrace();
|
||||
DECIMAL_FORMAT = new DecimalFormat("#,###.00", formatSymbols);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats a number to make it pretty. Example: 4322 to 4,322
|
||||
*
|
||||
* @param number The number to format.
|
||||
* @return The formatted number.
|
||||
*/
|
||||
public String formatInt(int number) {
|
||||
String finalNumber = COMMA_FORMAT.format(number);
|
||||
finalNumber = finalNumber.replaceAll("[\\x{202f}\\x{00A0}]", " ");
|
||||
return finalNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats a number to make it pretty. Example: 4322.33 to 4,322.33
|
||||
*
|
||||
* @param number The number to format.
|
||||
* @return The formatted number.
|
||||
*/
|
||||
public String formatDouble(double number) {
|
||||
String finalNumber = DECIMAL_FORMAT.format(number);
|
||||
finalNumber = finalNumber.replaceAll("[\\x{202f}\\x{00A0}]", " ");
|
||||
return finalNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats a date into the readable format.
|
||||
*
|
||||
* @param date The date to format.
|
||||
* @return The date into a readable format.
|
||||
*/
|
||||
public String formatDate(Date date) {
|
||||
return DATE_FORMAT.format(date);
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,24 @@
|
||||
* along with ToolStats. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package lol.hyper.toolstats;
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import org.bukkit.persistence.PersistentDataAdapterContext;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
137
src/main/java/lol/hyper/toolstats/tools/config/ConfigTools.java
Normal file
137
src/main/java/lol/hyper/toolstats/tools/config/ConfigTools.java
Normal file
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.bukkit.Material;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class ConfigTools {
|
||||
|
||||
private final ToolStats toolStats;
|
||||
public static final Pattern COLOR_CODES = Pattern.compile("[&§]([0-9a-fk-or])");
|
||||
public static final Pattern CONFIG_HEX_PATTERN = Pattern.compile("[&§]#([A-Fa-f0-9]{6})");
|
||||
public static final Pattern MINECRAFT_HEX_PATTERN = Pattern.compile("§x(?:§[a-fA-F0-9]){6}|§[a-fA-F0-9]");
|
||||
|
||||
public ConfigTools(ToolStats toolStats) {
|
||||
this.toolStats = toolStats;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the config to see if we want to show lore on certain items.
|
||||
*
|
||||
* @param material The item type to check.
|
||||
* @param configName The config we are checking under.
|
||||
* @return If we want to allow lore or not.
|
||||
*/
|
||||
public boolean checkConfig(Material material, String configName) {
|
||||
String itemName = material.toString().toLowerCase();
|
||||
String itemType = null;
|
||||
// hardcode these
|
||||
if (material == Material.BOW || material == Material.CROSSBOW || material == Material.SHEARS || material == Material.TRIDENT || material == Material.FISHING_ROD) {
|
||||
switch (material) {
|
||||
case CROSSBOW:
|
||||
case BOW: {
|
||||
itemType = "bow";
|
||||
break;
|
||||
}
|
||||
case SHEARS: {
|
||||
itemType = "shears";
|
||||
break;
|
||||
}
|
||||
case TRIDENT: {
|
||||
itemType = "trident";
|
||||
break;
|
||||
}
|
||||
case FISHING_ROD: {
|
||||
itemType = "fishing-rod";
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
itemType = itemName.substring(itemName.indexOf('_') + 1);
|
||||
}
|
||||
|
||||
return switch (itemType) {
|
||||
case "pickaxe" -> toolStats.config.getBoolean("enabled." + configName + ".pickaxe");
|
||||
case "sword" -> toolStats.config.getBoolean("enabled." + configName + ".sword");
|
||||
case "shovel" -> toolStats.config.getBoolean("enabled." + configName + ".shovel");
|
||||
case "axe" -> toolStats.config.getBoolean("enabled." + configName + ".axe");
|
||||
case "hoe" -> toolStats.config.getBoolean("enabled." + configName + ".hoe");
|
||||
case "shears" -> toolStats.config.getBoolean("enabled." + configName + ".shears");
|
||||
case "crossbow", "bow" -> toolStats.config.getBoolean("enabled." + configName + ".bow");
|
||||
case "trident" -> toolStats.config.getBoolean("enabled." + configName + ".trident");
|
||||
case "fishing-rod" -> toolStats.config.getBoolean("enabled." + configName + ".fishing-rod");
|
||||
case "mace" -> toolStats.config.getBoolean("enabled." + configName + ".mace");
|
||||
case "helmet", "chestplate", "leggings", "boots" ->
|
||||
toolStats.config.getBoolean("enabled." + configName + ".armor");
|
||||
default -> false;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a string to be ready for lore usage.
|
||||
*
|
||||
* @param configName The message to use.
|
||||
* @param placeHolder The placeholder text in the message.
|
||||
* @param value The value to set the placeholder.
|
||||
* @return Formatted string, null if the configName doesn't exist.
|
||||
*/
|
||||
public Component formatLore(String configName, String placeHolder, Object value) {
|
||||
String lore = toolStats.config.getString("messages." + configName);
|
||||
if (lore == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// the final component for this lore
|
||||
Component component;
|
||||
|
||||
// set the placeholder to the value
|
||||
lore = lore.replace(placeHolder, String.valueOf(value));
|
||||
|
||||
// if we match the old color codes, then format them as so
|
||||
Matcher hexMatcher = CONFIG_HEX_PATTERN.matcher(lore);
|
||||
Matcher colorMatcher = COLOR_CODES.matcher(lore);
|
||||
if (hexMatcher.find() || colorMatcher.find()) {
|
||||
component = LegacyComponentSerializer.legacyAmpersand().deserialize(lore);
|
||||
} else {
|
||||
// otherwise format them normally
|
||||
component = Component.text(lore);
|
||||
}
|
||||
|
||||
return component.decorationIfAbsent(TextDecoration.ITALIC, TextDecoration.State.FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all color codes from a message.
|
||||
*
|
||||
* @param message The message.
|
||||
* @return The message without color codes.
|
||||
*/
|
||||
public String removeColor(String message) {
|
||||
message = MINECRAFT_HEX_PATTERN.matcher(message).replaceAll("");
|
||||
message = COLOR_CODES.matcher(message).replaceAll("");
|
||||
message = CONFIG_HEX_PATTERN.matcher(message).replaceAll("");
|
||||
return message;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import lol.hyper.toolstats.tools.config.versions.Version6;
|
||||
import lol.hyper.toolstats.tools.config.versions.Version7;
|
||||
import lol.hyper.toolstats.tools.config.versions.Version8;
|
||||
|
||||
public class ConfigUpdater {
|
||||
|
||||
private final ToolStats toolStats;
|
||||
|
||||
public ConfigUpdater(ToolStats toolStats) {
|
||||
this.toolStats = toolStats;
|
||||
}
|
||||
|
||||
public void updateConfig() {
|
||||
int version = toolStats.config.getInt("config-version");
|
||||
|
||||
switch(version) {
|
||||
case 5: {
|
||||
// Version 5 to 6
|
||||
Version6 version6 = new Version6(toolStats);
|
||||
version6.update();
|
||||
break;
|
||||
}
|
||||
case 6: {
|
||||
// Version 6 to 7
|
||||
Version7 version7 = new Version7(toolStats);
|
||||
version7.update();
|
||||
break;
|
||||
}
|
||||
case 7: {
|
||||
// Version 7 to 8
|
||||
Version8 version8 = new Version8(toolStats);
|
||||
version8.update();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
* 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 java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class Version6 {
|
||||
|
||||
private final ToolStats toolStats;
|
||||
|
||||
/**
|
||||
* Used for updating from version 5 to 6.
|
||||
*
|
||||
* @param toolStats ToolStats instance.
|
||||
*/
|
||||
public Version6(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-5.yml");
|
||||
} catch (IOException exception) {
|
||||
toolStats.logger.severe("Unable to save config-5.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 6.");
|
||||
toolStats.config.set("config-version", 6);
|
||||
toolStats.logger.info("Adding enabled.spawned-in.pickaxe to config.yml.");
|
||||
toolStats.config.set("enabled.spawned-in.pickaxe", true);
|
||||
|
||||
toolStats.logger.info("Adding enabled.spawned-in.sword to config.yml.");
|
||||
toolStats.config.set("enabled.spawned-in.sword", true);
|
||||
|
||||
toolStats.logger.info("Adding enabled.spawned-in.shovel to config.yml.");
|
||||
toolStats.config.set("enabled.spawned-in.shovel", true);
|
||||
|
||||
toolStats.logger.info("Adding enabled.spawned-in.axe to config.yml.");
|
||||
toolStats.config.set("enabled.spawned-in.axe", true);
|
||||
|
||||
toolStats.logger.info("Adding enabled.spawned-in.hoe to config.yml.");
|
||||
toolStats.config.set("enabled.spawned-in.hoe", true);
|
||||
|
||||
toolStats.logger.info("Adding enabled.spawned-in.fishing-rod to config.yml.");
|
||||
toolStats.config.set("enabled.spawned-in.fishing-rod", true);
|
||||
|
||||
toolStats.logger.info("Adding enabled.spawned-in.shears to config.yml.");
|
||||
toolStats.config.set("enabled.spawned-in.shears", true);
|
||||
|
||||
toolStats.logger.info("Adding enabled.spawned-in.bow to config.yml.");
|
||||
toolStats.config.set("enabled.spawned-in.bow", true);
|
||||
|
||||
toolStats.logger.info("Adding enabled.spawned-in.armor to config.yml.");
|
||||
toolStats.config.set("enabled.spawned-in.armor", true);
|
||||
|
||||
toolStats.logger.info("Adding messages.spawned-in.spawned-by to config.yml.");
|
||||
toolStats.config.set("messages.spawned-in.spawned-by", "&7Spawned in by: &8{player}");
|
||||
|
||||
toolStats.logger.info("Adding messages.spawned-in.spawned-on to config.yml.");
|
||||
toolStats.config.set("messages.spawned-in.spawned-on", "&7Spawned on: &8{date}");
|
||||
|
||||
toolStats.logger.info("Adding generate-hash-for-items to config.yml.");
|
||||
toolStats.config.set("generate-hash-for-items", true);
|
||||
|
||||
toolStats.logger.info("Adding enabled.arrows-shot to config.yml.");
|
||||
toolStats.config.set("enabled.arrows-shot", true);
|
||||
|
||||
toolStats.logger.info("Adding messages.arrows-shot to config.yml.");
|
||||
toolStats.config.set("messages.arrows-shot", "&7Arrows shot: &8{arrows}");
|
||||
|
||||
List<String> hashComments = new ArrayList<>();
|
||||
hashComments.add("When any tool is created, it will generate a hash for the item.");
|
||||
hashComments.add("This hash is not on the item lore, only stored in the NBT data.");
|
||||
hashComments.add("This has no use currently, but can be used for future features for dupe detection.");
|
||||
toolStats.config.setComments("generate-hash-for-items", hashComments);
|
||||
|
||||
toolStats.config.setComments("enabled.spawned-in", Collections.singletonList("Will show \"Spawned in by <player>\""));
|
||||
|
||||
// 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 6. A copy of version 5 has been saved as config-5.yml");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* 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 java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class Version7 {
|
||||
|
||||
private final ToolStats toolStats;
|
||||
|
||||
/**
|
||||
* Used for updating from version 6 to 7.
|
||||
*
|
||||
* @param toolStats ToolStats instance.
|
||||
*/
|
||||
public Version7(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-6.yml");
|
||||
} catch (IOException exception) {
|
||||
toolStats.logger.severe("Unable to save config-6.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 7.");
|
||||
toolStats.config.set("config-version", 7);
|
||||
|
||||
toolStats.logger.info("Adding messages.flight-time to config.yml.");
|
||||
toolStats.config.set("messages.flight-time", "&7Flight time: &8{time}");
|
||||
|
||||
toolStats.logger.info("Adding enabled.flight-time to config.yml.");
|
||||
toolStats.config.set("enabled.flight-time", true);
|
||||
|
||||
// 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 7. A copy of version 6 has been saved as config-6.yml");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* 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 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");
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ enabled:
|
||||
shears: true
|
||||
bow: true
|
||||
armor: true
|
||||
mace: true
|
||||
# Will show time the item is created
|
||||
created-date:
|
||||
pickaxe: true
|
||||
@@ -19,6 +20,7 @@ enabled:
|
||||
shears: true
|
||||
bow: true
|
||||
armor: true
|
||||
mace: true
|
||||
# Will show "Fished by <player>"
|
||||
fished-tag:
|
||||
pickaxe: true
|
||||
@@ -54,22 +56,37 @@ enabled:
|
||||
axe: true
|
||||
trident: true
|
||||
bow: true
|
||||
mace: true
|
||||
mob-kills:
|
||||
sword: true
|
||||
axe: true
|
||||
trident: true
|
||||
bow: true
|
||||
mace: true
|
||||
blocks-mined:
|
||||
pickaxe: true
|
||||
shovel: true
|
||||
axe: true
|
||||
hoe: true
|
||||
shears: true
|
||||
# Will show "Spawned in by <player>"
|
||||
spawned-in:
|
||||
pickaxe: true
|
||||
sword: true
|
||||
shovel: true
|
||||
axe: true
|
||||
hoe: true
|
||||
shears: true
|
||||
bow: true
|
||||
armor: true
|
||||
mace: true
|
||||
fish-caught: true
|
||||
sheep-sheared: true
|
||||
armor-damage: true
|
||||
dropped-by: true
|
||||
elytra-tag: true
|
||||
arrows-shot: true
|
||||
flight-time: true
|
||||
|
||||
messages:
|
||||
created:
|
||||
@@ -80,6 +97,8 @@ messages:
|
||||
caught-on: "&7Caught on: &8{date}"
|
||||
fish-caught: "&7Fish caught: &8{fish}"
|
||||
looted:
|
||||
looted-by: "&7Looted by: &8{player}"
|
||||
looted-on: "&7Looted on: &8{date}"
|
||||
found-by: "&7Found by: &8{player}"
|
||||
found-on: "&7Found on: &8{date}"
|
||||
traded:
|
||||
@@ -88,14 +107,41 @@ messages:
|
||||
kills:
|
||||
mob: "&7Mob kills: &8{kills}"
|
||||
player: "&7Player kills: &8{kills}"
|
||||
spawned-in:
|
||||
spawned-by: "&7Spawned in by: &8{player}"
|
||||
spawned-on: "&7Spawned on: &8{date}"
|
||||
blocks-mined: "&7Blocks mined: &8{blocks}"
|
||||
crops-harvested: "&7Crops harvested: &8{crops}"
|
||||
sheep-sheared: "&7Sheep sheared: &8{sheep}"
|
||||
dropped-by: "&7Dropped by: &8{name}" # name will be player/mob name
|
||||
damage-taken: "&7Damage taken: &8{damage}"
|
||||
arrows-shot: "&7Arrows shot: &8{arrows}"
|
||||
flight-time: "&7Flight time: &8{time}"
|
||||
# Display this message if the player shift click trades/crafts items. It's not really easy to get every single item
|
||||
# that is crafted. The tag will only be added to the first item. If you don't want this message, simply replace them both with ""
|
||||
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."
|
||||
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"
|
||||
|
||||
config-version: 3
|
||||
# Change the default formatting for dates.
|
||||
# See: https://www.digitalocean.com/community/tutorials/java-simpledateformat-java-date-format
|
||||
# Example: "dd/MM/yyyy"
|
||||
date-format: "M/dd/yyyy"
|
||||
|
||||
# Change number formatting.
|
||||
# You probably do not need to touch this.
|
||||
number-formats:
|
||||
comma-separator: ","
|
||||
decimal-separator: "."
|
||||
comma-format: "#,###"
|
||||
decimal-format: "#,###.00"
|
||||
|
||||
# When any tool is created, it will generate a hash for the item.
|
||||
# This hash is not on the item lore, only stored in the NBT data.
|
||||
# This has no use currently, but can be used for future features for dupe detection.
|
||||
generate-hash-for-items: true
|
||||
|
||||
config-version: 7
|
||||
@@ -1,18 +1,25 @@
|
||||
name: ToolStats
|
||||
version: '${project.version}'
|
||||
main: lol.hyper.toolstats.ToolStats
|
||||
api-version: 1.15
|
||||
api-version: 1.21
|
||||
author: hyperdefined
|
||||
description: Track various tool stats!
|
||||
website: https://github.com/hyperdefined/ToolStats
|
||||
folia-supported: true
|
||||
commands:
|
||||
toolstats:
|
||||
usage: /toolstats
|
||||
description: Main command.
|
||||
permission: toolstats.main
|
||||
permission: toolstats.command
|
||||
permissions:
|
||||
toolstats.main:
|
||||
description: Allows the usage of /toolstats
|
||||
toolstats.command:
|
||||
description: Allows the usage of /toolstats.
|
||||
default: true
|
||||
toolstats.reload:
|
||||
description: Allows the usage of /toolstats reload
|
||||
default: op
|
||||
description: Allows the usage of /toolstats reload.
|
||||
default: op
|
||||
toolstats.reset:
|
||||
description: Allows the usage of /toolstats reset.
|
||||
default: true
|
||||
toolstats.reset.confirm:
|
||||
description: Allows the usage of /toolstats reset confirm.
|
||||
default: true
|
||||
Reference in New Issue
Block a user