Compare commits

..

308 Commits
1.1 ... 1.9

Author SHA1 Message Date
hyperdefined
f78609b9ed Update Version9.java 2025-01-26 19:37:51 -05:00
hyperdefined
9ee1f773da handle lore better for tokens 2025-01-26 19:35:03 -05:00
hyperdefined
61f87a94f7 fix italics being on in names 2025-01-26 19:15:13 -05:00
hyperdefined
fd7f75fbb3 idk 2025-01-26 18:59:36 -05:00
hyperdefined
24ee5f9d42 im silly 2025-01-26 18:53:49 -05:00
hyperdefined
2b7c1350c3 Update Version9.java 2025-01-26 18:53:08 -05:00
hyperdefined
393f9b74c0 support for swapping modes
this makes sure the PDC matches when token mode is off so you can swap without issue
2025-01-26 18:51:36 -05:00
hyperdefined
c597b4ffeb make sure to do this for hoes 2025-01-26 18:16:03 -05:00
hyperdefined
a3f3e0552d Update config.yml 2025-01-26 17:15:15 -05:00
hyperdefined
636374134c Update ToolStats.java 2025-01-26 17:14:24 -05:00
hyperdefined
93f4363c9a Create reset-token.png 2025-01-26 17:01:00 -05:00
hyperdefined
a48a1492d2 Update TokenCrafting.java 2025-01-26 16:55:34 -05:00
hyperdefined
8e2e389f78 add this warning 2025-01-26 16:53:59 -05:00
hyperdefined
3da98afd49 correctly do the reset token 2025-01-26 16:48:34 -05:00
hyperdefined
e3629bf813 not possible, wroops 2025-01-26 16:14:46 -05:00
hyperdefined
f7697bccfa rename things 2025-01-26 14:43:47 -05:00
hyperdefined
73e472af3a add reset token 2025-01-26 14:37:24 -05:00
hyperdefined
4dda215805 use meta here instead 2025-01-26 14:36:45 -05:00
hyperdefined
eada8cc448 added missing picture 2025-01-26 13:41:33 -05:00
hyperdefined
5bb179bfa9 typo 2025-01-26 13:28:21 -05:00
hyperdefined
d515d66da8 allow axes player/mob kills 2025-01-26 13:25:22 -05:00
hyperdefined
b025fd0b46 removed more debugs 2025-01-26 13:24:45 -05:00
hyperdefined
390aeac226 allow hoes to have blocks mined 2025-01-26 13:21:16 -05:00
hyperdefined
985fb5380d Update config.yml 2025-01-26 13:16:01 -05:00
hyperdefined
dd584fd2b8 don't let the player use multiple tokens at once 2025-01-26 13:15:39 -05:00
hyperdefined
b8ac32f9b4 misc cleanup 2025-01-25 17:39:01 -05:00
hyperdefined
b14427ced2 Update README.md 2025-01-25 17:32:27 -05:00
hyperdefined
d0d2d1ad41 more images 2025-01-25 17:12:05 -05:00
hyperdefined
7051cfd8cf add images 2025-01-25 17:07:05 -05:00
hyperdefined
73254b3c88 classic 2025-01-25 16:59:11 -05:00
hyperdefined
d5a4c4e3ef Update pom.xml 2025-01-25 16:56:25 -05:00
hyperdefined
30b26533ef tokens update 2025-01-25 16:56:03 -05:00
hyperdefined
ff578e170e 1.8.7 2025-01-22 18:19:12 -05:00
hyperdefined
87aa26c7e9 Update ItemChecker.java 2025-01-22 18:17:49 -05:00
hyperdefined
2b5f784b93 Update config.yml 2025-01-22 18:17:33 -05:00
hyperdefined
94ff8f251d go back to text comparison
this broke something with another plugin
2025-01-22 18:10:35 -05:00
hyperdefined
f9fa15dbaf finally handle shift clicking
closes #89
2025-01-22 17:54:50 -05:00
hyperdefined
1a15fb94f4 misc cleanup 2025-01-22 17:02:31 -05:00
hyperdefined
44b70a8394 fix #90 2025-01-22 17:02:05 -05:00
hyperdefined
98ee84ad13 fix handling empty messages 2025-01-18 13:06:38 -05:00
hyperdefined
c68a04851b Update README.md 2024-12-31 13:21:41 -05:00
hyperdefined
06e063a072 Update hangar.yml 2024-12-30 23:29:24 -05:00
hyperdefined
c00c534d49 test complete 2024-12-30 23:28:35 -05:00
hyperdefined
d6f8176ce1 remove deprecated thing 2024-12-30 23:27:11 -05:00
hyperdefined
eb06dff0bc bro 2024-12-30 23:23:36 -05:00
hyperdefined
9a72c509ef hangar API test 2024-12-30 23:22:31 -05:00
hyperdefined
eaca8ac87d Update README.md 2024-12-23 19:24:04 -05:00
hyperdefined
44a2c5cd26 Update README.md 2024-12-23 19:16:29 -05:00
hyperdefined
0957a1c989 Update README.md 2024-12-23 19:07:03 -05:00
hyperdefined
7b12a130a0 1.8.5 2024-12-17 17:47:14 -05:00
hyperdefined
6b263be041 patience wizard 2024-12-15 18:31:38 -05:00
hyperdefined
aeaeee680b revert this since we can now 2024-12-15 18:31:09 -05:00
hyperdefined
d8c7425a5a 1.8.4 2024-12-15 18:29:46 -05:00
hyperdefined
86c92c9706 change these 2024-12-15 17:10:57 -05:00
hyperdefined
cd62f7309e update these 2024-12-14 18:31:14 -05:00
hyperdefined
e2b18cb5f1 Update README.md 2024-12-14 18:06:16 -05:00
hyperdefined
150956b2c9 Update pom.xml 2024-12-14 18:05:01 -05:00
hyperdefined
585e020baf migration to Paper API 2024-12-14 17:28:02 -05:00
hyperdefined
50b5823daf remove debug 2024-10-07 21:19:21 -04:00
hyperdefined
c87d0ca3bf Update pom.xml 2024-10-07 21:18:52 -04:00
hyperdefined
d1a16ff2e6 added missing breaks 2024-10-07 21:18:02 -04:00
hyperdefined
9134da31f4 support for mace #82 2024-10-07 21:16:07 -04:00
hyperdefined
0cf85edda6 support for custom mob names
closes #71
2024-10-07 21:05:46 -04:00
hyperdefined
7fe0234785 fix for older MC versions
fixes #81
2024-10-05 18:37:51 -04:00
hyperdefined
6385814b52 Merge pull request #80 from hyperdefined/dependabot/maven/org.bstats-bstats-bukkit-3.1.0
Bump org.bstats:bstats-bukkit from 3.0.3 to 3.1.0
2024-10-05 18:10:25 -04:00
hyperdefined
603e1ac1fd fix #79 2024-09-25 19:50:26 -04:00
dependabot[bot]
86dc5f421a Bump org.bstats:bstats-bukkit from 3.0.3 to 3.1.0
Bumps [org.bstats:bstats-bukkit](https://github.com/Bastian/bStats-Metrics) from 3.0.3 to 3.1.0.
- [Release notes](https://github.com/Bastian/bStats-Metrics/releases)
- [Commits](https://github.com/Bastian/bStats-Metrics/compare/v3.0.3...v3.1.0)

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

Signed-off-by: dependabot[bot] <support@github.com>
2024-09-23 11:36:47 +00:00
hyperdefined
7d9be0cfd1 Update README.md 2024-09-10 17:19:15 -04:00
hyperdefined
f7bacec617 Update README.md 2024-09-10 17:17:51 -04:00
hyperdefined
227723fe10 fix #75 2024-09-10 17:08:40 -04:00
hyperdefined
785333e8d1 Update pom.xml 2024-09-10 16:02:04 -04:00
hyperdefined
bc784b8d46 fix elytra flight calculations
fixes #74
2024-09-10 16:01:45 -04:00
hyperdefined
f5ddada892 support for gradient coloring
fixes #72
2024-09-10 16:01:24 -04:00
hyperdefined
a43155b0c5 Fix armor damage + arrows on reset command 2024-09-08 22:57:41 -04:00
hyperdefined
e327d132e2 Update pom.xml 2024-09-08 22:52:55 -04:00
hyperdefined
f09f2d3703 Fix armor damage breaking (#70) 2024-09-08 22:51:49 -04:00
hyperdefined
e9782c2985 bump to 1.8 instead 2024-09-07 15:50:27 -04:00
hyperdefined
b596310bfe redo lore replacement
Instead of partially matching the old lore, build the old lore and match it instead.
2024-09-06 17:47:07 -04:00
hyperdefined
6d1f0fe561 update config from 6 to 7 2024-08-29 00:16:22 -04:00
hyperdefined
fb0d179d37 add flight time (#62) 2024-08-29 00:10:01 -04:00
hyperdefined
e8ab578eef Update pom.xml 2024-08-28 23:23:20 -04:00
hyperdefined
57be2371e1 Merge pull request #67 from hyperdefined/dependabot/maven/net.kyori-adventure-platform-bukkit-4.3.4
Bump net.kyori:adventure-platform-bukkit from 4.3.3 to 4.3.4
2024-08-28 23:20:43 -04:00
hyperdefined
f3732a4eea Merge pull request #69 from hyperdefined/dependabot/maven/org.bstats-bstats-bukkit-3.0.3
Bump org.bstats:bstats-bukkit from 3.0.2 to 3.0.3
2024-08-28 23:20:33 -04:00
hyperdefined
7e13159056 support hex colors in lore (#68) 2024-08-28 23:20:16 -04:00
dependabot[bot]
7cdb8d55b5 Bump org.bstats:bstats-bukkit from 3.0.2 to 3.0.3
Bumps [org.bstats:bstats-bukkit](https://github.com/Bastian/bStats-Metrics) from 3.0.2 to 3.0.3.
- [Release notes](https://github.com/Bastian/bStats-Metrics/releases)
- [Commits](https://github.com/Bastian/bStats-Metrics/compare/v3.0.2...v3.0.3)

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

Signed-off-by: dependabot[bot] <support@github.com>
2024-08-19 11:27:39 +00:00
dependabot[bot]
368e59b1e1 Bump net.kyori:adventure-platform-bukkit from 4.3.3 to 4.3.4
Bumps [net.kyori:adventure-platform-bukkit](https://github.com/KyoriPowered/adventure-platform) from 4.3.3 to 4.3.4.
- [Release notes](https://github.com/KyoriPowered/adventure-platform/releases)
- [Commits](https://github.com/KyoriPowered/adventure-platform/compare/v4.3.3...v4.3.4)

---
updated-dependencies:
- dependency-name: net.kyori:adventure-platform-bukkit
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-08-07 11:04:11 +00:00
hyperdefined
9412dc02d7 Update README.md 2024-07-24 21:32:03 -04:00
hyperdefined
0765c49622 Update pom.xml 2024-07-24 21:29:12 -04:00
hyperdefined
91959c223e new damage cause, fix #64 #65 2024-07-19 20:12:50 -04:00
hyperdefined
a53cebc589 Merge pull request #63 from hyperdefined/dependabot/maven/org.apache.maven.plugins-maven-clean-plugin-3.4.0
Bump org.apache.maven.plugins:maven-clean-plugin from 3.3.2 to 3.4.0
2024-06-24 21:45:02 -04:00
dependabot[bot]
7f7c1d4656 Bump org.apache.maven.plugins:maven-clean-plugin from 3.3.2 to 3.4.0
Bumps [org.apache.maven.plugins:maven-clean-plugin](https://github.com/apache/maven-clean-plugin) from 3.3.2 to 3.4.0.
- [Release notes](https://github.com/apache/maven-clean-plugin/releases)
- [Commits](https://github.com/apache/maven-clean-plugin/compare/maven-clean-plugin-3.3.2...maven-clean-plugin-3.4.0)

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

Signed-off-by: dependabot[bot] <support@github.com>
2024-06-20 11:04:51 +00:00
hyperdefined
1e99fa5076 Merge pull request #60 from hyperdefined/dependabot/maven/org.apache.maven.plugins-maven-shade-plugin-3.6.0
Bump org.apache.maven.plugins:maven-shade-plugin from 3.5.3 to 3.6.0
2024-06-18 12:06:21 -04:00
hyperdefined
d50ee82a98 Merge pull request #61 from hyperdefined/dependabot/maven/net.kyori-adventure-platform-bukkit-4.3.3
Bump net.kyori:adventure-platform-bukkit from 4.3.2 to 4.3.3
2024-06-18 12:04:11 -04:00
dependabot[bot]
2a2c9a7376 Bump net.kyori:adventure-platform-bukkit from 4.3.2 to 4.3.3
Bumps [net.kyori:adventure-platform-bukkit](https://github.com/KyoriPowered/adventure-platform) from 4.3.2 to 4.3.3.
- [Release notes](https://github.com/KyoriPowered/adventure-platform/releases)
- [Commits](https://github.com/KyoriPowered/adventure-platform/compare/v4.3.2...v4.3.3)

---
updated-dependencies:
- dependency-name: net.kyori:adventure-platform-bukkit
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-06-03 11:19:58 +00:00
dependabot[bot]
813648e330 Bump org.apache.maven.plugins:maven-shade-plugin from 3.5.3 to 3.6.0
Bumps [org.apache.maven.plugins:maven-shade-plugin](https://github.com/apache/maven-shade-plugin) from 3.5.3 to 3.6.0.
- [Release notes](https://github.com/apache/maven-shade-plugin/releases)
- [Commits](https://github.com/apache/maven-shade-plugin/compare/maven-shade-plugin-3.5.3...maven-shade-plugin-3.6.0)

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

Signed-off-by: dependabot[bot] <support@github.com>
2024-05-31 11:33:03 +00:00
hyperdefined
330001e6de Update README.md 2024-05-25 15:53:34 -04:00
hyperdefined
75b1a95cb5 Merge pull request #56 from hyperdefined/dependabot/maven/org.apache.maven.plugins-maven-shade-plugin-3.5.3
Bump org.apache.maven.plugins:maven-shade-plugin from 3.5.2 to 3.5.3
2024-05-25 15:52:46 -04:00
hyperdefined
ca37021e5a Merge pull request #57 from hyperdefined/dependabot/maven/net.kyori-adventure-text-minimessage-4.17.0
Bump net.kyori:adventure-text-minimessage from 4.16.0 to 4.17.0
2024-05-25 15:52:39 -04:00
hyperdefined
f72ea3dbfa Update pom.xml 2024-05-25 15:41:49 -04:00
hyperdefined
03077d5e2f possibly fix #59 2024-05-25 15:41:16 -04:00
hyperdefined
608c870667 possibly fix #44 2024-05-25 15:38:44 -04:00
hyperdefined
ea27e4f4ab remove color codes when comparing 2024-05-25 15:37:52 -04:00
dependabot[bot]
8a7c6c720a Bump net.kyori:adventure-text-minimessage from 4.16.0 to 4.17.0
Bumps [net.kyori:adventure-text-minimessage](https://github.com/KyoriPowered/adventure) from 4.16.0 to 4.17.0.
- [Release notes](https://github.com/KyoriPowered/adventure/releases)
- [Commits](https://github.com/KyoriPowered/adventure/compare/v4.16.0...v4.17.0)

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

Signed-off-by: dependabot[bot] <support@github.com>
2024-05-08 11:41:03 +00:00
dependabot[bot]
12e2758ffd Bump org.apache.maven.plugins:maven-shade-plugin from 3.5.2 to 3.5.3
Bumps [org.apache.maven.plugins:maven-shade-plugin](https://github.com/apache/maven-shade-plugin) from 3.5.2 to 3.5.3.
- [Release notes](https://github.com/apache/maven-shade-plugin/releases)
- [Commits](https://github.com/apache/maven-shade-plugin/compare/maven-shade-plugin-3.5.2...maven-shade-plugin-3.5.3)

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

Signed-off-by: dependabot[bot] <support@github.com>
2024-04-24 11:09:18 +00:00
hyperdefined
5939b8f944 Merge pull request #54 from hyperdefined/dependabot/maven/org.apache.maven.plugins-maven-compiler-plugin-3.13.0
Bump org.apache.maven.plugins:maven-compiler-plugin from 3.12.1 to 3.13.0
2024-03-26 18:12:54 -04:00
hyperdefined
021d67e505 Merge pull request #55 from hyperdefined/dependabot/maven/space.arim.morepaperlib-morepaperlib-0.4.4
Bump space.arim.morepaperlib:morepaperlib from 0.4.3 to 0.4.4
2024-03-26 18:10:25 -04:00
dependabot[bot]
c0ee457c4d Bump space.arim.morepaperlib:morepaperlib from 0.4.3 to 0.4.4
Bumps space.arim.morepaperlib:morepaperlib from 0.4.3 to 0.4.4.

---
updated-dependencies:
- dependency-name: space.arim.morepaperlib:morepaperlib
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-03-25 11:28:14 +00:00
dependabot[bot]
4f4e4a961a Bump org.apache.maven.plugins:maven-compiler-plugin
Bumps [org.apache.maven.plugins:maven-compiler-plugin](https://github.com/apache/maven-compiler-plugin) from 3.12.1 to 3.13.0.
- [Release notes](https://github.com/apache/maven-compiler-plugin/releases)
- [Commits](https://github.com/apache/maven-compiler-plugin/compare/maven-compiler-plugin-3.12.1...maven-compiler-plugin-3.13.0)

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

Signed-off-by: dependabot[bot] <support@github.com>
2024-03-19 11:15:00 +00:00
hyperdefined
3412094f93 Merge pull request #51 from hyperdefined/dependabot/maven/net.kyori-adventure-text-minimessage-4.16.0
Bump net.kyori:adventure-text-minimessage from 4.15.0 to 4.16.0
2024-02-23 17:29:35 -05:00
hyperdefined
cdc46a1f5f Merge pull request #52 from hyperdefined/dependabot/maven/org.apache.maven.plugins-maven-shade-plugin-3.5.2 2024-02-22 09:33:56 -05:00
dependabot[bot]
d4c7770352 Bump org.apache.maven.plugins:maven-shade-plugin from 3.5.1 to 3.5.2
Bumps [org.apache.maven.plugins:maven-shade-plugin](https://github.com/apache/maven-shade-plugin) from 3.5.1 to 3.5.2.
- [Release notes](https://github.com/apache/maven-shade-plugin/releases)
- [Commits](https://github.com/apache/maven-shade-plugin/compare/maven-shade-plugin-3.5.1...maven-shade-plugin-3.5.2)

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

Signed-off-by: dependabot[bot] <support@github.com>
2024-02-21 11:22:24 +00:00
dependabot[bot]
85db07877d Bump net.kyori:adventure-text-minimessage from 4.15.0 to 4.16.0
Bumps [net.kyori:adventure-text-minimessage](https://github.com/KyoriPowered/adventure) from 4.15.0 to 4.16.0.
- [Release notes](https://github.com/KyoriPowered/adventure/releases)
- [Commits](https://github.com/KyoriPowered/adventure/compare/v4.15.0...v4.16.0)

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

Signed-off-by: dependabot[bot] <support@github.com>
2024-02-20 11:46:47 +00:00
hyperdefined
1e37fcd3cb Merge pull request #49 from hyperdefined/dependabot/maven/net.kyori-adventure-platform-bukkit-4.3.2
Bump net.kyori:adventure-platform-bukkit from 4.3.1 to 4.3.2
2023-12-26 12:06:21 -05:00
hyperdefined
10f9b9404e Merge pull request #50 from hyperdefined/dependabot/maven/org.apache.maven.plugins-maven-compiler-plugin-3.12.1
Bump org.apache.maven.plugins:maven-compiler-plugin from 3.12.0 to 3.12.1
2023-12-26 12:05:43 -05:00
dependabot[bot]
c350536ab6 Bump org.apache.maven.plugins:maven-compiler-plugin
Bumps [org.apache.maven.plugins:maven-compiler-plugin](https://github.com/apache/maven-compiler-plugin) from 3.12.0 to 3.12.1.
- [Release notes](https://github.com/apache/maven-compiler-plugin/releases)
- [Commits](https://github.com/apache/maven-compiler-plugin/compare/maven-compiler-plugin-3.12.0...maven-compiler-plugin-3.12.1)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-12-25 11:07:40 +00:00
dependabot[bot]
e12a0a80f5 Bump net.kyori:adventure-platform-bukkit from 4.3.1 to 4.3.2
Bumps [net.kyori:adventure-platform-bukkit](https://github.com/KyoriPowered/adventure-platform) from 4.3.1 to 4.3.2.
- [Release notes](https://github.com/KyoriPowered/adventure-platform/releases)
- [Commits](https://github.com/KyoriPowered/adventure-platform/compare/v4.3.1...v4.3.2)

---
updated-dependencies:
- dependency-name: net.kyori:adventure-platform-bukkit
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-12-22 11:57:41 +00:00
hyperdefined
44a3fc7d63 Merge pull request #46 from hyperdefined/dependabot/maven/net.kyori-adventure-text-minimessage-4.15.0
Bump net.kyori:adventure-text-minimessage from 4.14.0 to 4.15.0
2023-12-19 17:21:21 -05:00
hyperdefined
6a5bb994cc Merge pull request #48 from hyperdefined/dependabot/maven/org.apache.maven.plugins-maven-compiler-plugin-3.12.0
Bump org.apache.maven.plugins:maven-compiler-plugin from 3.11.0 to 3.12.0
2023-12-19 17:18:53 -05:00
dependabot[bot]
1c52664935 Bump org.apache.maven.plugins:maven-compiler-plugin
Bumps [org.apache.maven.plugins:maven-compiler-plugin](https://github.com/apache/maven-compiler-plugin) from 3.11.0 to 3.12.0.
- [Release notes](https://github.com/apache/maven-compiler-plugin/releases)
- [Commits](https://github.com/apache/maven-compiler-plugin/compare/maven-compiler-plugin-3.11.0...maven-compiler-plugin-3.12.0)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-12-19 12:01:49 +00:00
dependabot[bot]
4d18020065 Bump net.kyori:adventure-text-minimessage from 4.14.0 to 4.15.0
Bumps [net.kyori:adventure-text-minimessage](https://github.com/KyoriPowered/adventure) from 4.14.0 to 4.15.0.
- [Release notes](https://github.com/KyoriPowered/adventure/releases)
- [Commits](https://github.com/KyoriPowered/adventure/compare/v4.14.0...v4.15.0)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-12-18 11:40:53 +00:00
hyperdefined
ee5ebff614 Merge pull request #43 from hyperdefined/dependabot/maven/org.apache.maven.plugins-maven-clean-plugin-3.3.2
Bump org.apache.maven.plugins:maven-clean-plugin from 3.3.1 to 3.3.2
2023-10-27 13:35:41 -04:00
dependabot[bot]
fa7b19e3fc Bump org.apache.maven.plugins:maven-clean-plugin from 3.3.1 to 3.3.2
Bumps [org.apache.maven.plugins:maven-clean-plugin](https://github.com/apache/maven-clean-plugin) from 3.3.1 to 3.3.2.
- [Release notes](https://github.com/apache/maven-clean-plugin/releases)
- [Commits](https://github.com/apache/maven-clean-plugin/compare/maven-clean-plugin-3.3.1...maven-clean-plugin-3.3.2)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-10-27 11:06:37 +00:00
hyperdefined
cc4176cfbe awrf :3 2023-10-22 20:05:44 -04:00
hyperdefined
bd30b05246 Update README.md 2023-10-22 19:52:34 -04:00
hyperdefined
2ace1c4f16 bump version 2023-10-22 19:46:59 -04:00
hyperdefined
c3f47707c4 remove all "config" things into it's own thing 2023-10-22 19:43:22 -04:00
hyperdefined
ee1c197d72 more config updater changes 2023-10-22 19:35:41 -04:00
hyperdefined
74b529ba4f Update CommandToolStats.java 2023-10-22 19:23:30 -04:00
hyperdefined
c328b9e019 add "arrows shot" + fix jank 2023-10-22 19:13:44 -04:00
hyperdefined
38c37ea601 new images 2023-10-22 18:54:51 -04:00
hyperdefined
700e7bca2c more config changes
* fixed typo on config updater
* handle missing config messages a lot better
* only try to update lore if it's enabled, don't try then check if it's enabled
2023-10-21 18:52:58 -04:00
hyperdefined
59bfdf69ca improve various config things 2023-10-21 18:11:28 -04:00
hyperdefined
68aed25834 Update README.md 2023-10-19 18:04:57 -04:00
hyperdefined
0968497fc0 added a config updater 2023-10-19 17:59:53 -04:00
hyperdefined
c7a5aef9ee make item checking better
fixes #42
2023-10-19 17:05:15 -04:00
hyperdefined
e40e16c273 Update modrinth.yml 2023-10-19 12:25:22 -04:00
hyperdefined
fc9ef05afd Update modrinth.yml 2023-10-19 12:24:30 -04:00
hyperdefined
26ae28dcd8 Update README.md 2023-10-19 12:23:12 -04:00
hyperdefined
02a7920ad2 Create modrinth.yml 2023-10-19 12:22:08 -04:00
hyperdefined
68c9685477 added "spawned by" for creative items
closes #41
2023-10-17 14:17:41 -04:00
hyperdefined
9f81cb1f74 Merge pull request #40 from hyperdefined/dependabot/maven/net.kyori-adventure-platform-bukkit-4.3.1 2023-10-02 09:10:39 -04:00
hyperdefined
e068aeb9f4 never ending battle with deepsource 2023-09-30 20:52:30 -04:00
hyperdefined
b0733935ae handle loot generation better
edit the loot itself, not the contents of chest

also handle breaking chest instead of opening it
2023-09-30 20:43:54 -04:00
hyperdefined
664eddeab0 more hash work 2023-09-30 20:22:33 -04:00
hyperdefined
cda8d94199 ok 2023-09-30 20:07:46 -04:00
hyperdefined
5551c24202 lots of updates
- add hash to items when created
- added "crops harvested" for hoes
2023-09-30 20:05:31 -04:00
dependabot[bot]
951106177b Bump net.kyori:adventure-platform-bukkit from 4.3.0 to 4.3.1
Bumps [net.kyori:adventure-platform-bukkit](https://github.com/KyoriPowered/adventure-platform) from 4.3.0 to 4.3.1.
- [Release notes](https://github.com/KyoriPowered/adventure-platform/releases)
- [Commits](https://github.com/KyoriPowered/adventure-platform/compare/v4.3.0...v4.3.1)

---
updated-dependencies:
- dependency-name: net.kyori:adventure-platform-bukkit
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-09-29 11:18:32 +00:00
hyperdefined
0a3f46fc6e Merge pull request #39 from hyperdefined/dependabot/maven/org.apache.maven.plugins-maven-shade-plugin-3.5.1
Bump org.apache.maven.plugins:maven-shade-plugin from 3.5.0 to 3.5.1
2023-09-27 22:00:23 -04:00
dependabot[bot]
2894e2021a Bump org.apache.maven.plugins:maven-shade-plugin from 3.5.0 to 3.5.1
Bumps [org.apache.maven.plugins:maven-shade-plugin](https://github.com/apache/maven-shade-plugin) from 3.5.0 to 3.5.1.
- [Release notes](https://github.com/apache/maven-shade-plugin/releases)
- [Commits](https://github.com/apache/maven-shade-plugin/compare/maven-shade-plugin-3.5.0...maven-shade-plugin-3.5.1)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-09-25 11:47:01 +00:00
hyperdefined
2e34cb812a Merge pull request #38 from hyperdefined/dependabot/maven/lol.hyper-github-release-api-1.0.5
Bump lol.hyper:github-release-api from 1.0.4 to 1.0.5
2023-09-18 12:01:07 -04:00
dependabot[bot]
a38c148b80 Bump lol.hyper:github-release-api from 1.0.4 to 1.0.5
Bumps [lol.hyper:github-release-api](https://github.com/hyperdefined/GitHubReleaseAPI) from 1.0.4 to 1.0.5.
- [Release notes](https://github.com/hyperdefined/GitHubReleaseAPI/releases)
- [Commits](https://github.com/hyperdefined/GitHubReleaseAPI/compare/1.0.4...1.0.5)

---
updated-dependencies:
- dependency-name: lol.hyper:github-release-api
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-09-18 11:35:07 +00:00
hyperdefined
a55cea4b5d more work 2023-08-30 17:02:50 -04:00
hyperdefined
d0fcd4fc61 Update pom.xml 2023-08-30 16:38:13 -04:00
hyperdefined
f14b9bc474 imports 2023-08-30 16:37:36 -04:00
hyperdefined
366a54052a basic folia support 2023-08-29 10:41:08 -04:00
hyperdefined
fe96235ed1 removed unused function 2023-07-17 19:24:45 -04:00
hyperdefined
fe8052f9d6 add origin tag to existing items 2023-07-17 19:23:04 -04:00
hyperdefined
884bdef444 add missing elytra to item list 2023-07-17 19:22:32 -04:00
hyperdefined
be31202f65 config changes 2023-07-17 15:29:33 -04:00
hyperdefined
39d8a42110 clean this up a bit 2023-07-17 15:29:26 -04:00
hyperdefined
91090dd6cc fix this 2023-07-17 15:28:56 -04:00
hyperdefined
29a2a5150c update various things for origin NBT 2023-07-13 19:16:02 -04:00
hyperdefined
b38d2825cb added NBT for origins of items 2023-07-13 19:04:29 -04:00
hyperdefined
fd6c120a58 Merge pull request #36 from hyperdefined/dependabot/maven/org.apache.maven.plugins-maven-clean-plugin-3.3.1
Bump maven-clean-plugin from 3.2.0 to 3.3.1
2023-06-20 18:50:48 -04:00
dependabot[bot]
459569a1dc Bump maven-clean-plugin from 3.2.0 to 3.3.1
Bumps [maven-clean-plugin](https://github.com/apache/maven-clean-plugin) from 3.2.0 to 3.3.1.
- [Release notes](https://github.com/apache/maven-clean-plugin/releases)
- [Commits](https://github.com/apache/maven-clean-plugin/compare/maven-clean-plugin-3.2.0...maven-clean-plugin-3.3.1)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-06-20 11:59:37 +00:00
hyperdefined
9ba6200415 Merge pull request #35 from hyperdefined/dependabot/maven/org.apache.maven.plugins-maven-shade-plugin-3.5.0
Bump maven-shade-plugin from 3.4.1 to 3.5.0
2023-06-19 13:24:21 -04:00
dependabot[bot]
b94e0e8c36 Bump maven-shade-plugin from 3.4.1 to 3.5.0
Bumps [maven-shade-plugin](https://github.com/apache/maven-shade-plugin) from 3.4.1 to 3.5.0.
- [Release notes](https://github.com/apache/maven-shade-plugin/releases)
- [Commits](https://github.com/apache/maven-shade-plugin/compare/maven-shade-plugin-3.4.1...maven-shade-plugin-3.5.0)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-06-16 11:59:30 +00:00
hyperdefined
a42c526198 Merge pull request #34 from hyperdefined/dependabot/maven/net.kyori-adventure-text-minimessage-4.14.0
Bump adventure-text-minimessage from 4.13.1 to 4.14.0
2023-06-07 12:35:33 -04:00
dependabot[bot]
851a494935 Bump adventure-text-minimessage from 4.13.1 to 4.14.0
Bumps [adventure-text-minimessage](https://github.com/KyoriPowered/adventure) from 4.13.1 to 4.14.0.
- [Release notes](https://github.com/KyoriPowered/adventure/releases)
- [Commits](https://github.com/KyoriPowered/adventure/compare/v4.13.1...v4.14.0)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-06-07 11:59:12 +00:00
hyperdefined
72e869d5e2 Update pom.xml 2023-05-22 20:22:02 -04:00
hyperdefined
300fe56c5a use continue here, not return
closes #33
2023-05-22 20:21:16 -04:00
hyperdefined
fe5e55d746 Update pom.xml 2023-05-22 00:05:00 -04:00
hyperdefined
0574fb61a6 fix traded-by tags :3333 2023-05-22 00:03:42 -04:00
hyperdefined
433ab547cb minor adjustments 2023-05-21 23:49:07 -04:00
hyperdefined
9746789f2b added int damage value 2023-04-21 15:31:54 -04:00
hyperdefined
fd3c3ca8ed Merge pull request #31 from hyperdefined/dependabot/maven/org.bstats-bstats-bukkit-3.0.2
Bump bstats-bukkit from 3.0.1 to 3.0.2
2023-04-10 16:38:20 -04:00
hyperdefined
c6dc2c3368 Merge pull request #32 from hyperdefined/dependabot/maven/net.kyori-adventure-text-minimessage-4.13.1
Bump adventure-text-minimessage from 4.13.0 to 4.13.1
2023-04-10 16:36:01 -04:00
dependabot[bot]
d11211b1c7 Bump adventure-text-minimessage from 4.13.0 to 4.13.1
Bumps [adventure-text-minimessage](https://github.com/KyoriPowered/adventure) from 4.13.0 to 4.13.1.
- [Release notes](https://github.com/KyoriPowered/adventure/releases)
- [Commits](https://github.com/KyoriPowered/adventure/compare/v4.13.0...v4.13.1)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-04-10 12:02:00 +00:00
dependabot[bot]
e8c2296bd7 Bump bstats-bukkit from 3.0.1 to 3.0.2
Bumps [bstats-bukkit](https://github.com/Bastian/bStats-Metrics) from 3.0.1 to 3.0.2.
- [Release notes](https://github.com/Bastian/bStats-Metrics/releases)
- [Commits](https://github.com/Bastian/bStats-Metrics/compare/v3.0.1...v3.0.2)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-03-29 12:00:34 +00:00
hyperdefined
d8f296a085 Merge pull request #29 from hyperdefined/dependabot/maven/net.kyori-adventure-text-minimessage-4.13.0
Bump adventure-text-minimessage from 4.12.0 to 4.13.0
2023-03-16 10:42:18 -04:00
hyperdefined
58dee809f3 Merge pull request #30 from hyperdefined/dependabot/maven/net.kyori-adventure-platform-bukkit-4.3.0
Bump adventure-platform-bukkit from 4.2.0 to 4.3.0
2023-03-16 10:40:21 -04:00
dependabot[bot]
590cf6e8b0 Bump adventure-platform-bukkit from 4.2.0 to 4.3.0
Bumps [adventure-platform-bukkit](https://github.com/KyoriPowered/adventure-platform) from 4.2.0 to 4.3.0.
- [Release notes](https://github.com/KyoriPowered/adventure-platform/releases)
- [Commits](https://github.com/KyoriPowered/adventure-platform/compare/v4.2.0...v4.3.0)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-03-16 12:00:42 +00:00
dependabot[bot]
a7cc8671bd Bump adventure-text-minimessage from 4.12.0 to 4.13.0
Bumps [adventure-text-minimessage](https://github.com/KyoriPowered/adventure) from 4.12.0 to 4.13.0.
- [Release notes](https://github.com/KyoriPowered/adventure/releases)
- [Commits](https://github.com/KyoriPowered/adventure/compare/v4.12.0...v4.13.0)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-03-14 12:00:26 +00:00
hyperdefined
37a7c642d3 Merge pull request #28 from hyperdefined/dependabot/maven/org.apache.maven.plugins-maven-compiler-plugin-3.11.0
Bump maven-compiler-plugin from 3.10.1 to 3.11.0
2023-02-27 18:57:28 -05:00
dependabot[bot]
31acdd9527 Bump maven-compiler-plugin from 3.10.1 to 3.11.0
Bumps [maven-compiler-plugin](https://github.com/apache/maven-compiler-plugin) from 3.10.1 to 3.11.0.
- [Release notes](https://github.com/apache/maven-compiler-plugin/releases)
- [Commits](https://github.com/apache/maven-compiler-plugin/compare/maven-compiler-plugin-3.10.1...maven-compiler-plugin-3.11.0)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-02-27 12:10:48 +00:00
hyperdefined
9b0ac2d912 stfu deepsource 2023-02-20 22:28:33 -05:00
hyperdefined
4ea9e1600b return item lore back rather than nulling it 2023-02-20 22:02:48 -05:00
hyperdefined
72b8b31779 Merge pull request #27 from hyperdefined/dependabot/maven/org.bstats-bstats-bukkit-3.0.1
Bump bstats-bukkit from 3.0.0 to 3.0.1
2023-02-16 17:43:01 -05:00
dependabot[bot]
fce135f2f8 Bump bstats-bukkit from 3.0.0 to 3.0.1
Bumps [bstats-bukkit](https://github.com/Bastian/bStats-Metrics) from 3.0.0 to 3.0.1.
- [Release notes](https://github.com/Bastian/bStats-Metrics/releases)
- [Commits](https://github.com/Bastian/bStats-Metrics/compare/v3.0.0...v3.0.1)

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

Signed-off-by: dependabot[bot] <support@github.com>
2023-02-13 12:09:50 +00:00
hyperdefined
425b315104 Revert "Update ToolStats.java"
This reverts commit f2739cf433.
2023-01-16 13:41:50 -05:00
hyperdefined
50a0bc800c small command changes 2022-12-12 17:05:46 -05:00
hyperdefined
583cd824f4 Update EntityDamage.java 2022-12-12 12:06:06 -05:00
hyperdefined
d63f00166d Update NumberFormat.java 2022-12-12 11:30:26 -05:00
hyperdefined
0bcb0c7370 added missing tracking for mobs 2022-12-12 11:21:06 -05:00
hyperdefined
e4859de614 Merge pull request #26 from hyperdefined/dependabot/maven/net.kyori-adventure-platform-bukkit-4.2.0
Bump adventure-platform-bukkit from 4.1.2 to 4.2.0
2022-12-11 23:41:50 -05:00
dependabot[bot]
f7c1af153f Bump adventure-platform-bukkit from 4.1.2 to 4.2.0
Bumps [adventure-platform-bukkit](https://github.com/KyoriPowered/adventure-platform) from 4.1.2 to 4.2.0.
- [Release notes](https://github.com/KyoriPowered/adventure-platform/releases)
- [Commits](https://github.com/KyoriPowered/adventure-platform/compare/v4.1.2...v4.2.0)

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

Signed-off-by: dependabot[bot] <support@github.com>
2022-12-09 11:05:50 +00:00
hyperdefined
946dc591f5 Update pom.xml 2022-12-08 13:40:27 -05:00
hyperdefined
d279569199 Update EntityDamage.java 2022-12-08 13:40:12 -05:00
hyperdefined
f2739cf433 Update ToolStats.java 2022-12-07 16:21:14 -05:00
hyperdefined
bef854be14 removed logging 2022-12-07 15:19:32 -05:00
hyperdefined
2c971da1b9 unify lore management 2022-12-07 14:56:57 -05:00
hyperdefined
2e0ee18594 more possible plugin compatibility? 2022-12-01 17:56:41 -05:00
hyperdefined
98a5f20a86 better offhand/main hand detection 2022-11-30 14:41:34 -05:00
hyperdefined
dd8a0db3b6 fix using rods in offhand 2022-11-30 14:22:35 -05:00
hyperdefined
fee7d5cd99 Merge pull request #25 from hyperdefined/dependabot/maven/net.kyori-adventure-text-minimessage-4.12.0
Bump adventure-text-minimessage from 4.11.0 to 4.12.0
2022-11-29 23:21:12 -05:00
hyperdefined
70ebf49958 Merge branch 'master' of https://github.com/hyperdefined/ToolStats 2022-11-29 20:06:40 -05:00
dependabot[bot]
50d2ec0507 Bump adventure-text-minimessage from 4.11.0 to 4.12.0
Bumps [adventure-text-minimessage](https://github.com/KyoriPowered/adventure) from 4.11.0 to 4.12.0.
- [Release notes](https://github.com/KyoriPowered/adventure/releases)
- [Commits](https://github.com/KyoriPowered/adventure/compare/v4.11.0...v4.12.0)

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

Signed-off-by: dependabot[bot] <support@github.com>
2022-11-28 11:09:14 +00:00
hyperdefined
6428925e40 support for complete customization of numbers
closes #24
2022-11-24 00:44:59 -05:00
hyperdefined
1d4faa89a1 Merge branch 'master' of https://github.com/hyperdefined/ToolStats 2022-11-23 02:22:46 -05:00
hyperdefined
1ad650f42b Merge pull request #23 from hyperdefined/dependabot/maven/org.apache.maven.plugins-maven-shade-plugin-3.4.1
Bump maven-shade-plugin from 3.4.0 to 3.4.1
2022-11-06 19:20:20 -05:00
hyperdefined
fdb6626c42 update all items 1 tick later
this should fix #18
2022-11-04 20:26:55 -04:00
dependabot[bot]
cd80e6a675 Bump maven-shade-plugin from 3.4.0 to 3.4.1
Bumps [maven-shade-plugin](https://github.com/apache/maven-shade-plugin) from 3.4.0 to 3.4.1.
- [Release notes](https://github.com/apache/maven-shade-plugin/releases)
- [Commits](https://github.com/apache/maven-shade-plugin/compare/maven-shade-plugin-3.4.0...maven-shade-plugin-3.4.1)

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

Signed-off-by: dependabot[bot] <support@github.com>
2022-10-27 11:23:52 +00:00
hyperdefined
03d45ea8f7 Update pom.xml 2022-10-26 18:10:22 -04:00
hyperdefined
91a98cf664 fix the symbols regardless of Locale 2022-10-26 18:08:00 -04:00
hyperdefined
72b00e96f6 fix example date format in config 2022-10-24 21:27:40 -04:00
hyperdefined
07458bfc11 ignore mob drops with our tags
fixes #22
2022-10-24 21:21:45 -04:00
hyperdefined
24d30f6059 fix deepsource problems 2022-10-13 18:09:19 -04:00
hyperdefined
bea7e52347 Update pom.xml 2022-10-13 18:05:00 -04:00
hyperdefined
1b1b45ef6d even BETTER number formatting?!?!
closes #19
2022-10-13 17:58:40 -04:00
hyperdefined
2de2ae82a7 config for date formatting
closes #20
2022-10-12 13:21:54 -04:00
hyperdefined
7639943fea better formatting for numbers 2022-10-12 13:04:35 -04:00
hyperdefined
2b75ea094d maybe not do this? 2022-10-09 16:51:26 -04:00
hyperdefined
bc8496fad4 changed event priorities 2022-10-05 20:46:19 -04:00
hyperdefined
1cef74311e big cleanup 2022-10-05 16:20:36 -04:00
hyperdefined
cbbdb4e9c4 remove dumb stuff 2022-10-04 12:59:16 -04:00
hyperdefined
f6d35c459c Merge pull request #17 from hyperdefined/dependabot/maven/org.apache.maven.plugins-maven-shade-plugin-3.4.0
Bump maven-shade-plugin from 3.3.0 to 3.4.0
2022-09-19 22:32:43 -04:00
dependabot[bot]
4624d7a847 Bump maven-shade-plugin from 3.3.0 to 3.4.0
Bumps [maven-shade-plugin](https://github.com/apache/maven-shade-plugin) from 3.3.0 to 3.4.0.
- [Release notes](https://github.com/apache/maven-shade-plugin/releases)
- [Commits](https://github.com/apache/maven-shade-plugin/compare/maven-shade-plugin-3.3.0...maven-shade-plugin-3.4.0)

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

Signed-off-by: dependabot[bot] <support@github.com>
2022-09-15 11:29:08 +00:00
hyperdefined
3766db3454 Merge branch 'master' of https://github.com/hyperdefined/ToolStats 2022-09-12 16:57:35 -04:00
hyperdefined
5a5e29c5e2 ignore CUSTOM damage causes 2022-09-12 16:57:19 -04:00
hyperdefined
d188877f18 Update README.md 2022-08-30 10:28:29 -04:00
hyperdefined
05200f075b Update pom.xml 2022-08-19 18:27:57 -04:00
hyperdefined
9973d743a5 better handling of /kill
apparently minecraft:kill runs in multiple entity damage events?
2022-08-19 18:27:34 -04:00
hyperdefined
a89b9d6f6a Update CommandToolStats.java 2022-08-19 17:39:25 -04:00
hyperdefined
082f529c32 hopefully fixed long standing bug 2022-08-18 11:59:20 -04:00
hyperdefined
05f940026f ignore void and /kill damage 2022-08-18 10:27:43 -04:00
hyperdefined
59d0295b18 permission stuff 2022-08-15 11:51:23 -04:00
hyperdefined
af908f2eb6 Merge pull request #16 from hyperdefined/dependabot/maven/lol.hyper-github-release-api-1.0.4
Bump github-release-api from 1.0.3 to 1.0.4
2022-08-15 11:45:05 -04:00
dependabot[bot]
c86e96e200 Bump github-release-api from 1.0.3 to 1.0.4
Bumps [github-release-api](https://github.com/hyperdefined/GitHubReleaseAPI) from 1.0.3 to 1.0.4.
- [Release notes](https://github.com/hyperdefined/GitHubReleaseAPI/releases)
- [Commits](https://github.com/hyperdefined/GitHubReleaseAPI/compare/1.0.3...1.0.4)

---
updated-dependencies:
- dependency-name: lol.hyper:github-release-api
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-08-11 13:32:36 +00:00
hyperdefined
8061293810 Merge pull request #15 from hyperdefined/dependabot/maven/net.kyori-adventure-platform-bukkit-4.1.2
Bump adventure-platform-bukkit from 4.1.1 to 4.1.2
2022-08-04 12:25:29 -04:00
dependabot[bot]
656e265006 Bump adventure-platform-bukkit from 4.1.1 to 4.1.2
Bumps [adventure-platform-bukkit](https://github.com/KyoriPowered/adventure-platform) from 4.1.1 to 4.1.2.
- [Release notes](https://github.com/KyoriPowered/adventure-platform/releases)
- [Commits](https://github.com/KyoriPowered/adventure-platform/compare/v4.1.1...v4.1.2)

---
updated-dependencies:
- dependency-name: net.kyori:adventure-platform-bukkit
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-08-04 11:30:53 +00:00
hyperdefined
507813f106 Update pom.xml 2022-06-27 20:22:13 -04:00
hyperdefined
e3e1c6a690 Update pom.xml 2022-06-18 17:09:25 -04:00
hyperdefined
5eebcb9ff4 make sure chests are in the same world
fixes #14
2022-06-18 17:09:12 -04:00
hyperdefined
63d508fded fixed typo 2022-06-16 00:04:23 -04:00
hyperdefined
59a8079ba2 Update pom.xml 2022-06-16 00:00:19 -04:00
hyperdefined
3767ee2f63 fixed reseting lore for armor 2022-06-16 00:00:04 -04:00
hyperdefined
7d5f73ae96 better number formatting 2022-06-15 23:59:19 -04:00
hyperdefined
b581d9d178 much better item checking 2022-06-15 23:48:39 -04:00
hyperdefined
d355b7a429 moved class 2022-06-15 23:26:20 -04:00
hyperdefined
d06a1c4a40 support for adding lore to minecart items 2022-06-15 23:25:21 -04:00
hyperdefined
e22fc7b530 Merge pull request #13 from hyperdefined/dependabot/maven/net.kyori-adventure-platform-bukkit-4.1.1
Bump adventure-platform-bukkit from 4.1.0 to 4.1.1
2022-06-13 18:32:54 -04:00
dependabot[bot]
8478411b8f Bump adventure-platform-bukkit from 4.1.0 to 4.1.1
Bumps [adventure-platform-bukkit](https://github.com/KyoriPowered/adventure-platform) from 4.1.0 to 4.1.1.
- [Release notes](https://github.com/KyoriPowered/adventure-platform/releases)
- [Commits](https://github.com/KyoriPowered/adventure-platform/compare/v4.1.0...v4.1.1)

---
updated-dependencies:
- dependency-name: net.kyori:adventure-platform-bukkit
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-06-13 11:38:33 +00:00
hyperdefined
85d072667a Update CommandToolStats.java 2022-06-13 03:10:39 -04:00
hyperdefined
010ca54144 gamemode check 2022-06-13 03:07:37 -04:00
hyperdefined
6af49d6c30 better null handling 2022-06-13 02:55:11 -04:00
hyperdefined
c4e4ce01fd removed debug message 2022-06-13 02:21:32 -04:00
hyperdefined
983a35bd0b Update README.md 2022-06-08 21:01:15 -04:00
hyperdefined
d9ad7ebcad shade stuff 2022-06-07 17:58:46 -04:00
hyperdefined
995f80e159 Update plugin.yml 2022-06-06 13:26:05 -04:00
hyperdefined
56850c40d1 Merge pull request #11 from hyperdefined/dependabot/maven/net.kyori-adventure-text-minimessage-4.11.0
Bump adventure-text-minimessage from 4.10.1 to 4.11.0
2022-06-06 13:25:15 -04:00
dependabot[bot]
b9e4bbd1e8 Bump adventure-text-minimessage from 4.10.1 to 4.11.0
Bumps [adventure-text-minimessage](https://github.com/KyoriPowered/adventure) from 4.10.1 to 4.11.0.
- [Release notes](https://github.com/KyoriPowered/adventure/releases)
- [Commits](https://github.com/KyoriPowered/adventure/compare/v4.10.1...v4.11.0)

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

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

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

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

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

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

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

Signed-off-by: dependabot[bot] <support@github.com>
2022-03-11 11:26:04 +00:00
hyperdefined
7cdb71df50 cleanup 2022-03-01 23:33:55 -05:00
hyperdefined
bd80d6718c Update CommandToolStats.java 2022-03-01 23:33:26 -05:00
hyperdefined
b9907eedec unify item arrays & date formats 2022-03-01 23:32:30 -05:00
hyperdefined
61cf44a407 handle finding who opens a newly spawned chest better 2022-03-01 23:21:09 -05:00
hyperdefined
337f88ce36 Update pom.xml 2022-02-24 11:46:50 -05:00
hyperdefined
42f100f0b0 added missing return (fixes #7) 2022-02-24 11:46:08 -05:00
hyperdefined
63b3cb1d03 Update pom.xml 2022-02-23 19:57:41 -05:00
hyperdefined
7717b6b5a5 Update EntityDamage.java 2022-02-23 19:53:54 -05:00
hyperdefined
a421430fa8 only add damage to valid armor
closes #6
2022-02-23 19:52:58 -05:00
hyperdefined
7a89b31766 removed unused set 2022-02-22 19:05:00 -05:00
hyperdefined
0334681971 getFinalDamage() instead because of armor reductions 2022-02-22 17:33:48 -05:00
hyperdefined
df23f40d6b Update pom.xml 2022-02-22 15:08:38 -05:00
hyperdefined
0221ee40cf handle logic of lore reset better 2022-02-22 15:07:51 -05:00
hyperdefined
a01d07af4a fixed removing new tag for elytras
this fixes #5
2022-02-22 15:07:30 -05:00
hyperdefined
e402d3078a Merge pull request #4 from hyperdefined/dependabot/maven/org.apache.maven.plugins-maven-compiler-plugin-3.10.0
Bump maven-compiler-plugin from 3.9.0 to 3.10.0
2022-02-14 21:07:02 -05:00
dependabot[bot]
4f44ca0777 Bump maven-compiler-plugin from 3.9.0 to 3.10.0
Bumps [maven-compiler-plugin](https://github.com/apache/maven-compiler-plugin) from 3.9.0 to 3.10.0.
- [Release notes](https://github.com/apache/maven-compiler-plugin/releases)
- [Commits](https://github.com/apache/maven-compiler-plugin/compare/maven-compiler-plugin-3.9.0...maven-compiler-plugin-3.10.0)

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

Signed-off-by: dependabot[bot] <support@github.com>
2022-02-14 11:38:14 +00:00
hyperdefined
53fd7f734c Update pom.xml 2022-02-12 20:47:52 -05:00
hyperdefined
75cd4fa17e fixed small typo 2022-02-12 20:47:32 -05:00
hyperdefined
e296c27a5b added comments to better explain what is going on 2022-02-11 19:19:05 -05:00
hyperdefined
adb1c637dc smh 2022-02-11 18:34:42 -05:00
hyperdefined
4b8f8061b4 Merge branch 'master' of https://github.com/hyperdefined/ToolStats 2022-02-11 15:09:49 -05:00
hyperdefined
464916e08b Update CommandToolStats.java 2022-02-11 15:09:32 -05:00
hyperdefined
6b6b65d1df Update README.md 2022-02-11 15:05:55 -05:00
hyperdefined
a1c39dffd0 Update pom.xml 2022-02-11 15:05:18 -05:00
hyperdefined
88eab81906 added tab completions to sub commands 2022-02-11 15:03:37 -05:00
hyperdefined
be233de90d fixed plugin.yml 2022-02-11 15:03:21 -05:00
hyperdefined
2437424e39 added reset lore command 2022-02-11 14:46:25 -05:00
hyperdefined
63b08062c8 Update CraftItem.java 2022-02-11 14:04:12 -05:00
hyperdefined
d23c2446dd fix fishing rods not updating lore correctly 2022-02-11 14:03:51 -05:00
hyperdefined
77b1be62d4 fixes 2022-02-10 21:41:23 -05:00
hyperdefined
29e6c998cf bump 2022-02-06 12:27:58 -05:00
hyperdefined
89951611fe changed api version to support more versions 2022-02-06 12:27:18 -05:00
hyperdefined
1c18a1a90c added missing check (fixes #2) 2022-02-05 16:42:42 -05:00
hyperdefined
f0ec409ef4 Update README.md 2022-01-31 17:40:51 -05:00
hyperdefined
0f9d75db06 Update pom.xml 2022-01-31 17:40:32 -05:00
hyperdefined
975445b8f3 support for custom lore messages 2022-01-31 17:40:10 -05:00
56 changed files with 4820 additions and 785 deletions

31
.github/workflows/hangar.yml vendored Normal file
View File

@@ -0,0 +1,31 @@
name: Update Hangar Description
on:
push:
branches: [ master ]
jobs:
update-hangar-page:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Authenticate with Hangar
id: authenticate
run: |
RESPONSE=$(curl -s -X POST "https://hangar.papermc.io/api/v1/authenticate?apiKey=${{ secrets.HANGAR }}" -H 'accept: application/json')
TOKEN=$(echo $RESPONSE | jq -r '.token')
if [[ "$TOKEN" == "null" ]]; then
echo "Error: Unable to fetch JWT token"
exit 1
fi
echo "::add-mask::$TOKEN"
echo "token=$TOKEN" >> $GITHUB_OUTPUT
- name: Update Project Description
run: |
README_CONTENT=$(cat README.md | jq -Rs .)
curl -s -X PATCH "https://hangar.papermc.io/api/v1/pages/editmain/ToolStats" \
-H "content-type: application/json" \
-H "Authorization: HangarAuth ${{ steps.authenticate.outputs.token }}" \
-d "{\"content\":$README_CONTENT}"

View File

@@ -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

13
.github/workflows/modrinth.yml vendored Normal file
View File

@@ -0,0 +1,13 @@
name: Update Modrinth Description
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'

View File

@@ -1,28 +1,31 @@
<h1 align="center">ToolStats</h1>
<p align="center">
<img src="https://img.shields.io/badge/Minecraft-1.18+-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>
<a href="https://ko-fi.com/hyperdefined"><img src="https://img.shields.io/badge/Donate-Ko--fi-red" alt="Donate via Ko-fi"></a>
<a href="https://www.gnu.org/licenses/gpl-3.0"><img src="https://img.shields.io/badge/License-GPLv3-blue.svg" alt="License: GPL v3"></a>
<a href="https://wakatime.com/badge/user/992a7647-176a-477c-8086-e1abfba87ff4/project/0200f07a-f303-4103-a5f2-34b38c9c1fa4"><img src="https://wakatime.com/badge/user/992a7647-176a-477c-8086-e1abfba87ff4/project/0200f07a-f303-4103-a5f2-34b38c9c1fa4.svg" alt="wakatime"></a>
<a href="https://modrinth.com/plugin/ToolStats"><img alt="modrinth" height="40" src="https://cdn.jsdelivr.net/npm/@intergrav/devins-badges@3/assets/compact/available/modrinth_vector.svg"></a>
<a href="https://hangar.papermc.io/hyperdefined/ToolStats"><img alt="hangar" height="40" src="https://cdn.jsdelivr.net/npm/@intergrav/devins-badges@3/assets/compact/available/hangar_vector.svg"></a>
<a href="https://papermc.io"><img alt="paper" height="40" src="https://cdn.jsdelivr.net/npm/@intergrav/devins-badges@3/assets/compact/supported/paper_vector.svg"></a>
<a href="https://github.com/hyperdefined/ToolStats/wiki"><img alt="ghpages" height="40" src="https://cdn.jsdelivr.net/npm/@intergrav/devins-badges@3/assets/compact/documentation/ghpages_vector.svg"></a>
<a href="https://discord.gg/rJuQXVcJz8"><img alt="discord-singular" height="40" src="https://cdn.jsdelivr.net/npm/@intergrav/devins-badges@3/assets/compact/social/discord-singular_vector.svg"></a>
<a href="https://buymeacoffee.com/hyperdefined"><img alt="buymeacoffee-singular" height="40" src="https://cdn.jsdelivr.net/npm/@intergrav/devins-badges@3/assets/compact/donate/buymeacoffee-singular_vector.svg"></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 either track all statistics by default, or a use a token system to add statistics to tool/armor. You can configure how each statistic is shown on the item, or disable it!
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)
* Flight time with elytras.
The best part is, this data is stored on the item itself.
If item lore is ever incorrect/missing, you can run `/toolstats reset`. This command fixes the lore on whatever item you are holding.
![Image](https://raw.githubusercontent.com/hyperdefined/ToolStats/master/images/image.png)
![Image](https://raw.githubusercontent.com/hyperdefined/ToolStats/master/images/image2.png)
![Image](https://raw.githubusercontent.com/hyperdefined/ToolStats/master/images/image3.png)
@@ -33,6 +36,13 @@ The best part is, this data is stored on the item itself.
![Image](https://raw.githubusercontent.com/hyperdefined/ToolStats/master/images/image8.png)
![Image](https://raw.githubusercontent.com/hyperdefined/ToolStats/master/images/image9.png)
![Image](https://raw.githubusercontent.com/hyperdefined/ToolStats/master/images/image10.png)
![Image](https://raw.githubusercontent.com/hyperdefined/ToolStats/master/images/image11.png)
![Image](https://raw.githubusercontent.com/hyperdefined/ToolStats/master/images/image13.png)
![Image](https://raw.githubusercontent.com/hyperdefined/ToolStats/master/images/image14.png)
![Image](https://raw.githubusercontent.com/hyperdefined/ToolStats/master/images/image12.png)
## Documentation
Visit the [wiki](https://github.com/hyperdefined/ToolStats/wiki) for help.
## License
This plugin is released under GNU General Public License v3. See [LICENSE](https://github.com/hyperdefined/ToolStats/blob/master/LICENSE).
This plugin is released under GNU General Public License v3. See [LICENSE](https://github.com/hyperdefined/ToolStats/blob/master/LICENSE).

BIN
images/crafting/anvil.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.4 KiB

BIN
images/image11.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

BIN
images/image12.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 94 KiB

BIN
images/image13.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

BIN
images/image14.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

35
pom.xml
View File

@@ -23,13 +23,13 @@
<groupId>lol.hyper</groupId>
<artifactId>toolstats</artifactId>
<version>1.1</version>
<version>1.9</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.9.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>

View File

@@ -21,12 +21,15 @@ 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.*;
import lol.hyper.toolstats.tools.config.ConfigTools;
import lol.hyper.toolstats.tools.config.ConfigUpdater;
import lol.hyper.toolstats.tools.config.TokenItems;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.ShapedRecipe;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
@@ -37,28 +40,85 @@ import java.util.logging.Logger;
public final class ToolStats extends JavaPlugin {
// stores who created an item
public final NamespacedKey genericOwner = new NamespacedKey(this, "owner");
// stores when an item was created
/**
* Stores who created an item.
*/
public final NamespacedKey itemOwner = new NamespacedKey(this, "owner");
/**
* Stores when the item was created.
*/
public final NamespacedKey timeCreated = new NamespacedKey(this, "time-created");
// stores how many player kills by sword
public final NamespacedKey swordPlayerKills = new NamespacedKey(this, "player-kills");
// stores how many mob kills by sword
public final NamespacedKey swordMobKills = new NamespacedKey(this, "mob-kills");
// stores how blocks mined (used for all tools)
public final NamespacedKey genericMined = new NamespacedKey(this, "generic-mined");
// stores how many fish were caught
public final NamespacedKey fishingRodCaught = new NamespacedKey(this, "fish-caught");
// stores how many times sheep were sheared
public final NamespacedKey shearsSheared = new NamespacedKey(this, "sheared");
// stores how much damage armor has taken
/**
* Stores how many player kills.
*/
public final NamespacedKey playerKills = new NamespacedKey(this, "player-kills");
/**
* Stores how many mob kills.
*/
public final NamespacedKey mobKills = new NamespacedKey(this, "mob-kills");
/**
* Stores how many blocks were mined.
*/
public final NamespacedKey blocksMined = new NamespacedKey(this, "generic-mined");
/**
* Stores how many crops were harvested.
*/
public final NamespacedKey cropsHarvested = new NamespacedKey(this, "crops-mined");
/**
* Stores how many fish were caught.
*/
public final NamespacedKey fishCaught = new NamespacedKey(this, "fish-caught");
/**
* Stores how many sheep were sheared.
*/
public final NamespacedKey sheepSheared = new NamespacedKey(this, "sheared");
/**
* 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");
/**
* Key for token type. This is for the token itself.
*/
public final NamespacedKey tokenType = new NamespacedKey(this, "token-type");
/**
* Key for applied token. This is what goes onto the tool/armor to record the type.
*/
public final NamespacedKey tokenApplied = new NamespacedKey(this, "token-applied");
/**
* 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 Set<NamespacedKey> keys = new HashSet<>();
public final int CONFIG_VERSION = 9;
public final Logger logger = this.getLogger();
public final File configFile = new File(this.getDataFolder(), "config.yml");
public boolean tokens = false;
public final Set<NamespacedKey> tokenKeys = new HashSet<>();
public BlocksMined blocksMined;
public BlockBreak blockBreak;
public ChunkPopulate chunkPopulate;
public CraftItem craftItem;
public EntityDeath entityDeath;
@@ -66,14 +126,25 @@ 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 = 2;
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;
public TokenItems tokenItems;
public TokenCrafting tokenCrafting;
public AnvilEvent anvilEvent;
public PrepareCraft prepareCraft;
@Override
public void onEnable() {
@@ -81,8 +152,19 @@ public final class ToolStats extends JavaPlugin {
this.saveResource("config.yml", true);
logger.info("Copying default config!");
}
loadConfig();
blocksMined = new BlocksMined(this);
configTools = new ConfigTools(this);
tokenItems = new TokenItems(this);
tokenCrafting = new TokenCrafting(this);
tokenCrafting.setup();
for (ShapedRecipe recipe : tokenCrafting.getRecipes()) {
if (tokens && config.getBoolean("tokens.craft-tokens")) {
Bukkit.addRecipe(recipe);
}
}
hashMaker = new HashMaker(this);
blockBreak = new BlockBreak(this);
craftItem = new CraftItem(this);
chunkPopulate = new ChunkPopulate(this);
entityDeath = new EntityDeath(this);
@@ -90,11 +172,33 @@ 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(this);
itemChecker.setup();
shootBow = new ShootBow(this);
anvilEvent = new AnvilEvent(this);
prepareCraft = new PrepareCraft(this);
Bukkit.getServer().getPluginManager().registerEvents(blocksMined, this);
// save which stat can be used by a reset token
tokenKeys.add(blocksMined);
tokenKeys.add(playerKills);
tokenKeys.add(mobKills);
tokenKeys.add(cropsHarvested);
tokenKeys.add(sheepSheared);
tokenKeys.add(fishCaught);
tokenKeys.add(flightTime);
tokenKeys.add(arrowsShot);
tokenKeys.add(armorDamage);
Bukkit.getServer().getPluginManager().registerEvents(blockBreak, this);
Bukkit.getServer().getPluginManager().registerEvents(chunkPopulate, this);
Bukkit.getServer().getPluginManager().registerEvents(craftItem, this);
Bukkit.getServer().getPluginManager().registerEvents(entityDeath, this);
@@ -102,30 +206,40 @@ 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);
Bukkit.getServer().getPluginManager().registerEvents(anvilEvent, this);
Bukkit.getServer().getPluginManager().registerEvents(prepareCraft, this);
this.getCommand("toolstats").setExecutor(commandToolStats);
new Metrics(this, 14110);
Bukkit.getScheduler().runTaskAsynchronously(this, this::checkForUpdates);
keys.add(genericOwner);
keys.add(timeCreated);
keys.add(swordPlayerKills);
keys.add(swordMobKills);
keys.add(genericMined);
keys.add(fishingRodCaught);
keys.add(shearsSheared);
keys.add(armorDamage);
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();
}
if (config.getBoolean("tokens.enabled")) {
logger.info("The token system is enabled! This means you must apply tokens to items in order for them to track.");
logger.info("Item origins (crafted, traded, found, etc) will still apply to items.");
logger.info("https://github.com/hyperdefined/ToolStats/wiki/Token-System");
}
tokens = config.getBoolean("tokens.enabled");
numberFormat = new NumberFormat(this);
}
public void checkForUpdates() {
@@ -137,7 +251,7 @@ public final class ToolStats extends JavaPlugin {
e.printStackTrace();
return;
}
GitHubRelease current = api.getReleaseByTag(this.getDescription().getVersion());
GitHubRelease current = api.getReleaseByTag(this.getPluginMeta().getVersion());
GitHubRelease latest = api.getLatestVersion();
if (current == null) {
logger.warning("You are running a version that does not exist on GitHub. If you are in a dev environment, you can ignore this. Otherwise, this is a bug!");
@@ -150,54 +264,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.");
}
}
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;
}
}

View File

@@ -18,13 +18,28 @@
package lol.hyper.toolstats.commands;
import lol.hyper.toolstats.ToolStats;
import org.bukkit.ChatColor;
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.CommandExecutor;
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;
import org.bukkit.inventory.ShapedRecipe;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.persistence.PersistentDataType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class CommandToolStats implements CommandExecutor {
import java.util.*;
public class CommandToolStats implements TabExecutor {
private final ToolStats toolStats;
@@ -34,20 +49,432 @@ public class CommandToolStats implements CommandExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
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.");
} else if (args.length == 1) {
if (args[0].equalsIgnoreCase("reload")) {
if (sender.isOp() || sender.hasPermission("toolstats.reload")) {
sender.sendMessage(Component.text("ToolStats version " + toolStats.getPluginMeta().getVersion() + ". Created by hyperdefined.", NamedTextColor.GREEN));
return true;
}
switch (args[0]) {
case "reload": {
if (sender.hasPermission("toolstats.reload")) {
boolean oldTokensStatus = toolStats.tokens;
toolStats.loadConfig();
sender.sendMessage(ChatColor.GREEN + "Configuration reloaded!");
toolStats.tokenCrafting.getRecipes().clear();
toolStats.tokenCrafting.setup();
// if the server went from tokens off -> on, add the recipes
// if the server went from tokens on -> off, remove the recipes
if (toolStats.tokens != oldTokensStatus) {
// tokens are now enabled
if (toolStats.tokens) {
sender.sendMessage(Component.text("It looks like you ENABLED the token system. While this is fine, it can break. Please restart your server instead.", NamedTextColor.YELLOW));
if (toolStats.config.getBoolean("tokens.craft-token")) {
for (ShapedRecipe recipe : toolStats.tokenCrafting.getRecipes()) {
Bukkit.addRecipe(recipe);
}
}
} else {
// tokens are now disabled
sender.sendMessage(Component.text("It looks like you DISABLED the token system. While this is fine, it can break. Please restart your server instead.", NamedTextColor.YELLOW));
for (ShapedRecipe recipe : toolStats.tokenCrafting.getRecipes()) {
Bukkit.removeRecipe(recipe.getKey());
}
}
}
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));
}
} else {
sender.sendMessage(ChatColor.RED + "Invalid sub-command.");
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 (!toolStats.itemChecker.isValidItem(heldItem.getType())) {
sender.sendMessage(Component.text("You must hold a valid item.", NamedTextColor.RED));
return true;
}
fixItemLore(heldItem, player);
sender.sendMessage(Component.text("The lore was reset!", NamedTextColor.GREEN));
return true;
}
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;
}
case "givetokens": {
if (!sender.hasPermission("toolstats.givetokens")) {
sender.sendMessage(Component.text("You do not have permission for this command.", NamedTextColor.RED));
return true;
}
// Make sure /toolstats givetoken <player> <token> is present
if (args.length < 3) {
sender.sendMessage(Component.text("Invalid syntax. Usage: /toolstats givetokens <player> <token>", NamedTextColor.RED));
return true;
}
Player target = Bukkit.getPlayerExact(args[1]);
if (target == null) {
sender.sendMessage(Component.text("Player not found.", NamedTextColor.RED));
return true;
}
String tokenType = args[2];
if (!toolStats.tokenCrafting.getTokenTypes().contains(tokenType)) {
sender.sendMessage(Component.text("Invalid token type.", NamedTextColor.RED));
return true;
}
// make sure tokens are enabled before giving
if (!toolStats.config.getBoolean("tokens.enabled")) {
sender.sendMessage(Component.text("Unable to give tokens. Tokens are disabled", NamedTextColor.RED));
return true;
}
// if the user does not send in a number, default to 1
int amount = 1;
if (args.length >= 4) {
try {
amount = Integer.parseInt(args[3]);
if (amount <= 0) { // Optional: Prevent negative or zero values
sender.sendMessage(Component.text("Token quantity must be above or 1.", NamedTextColor.RED));
return true;
}
} catch (NumberFormatException exception) {
sender.sendMessage(Component.text("Invalid token quantity.", NamedTextColor.RED));
return true;
}
}
giveToken(target, tokenType, amount);
if (sender instanceof Player) {
sender.sendMessage(Component.text("Gave " + target.getName() + " " + amount + " " + tokenType + " tokens.", NamedTextColor.GREEN));
}
return true;
}
default: {
sender.sendMessage(Component.text("Invalid sub-command.", NamedTextColor.RED));
}
}
return true;
}
/**
* 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.
*/
private void fixItemLore(ItemStack original, Player player) {
ItemStack finalItem = original.clone();
ItemMeta finalMeta = finalItem.getItemMeta();
if (finalMeta == null) {
return;
}
PersistentDataContainer container = finalMeta.getPersistentDataContainer();
List<Component> lore = new ArrayList<>();
// set how the item was obtained
Integer origin = -1;
if (container.has(toolStats.originType, PersistentDataType.INTEGER)) {
origin = container.get(toolStats.originType, PersistentDataType.INTEGER);
}
// set to -1 if it's invalid
if (origin == null) {
origin = -1;
}
// hard code elytras
if (finalItem.getType() == Material.ELYTRA) {
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.configTools.checkConfig(original.getType(), "created-by")) {
if (container.has(toolStats.itemOwner, new UUIDDataType())) {
UUID owner = container.get(toolStats.itemOwner, 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.itemOwner, new UUIDDataType(), player.getUniqueId());
}
// show how the item was created based on the previous lore
switch (origin) {
case 0: {
lore.add(toolStats.configTools.formatLore("created.created-by", "{player}", ownerName));
break;
}
case 2: {
lore.add(toolStats.configTools.formatLore("looted.looted-by", "{player}", ownerName));
break;
}
case 3: {
lore.add(toolStats.configTools.formatLore("traded.traded-by", "{player}", ownerName));
break;
}
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.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 (origin) {
case 0: {
lore.add(toolStats.configTools.formatLore("created.created-on", "{date}", date));
break;
}
case 2: {
lore.add(toolStats.configTools.formatLore("looted.looted-on", "{date}", date));
break;
}
case 3: {
lore.add(toolStats.configTools.formatLore("traded.traded-on", "{date}", date));
break;
}
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.configTools.checkConfig(original.getType(), "player-kills")) {
if (container.has(toolStats.playerKills, PersistentDataType.INTEGER)) {
Integer kills = container.get(toolStats.playerKills, PersistentDataType.INTEGER);
if (kills != null) {
lore.add(toolStats.configTools.formatLore("kills.player", "{kills}", toolStats.numberFormat.formatInt(kills)));
}
}
}
if (toolStats.configTools.checkConfig(original.getType(), "mob-kills")) {
if (container.has(toolStats.mobKills, PersistentDataType.INTEGER)) {
Integer kills = container.get(toolStats.mobKills, PersistentDataType.INTEGER);
if (kills != null) {
lore.add(toolStats.configTools.formatLore("kills.mob", "{kills}", toolStats.numberFormat.formatInt(kills)));
}
}
}
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.blocksMined, PersistentDataType.INTEGER)) {
Integer blocksMined = container.get(toolStats.blocksMined, PersistentDataType.INTEGER);
if (blocksMined != null) {
lore.add(toolStats.configTools.formatLore("blocks-mined", "{blocks}", toolStats.numberFormat.formatInt(blocksMined)));
}
}
}
if (toolStats.config.getBoolean("enabled.fish-caught")) {
if (container.has(toolStats.fishCaught, PersistentDataType.INTEGER)) {
Integer fish = container.get(toolStats.fishCaught, PersistentDataType.INTEGER);
if (fish != null) {
lore.add(toolStats.configTools.formatLore("fished.fish-caught", "{fish}", toolStats.numberFormat.formatInt(fish)));
}
}
}
if (toolStats.config.getBoolean("enabled.sheep-sheared")) {
if (container.has(toolStats.sheepSheared, PersistentDataType.INTEGER)) {
Integer sheep = container.get(toolStats.sheepSheared, PersistentDataType.INTEGER);
if (sheep != null) {
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.DOUBLE)) {
Double damage = container.get(toolStats.armorDamage, PersistentDataType.DOUBLE);
if (damage != null) {
lore.add(toolStats.configTools.formatLore("damage-taken", "{damage}", toolStats.numberFormat.formatDouble(damage)));
}
}
}
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);
}
/**
* Gives a player a token.
*
* @param target The player.
* @param tokenType The token type.
*/
private void giveToken(Player target, String tokenType, int amount) {
switch (tokenType) {
case "crops-mined": {
ItemStack itemStack = toolStats.tokenItems.cropsMined();
itemStack.setAmount(amount);
target.getInventory().addItem(itemStack);
break;
}
case "blocks-mined": {
ItemStack itemStack = toolStats.tokenItems.blocksMined();
itemStack.setAmount(amount);
target.getInventory().addItem(itemStack);
break;
}
case "damage-taken": {
ItemStack itemStack = toolStats.tokenItems.damageTaken();
itemStack.setAmount(amount);
target.getInventory().addItem(itemStack);
break;
}
case "mob-kills": {
ItemStack itemStack = toolStats.tokenItems.mobKills();
itemStack.setAmount(amount);
target.getInventory().addItem(itemStack);
break;
}
case "player-kills": {
ItemStack itemStack = toolStats.tokenItems.playerKills();
itemStack.setAmount(amount);
target.getInventory().addItem(itemStack);
break;
}
case "arrows-shot": {
ItemStack itemStack = toolStats.tokenItems.arrowsShot();
itemStack.setAmount(amount);
target.getInventory().addItem(itemStack);
break;
}
case "sheep-sheared": {
ItemStack itemStack = toolStats.tokenItems.sheepSheared();
itemStack.setAmount(amount);
target.getInventory().addItem(itemStack);
break;
}
case "flight-time": {
ItemStack itemStack = toolStats.tokenItems.flightTime();
itemStack.setAmount(amount);
target.getInventory().addItem(itemStack);
break;
}
case "fish-caught": {
ItemStack itemStack = toolStats.tokenItems.fishCaught();
itemStack.setAmount(amount);
target.getInventory().addItem(itemStack);
break;
}
case "reset": {
ItemStack itemStack = toolStats.tokenItems.resetToken();
itemStack.setAmount(amount);
target.getInventory().addItem(itemStack);
break;
}
}
}
@Nullable
@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) {
if (args.length == 1) {
List<String> suggestions = new ArrayList<>();
if (sender.hasPermission("toolstats.reload")) {
suggestions.add("reload");
}
if (sender.hasPermission("toolstats.reset")) {
suggestions.add("reset");
}
if (sender.hasPermission("toolstats.givetokens")) {
suggestions.add("givetokens");
}
return suggestions.isEmpty() ? null : suggestions;
}
if (args.length == 2 && args[0].equalsIgnoreCase("reset") && sender.hasPermission("toolstats.reset.confirm")) {
return Collections.singletonList("confirm");
}
if (args.length == 3 && args[0].equalsIgnoreCase("givetokens") && sender.hasPermission("toolstats.givetokens")) {
return toolStats.tokenCrafting.getTokenTypes();
}
return null;
}
}

View File

@@ -0,0 +1,318 @@
/*
* This file is part of ToolStats.
*
* ToolStats is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ToolStats is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ToolStats. If not, see <https://www.gnu.org/licenses/>.
*/
package lol.hyper.toolstats.events;
import lol.hyper.toolstats.ToolStats;
import org.bukkit.Material;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.PrepareAnvilEvent;
import org.bukkit.inventory.AnvilInventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.persistence.PersistentDataType;
import java.util.Locale;
public class AnvilEvent implements Listener {
private final ToolStats toolStats;
public AnvilEvent(ToolStats toolStats) {
this.toolStats = toolStats;
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onAnvilEvent(PrepareAnvilEvent event) {
// only listen if the token system is enabled
if (!toolStats.config.getBoolean("tokens.enabled")) {
return;
}
AnvilInventory inventory = event.getInventory();
ItemStack firstSlot = inventory.getItem(0);
ItemStack secondSlot = inventory.getItem(1);
// make sure both slots have items
if (firstSlot == null || secondSlot == null) {
return;
}
Material firstSlotMaterial = firstSlot.getType();
Material secondSlotMaterial = secondSlot.getType();
// make sure the first item is a valid item
if (!toolStats.itemChecker.isValidItem(firstSlotMaterial)) {
return;
}
PersistentDataContainer secondSlotContainer = secondSlot.getItemMeta().getPersistentDataContainer();
// make sure the 2nd item is one of ours
if (secondSlotMaterial != Material.PAPER || !secondSlotContainer.has(toolStats.tokenType, PersistentDataType.STRING)) {
return;
}
// get the type from the token
String tokenType = secondSlotContainer.get(toolStats.tokenType, PersistentDataType.STRING);
if (tokenType == null) {
return;
}
// don't let the player use more than one
if (secondSlot.getAmount() > 1) {
return;
}
// clone the item
ItemStack clone = firstSlot.clone();
if (tokenType.equalsIgnoreCase("reset")) {
reset(event, clone);
return;
}
// if the item is a mining tool
if (toolStats.itemChecker.isMineTool(firstSlotMaterial)) {
if (firstSlotMaterial.toString().toLowerCase(Locale.ROOT).contains("hoe")) {
// the item is a hoe
if (tokenType.equalsIgnoreCase("blocks-mined")) {
addToken(event, tokenType, "blocks-mined", clone);
}
if (tokenType.equalsIgnoreCase("crops-mined")) {
addToken(event, tokenType, "crops-mined", clone);
}
} else {
// since shears will fall under here, check if the token is for sheep sheared
if (firstSlotMaterial == Material.SHEARS && tokenType.equals("sheep-sheared")) {
addToken(event, tokenType, "sheep-sheared", clone);
return;
}
addToken(event, tokenType, "blocks-mined", clone);
}
// axes are a mining tool, so double check them here for player/mob kills
if (firstSlotMaterial.toString().toLowerCase(Locale.ROOT).contains("_axe")) {
if (tokenType.equalsIgnoreCase("player-kills")) {
addToken(event, tokenType, "player-kills", clone);
return;
}
if (tokenType.equalsIgnoreCase("mob-kills")) {
addToken(event, tokenType, "mob-kills", clone);
return;
}
}
return;
}
if (toolStats.itemChecker.isArmor(firstSlotMaterial)) {
addToken(event, tokenType, "damage-taken", clone);
return;
}
if (toolStats.itemChecker.isMeleeWeapon(firstSlotMaterial)) {
if (tokenType.equalsIgnoreCase("player-kills")) {
addToken(event, tokenType, "player-kills", clone);
return;
}
if (tokenType.equalsIgnoreCase("mob-kills")) {
addToken(event, tokenType, "mob-kills", clone);
return;
}
return;
}
if (firstSlotMaterial == Material.BOW || firstSlotMaterial == Material.CROSSBOW) {
if (tokenType.equalsIgnoreCase("player-kills")) {
addToken(event, tokenType, "player-kills", clone);
return;
}
if (tokenType.equalsIgnoreCase("mob-kills")) {
addToken(event, tokenType, "mob-kills", clone);
return;
}
if (tokenType.equalsIgnoreCase("arrows-shot")) {
addToken(event, tokenType, "arrows-shot", clone);
return;
}
return;
}
if (firstSlotMaterial == Material.ELYTRA) {
addToken(event, tokenType, "flight-time", clone);
return;
}
if (firstSlotMaterial == Material.FISHING_ROD) {
addToken(event, tokenType, "fish-caught", clone);
}
}
/**
* Add token to an item.
*
* @param event The anvil event.
* @param attemptToken The token in the 2nd slot of the anvil. The one the player wants to add.
* @param targetToken The token we are checking for. This should match the tool.
* @param firstSlotItem The item in the first slot.
*/
private void addToken(PrepareAnvilEvent event, String attemptToken, String targetToken, ItemStack firstSlotItem) {
// make sure the token we are using is for this tool
if (!attemptToken.equalsIgnoreCase(targetToken)) {
event.setResult(null);
return;
}
// if the item already has the token, ignore
if (toolStats.itemChecker.checkTokens(firstSlotItem.getItemMeta().getPersistentDataContainer(), targetToken)) {
event.setResult(null);
return;
}
// apply the token and set the result
ItemStack newItem = toolStats.itemChecker.addToken(firstSlotItem, targetToken);
switch (targetToken) {
case "crops-mined": {
newItem.setItemMeta(toolStats.itemLore.updateCropsMined(newItem, 0));
break;
}
case "blocks-mined": {
newItem.setItemMeta(toolStats.itemLore.updateBlocksMined(newItem, 0));
break;
}
case "damage-taken": {
newItem.setItemMeta(toolStats.itemLore.updateDamage(newItem, 0.0, false));
break;
}
case "mob-kills": {
newItem.setItemMeta(toolStats.itemLore.updateMobKills(newItem, 0));
break;
}
case "player-kills": {
newItem.setItemMeta(toolStats.itemLore.updatePlayerKills(newItem, 0));
break;
}
case "arrows-shot": {
newItem.setItemMeta(toolStats.itemLore.updateArrowsShot(newItem, 0));
break;
}
case "sheep-sheared": {
newItem.setItemMeta(toolStats.itemLore.updateSheepSheared(newItem, 0));
break;
}
case "flight-time": {
newItem.setItemMeta(toolStats.itemLore.updateFlightTime(newItem, 0));
break;
}
case "fish-caught": {
newItem.setItemMeta(toolStats.itemLore.updateFishCaught(newItem, 0));
break;
}
}
event.setResult(newItem);
event.getView().setRepairCost(toolStats.itemChecker.getCost(targetToken));
}
/**
* Reset an item's stats. This function is... gross.
* Because of how the lore system is set up, we have to basically revert the stats.
* The lore function requires the old value, then adds x to the current stat.
* This is required, so it can find the old line in the lore and update it.
* So we simply make the stat negative, and add it to reset it to zero.
* Gross? Yeah, but I don't want to rewrite the lore system again...
*
* @param event The PrepareAnvilEvent event.
* @param inputItem The input item to reset.
*/
private void reset(PrepareAnvilEvent event, ItemStack inputItem) {
ItemStack finalItem = inputItem.clone();
ItemMeta meta = finalItem.getItemMeta();
PersistentDataContainer container = meta.getPersistentDataContainer();
if (container.has(toolStats.playerKills)) {
Integer playerKills = container.get(toolStats.playerKills, PersistentDataType.INTEGER);
if (playerKills == null) {
return;
}
meta = toolStats.itemLore.updatePlayerKills(finalItem, -playerKills);
finalItem.setItemMeta(meta);
}
if (container.has(toolStats.mobKills)) {
Integer mobKills = container.get(toolStats.mobKills, PersistentDataType.INTEGER);
if (mobKills == null) {
return;
}
meta = toolStats.itemLore.updateMobKills(finalItem, -mobKills);
finalItem.setItemMeta(meta);
}
if (container.has(toolStats.blocksMined)) {
Integer blocksMined = container.get(toolStats.blocksMined, PersistentDataType.INTEGER);
if (blocksMined == null) {
return;
}
meta = toolStats.itemLore.updateBlocksMined(finalItem, -blocksMined);
finalItem.setItemMeta(meta);
}
if (container.has(toolStats.cropsHarvested)) {
Integer cropsHarvested = container.get(toolStats.playerKills, PersistentDataType.INTEGER);
if (cropsHarvested == null) {
return;
}
meta = toolStats.itemLore.updateCropsMined(finalItem, -cropsHarvested);
finalItem.setItemMeta(meta);
}
if (container.has(toolStats.fishCaught)) {
Integer fishCaught = container.get(toolStats.fishCaught, PersistentDataType.INTEGER);
if (fishCaught == null) {
return;
}
meta = toolStats.itemLore.updateFishCaught(finalItem, -fishCaught);
finalItem.setItemMeta(meta);
}
if (container.has(toolStats.sheepSheared)) {
Integer sheepSheared = container.get(toolStats.sheepSheared, PersistentDataType.INTEGER);
if (sheepSheared == null) {
return;
}
meta = toolStats.itemLore.updateSheepSheared(finalItem, -sheepSheared);
finalItem.setItemMeta(meta);
}
if (container.has(toolStats.armorDamage)) {
Double armorDamage = container.get(toolStats.armorDamage, PersistentDataType.DOUBLE);
if (armorDamage == null) {
return;
}
meta = toolStats.itemLore.updateDamage(finalItem, -armorDamage, true);
finalItem.setItemMeta(meta);
}
if (container.has(toolStats.arrowsShot)) {
Integer arrowsShot = container.get(toolStats.arrowsShot, PersistentDataType.INTEGER);
if (arrowsShot == null) {
return;
}
meta = toolStats.itemLore.updateArrowsShot(finalItem, -arrowsShot);
finalItem.setItemMeta(meta);
}
if (container.has(toolStats.flightTime)) {
Long flightTime = container.get(toolStats.flightTime, PersistentDataType.LONG);
if (flightTime == null) {
return;
}
meta = toolStats.itemLore.updateFlightTime(finalItem, -flightTime);
finalItem.setItemMeta(meta);
}
event.setResult(finalItem);
event.getView().setRepairCost(toolStats.itemChecker.getCost("reset"));
}
}

View File

@@ -0,0 +1,99 @@
/*
* This file is part of ToolStats.
*
* ToolStats is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ToolStats is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ToolStats. If not, see <https://www.gnu.org/licenses/>.
*/
package lol.hyper.toolstats.events;
import lol.hyper.toolstats.ToolStats;
import org.bukkit.Bukkit;
import org.bukkit.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 java.util.Locale;
public class BlockBreak implements Listener {
private final ToolStats toolStats;
public BlockBreak(ToolStats toolStats) {
this.toolStats = toolStats;
}
@EventHandler(priority = EventPriority.MONITOR)
public void onBreak(BlockBreakEvent event) {
if (event.isCancelled()) {
return;
}
Player player = event.getPlayer();
if (player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.SPECTATOR) {
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
if (!toolStats.itemChecker.isMineTool(heldItem.getType())) {
return;
}
// if the item is a hoe
if (heldItem.getType().toString().toLowerCase(Locale.ROOT).contains("hoe")) {
// player is breaking crops with a hoe
if (block.getBlockData() instanceof Ageable ageable) {
// ignore crops that are not fully grown
if (ageable.getAge() != ageable.getMaximumAge()) {
return;
}
ItemMeta newMeta = toolStats.itemLore.updateCropsMined(heldItem, 1);
if (newMeta != null) {
// replace item in main hand
heldItem.setItemMeta(newMeta);
}
} else {
// item is a hoe, but not breaking crops
ItemMeta newMeta = toolStats.itemLore.updateBlocksMined(heldItem, 1);
if (newMeta != null) {
// replace item in main hand
heldItem.setItemMeta(newMeta);
}
}
} else {
// item is not a hoe
// update the blocks mined
ItemMeta newMeta = toolStats.itemLore.updateBlocksMined(heldItem, 1);
if (newMeta != null) {
// replace item in main hand
heldItem.setItemMeta(newMeta);
}
}
}
}

View File

@@ -1,109 +0,0 @@
/*
* This file is part of ToolStats.
*
* ToolStats is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ToolStats is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ToolStats. If not, see <https://www.gnu.org/licenses/>.
*/
package lol.hyper.toolstats.events;
import lol.hyper.toolstats.ToolStats;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.persistence.PersistentDataType;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class BlocksMined implements Listener {
private final ToolStats toolStats;
private final String[] validTools = {"pickaxe", "axe", "hoe", "shovel", "shear"};
private final String blocksMinedLore = ChatColor.GRAY + "Blocks mined: " + ChatColor.DARK_GRAY + "X";
public BlocksMined(ToolStats toolStats) {
this.toolStats = toolStats;
}
@EventHandler
public void onBreak(BlockBreakEvent event) {
Player player = event.getPlayer();
if (player.getGameMode() != GameMode.SURVIVAL) {
return;
}
ItemStack heldItem = player.getInventory().getItem(player.getInventory().getHeldItemSlot());
if (heldItem == null || heldItem.getType() == Material.AIR) {
return;
}
String itemName = heldItem.getType().toString().toLowerCase();
if (Arrays.stream(validTools).noneMatch(itemName::contains)) {
return;
}
updateBlocksMined(heldItem);
}
private void updateBlocksMined(ItemStack itemStack) {
ItemMeta meta = itemStack.getItemMeta();
if (meta == null) {
return;
}
Integer blocksMined = 0;
PersistentDataContainer container = meta.getPersistentDataContainer();
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);
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("Blocks mined")) {
hasLore = true;
lore.set(x, blocksMinedLore.replace("X", Integer.toString(blocksMined)));
break;
}
}
// if the item has lore but doesn't have the tag, add it
if (!hasLore) {
lore.add(blocksMinedLore.replace("X", Integer.toString(blocksMined)));
}
} else {
// if the item has no lore, create a new list and add the string
lore = new ArrayList<>();
lore.add(blocksMinedLore.replace("X", Integer.toString(blocksMined)));
}
if (toolStats.checkConfig(itemStack, "blocks-mined")) {
meta.setLore(lore);
}
itemStack.setItemMeta(meta);
}
}

View File

@@ -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,29 +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 (entity instanceof ItemFrame) {
ItemFrame itemFrame = (ItemFrame) entity;
if (itemFrame.getItem().getType() == Material.ELYTRA) {
ItemStack elytraCopy = itemFrame.getItem();
ItemMeta meta = elytraCopy.getItemMeta();
if (meta == null) {
return;
}
PersistentDataContainer container = meta.getPersistentDataContainer();
container.set(toolStats.newElytra, PersistentDataType.INTEGER, 1);
elytraCopy.setItemMeta(meta);
itemFrame.setItem(elytraCopy);
// if there is a new item frame
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);

View File

@@ -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,63 +32,139 @@ 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 String timeCreatedLore = ChatColor.GRAY + "Crafted on: " + ChatColor.DARK_GRAY + "X";
private final String ownerLore = ChatColor.GRAY + "Crafted by: " + ChatColor.DARK_GRAY + "X";
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) {
Player player = (Player) event.getWhoClicked();
ItemStack itemStack = event.getCurrentItem();
if (itemStack == null || itemStack.getType() == Material.AIR) {
if (event.isCancelled()) {
return;
}
String name = itemStack.getType().toString().toLowerCase(Locale.ROOT);
for (String x : validItems) {
if (name.contains(x)) {
event.setCurrentItem(addLore(itemStack, player));
}
Player player = (Player) event.getWhoClicked();
if (player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.SPECTATOR) {
return;
}
ItemStack craftedItem = event.getCurrentItem();
if (craftedItem == null || craftedItem.getType() == Material.AIR) {
return;
}
Material craftedMaterial = craftedItem.getType();
// only check certain items
if (!toolStats.itemChecker.isValidItem(craftedMaterial)) {
return;
}
// if the player shift clicks
if (event.isShiftClick()) {
// store the player inventory before they craft the items
ItemStack[] beforeCraft = player.getInventory().getContents();
// run a tick after to see the changes
player.getScheduler().runDelayed(toolStats, scheduledTask -> {
// get their inventory after the craft
ItemStack[] afterCraft = player.getInventory().getContents();
for (int i = 0; i < afterCraft.length; i++) {
ItemStack newSlotItem = afterCraft[i];
ItemStack oldSlotItem = beforeCraft[i];
// if this slot is empty after crafting, skip it
if (newSlotItem == null) {
continue;
}
// if the item matches what we crafted
if (newSlotItem.getType() == craftedMaterial) {
// if the slot was empty before we crafted, this means we just made it
if (oldSlotItem == null) {
// add the lore
ItemStack newItem = addLore(newSlotItem, player);
if (newItem != null) {
player.getInventory().setItem(i, newItem);
}
}
}
}
}, null, 1);
return;
}
// the player did not shift click
ItemStack newItem = addLore(craftedItem, 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.
* @return A copy of the item with the tags + lore.
*/
private ItemStack addLore(ItemStack itemStack, Player owner) {
// clone the item
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
long timeCreated = System.currentTimeMillis();
Date finalDate = new Date(timeCreated);
PersistentDataContainer container = meta.getPersistentDataContainer();
// if the item already has the tag
// this is to prevent duplicate tags
if (container.has(toolStats.timeCreated, PersistentDataType.LONG) || container.has(toolStats.itemOwner, PersistentDataType.LONG)) {
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());
List<String> lore;
container.set(toolStats.itemOwner, new UUIDDataType(), owner.getUniqueId());
container.set(toolStats.originType, PersistentDataType.INTEGER, 0);
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<>();
}
if (toolStats.checkConfig(itemStack, "created-date")) {
lore.add(timeCreatedLore.replace("X", format.format(finalDate)));
// do we add the lore based on the config?
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(ownerLore.replace("X", 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;
}

View 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.itemOwner, 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;
}
}

View File

@@ -18,11 +18,13 @@
package lol.hyper.toolstats.events;
import lol.hyper.toolstats.ToolStats;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.entity.*;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Trident;
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;
@@ -30,272 +32,200 @@ import org.bukkit.event.entity.EntityDamageEvent;
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 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 String playerKillsLore = ChatColor.GRAY + "Player kills: " + ChatColor.DARK_GRAY + "X";
private final String mobKillsLore = ChatColor.GRAY + "Mob kills: " + ChatColor.DARK_GRAY + "X";
private final String damageTakenLore = ChatColor.GRAY + "Damage taken: " + ChatColor.DARK_GRAY + "X";
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.getEntity() instanceof LivingEntity)) {
if (event.isCancelled()) {
return;
}
LivingEntity livingEntity = (LivingEntity) event.getEntity();
if (!(event.getEntity() instanceof LivingEntity mobBeingAttacked)) {
return;
}
// 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;
}
ItemStack heldItem = player.getInventory().getItem(player.getInventory().getHeldItemSlot());
if (heldItem == null || heldItem.getType() == Material.AIR) {
return;
}
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) {
ItemMeta newItem = toolStats.itemLore.updatePlayerKills(heldItem, 1);
if (newItem != null) {
attackingPlayerInventory.getItemInMainHand().setItemMeta(newItem);
}
return;
}
// player is killing regular mob
player.getInventory().setItem(player.getInventory().getHeldItemSlot(), updateMobKills(heldItem));
trackedMobs.add(livingEntity.getUniqueId());
ItemMeta newItem = toolStats.itemLore.updateMobKills(heldItem, 1);
if (newItem != null) {
attackingPlayerInventory.getItemInMainHand().setItemMeta(newItem);
}
trackedMobs.add(mobBeingAttacked.getUniqueId());
}
if (event.getDamager() instanceof Trident) {
Trident trident = (Trident) event.getDamager();
ItemStack clone;
if (livingEntity instanceof Player) {
clone = updatePlayerKills(trident.getItem());
// trident is being thrown at something
if (event.getDamager() instanceof Trident trident) {
ItemStack newTrident = trident.getItemStack();
ItemMeta newMeta;
// trident is killing player
if (mobBeingAttacked instanceof Player) {
newMeta = toolStats.itemLore.updatePlayerKills(trident.getItemStack(), 1);
} else {
clone = updateMobKills(trident.getItem());
// trident is killing a mob
newMeta = toolStats.itemLore.updateMobKills(trident.getItemStack(), 1);
trackedMobs.add(mobBeingAttacked.getUniqueId());
}
if (clone == null) {
return;
if (newMeta != null) {
newTrident.setItemMeta(newMeta);
trident.setItemStack(newTrident);
}
trident.setItem(clone);
}
if (event.getDamager() instanceof Arrow) {
Arrow arrow = (Arrow) event.getDamager();
if (arrow.getShooter() instanceof Player) {
Player player = (Player) arrow.getShooter();
ItemStack heldItem = player.getInventory().getItem(player.getInventory().getHeldItemSlot());
if (heldItem == null) {
// arrow is being shot
if (event.getDamager() instanceof Arrow arrow) {
// if the shooter is a player
if (arrow.getShooter() instanceof Player shootingPlayer) {
if (shootingPlayer.getGameMode() == GameMode.CREATIVE || shootingPlayer.getGameMode() == GameMode.SPECTATOR) {
return;
}
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 shootingPlayerInventory = shootingPlayer.getInventory();
ItemStack heldBow = toolStats.itemChecker.getBow(shootingPlayerInventory);
if (heldBow == null) {
return;
}
// player is shooting another player
if (mobBeingAttacked instanceof Player) {
ItemMeta newItem = toolStats.itemLore.updatePlayerKills(heldBow, 1);
if (newItem != null) {
shootingPlayerInventory.getItemInMainHand().setItemMeta(newItem);
}
} else {
// player is shooting a mob
ItemMeta newItem = toolStats.itemLore.updateMobKills(heldBow, 1);
if (newItem != null) {
shootingPlayerInventory.getItemInMainHand().setItemMeta(newItem);
}
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) {
updateArmorDamage(armor, event.getDamage());
if (mobBeingAttacked instanceof Player playerTakingDamage) {
if (playerTakingDamage.getGameMode() == GameMode.CREATIVE || playerTakingDamage.getGameMode() == GameMode.SPECTATOR) {
return;
}
PlayerInventory playerInventory = playerTakingDamage.getInventory();
ItemStack[] armorContents = playerInventory.getArmorContents();
for (ItemStack armorPiece : armorContents) {
if (armorPiece != null) {
if (toolStats.itemChecker.isArmor(armorPiece.getType())) {
ItemMeta newItem = toolStats.itemLore.updateDamage(armorPiece, event.getFinalDamage(), false);
if (newItem != null) {
armorPiece.setItemMeta(newItem);
}
}
}
}
// apply the new armor
playerInventory.setArmorContents(armorContents);
}
}
@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();
if (livingEntity instanceof Player) {
Player player = (Player) livingEntity;
PlayerInventory inventory = player.getInventory();
for (ItemStack armor : inventory.getArmorContents()) {
if (armor != null) {
updateArmorDamage(armor, event.getDamage());
// ignore void and /kill damage
EntityDamageEvent.DamageCause cause = event.getCause();
if (ignoredCauses.contains(cause)) {
return;
}
// player is taken damage but not being killed
if (mobBeingAttacked instanceof Player playerTakingDamage) {
if (playerTakingDamage.getGameMode() == GameMode.CREATIVE || playerTakingDamage.getGameMode() == GameMode.SPECTATOR) {
return;
}
PlayerInventory playerInventory = playerTakingDamage.getInventory();
ItemStack[] armorContents = playerInventory.getArmorContents();
for (ItemStack armorPiece : armorContents) {
if (armorPiece != null) {
if (toolStats.itemChecker.isArmor(armorPiece.getType())) {
ItemMeta newItem = toolStats.itemLore.updateDamage(armorPiece, event.getFinalDamage(),false);
if (newItem != null) {
armorPiece.setItemMeta(newItem);
}
}
}
}
// apply the new armor
playerInventory.setArmorContents(armorContents);
}
}
@EventHandler
@EventHandler(priority = EventPriority.MONITOR)
public void onDamage(EntityDamageByBlockEvent event) {
LivingEntity livingEntity = (LivingEntity) event.getEntity();
if (livingEntity instanceof Player) {
Player player = (Player) livingEntity;
PlayerInventory inventory = player.getInventory();
for (ItemStack armor : inventory.getArmorContents()) {
if (armor != null) {
updateArmorDamage(armor, event.getDamage());
}
}
}
}
private ItemStack updatePlayerKills(ItemStack itemStack) {
ItemStack finalItem = itemStack.clone();
ItemMeta meta = finalItem.getItemMeta();
if (meta == null) {
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) {
return null;
} else {
playerKills++;
}
container.set(toolStats.swordPlayerKills, PersistentDataType.INTEGER, playerKills);
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("Player kills")) {
hasLore = true;
lore.set(x, playerKillsLore.replace("X", Integer.toString(playerKills)));
break;
}
}
// if the item has lore but doesn't have the tag, add it
if (!hasLore) {
lore.add(playerKillsLore.replace("X", Integer.toString(playerKills)));
}
} else {
// if the item has no lore, create a new list and add the string
lore = new ArrayList<>();
lore.add(playerKillsLore.replace("X", Integer.toString(playerKills)));
}
if (toolStats.checkConfig(itemStack, "player-kills")) {
meta.setLore(lore);
}
finalItem.setItemMeta(meta);
return finalItem;
}
private ItemStack updateMobKills(ItemStack itemStack) {
ItemStack finalItem = itemStack.clone();
ItemMeta meta = finalItem.getItemMeta();
if (meta == null) {
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) {
return null;
} else {
mobKills++;
}
container.set(toolStats.swordMobKills, PersistentDataType.INTEGER, mobKills);
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("Mob kills")) {
hasLore = true;
lore.set(x, mobKillsLore.replace("X", Integer.toString(mobKills)));
break;
}
}
// if the item has lore but doesn't have the tag, add it
if (!hasLore) {
lore.add(mobKillsLore.replace("X", Integer.toString(mobKills)));
}
} else {
// if the item has no lore, create a new list and add the string
lore = new ArrayList<>();
lore.add(mobKillsLore.replace("X", Integer.toString(mobKills)));
}
if (toolStats.checkConfig(itemStack, "mob-kills")) {
meta.setLore(lore);
}
finalItem.setItemMeta(meta);
return finalItem;
}
private void updateArmorDamage(ItemStack itemStack, double damage) {
ItemMeta meta = itemStack.getItemMeta();
if (meta == null) {
if (!(event.getEntity() instanceof LivingEntity mobBeingAttacked)) {
return;
}
Double damageTaken = 0.0;
PersistentDataContainer container = meta.getPersistentDataContainer();
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);
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("Damage taken")) {
hasLore = true;
lore.set(x, damageTakenLore.replace("X", decimalFormat.format(damageTaken)));
break;
// ignore void and /kill damage
EntityDamageEvent.DamageCause cause = event.getCause();
if (ignoredCauses.contains(cause)) {
return;
}
// player is taken damage but not being killed
if (mobBeingAttacked instanceof Player playerTakingDamage) {
if (playerTakingDamage.getGameMode() == GameMode.CREATIVE || playerTakingDamage.getGameMode() == GameMode.SPECTATOR) {
return;
}
PlayerInventory playerInventory = playerTakingDamage.getInventory();
ItemStack[] armorContents = playerInventory.getArmorContents();
for (ItemStack armorPiece : armorContents) {
if (armorPiece != null) {
if (toolStats.itemChecker.isArmor(armorPiece.getType())) {
ItemMeta newItem = toolStats.itemLore.updateDamage(armorPiece, event.getFinalDamage(), false);
if (newItem != null) {
armorPiece.setItemMeta(newItem);
}
}
}
}
// if the item has lore but doesn't have the tag, add it
if (!hasLore) {
lore.add(damageTakenLore.replace("X", decimalFormat.format(damageTaken)));
}
} else {
// if the item has no lore, create a new list and add the string
lore = new ArrayList<>();
lore.add(damageTakenLore.replace("X", decimalFormat.format(damageTaken)));
// apply the new armor
playerInventory.setArmorContents(armorContents);
}
if (toolStats.config.getBoolean("enabled.armor-damage")) {
meta.setLore(lore);
}
itemStack.setItemMeta(meta);
}
}

View File

@@ -18,39 +18,52 @@
package lol.hyper.toolstats.events;
import lol.hyper.toolstats.ToolStats;
import org.bukkit.ChatColor;
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 {
private final ToolStats toolStats;
private final String droppedLore = ChatColor.GRAY + "Dropped by: " + ChatColor.DARK_GRAY + "X";
public EntityDeath(ToolStats toolStats) {
this.toolStats = toolStats;
}
@EventHandler
@EventHandler(priority = EventPriority.HIGHEST)
public void onDeath(EntityDeathEvent event) {
LivingEntity livingEntity = event.getEntity();
if (livingEntity instanceof Player) {
return;
}
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);
}
}
}
@@ -58,33 +71,32 @@ public class EntityDeath implements Listener {
}
}
private void addLore(ItemStack itemStack, String mob) {
ItemMeta meta = itemStack.getItemMeta();
/**
* Adds "drop by" tag to item.
*
* @param oldItem The item to add lore to.
* @param entity The mob dying.
*/
private ItemStack addLore(ItemStack oldItem, LivingEntity entity) {
ItemStack newItem = oldItem.clone();
ItemMeta meta = newItem.getItemMeta();
if (meta == null) {
return;
}
boolean hasTag = false;
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("Dropped by")) {
// replace existing tag
lore.set(x, droppedLore.replace("X", 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(droppedLore.replace("X", mob));
return null;
}
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;
}
}

View File

@@ -18,66 +18,80 @@
package lol.hyper.toolstats.events;
import lol.hyper.toolstats.ToolStats;
import lol.hyper.toolstats.UUIDDataType;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
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;
private final String LOOT_OWNER = ChatColor.GRAY + "Looted by: " + ChatColor.DARK_GRAY + "X";
private final String LOOT_TIME = ChatColor.GRAY + "Looted on: " + ChatColor.DARK_GRAY + "X";
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();
Bukkit.getScheduler().runTaskLater(toolStats, () -> {
Player player = (Player) chest.getViewers().get(0);
for (int i = 0; i < chest.getContents().length; i++) {
ItemStack itemStack = chest.getItem(i);
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.
* @return The item with the lore.
*/
private ItemStack addLore(ItemStack itemStack, Player owner) {
ItemStack newItem = itemStack.clone();
ItemMeta meta = itemStack.getItemMeta();
@@ -87,21 +101,49 @@ public class GenerateLoot implements Listener {
long timeCreated = System.currentTimeMillis();
Date finalDate = new Date(timeCreated);
PersistentDataContainer container = meta.getPersistentDataContainer();
if (container.has(toolStats.timeCreated, PersistentDataType.LONG) || container.has(toolStats.itemOwner, PersistentDataType.LONG)) {
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());
List<String> lore;
if (meta.hasLore()) {
lore = meta.getLore();
assert lore != null;
} else {
lore = new ArrayList<>();
container.set(toolStats.itemOwner, new UUIDDataType(), owner.getUniqueId());
container.set(toolStats.originType, PersistentDataType.INTEGER, 2);
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);
}
if (toolStats.checkConfig(newItem, "looted-tag")) {
lore.add(LOOT_TIME.replace("X", format.format(finalDate)));
lore.add(LOOT_OWNER.replace("X", 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);
}
}
}
}
}

View File

@@ -0,0 +1,105 @@
/*
* 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 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 java.util.UUID;
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();
if (toolStats.config.getBoolean("tokens.enabled")) {
// if the token system is on and the item doesn't have stat keys
if (toolStats.itemChecker.keyCheck(container) && !container.has(toolStats.tokenType)) {
// add the tokens
String newTokens = toolStats.itemChecker.addTokensToExisting(itemStack);
if (newTokens == null) {
return;
}
container.set(toolStats.tokenApplied, PersistentDataType.STRING, newTokens);
itemStack.setItemMeta(itemMeta);
}
}
// 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.itemOwner, new UUIDDataType())) {
continue;
}
UUID owner = container.get(toolStats.itemOwner, 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();
if (location != null) {
Bukkit.getRegionScheduler().runDelayed(toolStats, location, scheduledTask -> itemStack.setItemMeta(clone), 1);
}
}
}
}

View File

@@ -18,12 +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.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;
@@ -31,65 +32,81 @@ 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 String FOUND_BY = ChatColor.GRAY + "Found by: " + ChatColor.DARK_GRAY + "X";
private final String FOUND_ON = ChatColor.GRAY + "Found on: " + ChatColor.DARK_GRAY + "X";
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)) {
container.remove(toolStats.newElytra);
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);
}
}
}
}
}
}
private void addLore(ItemStack itemStack, Player owner) {
ItemMeta meta = itemStack.getItemMeta();
/**
* Adds "looted by" tags for elytras.
*
* @param itemStack The elytra to add lore to.
* @param owner The player who found it.
*/
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());
List<String> lore;
if (meta.hasLore()) {
lore = meta.getLore();
assert lore != null;
} else {
lore = new ArrayList<>();
}
container.set(toolStats.itemOwner, new UUIDDataType(), owner.getUniqueId());
container.set(toolStats.originType, PersistentDataType.INTEGER, 4);
container.remove(toolStats.newElytra);
if (toolStats.config.getBoolean("enabled.elytra-tag")) {
lore.add(FOUND_ON.replace("X", format.format(finalDate)));
lore.add(FOUND_BY.replace("X", 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;
}
}

View File

@@ -18,131 +18,116 @@
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.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 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;
private final String fishCaughtLore = ChatColor.GRAY + "Fish caught: " + ChatColor.DARK_GRAY + "X";
private final String FISH_OWNER = ChatColor.GRAY + "Caught by: " + ChatColor.DARK_GRAY + "X";
private final String FISH_TIME = ChatColor.GRAY + "Caught on: " + ChatColor.DARK_GRAY + "X";
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;
}
// only listen to when a player catches a fish
if (event.getState() != PlayerFishEvent.State.CAUGHT_FISH) {
return;
}
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 = toolStats.itemChecker.getFishingRod(player.getInventory());
// player swapped items?
if (fishingRod == null) {
return;
}
// update the fishing rod!
ItemMeta newFishingRod = toolStats.itemLore.updateFishCaught(fishingRod, 1);
if (newFishingRod != null) {
PlayerInventory inventory = player.getInventory();
boolean isMain = inventory.getItemInMainHand().getType() == Material.FISHING_ROD;
boolean isOffHand = inventory.getItemInOffHand().getType() == Material.FISHING_ROD;
if (isMain) {
inventory.getItemInMainHand().setItemMeta(newFishingRod);
}
if (isOffHand) {
inventory.getItemInOffHand().setItemMeta(newFishingRod);
}
}
// 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 void updateFishCount(ItemStack itemStack) {
ItemMeta meta = itemStack.getItemMeta();
/**
* 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 ItemStack addNewLore(ItemStack originalItem, Player owner) {
ItemStack newItem = originalItem.clone();
ItemMeta meta = originalItem.getItemMeta();
if (meta == null) {
return;
}
Integer fishCaught = 0;
PersistentDataContainer container = meta.getPersistentDataContainer();
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);
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("Fish caught")) {
hasLore = true;
lore.set(x, fishCaughtLore.replace("X", Integer.toString(fishCaught)));
break;
}
}
// if the item has lore but doesn't have the tag, add it
if (!hasLore) {
lore.add(fishCaughtLore.replace("X", Integer.toString(fishCaught)));
}
} else {
// if the item has no lore, create a new list and add the string
lore = new ArrayList<>();
lore.add(fishCaughtLore.replace("X", Integer.toString(fishCaught)));
}
if (toolStats.config.getBoolean("enabled.fish-caught")) {
meta.setLore(lore);
}
itemStack.setItemMeta(meta);
}
private void addNewLore(ItemStack itemStack, Player owner) {
ItemMeta meta = itemStack.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.itemOwner, PersistentDataType.LONG)) {
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());
List<String> lore;
if (meta.hasLore()) {
lore = meta.getLore();
assert lore != null;
} else {
lore = new ArrayList<>();
container.set(toolStats.itemOwner, new UUIDDataType(), owner.getUniqueId());
container.set(toolStats.originType, PersistentDataType.INTEGER, 5);
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);
}
if (toolStats.checkConfig(itemStack, "fished-tag")) {
lore.add(FISH_TIME.replace("X", format.format(finalDate)));
lore.add(FISH_OWNER.replace("X", owner.getName()));
}
meta.setLore(lore);
itemStack.setItemMeta(meta);
newItem.setItemMeta(meta);
return newItem;
}
}

View 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 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 java.util.HashMap;
import java.util.Map;
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);
}
}
}

View File

@@ -0,0 +1,95 @@
/*
* 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 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 java.util.UUID;
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();
if (toolStats.config.getBoolean("tokens.enabled")) {
// if the token system is on and the item doesn't have stat keys
if (toolStats.itemChecker.keyCheck(container) && !container.has(toolStats.tokenType)) {
// add the tokens
String newTokens = toolStats.itemChecker.addTokensToExisting(itemStack);
if (newTokens == null) {
return;
}
container.set(toolStats.tokenApplied, PersistentDataType.STRING, newTokens);
itemStack.setItemMeta(itemMeta);
}
}
// 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.itemOwner, new UUIDDataType())) {
continue;
}
UUID owner = container.get(toolStats.itemOwner, 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);
}
}
}

View File

@@ -0,0 +1,69 @@
/*
* This file is part of ToolStats.
*
* ToolStats is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ToolStats is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ToolStats. If not, see <https://www.gnu.org/licenses/>.
*/
package lol.hyper.toolstats.events;
import lol.hyper.toolstats.ToolStats;
import org.bukkit.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.PlayerInventory;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.HashMap;
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)) {
PlayerInventory inventory = player.getInventory();
ItemStack chest = inventory.getChestplate();
// make sure the player is wearing an elytra
if (chest != null && chest.getType() == Material.ELYTRA) {
long duration = (System.currentTimeMillis() - playerStartFlight.get(player));
ItemMeta newItem = toolStats.itemLore.updateFlightTime(chest, duration);
if (newItem != null) {
inventory.getChestplate().setItemMeta(newItem);
}
}
playerStartFlight.remove(player);
}
}
}
}

View File

@@ -0,0 +1,57 @@
/*
* This file is part of ToolStats.
*
* ToolStats is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ToolStats is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ToolStats. If not, see <https://www.gnu.org/licenses/>.
*/
package lol.hyper.toolstats.events;
import lol.hyper.toolstats.ToolStats;
import org.bukkit.Material;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.PrepareItemCraftEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataContainer;
public class PrepareCraft implements Listener {
private final ToolStats toolStats;
public PrepareCraft(ToolStats toolStats) {
this.toolStats = toolStats;
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onCraft(PrepareItemCraftEvent event) {
// get the items in the crafting grid
ItemStack[] grid = event.getInventory().getMatrix();
for (ItemStack item : grid) {
if (item == null || item.getType() != Material.PAPER) {
continue;
}
ItemMeta meta = item.getItemMeta();
if (meta == null) {
continue;
}
// if the paper item has our PDC, cancel it
PersistentDataContainer container = meta.getPersistentDataContainer();
if (container.has(toolStats.tokenType)) {
event.getInventory().setResult(null);
}
}
}
}

View File

@@ -18,91 +18,64 @@
package lol.hyper.toolstats.events;
import lol.hyper.toolstats.ToolStats;
import org.bukkit.ChatColor;
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 java.util.ArrayList;
import java.util.List;
public class SheepShear implements Listener {
private final ToolStats toolStats;
private final String sheepShearLore = ChatColor.GRAY + "Sheep sheared: " + ChatColor.DARK_GRAY + "X";
public SheepShear(ToolStats toolStats) {
this.toolStats = toolStats;
}
@EventHandler
@EventHandler(priority = EventPriority.MONITOR)
public void onShear(PlayerInteractEntityEvent event) {
if (event.isCancelled()) {
return;
}
Player player = event.getPlayer();
if (player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.SPECTATOR) {
return;
}
Entity entity = event.getRightClicked();
if (!(entity instanceof Sheep)) {
return;
}
ItemStack heldItem = player.getInventory().getItem(player.getInventory().getHeldItemSlot());
if (heldItem == null || heldItem.getType() == Material.AIR || heldItem.getType() != Material.SHEARS) {
if (!(entity instanceof Sheep sheep)) {
return;
}
Sheep sheep = (Sheep) entity;
if (!sheep.isSheared()) {
addLore(heldItem);
ItemStack heldShears = toolStats.itemChecker.getShears(player.getInventory());
// player swapped or we can't get the shears
if (heldShears == null) {
return;
}
}
private void addLore(ItemStack itemStack) {
ItemMeta meta = itemStack.getItemMeta();
if (meta == null) {
// make sure the sheep is not sheared
if (sheep.isSheared()) {
return;
}
Integer sheepSheared = 0;
PersistentDataContainer container = meta.getPersistentDataContainer();
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);
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("Sheep sheared")) {
hasLore = true;
lore.set(x, sheepShearLore.replace("X", Integer.toString(sheepSheared)));
break;
}
// update the stats
ItemMeta newItem = toolStats.itemLore.updateSheepSheared(heldShears, 1);
if (newItem != null) {
PlayerInventory inventory = player.getInventory();
boolean isMain = inventory.getItemInMainHand().getType() == Material.SHEARS;
boolean isOffHand = inventory.getItemInOffHand().getType() == Material.SHEARS;
if (isMain) {
inventory.getItemInMainHand().setItemMeta(newItem);
}
// if the item has lore but doesn't have the tag, add it
if (!hasLore) {
lore.add(sheepShearLore.replace("X", Integer.toString(sheepSheared)));
if (isOffHand) {
inventory.getItemInOffHand().setItemMeta(newItem);
}
} else {
// if the item has no lore, create a new list and add the string
lore = new ArrayList<>();
lore.add(sheepShearLore.replace("X", Integer.toString(sheepSheared)));
}
if (toolStats.config.getBoolean("enabled.sheep-sheared")) {
meta.setLore(lore);
}
itemStack.setItemMeta(meta);
}
}

View File

@@ -0,0 +1,72 @@
/*
* This file is part of ToolStats.
*
* ToolStats is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ToolStats is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ToolStats. If not, see <https://www.gnu.org/licenses/>.
*/
package lol.hyper.toolstats.events;
import lol.hyper.toolstats.ToolStats;
import org.bukkit.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;
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;
}
ItemStack heldBow = toolStats.itemChecker.getBow(player.getInventory());
// player swapped or we can't get the bow
if (heldBow == null) {
return;
}
ItemMeta newItem = toolStats.itemLore.updateArrowsShot(heldBow, 1);
if (newItem != null) {
PlayerInventory inventory = player.getInventory();
boolean isMain = inventory.getItemInMainHand().getType() == Material.BOW || inventory.getItemInMainHand().getType() == Material.CROSSBOW;
boolean isOffHand = inventory.getItemInOffHand().getType() == Material.BOW || inventory.getItemInOffHand().getType() == Material.CROSSBOW;
if (isMain) {
inventory.getItemInMainHand().setItemMeta(newItem);
}
if (isOffHand) {
inventory.getItemInOffHand().setItemMeta(newItem);
}
}
}
}

View File

@@ -18,10 +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.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryType;
@@ -32,68 +35,120 @@ 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;
private final String TRADED_OWNER = ChatColor.GRAY + "Traded by: " + ChatColor.DARK_GRAY + "X";
private final String TRADED_TIME = ChatColor.GRAY + "Traded on: " + ChatColor.DARK_GRAY + "X";
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 (inventory instanceof MerchantInventory) {
if (event.getSlotType() == InventoryType.SlotType.RESULT) {
ItemStack item = event.getCurrentItem();
for (String x : validItems) {
if (item.getType().toString().toLowerCase(Locale.ROOT).contains(x)) {
ItemStack newItem = addLore(item, (Player) event.getWhoClicked());
event.getView().setCursor(newItem);
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)) {
return;
}
// only check the result slot (the item you receive)
if (event.getSlotType() != InventoryType.SlotType.RESULT) {
return;
}
ItemStack tradedItem = event.getCurrentItem();
Material tradedMaterial = tradedItem.getType();
// only check items we want
if (!toolStats.itemChecker.isValidItem(tradedMaterial)) {
return;
}
// if the player shift clicks
if (event.isShiftClick()) {
// store the player inventory before they trade the items
ItemStack[] beforeTrade = player.getInventory().getContents();
// run a tick after to see the changes
player.getScheduler().runDelayed(toolStats, scheduledTask -> {
// get their inventory after the trade
ItemStack[] afterTrade = player.getInventory().getContents();
for (int i = 0; i < afterTrade.length; i++) {
ItemStack newSlotItem = afterTrade[i];
ItemStack oldSlotItem = beforeTrade[i];
// if this slot is empty after trading, skip it
if (newSlotItem == null) {
continue;
}
// if the item matches what we traded
if (newSlotItem.getType() == tradedMaterial) {
// if the slot was empty before we traded, this means we just traded it
if (oldSlotItem == null) {
// add the lore
ItemStack newItem = addLore(newSlotItem, player);
if (newItem != null) {
player.getInventory().setItem(i, newItem);
}
}
}
}
}
}, null, 1);
return;
}
ItemStack newItem = addLore(tradedItem, player);
if (newItem != null) {
// set the new item
inventory.setItem(event.getSlot(), newItem);
}
}
private ItemStack addLore(ItemStack itemStack, Player owner) {
ItemMeta meta = itemStack.getItemMeta();
/**
* Adds "traded by" tags to item.
*
* @param oldItem The item to add lore.
* @param owner The player who traded.
* @return The item with lore.
*/
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();
Date finalDate = new Date(timeCreated);
PersistentDataContainer container = meta.getPersistentDataContainer();
if (container.has(toolStats.timeCreated, PersistentDataType.LONG) || container.has(toolStats.itemOwner, PersistentDataType.LONG)) {
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());
List<String> lore;
if (meta.hasLore()) {
lore = meta.getLore();
assert lore != null;
} else {
lore = new ArrayList<>();
container.set(toolStats.itemOwner, new UUIDDataType(), owner.getUniqueId());
container.set(toolStats.originType, PersistentDataType.INTEGER, 3);
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);
}
if (toolStats.checkConfig(itemStack, "traded-tag")) {
lore.add(TRADED_TIME.replace("X", format.format(finalDate)));
lore.add(TRADED_OWNER.replace("X", owner.getName()));
}
meta.setLore(lore);
itemStack.setItemMeta(meta);
return itemStack;
newItem.setItemMeta(meta);
return newItem;
}
}

View File

@@ -0,0 +1,60 @@
/*
* This file is part of ToolStats.
*
* ToolStats is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ToolStats is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ToolStats. If not, see <https://www.gnu.org/licenses/>.
*/
package lol.hyper.toolstats.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();
}
}
}

View File

@@ -0,0 +1,345 @@
/*
* 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 org.bukkit.NamespacedKey;
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.Arrays;
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<>();
private final ToolStats toolStats;
public ItemChecker(ToolStats toolStats) {
this.toolStats = toolStats;
}
/**
* Set up the item checker.
*/
public void setup() {
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);
}
}
// hardcode these
mineItems.add(Material.SHEARS);
meleeItems.add(Material.TRIDENT);
meleeItems.add(Material.MACE);
validItems.add(Material.BOW);
validItems.add(Material.CROSSBOW);
validItems.add(Material.FISHING_ROD);
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);
}
/**
* Check a given item for a target token.
*
* @param container The PDC of the item.
* @param targetToken The target to look for.
* @return True if the item has a given token, false if not.
*/
public boolean checkTokens(PersistentDataContainer container, String targetToken) {
// make sure the item has tokens
if (!container.has(toolStats.tokenApplied, PersistentDataType.STRING)) {
return false;
}
// get the tokens for this item
String tokens = container.get(toolStats.tokenApplied, PersistentDataType.STRING);
if (tokens == null) {
return false;
}
return tokens.contains(targetToken);
}
/**
* Get the tokens for a given item.
*
* @param item The item.
* @return An array of the tokens, empty if there are none.
*/
private String[] getTokens(ItemStack item) {
// make sure the item has tokens
ItemMeta meta = item.getItemMeta();
if (meta == null) {
return new String[0];
}
PersistentDataContainer container = meta.getPersistentDataContainer();
if (!container.has(toolStats.tokenApplied, PersistentDataType.STRING)) {
return new String[0];
}
// get the tokens for this item
String tokensRaw = container.get(toolStats.tokenApplied, PersistentDataType.STRING);
if (tokensRaw == null) {
return new String[0];
}
return tokensRaw.split(",");
}
/**
* Add a token to an item.
*
* @param item The item.
* @param token The token to add.
* @return The new PDC with the new token. Null if something went wrong.
*/
public ItemStack addToken(ItemStack item, String token) {
ItemMeta meta = item.getItemMeta();
if (meta == null) {
return null;
}
PersistentDataContainer container = meta.getPersistentDataContainer();
String[] tokens = getTokens(item);
// there are no tokens
if (tokens.length == 0) {
container.set(toolStats.tokenApplied, PersistentDataType.STRING, token);
} else {
// other tokens exist, so add
String[] newTokens = Arrays.copyOf(tokens, tokens.length + 1);
newTokens[tokens.length] = token;
container.set(toolStats.tokenApplied, PersistentDataType.STRING, String.join(",", newTokens));
}
item.setItemMeta(meta);
return item;
}
/**
* Get the XP levels required to use token in anvil.
*
* @param tokenType The token type.
* @return The amount of levels to use.
*/
public int getCost(String tokenType) {
return toolStats.config.getInt("tokens.data." + tokenType + ".levels");
}
/**
* Get the player's bow/crossbow.
*
* @param inventory Their inventory.
* @return Their bow/crossbow, either main or offhand.
*/
public @Nullable ItemStack getBow(PlayerInventory inventory) {
ItemStack main = inventory.getItemInMainHand();
ItemStack offHand = inventory.getItemInOffHand();
boolean isMain = main.getType() == Material.BOW || main.getType() == Material.CROSSBOW;
boolean isOffHand = offHand.getType() == Material.BOW || offHand.getType() == Material.CROSSBOW;
// if the player is holding a bow in their main hand, use that one
// if the bow is in their offhand instead, use that one after checking main hand
// Minecraft prioritizes main hand if the player holds in both hands
if (isMain) {
return main;
}
if (isOffHand) {
return offHand;
}
return null;
}
/**
* Get the player's shears.
*
* @param inventory Their inventory.
* @return Their shears, either main or offhand.
*/
public @Nullable ItemStack getShears(PlayerInventory inventory) {
ItemStack main = inventory.getItemInMainHand();
ItemStack offHand = inventory.getItemInOffHand();
boolean isMain = main.getType() == Material.SHEARS;
boolean isOffHand = offHand.getType() == Material.SHEARS;
// if the player is holding shears in their main hand, use that one
// if the shears are in their offhand instead, use that one after checking main hand
// Minecraft prioritizes main hand if the player holds in both hands
if (isMain) {
return main;
}
if (isOffHand) {
return offHand;
}
return null;
}
/**
* Get the player's fishing rod.
*
* @param inventory Their inventory.
* @return Their fishing rod, either main or offhand.
*/
public @Nullable ItemStack getFishingRod(PlayerInventory inventory) {
ItemStack main = inventory.getItemInMainHand();
ItemStack offHand = inventory.getItemInOffHand();
boolean isMain = main.getType() == Material.FISHING_ROD;
boolean isOffHand = offHand.getType() == Material.FISHING_ROD;
// if the player is holding a fishing rod in their main hand, use that one
// if the fishing rod is in their offhand instead, use that one after checking main hand
// Minecraft prioritizes main hand if the player holds in both hands
if (isMain) {
return main;
}
if (isOffHand) {
return offHand;
}
return null;
}
/**
* Checks the keys of the item and returns the tokens we should add.
* If the server swaps token systems this should allow compatability.
*
* @param item The input item.
* @return The tokens we should add.
*/
public String addTokensToExisting(ItemStack item) {
ItemStack clone = item.clone();
ItemMeta meta = clone.getItemMeta();
if (meta == null) {
return null;
}
PersistentDataContainer container = meta.getPersistentDataContainer();
ArrayList<String> tokens = new ArrayList<>();
if (container.has(toolStats.playerKills)) {
tokens.add("player-kills");
}
if (container.has(toolStats.mobKills)) {
tokens.add("mob-kills");
}
if (container.has(toolStats.blocksMined)) {
tokens.add("blocks-mined");
}
if (container.has(toolStats.cropsHarvested)) {
tokens.add("crops-mined");
}
if (container.has(toolStats.fishCaught)) {
tokens.add("fish-caught");
}
if (container.has(toolStats.sheepSheared)) {
tokens.add("sheep-sheared");
}
if (container.has(toolStats.armorDamage)) {
tokens.add("damage-taken");
}
if (container.has(toolStats.arrowsShot)) {
tokens.add("arrows-shot");
}
if (container.has(toolStats.flightTime)) {
tokens.add("flight-time");
}
if (tokens.isEmpty()) {
return null;
}
return String.join(",", tokens);
}
/**
* Check to see if a given container has our keys for stats.
*
* @param container The container.
* @return True/false if the container has keys.
*/
public boolean keyCheck(PersistentDataContainer container) {
return container.getKeys().stream()
.map(NamespacedKey::getKey)
.anyMatch(key -> toolStats.tokenKeys.stream().anyMatch(tokenKey -> tokenKey.getKey().equalsIgnoreCase(key)));
}
}

View File

@@ -0,0 +1,821 @@
/*
* 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.ItemStack;
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++) {
String line = PlainTextComponentSerializer.plainText().serialize(itemLore.get(x));
// find the old line to update, keeping index
// this means we update this line only!
if (line.equals(PlainTextComponentSerializer.plainText().serialize(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;
}
/**
* Add lore to a given item.
*
* @param itemMeta The item's meta.
* @param newLine The new line to add to the lore.
* @return The new item's lore.
*/
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;
}
/**
* Add x to the crops mined stat.
*
* @param playerTool The tool to update.
*/
public ItemMeta updateCropsMined(ItemStack playerTool, int add) {
ItemStack clone = playerTool.clone();
ItemMeta meta = clone.getItemMeta();
if (meta == null) {
toolStats.logger.warning(clone + " does NOT have any meta! Unable to update stats.");
return null;
}
// read the current stats from the item
// if they don't exist, then start from 0
PersistentDataContainer container = meta.getPersistentDataContainer();
// check for tokens
boolean validToken = toolStats.itemChecker.checkTokens(container, "crops-mined");
// check for tokens
if (toolStats.config.getBoolean("tokens.enabled")) {
// if the item has stats but no token, add the token
if (container.has(toolStats.cropsHarvested) && !validToken) {
String newTokens = toolStats.itemChecker.addTokensToExisting(clone);
if (newTokens != null) {
container.set(toolStats.tokenApplied, PersistentDataType.STRING, newTokens);
}
}
// the item does not have a valid token
if (!validToken) {
return null;
}
} else {
if (!validToken) {
String newTokens = toolStats.itemChecker.addTokensToExisting(clone);
if (newTokens != null) {
container.set(toolStats.tokenApplied, PersistentDataType.STRING, newTokens);
}
}
}
Integer cropsMined = 0;
if (container.has(toolStats.cropsHarvested, PersistentDataType.INTEGER)) {
cropsMined = container.get(toolStats.cropsHarvested, PersistentDataType.INTEGER);
}
if (cropsMined == null) {
cropsMined = 0;
toolStats.logger.warning(clone + " does not have valid crops-mined set! Resting to zero. This should NEVER happen.");
}
container.set(toolStats.cropsHarvested, PersistentDataType.INTEGER, cropsMined + add);
// do we add the lore based on the config?
if (toolStats.configTools.checkConfig(clone.getType(), "blocks-mined")) {
String oldCropsMinedFormatted = toolStats.numberFormat.formatInt(cropsMined);
String newCropsMinedFormatted = toolStats.numberFormat.formatInt(cropsMined + add);
Component oldLine = toolStats.configTools.formatLore("crops-harvested", "{crops}", oldCropsMinedFormatted);
Component newLine = toolStats.configTools.formatLore("crops-harvested", "{crops}", newCropsMinedFormatted);
if (oldLine == null || newLine == null) {
return null;
}
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
meta.lore(newLore);
}
return meta;
}
/**
* Add x to the blocks mined stat.
*
* @param playerTool The tool to update.
*/
public ItemMeta updateBlocksMined(ItemStack playerTool, int add) {
ItemStack clone = playerTool.clone();
ItemMeta meta = clone.getItemMeta();
if (meta == null) {
toolStats.logger.warning(clone + " does NOT have any meta! Unable to update stats.");
return null;
}
PersistentDataContainer container = meta.getPersistentDataContainer();
boolean validToken = toolStats.itemChecker.checkTokens(container, "blocks-mined");
// check for tokens
if (toolStats.config.getBoolean("tokens.enabled")) {
// if the item has stats but no token, add the token
if (container.has(toolStats.blocksMined) && !validToken) {
String newTokens = toolStats.itemChecker.addTokensToExisting(clone);
if (newTokens != null) {
container.set(toolStats.tokenApplied, PersistentDataType.STRING, newTokens);
}
}
// the item does not have a valid token
if (!validToken) {
return null;
}
} else {
if (!validToken) {
String newTokens = toolStats.itemChecker.addTokensToExisting(clone);
if (newTokens != null) {
container.set(toolStats.tokenApplied, PersistentDataType.STRING, newTokens);
}
}
}
// read the current stats from the item
// if they don't exist, then start from 0
Integer blocksMined = 0;
if (container.has(toolStats.blocksMined, PersistentDataType.INTEGER)) {
blocksMined = container.get(toolStats.blocksMined, PersistentDataType.INTEGER);
}
if (blocksMined == null) {
blocksMined = 0;
toolStats.logger.warning(clone + " does not have valid generic-mined set! Resting to zero. This should NEVER happen.");
}
container.set(toolStats.blocksMined, PersistentDataType.INTEGER, blocksMined + add);
// do we add the lore based on the config?
if (toolStats.configTools.checkConfig(clone.getType(), "blocks-mined")) {
String oldBlocksMinedFormatted = toolStats.numberFormat.formatInt(blocksMined);
String newBlocksMinedFormatted = toolStats.numberFormat.formatInt(blocksMined + add);
Component oldLine = toolStats.configTools.formatLore("blocks-mined", "{blocks}", oldBlocksMinedFormatted);
Component newLine = toolStats.configTools.formatLore("blocks-mined", "{blocks}", newBlocksMinedFormatted);
if (oldLine == null || newLine == null) {
return null;
}
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
meta.lore(newLore);
}
return meta;
}
/**
* Add +1 to the player kills stat.
*
* @param playerWeapon The tool to update.
*/
public ItemMeta updatePlayerKills(ItemStack playerWeapon, int add) {
ItemStack clone = playerWeapon.clone();
ItemMeta meta = clone.getItemMeta();
if (meta == null) {
toolStats.logger.warning(clone + " does NOT have any meta! Unable to update stats.");
return null;
}
PersistentDataContainer container = meta.getPersistentDataContainer();
// check for tokens
boolean validToken = toolStats.itemChecker.checkTokens(container, "player-kills");
// check for tokens
if (toolStats.config.getBoolean("tokens.enabled")) {
// if the item has stats but no token, add the token
if (container.has(toolStats.playerKills) && !validToken) {
String newTokens = toolStats.itemChecker.addTokensToExisting(clone);
if (newTokens != null) {
container.set(toolStats.tokenApplied, PersistentDataType.STRING, newTokens);
}
}
// the item does not have a valid token
if (!validToken) {
return null;
}
} else {
if (!validToken) {
String newTokens = toolStats.itemChecker.addTokensToExisting(clone);
if (newTokens != null) {
container.set(toolStats.tokenApplied, PersistentDataType.STRING, newTokens);
}
}
}
Integer playerKills = 0;
if (container.has(toolStats.playerKills, PersistentDataType.INTEGER)) {
playerKills = container.get(toolStats.playerKills, PersistentDataType.INTEGER);
}
if (playerKills == null) {
playerKills = 0;
toolStats.logger.warning(clone + " does not have valid player-kills set! Resting to zero. This should NEVER happen.");
}
container.set(toolStats.playerKills, PersistentDataType.INTEGER, playerKills + add);
// do we add the lore based on the config?
if (toolStats.configTools.checkConfig(clone.getType(), "player-kills")) {
String oldPlayerKillsFormatted = toolStats.numberFormat.formatInt(playerKills);
String newPlayerKillsFormatted = toolStats.numberFormat.formatInt(playerKills + add);
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);
}
return meta;
}
/**
* Add x to the mob kills stat.
*
* @param playerWeapon The tool to update.
*/
public ItemMeta updateMobKills(ItemStack playerWeapon, int add) {
ItemStack clone = playerWeapon.clone();
ItemMeta meta = clone.getItemMeta();
if (meta == null) {
toolStats.logger.warning(clone + " does NOT have any meta! Unable to update stats.");
return null;
}
PersistentDataContainer container = meta.getPersistentDataContainer();
// check for tokens
boolean validToken = toolStats.itemChecker.checkTokens(container, "mob-kills");
// check for tokens
if (toolStats.config.getBoolean("tokens.enabled")) {
// if the item has stats but no token, add the token
if (container.has(toolStats.mobKills) && !validToken) {
String newTokens = toolStats.itemChecker.addTokensToExisting(clone);
if (newTokens != null) {
container.set(toolStats.tokenApplied, PersistentDataType.STRING, newTokens);
}
}
// the item does not have a valid token
if (!validToken) {
return null;
}
} else {
if (!validToken) {
String newTokens = toolStats.itemChecker.addTokensToExisting(clone);
if (newTokens != null) {
container.set(toolStats.tokenApplied, PersistentDataType.STRING, newTokens);
}
}
}
Integer mobKills = 0;
if (container.has(toolStats.mobKills, PersistentDataType.INTEGER)) {
mobKills = container.get(toolStats.mobKills, PersistentDataType.INTEGER);
}
if (mobKills == null) {
mobKills = 0;
toolStats.logger.warning(clone + " does not have valid mob-kills set! Resting to zero. This should NEVER happen.");
}
container.set(toolStats.mobKills, PersistentDataType.INTEGER, mobKills + add);
// do we add the lore based on the config?
if (toolStats.configTools.checkConfig(clone.getType(), "mob-kills")) {
String oldMobKillsFormatted = toolStats.numberFormat.formatInt(mobKills);
String newMobKillsFormatted = toolStats.numberFormat.formatInt(mobKills + add);
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);
}
return meta;
}
/**
* Add damage to an armor piece.
*
* @param armorPiece The armor to update.
* @param damage The amount of damage to apply.
* @param bypass Bypass the negative damage check.
*/
public ItemMeta updateDamage(ItemStack armorPiece, double damage, boolean bypass) {
// ignore if the damage is zero or negative
if (damage < 0) {
if (!bypass) {
return null;
}
}
ItemStack clone = armorPiece.clone();
ItemMeta meta = clone.getItemMeta();
if (meta == null) {
toolStats.logger.warning(clone + " does NOT have any meta! Unable to update stats.");
return null;
}
PersistentDataContainer container = meta.getPersistentDataContainer();
// check for tokens
boolean validToken = toolStats.itemChecker.checkTokens(container, "damage-taken");
// check for tokens
if (toolStats.config.getBoolean("tokens.enabled")) {
// if the item has stats but no token, add the token
if (container.has(toolStats.armorDamage) && !validToken) {
String newTokens = toolStats.itemChecker.addTokensToExisting(clone);
if (newTokens != null) {
container.set(toolStats.tokenApplied, PersistentDataType.STRING, newTokens);
}
}
// the item does not have a valid token
if (!validToken) {
return null;
}
} else {
if (!validToken) {
String newTokens = toolStats.itemChecker.addTokensToExisting(clone);
if (newTokens != null) {
container.set(toolStats.tokenApplied, PersistentDataType.STRING, newTokens);
}
}
}
Double damageTaken = 0.0;
if (container.has(toolStats.armorDamage, PersistentDataType.DOUBLE)) {
damageTaken = container.get(toolStats.armorDamage, PersistentDataType.DOUBLE);
}
if (damageTaken == null) {
damageTaken = 0.0;
toolStats.logger.warning(clone + " does not have valid damage-taken set! Resting to zero. This should NEVER happen.");
}
container.set(toolStats.armorDamage, PersistentDataType.DOUBLE, damageTaken + damage);
if (toolStats.config.getBoolean("enabled.armor-damage")) {
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 null;
}
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
meta.lore(newLore);
}
return meta;
}
/**
* Add flight time to an elytra.
*
* @param elytra The player's elytra.
*/
public ItemMeta updateFlightTime(ItemStack elytra, long duration) {
ItemStack clone = elytra.clone();
ItemMeta meta = clone.getItemMeta();
if (meta == null) {
toolStats.logger.warning(clone + " does NOT have any meta! Unable to update stats.");
return null;
}
PersistentDataContainer container = meta.getPersistentDataContainer();
// check for tokens
boolean validToken = toolStats.itemChecker.checkTokens(container, "flight-time");
// check for tokens
if (toolStats.config.getBoolean("tokens.enabled")) {
// if the item has stats but no token, add the token
if (container.has(toolStats.flightTime) && !validToken) {
String newTokens = toolStats.itemChecker.addTokensToExisting(clone);
if (newTokens != null) {
container.set(toolStats.tokenApplied, PersistentDataType.STRING, newTokens);
}
}
// the item does not have a valid token
if (!validToken) {
return null;
}
} else {
if (!validToken) {
String newTokens = toolStats.itemChecker.addTokensToExisting(clone);
if (newTokens != null) {
container.set(toolStats.tokenApplied, PersistentDataType.STRING, newTokens);
}
}
}
// read the current stats from the item
// if they don't exist, then start from 0
Long flightTime = 0L;
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.");
}
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((double) (flightTime + duration) / 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 null;
}
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
meta.lore(newLore);
}
return meta;
}
/**
* Add x to sheep sheared stat.
*
* @param shears The shears.
*/
public ItemMeta updateSheepSheared(ItemStack shears, int add) {
ItemStack clone = shears.clone();
ItemMeta meta = clone.getItemMeta();
if (meta == null) {
toolStats.logger.warning(clone + " does NOT have any meta! Unable to update stats.");
return null;
}
PersistentDataContainer container = meta.getPersistentDataContainer();
// check for tokens
boolean validToken = toolStats.itemChecker.checkTokens(container, "sheep-sheared");
// check for tokens
if (toolStats.config.getBoolean("tokens.enabled")) {
// if the item has stats but no token, add the token
if (container.has(toolStats.sheepSheared) && !validToken) {
String newTokens = toolStats.itemChecker.addTokensToExisting(clone);
if (newTokens != null) {
container.set(toolStats.tokenApplied, PersistentDataType.STRING, newTokens);
}
}
// the item does not have a valid token
if (!validToken) {
return null;
}
} else {
if (!validToken) {
String newTokens = toolStats.itemChecker.addTokensToExisting(clone);
if (newTokens != null) {
container.set(toolStats.tokenApplied, PersistentDataType.STRING, newTokens);
}
}
}
Integer sheepSheared = 0;
if (container.has(toolStats.sheepSheared, PersistentDataType.INTEGER)) {
sheepSheared = container.get(toolStats.sheepSheared, PersistentDataType.INTEGER);
}
if (sheepSheared == null) {
sheepSheared = 0;
toolStats.logger.warning(clone + " does not have valid sheared set! Resting to zero. This should NEVER happen.");
}
container.set(toolStats.sheepSheared, PersistentDataType.INTEGER, sheepSheared + add);
if (toolStats.config.getBoolean("enabled.sheep-sheared")) {
String oldSheepFormatted = toolStats.numberFormat.formatInt(sheepSheared);
String newSheepFormatted = toolStats.numberFormat.formatInt(sheepSheared + add);
Component oldLine = toolStats.configTools.formatLore("sheep-sheared", "{sheep}", oldSheepFormatted);
Component newLine = toolStats.configTools.formatLore("sheep-sheared", "{sheep}", newSheepFormatted);
if (oldLine == null || newLine == null) {
return null;
}
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
meta.lore(newLore);
}
return meta;
}
/**
* Add x to arrows shot stat.
*
* @param bow The bow.
*/
public ItemMeta updateArrowsShot(ItemStack bow, int add) {
ItemStack clone = bow.clone();
ItemMeta meta = clone.getItemMeta();
if (meta == null) {
toolStats.logger.warning(clone + " does NOT have any meta! Unable to update stats.");
return null;
}
PersistentDataContainer container = meta.getPersistentDataContainer();
// check for tokens
boolean validToken = toolStats.itemChecker.checkTokens(container, "arrows-shot");
// check for tokens
if (toolStats.config.getBoolean("tokens.enabled")) {
// if the item has stats but no token, add the token
if (container.has(toolStats.arrowsShot) && !validToken) {
String newTokens = toolStats.itemChecker.addTokensToExisting(clone);
if (newTokens != null) {
container.set(toolStats.tokenApplied, PersistentDataType.STRING, newTokens);
}
}
// the item does not have a valid token
if (!validToken) {
return null;
}
} else {
if (!validToken) {
String newTokens = toolStats.itemChecker.addTokensToExisting(clone);
if (newTokens != null) {
container.set(toolStats.tokenApplied, PersistentDataType.STRING, newTokens);
}
}
}
// read the current stats from the item
// if they don't exist, then start from 0
Integer arrowsShot = 0;
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 + add);
// 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 + add);
Component oldLine = toolStats.configTools.formatLore("arrows-shot", "{arrows}", oldArrowsFormatted);
Component newLine = toolStats.configTools.formatLore("arrows-shot", "{arrows}", newArrowsFormatted);
if (oldLine == null || newLine == null) {
return null;
}
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
meta.lore(newLore);
}
return meta;
}
/**
* Add x to fish caught stat.
*
* @param fishingRod The fishing rod.
*/
public ItemMeta updateFishCaught(ItemStack fishingRod, int add) {
ItemStack clone = fishingRod.clone();
ItemMeta meta = clone.getItemMeta();
if (meta == null) {
toolStats.logger.warning(clone + " does NOT have any meta! Unable to update stats.");
return null;
}
PersistentDataContainer container = meta.getPersistentDataContainer();
// check for tokens
boolean validToken = toolStats.itemChecker.checkTokens(container, "fish-caught");
// check for tokens
if (toolStats.config.getBoolean("tokens.enabled")) {
// if the item has stats but no token, add the token
if (container.has(toolStats.fishCaught) && !validToken) {
String newTokens = toolStats.itemChecker.addTokensToExisting(clone);
if (newTokens != null) {
container.set(toolStats.tokenApplied, PersistentDataType.STRING, newTokens);
}
}
// the item does not have a valid token
if (!validToken) {
return null;
}
} else {
if (!validToken) {
String newTokens = toolStats.itemChecker.addTokensToExisting(clone);
if (newTokens != null) {
container.set(toolStats.tokenApplied, PersistentDataType.STRING, newTokens);
}
}
}
Integer fishCaught = 0;
if (container.has(toolStats.fishCaught, PersistentDataType.INTEGER)) {
fishCaught = container.get(toolStats.fishCaught, PersistentDataType.INTEGER);
}
if (fishCaught == null) {
fishCaught = 0;
toolStats.logger.warning(clone + " does not have valid fish-caught set! Resting to zero. This should NEVER happen.");
}
container.set(toolStats.fishCaught, PersistentDataType.INTEGER, fishCaught + add);
if (toolStats.config.getBoolean("enabled.fish-caught")) {
String oldFishFormatted = toolStats.numberFormat.formatInt(fishCaught);
String newFishFormatted = toolStats.numberFormat.formatInt(fishCaught + add);
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 null;
}
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
meta.lore(newLore);
}
return meta;
}
}

View 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 = "#,##0.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);
}
}

View File

@@ -0,0 +1,128 @@
/*
* 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 org.bukkit.NamespacedKey;
import org.bukkit.inventory.ShapedRecipe;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
public class TokenCrafting {
private final ToolStats toolStats;
private final Set<ShapedRecipe> recipes = new HashSet<>();
private final ArrayList<String> tokenTypes = new ArrayList<>();
public TokenCrafting(ToolStats toolStats) {
this.toolStats = toolStats;
}
public void setup() {
NamespacedKey playerKillsKey = new NamespacedKey(toolStats, "player-kills-token");
ShapedRecipe playerKillRecipe = new ShapedRecipe(playerKillsKey, toolStats.tokenItems.playerKills());
playerKillRecipe.shape(" P ", "PSP", " P ");
playerKillRecipe.setIngredient('P', Material.PAPER);
playerKillRecipe.setIngredient('S', Material.WOODEN_SWORD);
recipes.add(playerKillRecipe);
NamespacedKey mobKillsKey = new NamespacedKey(toolStats, "mob-kills-token");
ShapedRecipe mobKillsRecipe = new ShapedRecipe(mobKillsKey, toolStats.tokenItems.mobKills());
mobKillsRecipe.shape(" P ", "PRP", " P ");
mobKillsRecipe.setIngredient('P', Material.PAPER);
mobKillsRecipe.setIngredient('R', Material.ROTTEN_FLESH);
recipes.add(mobKillsRecipe);
NamespacedKey blocksMinedKey = new NamespacedKey(toolStats, "blocks-mined-token");
ShapedRecipe blocksMinedRecipe = new ShapedRecipe(blocksMinedKey, toolStats.tokenItems.blocksMined());
blocksMinedRecipe.shape(" P ", "PSP", " P ");
blocksMinedRecipe.setIngredient('P', Material.PAPER);
blocksMinedRecipe.setIngredient('S', Material.WOODEN_PICKAXE);
recipes.add(blocksMinedRecipe);
NamespacedKey cropsMinedKey = new NamespacedKey(toolStats, "crops-mined-token");
ShapedRecipe cropsMinedRecipe = new ShapedRecipe(cropsMinedKey, toolStats.tokenItems.cropsMined());
cropsMinedRecipe.shape(" P ", "PHP", " P ");
cropsMinedRecipe.setIngredient('P', Material.PAPER);
cropsMinedRecipe.setIngredient('H', Material.WOODEN_HOE);
recipes.add(cropsMinedRecipe);
NamespacedKey fishCaughtKey = new NamespacedKey(toolStats, "fish-caught-token");
ShapedRecipe fishCaughtRecipe = new ShapedRecipe(fishCaughtKey, toolStats.tokenItems.fishCaught());
fishCaughtRecipe.shape(" P ", "PCP", " P ");
fishCaughtRecipe.setIngredient('P', Material.PAPER);
fishCaughtRecipe.setIngredient('C', Material.COD);
recipes.add(fishCaughtRecipe);
NamespacedKey sheepShearedKey = new NamespacedKey(toolStats, "sheep-sheared-token");
ShapedRecipe sheepShearedRecipe = new ShapedRecipe(sheepShearedKey, toolStats.tokenItems.sheepSheared());
sheepShearedRecipe.shape(" P ", "PWP", " P ");
sheepShearedRecipe.setIngredient('P', Material.PAPER);
sheepShearedRecipe.setIngredient('W', Material.WHITE_WOOL);
recipes.add(sheepShearedRecipe);
NamespacedKey armorDamageKey = new NamespacedKey(toolStats, "damage-taken-token");
ShapedRecipe armorDamageRecipe = new ShapedRecipe(armorDamageKey, toolStats.tokenItems.damageTaken());
armorDamageRecipe.shape(" P ", "PCP", " P ");
armorDamageRecipe.setIngredient('P', Material.PAPER);
armorDamageRecipe.setIngredient('C', Material.LEATHER_CHESTPLATE);
recipes.add(armorDamageRecipe);
NamespacedKey arrowsShotKey = new NamespacedKey(toolStats, "arrows-shot-token");
ShapedRecipe arrowsShotRecipe = new ShapedRecipe(arrowsShotKey, toolStats.tokenItems.arrowsShot());
arrowsShotRecipe.shape(" P ", "PAP", " P ");
arrowsShotRecipe.setIngredient('P', Material.PAPER);
arrowsShotRecipe.setIngredient('A', Material.ARROW);
recipes.add(arrowsShotRecipe);
NamespacedKey flightTimeKey = new NamespacedKey(toolStats, "flight-time-token");
ShapedRecipe flightTimeRecipe = new ShapedRecipe(flightTimeKey, toolStats.tokenItems.flightTime());
flightTimeRecipe.shape(" P ", "PFP", " P ");
flightTimeRecipe.setIngredient('P', Material.PAPER);
flightTimeRecipe.setIngredient('F', Material.FEATHER);
recipes.add(flightTimeRecipe);
NamespacedKey resetKey = new NamespacedKey(toolStats, "reset-token");
ShapedRecipe resetRecipe = new ShapedRecipe(resetKey, toolStats.tokenItems.resetToken());
resetRecipe.shape(" P ", "PPP", " P ");
resetRecipe.setIngredient('P', Material.PAPER);
recipes.add(resetRecipe);
tokenTypes.add("crops-mined");
tokenTypes.add("blocks-mined");
tokenTypes.add("damage-taken");
tokenTypes.add("mob-kills");
tokenTypes.add("player-kills");
tokenTypes.add("arrows-shot");
tokenTypes.add("sheep-sheared");
tokenTypes.add("flight-time");
tokenTypes.add("fish-caught");
tokenTypes.add("reset");
}
public Set<ShapedRecipe> getRecipes() {
return recipes;
}
public ArrayList<String> getTokenTypes() {
return tokenTypes;
}
}

View File

@@ -15,7 +15,7 @@
* along with ToolStats. If not, see <https://www.gnu.org/licenses/>.
*/
package lol.hyper.toolstats;
package lol.hyper.toolstats.tools;
import org.bukkit.persistence.PersistentDataAdapterContext;
import org.bukkit.persistence.PersistentDataType;

View File

@@ -0,0 +1,198 @@
/*
* 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.minimessage.MiniMessage;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.bukkit.Material;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
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 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) {
toolStats.logger.warning("Unable to find config message for: messages." + configName);
return null;
}
// if the config message is empty, don't send it
if (lore.isEmpty()) {
return null;
}
// the final component for this lore
Component component;
// set the placeholder to the value
if (placeHolder != null && value != null) {
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 = MiniMessage.miniMessage().deserialize(lore);
}
return component.decorationIfAbsent(TextDecoration.ITALIC, TextDecoration.State.FALSE);
}
/**
* Format a string from the config.
*
* @param configName The config to format.
* @return Formatted string, null if the configName doesn't exist.
*/
public Component format(String configName) {
String message = toolStats.config.getString(configName);
if (message == null) {
toolStats.logger.warning("Unable to find config message for: " + configName);
return null;
}
// if the config message is empty, don't send it
if (message.isEmpty()) {
return null;
}
// the final component for this lore
Component component;
// if we match the old color codes, then format them as so
Matcher hexMatcher = CONFIG_HEX_PATTERN.matcher(message);
Matcher colorMatcher = COLOR_CODES.matcher(message);
if (hexMatcher.find() || colorMatcher.find()) {
component = LegacyComponentSerializer.legacyAmpersand().deserialize(message);
} else {
// otherwise format them normally
component = MiniMessage.miniMessage().deserialize(message);
}
return component.decorationIfAbsent(TextDecoration.ITALIC, TextDecoration.State.FALSE);
}
/**
* Get the token item's lore from config.
*
* @param tokenType The type.
* @return The lore.
*/
public List<Component> getTokenLore(String tokenType) {
List<String> raw = toolStats.config.getStringList("tokens.data." + tokenType + ".lore");
if (raw.isEmpty()) {
return Collections.emptyList();
}
List<Component> finalLore = new ArrayList<>();
for (String line : raw) {
Component component;
// if we match the old color codes, then format them as so
Matcher hexMatcher = CONFIG_HEX_PATTERN.matcher(line);
Matcher colorMatcher = COLOR_CODES.matcher(line);
if (hexMatcher.find() || colorMatcher.find()) {
component = LegacyComponentSerializer.legacyAmpersand().deserialize(line);
} else {
// otherwise format them normally
component = MiniMessage.miniMessage().deserialize(line);
}
component = component.decorationIfAbsent(TextDecoration.ITALIC, TextDecoration.State.FALSE);
finalLore.add(component);
}
return finalLore;
}
}

View File

@@ -0,0 +1,64 @@
/*
* 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;
import lol.hyper.toolstats.tools.config.versions.Version9;
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;
}
case 8: {
// Version 8 to 9
Version9 version9 = new Version9(toolStats);
version9.update();
break;
}
}
}
}

View File

@@ -0,0 +1,218 @@
/*
* 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 org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
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 TokenItems {
private final ToolStats toolStats;
public TokenItems(ToolStats toolStats) {
this.toolStats = toolStats;
}
public ItemStack playerKills() {
// set up the item
ItemStack token = new ItemStack(Material.PAPER);
ItemMeta tokenMeta = token.getItemMeta();
PersistentDataContainer tokenData = tokenMeta.getPersistentDataContainer();
// set the title and lore
Component title = toolStats.configTools.format("tokens.data.player-kills.title");
List<Component> lore = toolStats.configTools.getTokenLore("player-kills");
tokenMeta.displayName(title);
tokenMeta.lore(lore);
// set the PDC
tokenData.set(toolStats.tokenType, PersistentDataType.STRING, "player-kills");
token.setItemMeta(tokenMeta);
return token;
}
public ItemStack mobKills() {
// set up the item
ItemStack token = new ItemStack(Material.PAPER);
ItemMeta tokenMeta = token.getItemMeta();
PersistentDataContainer tokenData = tokenMeta.getPersistentDataContainer();
// set the title and lore
Component title = toolStats.configTools.format("tokens.data.mob-kills.title");
List<Component> lore = toolStats.configTools.getTokenLore("mob-kills");
tokenMeta.displayName(title);
tokenMeta.lore(lore);
// set the PDC
tokenData.set(toolStats.tokenType, PersistentDataType.STRING, "mob-kills");
token.setItemMeta(tokenMeta);
return token;
}
public ItemStack blocksMined() {
// set up the item
ItemStack token = new ItemStack(Material.PAPER);
ItemMeta tokenMeta = token.getItemMeta();
PersistentDataContainer tokenData = tokenMeta.getPersistentDataContainer();
// set the title and lore
Component title = toolStats.configTools.format("tokens.data.blocks-mined.title");
List<Component> lore = toolStats.configTools.getTokenLore("blocks-mined");
tokenMeta.displayName(title);
tokenMeta.lore(lore);
// set the PDC
tokenData.set(toolStats.tokenType, PersistentDataType.STRING, "blocks-mined");
token.setItemMeta(tokenMeta);
return token;
}
public ItemStack cropsMined() {
// set up the item
ItemStack token = new ItemStack(Material.PAPER);
ItemMeta tokenMeta = token.getItemMeta();
PersistentDataContainer tokenData = tokenMeta.getPersistentDataContainer();
// set the title and lore
Component title = toolStats.configTools.format("tokens.data.crops-mined.title");
List<Component> lore = toolStats.configTools.getTokenLore("crops-mined");
tokenMeta.displayName(title);
tokenMeta.lore(lore);
// set the PDC
tokenData.set(toolStats.tokenType, PersistentDataType.STRING, "crops-mined");
token.setItemMeta(tokenMeta);
return token;
}
public ItemStack fishCaught() {
// set up the item
ItemStack token = new ItemStack(Material.PAPER);
ItemMeta tokenMeta = token.getItemMeta();
PersistentDataContainer tokenData = tokenMeta.getPersistentDataContainer();
// set the title and lore
Component title = toolStats.configTools.format("tokens.data.fish-caught.title");
List<Component> lore = toolStats.configTools.getTokenLore("fight-caught");
tokenMeta.displayName(title);
tokenMeta.lore(lore);
// set the PDC
tokenData.set(toolStats.tokenType, PersistentDataType.STRING, "fish-caught");
token.setItemMeta(tokenMeta);
return token;
}
public ItemStack sheepSheared() {
// set up the item
ItemStack token = new ItemStack(Material.PAPER);
ItemMeta tokenMeta = token.getItemMeta();
PersistentDataContainer tokenData = tokenMeta.getPersistentDataContainer();
// set the title and lore
Component title = toolStats.configTools.format("tokens.data.sheep-sheared.title");
List<Component> lore = toolStats.configTools.getTokenLore("sheep-sheared");
tokenMeta.displayName(title);
tokenMeta.lore(lore);
// set the PDC
tokenData.set(toolStats.tokenType, PersistentDataType.STRING, "sheep-sheared");
token.setItemMeta(tokenMeta);
return token;
}
public ItemStack damageTaken() {
// set up the item
ItemStack token = new ItemStack(Material.PAPER);
ItemMeta tokenMeta = token.getItemMeta();
PersistentDataContainer tokenData = tokenMeta.getPersistentDataContainer();
// set the title and lore
Component title = toolStats.configTools.format("tokens.data.damage-taken.title");
List<Component> lore = toolStats.configTools.getTokenLore("damage-taken");
tokenMeta.displayName(title);
tokenMeta.lore(lore);
// set the PDC
tokenData.set(toolStats.tokenType, PersistentDataType.STRING, "damage-taken");
token.setItemMeta(tokenMeta);
return token;
}
public ItemStack arrowsShot() {
// set up the item
ItemStack token = new ItemStack(Material.PAPER);
ItemMeta tokenMeta = token.getItemMeta();
PersistentDataContainer tokenData = tokenMeta.getPersistentDataContainer();
// set the title and lore
Component title = toolStats.configTools.format("tokens.data.arrows-shot.title");
List<Component> lore = toolStats.configTools.getTokenLore("arrows-shot");
tokenMeta.displayName(title);
tokenMeta.lore(lore);
// set the PDC
tokenData.set(toolStats.tokenType, PersistentDataType.STRING, "arrows-shot");
token.setItemMeta(tokenMeta);
return token;
}
public ItemStack flightTime() {
// set up the item
ItemStack token = new ItemStack(Material.PAPER);
ItemMeta tokenMeta = token.getItemMeta();
PersistentDataContainer tokenData = tokenMeta.getPersistentDataContainer();
// set the title and lore
Component title = toolStats.configTools.format("tokens.data.flight-time.title");
List<Component> lore = toolStats.configTools.getTokenLore("flight-time");
tokenMeta.displayName(title);
tokenMeta.lore(lore);
// set the PDC
tokenData.set(toolStats.tokenType, PersistentDataType.STRING, "flight-time");
token.setItemMeta(tokenMeta);
return token;
}
public ItemStack resetToken() {
// set up the item
ItemStack token = new ItemStack(Material.PAPER);
ItemMeta tokenMeta = token.getItemMeta();
PersistentDataContainer tokenData = tokenMeta.getPersistentDataContainer();
// set the title and lore
Component title = toolStats.configTools.format("tokens.data.reset.title");
List<Component> lore = toolStats.configTools.getTokenLore("reset");
tokenMeta.displayName(title);
tokenMeta.lore(lore);
// set the PDC
tokenData.set(toolStats.tokenType, PersistentDataType.STRING, "reset");
token.setItemMeta(tokenMeta);
return token;
}
}

View File

@@ -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");
}
}

View File

@@ -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");
}
}

View File

@@ -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");
}
}

View File

@@ -0,0 +1,103 @@
/*
* 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 Version9 {
private final ToolStats toolStats;
/**
* Used for updating from version 8 to 9.
*
* @param toolStats ToolStats instance.
*/
public Version9(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-8.yml");
} catch (IOException exception) {
toolStats.logger.severe("Unable to save config-8.yml!");
throw new RuntimeException(exception);
}
toolStats.logger.info("Updating config.yml to version 9.");
toolStats.config.set("config-version", 9);
toolStats.logger.info("Adding new tokens configuration! Don't worry, this is disabled by default.");
toolStats.logger.info("You can find more information here: https://github.com/hyperdefined/ToolStats/wiki/Token-System");
// false by default so it doesn't break servers on updating
toolStats.config.set("tokens.enabled", false);
toolStats.config.set("tokens.craft-tokens", true);
List<String> tokenComments = new ArrayList<>();
tokenComments.add("Use token system for tracking stats.");
tokenComments.add("See https://github.com/hyperdefined/ToolStats/wiki/Token-System");
toolStats.config.setComments("tokens", tokenComments);
addToken("player-kills", "&7ToolStats: &8Player Kills Token", "&8Combine with a melee or ranged weapon in an anvil to track player kills.");
addToken("mob-kills", "&7ToolStats: &8Mob Kills Token", "&8Combine with a melee or ranged weapon in an anvil to track mob kills.");
addToken("blocks-mined", "&7ToolStats: &8Blocks Mined Token", "&8Combine with a pickaxe, axe, shovel, or shears in an anvil to track blocks mined.");
addToken("crops-mined", "&7ToolStats: &8Crops Mined Token", "&8Combine with a hoe in an anvil to track crops broken.");
addToken("fish-caught", "&7ToolStats: &8Fish Caught Token", "&8Combine with a fishing rod in an anvil to track fish caught.");
addToken("sheep-sheared", "&7ToolStats: &8Sheep Sheared Token", "&8Combine with shears in an anvil to track sheep sheared.");
addToken("damage-taken", "&7ToolStats: &8Damage Taken Token", "&8Combine with an armor piece in an anvil to track damage taken.");
addToken("arrows-shot", "&7ToolStats: &8Arrows Shot Token", "&8Combine with a bow or crossbow in an anvil to track arrows shot.");
addToken("flight-time", "&7ToolStats: &8Flight Time Token", "&8Combine with an elytra in an anvil to track flight time.");
addToken("reset", "&7ToolStats: &8Reset Token", "&8Combine in an anvil with to reset ALL stats for this item. Tokens on this item stay.");
// 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 9. A copy of version 8 has been saved as config-8.yml");
}
/**
* Add a given token to the config. Made this since I was lazy.
*
* @param tokenType The token type to add.
* @param title The title for the item.
* @param lore The lore of the item.
*/
private void addToken(String tokenType, String title, String lore) {
toolStats.logger.info("Adding token type configuration for " + tokenType);
toolStats.config.set("tokens.data." + tokenType + ".title", title);
List<String> loreList = new ArrayList<>();
loreList.add(lore);
toolStats.config.set("tokens.data." + tokenType + ".lore", loreList);
toolStats.config.set("tokens.data." + tokenType + ".levels", 1);
}
}

View File

@@ -1,3 +1,60 @@
# Use token system for tracking stats.
# See https://github.com/hyperdefined/ToolStats/wiki/Token-System
tokens:
enabled: false
craft-tokens: true
data:
player-kills:
title: "&7ToolStats: &8Player Kills Token"
lore:
- "&8Combine with a melee or ranged weapon in an anvil to track player kills."
levels: 1
mob-kills:
title: "&7ToolStats: &8Mob Kills Token"
lore:
- "&8Combine with a melee or ranged weapon in an anvil to track mob kills."
levels: 1
blocks-mined:
title: "&7ToolStats: &8Blocks Mined Token"
lore:
- "&8Combine with a pickaxe, axe, shovel, or shears in an anvil to track blocks mined."
levels: 1
crops-mined:
title: "&7ToolStats: &8Crops Mined Token"
lore:
- "&8Combine with a hoe in an anvil to track crops broken."
levels: 1
fish-caught:
title: "&7ToolStats: &8Fish Caught Token"
lore:
- "&8Combine with a fishing rod in an anvil to track fish caught."
levels: 1
sheep-sheared:
title: "&7ToolStats: &8Sheep Sheared Token"
lore:
- "&8Combine with shears in an anvil to track sheep sheared."
levels: 1
damage-taken:
title: "&7ToolStats: &8Damage Taken Token"
lore:
- "&8Combine with an armor piece in an anvil to track damage taken."
levels: 1
arrows-shot:
title: "&7ToolStats: &8Arrows Shot Token"
lore:
- "&8Combine with a bow or crossbow in an anvil to track arrows shot."
levels: 1
flight-time:
title: "&7ToolStats: &8Flight Time Token"
lore:
- "&8Combine with an elytra in an anvil to track flight time."
levels: 1
reset:
title: "&7ToolStats: &8Reset Token"
lore:
- "&8Combine in an anvil with to reset ALL stats for this item. Tokens on this item stay."
levels: 1
enabled:
# Will show ownership of items when they are created/found.
created-by:
@@ -9,6 +66,7 @@ enabled:
shears: true
bow: true
armor: true
mace: true
# Will show time the item is created
created-date:
pickaxe: true
@@ -19,6 +77,7 @@ enabled:
shears: true
bow: true
armor: true
mace: true
# Will show "Fished by <player>"
fished-tag:
pickaxe: true
@@ -54,21 +113,87 @@ 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
config-version: 2
messages:
created:
created-by: "&7Crafted by: &8{player}"
created-on: "&7Crafted on: &8{date}"
fished:
caught-by: "&7Caught by: &8{player}"
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:
traded-by: "&7Traded by: &8{player}"
traded-on: "&7Traded on: &8{date}"
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}"
# Set display name for mobs. See: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/entity/EntityType.html
mobs:
ZOMBIE: "Zombie"
# Change the default formatting for dates.
# 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: "#,##0.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: 9

View File

@@ -1,15 +1,28 @@
name: ToolStats
version: '${project.version}'
main: lol.hyper.toolstats.ToolStats
api-version: 1.18
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: randomenchant.reload
permission: toolstats.command
permissions:
randomenchant.reload:
description: Allows the usage of /randomenchant reload
toolstats.command:
description: Allows the usage of /toolstats.
default: true
toolstats.reload:
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
toolstats.givetokens:
description: Allows the usage of /toolstats givetoken.
default: op