Compare commits

...

53 Commits
1.7.1 ... 1.8.2

Author SHA1 Message Date
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
21 changed files with 504 additions and 311 deletions

View File

@@ -1,7 +1,7 @@
<h1 align="center">ToolStats</h1>
<p align="center">
<img src="https://img.shields.io/badge/Minecraft-1.15--1.20.2-orange" alt="Minecraft versions">
<img src="https://img.shields.io/badge/Minecraft-1.15--1.21-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>
<img src="https://img.shields.io/badge/made%20with-love%20&%20fluff-red" alt="Made with love & fluff">

22
pom.xml
View File

@@ -23,7 +23,7 @@
<groupId>lol.hyper</groupId>
<artifactId>toolstats</artifactId>
<version>1.7.1</version>
<version>1.8.2</version>
<packaging>jar</packaging>
<name>ToolStats</name>
@@ -37,7 +37,7 @@
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.3.1</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.11.0</version>
<version>3.13.0</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
@@ -60,7 +60,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.5.1</version>
<version>3.6.0</version>
<configuration>
<relocations>
<relocation>
@@ -123,7 +123,7 @@
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
<version>3.0.2</version>
<version>3.0.3</version>
<scope>compile</scope>
</dependency>
<dependency>
@@ -135,20 +135,26 @@
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-text-minimessage</artifactId>
<version>4.14.0</version>
<version>4.17.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-platform-bukkit</artifactId>
<version>4.3.1</version>
<version>4.3.4</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>space.arim.morepaperlib</groupId>
<artifactId>morepaperlib</artifactId>
<version>0.4.3</version>
<version>0.4.4</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-chat</artifactId>
<version>1.20-R0.2</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@@ -97,6 +97,10 @@ public final class ToolStats extends JavaPlugin {
* Key for arrows shot.
*/
public final NamespacedKey arrowsShot = new NamespacedKey(this, "arrows-shot");
/**
* Key for tracking flight time.
*/
public final NamespacedKey flightTime = new NamespacedKey(this, "flightTime");
/**
* Stores how an item was created.
* 0 = crafted.
@@ -109,7 +113,7 @@ public final class ToolStats extends JavaPlugin {
*/
public final NamespacedKey originType = new NamespacedKey(this, "origin");
public final int CONFIG_VERSION = 6;
public final int CONFIG_VERSION = 7;
public final Logger logger = this.getLogger();
public final File configFile = new File(this.getDataFolder(), "config.yml");
@@ -134,6 +138,7 @@ public final class ToolStats extends JavaPlugin {
public MorePaperLib morePaperLib;
public HashMaker hashMaker;
public CreativeEvent creativeEvent;
public PlayerMove playerMove;
public ItemChecker itemChecker;
public ShootBow shootBow;
public ConfigTools configTools;
@@ -164,6 +169,7 @@ public final class ToolStats extends JavaPlugin {
inventoryOpen = new InventoryOpen(this);
playerJoin = new PlayerJoin(this);
creativeEvent = new CreativeEvent(this);
playerMove = new PlayerMove(this);
itemChecker = new ItemChecker();
shootBow = new ShootBow(this);
configTools = new ConfigTools(this);
@@ -183,6 +189,7 @@ public final class ToolStats extends JavaPlugin {
Bukkit.getServer().getPluginManager().registerEvents(playerJoin, this);
Bukkit.getServer().getPluginManager().registerEvents(creativeEvent, this);
Bukkit.getServer().getPluginManager().registerEvents(shootBow, this);
Bukkit.getServer().getPluginManager().registerEvents(playerMove, this);
this.getCommand("toolstats").setExecutor(commandToolStats);

View File

@@ -121,16 +121,6 @@ public class CommandToolStats implements TabExecutor {
PersistentDataContainer container = finalMeta.getPersistentDataContainer();
List<String> lore = new ArrayList<>();
String caughtByLore = toolStats.configTools.getLoreFromConfig("fished.caught-by", false);
String lootedByLore = toolStats.configTools.getLoreFromConfig("looted.found-by", false);
String tradedByLore = toolStats.configTools.getLoreFromConfig("traded.traded-by", false);
String spawnedByLore = toolStats.configTools.getLoreFromConfig("spawned-in.spawned-by", false);
// make sure the config messages are not null
if (caughtByLore == null || lootedByLore == null || tradedByLore == null || spawnedByLore == null) {
return;
}
// set how the item was obtained
Integer origin = -1;
if (container.has(toolStats.originType, PersistentDataType.INTEGER)) {
@@ -144,20 +134,33 @@ public class CommandToolStats implements TabExecutor {
// hard code elytras
if (finalItem.getType() == Material.ELYTRA) {
if (toolStats.config.getBoolean("enabled.elytra-tag")) {
lore.add(toolStats.configTools.getLoreFromConfig("looted.found-by", true).replace("{player}", player.getName()));
Long flightTime = null;
Long timeCreated = null;
if (container.has(toolStats.timeCreated, PersistentDataType.LONG)) {
Long time = container.get(toolStats.timeCreated, PersistentDataType.LONG);
if (time != null) {
lore.add(toolStats.configTools.getLoreFromConfig("looted.found-on", true).replace("{date}", toolStats.numberFormat.formatDate(new Date(time))));
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")) {
String line = toolStats.configTools.formatLore("flight-time", "{time}", toolStats.numberFormat.formatDouble((double) flightTime / 1000));
lore.add(line);
}
}
if (timeCreated != null) {
String timeCreatedLine = toolStats.configTools.formatLore("looted.found-by", "{player}", player.getName());
String playerOwnerLine = toolStats.configTools.formatLore("looted.found-on", "{date}", toolStats.numberFormat.formatDate(new Date(timeCreated)));
lore.add(timeCreatedLine);
lore.add(playerOwnerLine);
}
finalMeta.setLore(lore);
finalItem.setItemMeta(finalMeta);
int slot = player.getInventory().getHeldItemSlot();
player.getInventory().setItem(slot, finalItem);
return;
}
}
if (toolStats.configTools.checkConfig(original.getType(), "created-by")) {
@@ -181,27 +184,27 @@ public class CommandToolStats implements TabExecutor {
// show how the item was created based on the previous lore
switch (origin) {
case 0: {
lore.add(toolStats.configTools.getLoreFromConfig("created.created-by", true).replace("{player}", ownerName));
lore.add(toolStats.configTools.formatLore("created.created-by", "{player}", ownerName));
break;
}
case 2: {
lore.add(toolStats.configTools.getLoreFromConfig("looted.looted-by", true).replace("{player}", ownerName));
lore.add(toolStats.configTools.formatLore("looted.looted-by", "{player}", ownerName));
break;
}
case 3: {
lore.add(toolStats.configTools.getLoreFromConfig("traded.traded-by", true).replace("{player}", ownerName));
lore.add(toolStats.configTools.formatLore("traded.traded-by", "{player}", ownerName));
break;
}
case 4: {
lore.add(toolStats.configTools.getLoreFromConfig("looted.found-by", true).replace("{player}", ownerName));
lore.add(toolStats.configTools.formatLore("looted.found-by", "{player}", ownerName));
break;
}
case 5: {
lore.add(toolStats.configTools.getLoreFromConfig("fished.caught-by", true).replace("{player}", ownerName));
lore.add(toolStats.configTools.formatLore("fished.caught-by", "{player}", ownerName));
break;
}
case 6: {
lore.add(toolStats.configTools.getLoreFromConfig("spawned-in.spawned-by", true).replace("{player}", ownerName));
lore.add(toolStats.configTools.formatLore("spawned-in.spawned-by", "{player}", ownerName));
break;
}
}
@@ -211,30 +214,31 @@ public class CommandToolStats implements TabExecutor {
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.getLoreFromConfig("created.created-on", true).replace("{date}", toolStats.numberFormat.formatDate(new Date(time))));
lore.add(toolStats.configTools.formatLore("created.created-on", "{date}", date));
break;
}
case 2: {
lore.add(toolStats.configTools.getLoreFromConfig("looted.looted-on", true).replace("{date}", toolStats.numberFormat.formatDate(new Date(time))));
lore.add(toolStats.configTools.formatLore("looted.looted-on", "{date}", date));
break;
}
case 3: {
lore.add(toolStats.configTools.getLoreFromConfig("traded.traded-on", true).replace("{date}", toolStats.numberFormat.formatDate(new Date(time))));
lore.add(toolStats.configTools.formatLore("traded.traded-on", "{date}", date));
break;
}
case 4: {
lore.add(toolStats.configTools.getLoreFromConfig("looted.found-on", true).replace("{date}", toolStats.numberFormat.formatDate(new Date(time))));
lore.add(toolStats.configTools.formatLore("looted.found-on", "{date}", date));
break;
}
case 5: {
lore.add(toolStats.configTools.getLoreFromConfig("fished.caught-on", true).replace("{date}", toolStats.numberFormat.formatDate(new Date(time))));
lore.add(toolStats.configTools.formatLore("fished.caught-on", "{date}", date));
break;
}
case 6: {
lore.add(toolStats.configTools.getLoreFromConfig("spawned-in.spawned-on", true).replace("{date}", toolStats.numberFormat.formatDate(new Date(time))));
lore.add(toolStats.configTools.formatLore("spawned-in.spawned-on", "{date}", date));
break;
}
}
@@ -245,7 +249,7 @@ public class CommandToolStats implements TabExecutor {
if (container.has(toolStats.swordPlayerKills, PersistentDataType.INTEGER)) {
Integer kills = container.get(toolStats.swordPlayerKills, PersistentDataType.INTEGER);
if (kills != null) {
lore.add(toolStats.configTools.getLoreFromConfig("kills.player", true).replace("{kills}", toolStats.numberFormat.formatInt(kills)));
lore.add(toolStats.configTools.formatLore("kills.player", "{kills}", toolStats.numberFormat.formatInt(kills)));
}
}
}
@@ -253,7 +257,7 @@ public class CommandToolStats implements TabExecutor {
if (container.has(toolStats.swordMobKills, PersistentDataType.INTEGER)) {
Integer kills = container.get(toolStats.swordMobKills, PersistentDataType.INTEGER);
if (kills != null) {
lore.add(toolStats.configTools.getLoreFromConfig("kills.mob", true).replace("{kills}", toolStats.numberFormat.formatInt(kills)));
lore.add(toolStats.configTools.formatLore("kills.mob", "{kills}", toolStats.numberFormat.formatInt(kills)));
}
}
}
@@ -262,14 +266,14 @@ public class CommandToolStats implements TabExecutor {
if (container.has(toolStats.cropsHarvested, PersistentDataType.INTEGER)) {
Integer crops = container.get(toolStats.cropsHarvested, PersistentDataType.INTEGER);
if (crops != null) {
lore.add(toolStats.configTools.getLoreFromConfig("crops-harvested", true).replace("{crops}", toolStats.numberFormat.formatInt(crops)));
lore.add(toolStats.configTools.formatLore("crops-harvested", "{crops}", toolStats.numberFormat.formatInt(crops)));
}
}
}
if (container.has(toolStats.genericMined, PersistentDataType.INTEGER)) {
Integer blocksMined = container.get(toolStats.genericMined, PersistentDataType.INTEGER);
if (blocksMined != null) {
lore.add(toolStats.configTools.getLoreFromConfig("blocks-mined", true).replace("{blocks}", toolStats.numberFormat.formatInt(blocksMined)));
lore.add(toolStats.configTools.formatLore("blocks-mined", "{blocks}", toolStats.numberFormat.formatInt(blocksMined)));
}
}
}
@@ -277,7 +281,7 @@ public class CommandToolStats implements TabExecutor {
if (container.has(toolStats.fishingRodCaught, PersistentDataType.INTEGER)) {
Integer fish = container.get(toolStats.fishingRodCaught, PersistentDataType.INTEGER);
if (fish != null) {
lore.add(toolStats.configTools.getLoreFromConfig("fished.fish-caught", true).replace("{fish}", toolStats.numberFormat.formatInt(fish)));
lore.add(toolStats.configTools.formatLore("fished.fish-caught", "{fish}", toolStats.numberFormat.formatInt(fish)));
}
}
}
@@ -285,7 +289,7 @@ public class CommandToolStats implements TabExecutor {
if (container.has(toolStats.shearsSheared, PersistentDataType.INTEGER)) {
Integer sheep = container.get(toolStats.shearsSheared, PersistentDataType.INTEGER);
if (sheep != null) {
lore.add(toolStats.configTools.getLoreFromConfig("sheep-sheared", true).replace("{sheep}", toolStats.numberFormat.formatInt(sheep)));
lore.add(toolStats.configTools.formatLore("sheep-sheared", "{sheep}", toolStats.numberFormat.formatInt(sheep)));
}
}
}
@@ -293,7 +297,7 @@ public class CommandToolStats implements TabExecutor {
if (container.has(toolStats.armorDamage, PersistentDataType.DOUBLE)) {
Double damage = container.get(toolStats.armorDamage, PersistentDataType.DOUBLE);
if (damage != null) {
lore.add(toolStats.configTools.getLoreFromConfig("damage-taken", true).replace("{damage}", toolStats.numberFormat.formatDouble(damage)));
lore.add(toolStats.configTools.formatLore("damage-taken", "{damage}", toolStats.numberFormat.formatDouble(damage)));
}
}
}
@@ -301,7 +305,7 @@ public class CommandToolStats implements TabExecutor {
if (container.has(toolStats.arrowsShot, PersistentDataType.INTEGER)) {
Integer arrows = container.get(toolStats.arrowsShot, PersistentDataType.INTEGER);
if (arrows != null) {
lore.add(toolStats.configTools.getLoreFromConfig("arrows-shot", true).replace("{arrows}", toolStats.numberFormat.formatInt(arrows)));
lore.add(toolStats.configTools.formatLore("arrows-shot", "{arrows}", toolStats.numberFormat.formatInt(arrows)));
}
}
}

View File

@@ -104,13 +104,18 @@ public class BlocksMined implements Listener {
toolStats.logger.warning(playerTool + " does not have valid generic-mined set! Resting to zero. This should NEVER happen.");
}
blocksMined++;
container.set(toolStats.genericMined, PersistentDataType.INTEGER, blocksMined);
container.set(toolStats.genericMined, PersistentDataType.INTEGER, blocksMined + 1);
// do we add the lore based on the config?
if (toolStats.configTools.checkConfig(playerTool.getType(), "blocks-mined")) {
String blocksMinedFormatted = toolStats.numberFormat.formatInt(blocksMined);
List<String> newLore = toolStats.itemLore.addItemLore(meta, "{blocks}", blocksMinedFormatted, "blocks-mined");
String oldBlocksMinedFormatted = toolStats.numberFormat.formatInt(blocksMined);
String newBlocksMinedFormatted = toolStats.numberFormat.formatInt(blocksMined + 1);
String oldLine = toolStats.configTools.formatLore("blocks-mined", "{blocks}", oldBlocksMinedFormatted);
String newLine = toolStats.configTools.formatLore("blocks-mined", "{blocks}", newBlocksMinedFormatted);
if (oldLine == null || newLine == null) {
return;
}
List<String> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
meta.setLore(newLore);
}
playerTool.setItemMeta(meta);
@@ -140,13 +145,18 @@ public class BlocksMined implements Listener {
toolStats.logger.warning(playerTool + " does not have valid crops-mined set! Resting to zero. This should NEVER happen.");
}
cropsMined++;
container.set(toolStats.cropsHarvested, PersistentDataType.INTEGER, cropsMined);
container.set(toolStats.cropsHarvested, PersistentDataType.INTEGER, cropsMined + 1);
// do we add the lore based on the config?
if (toolStats.configTools.checkConfig(playerTool.getType(), "blocks-mined")) {
String cropsMinedFormatted = toolStats.numberFormat.formatInt(cropsMined);
List<String> newLore = toolStats.itemLore.addItemLore(meta, "{crops}", cropsMinedFormatted, "crops-harvested");
String oldCropsMinedFormatted = toolStats.numberFormat.formatInt(cropsMined);
String newCropsMinedFormatted = toolStats.numberFormat.formatInt(cropsMined + 1);
String oldLine = toolStats.configTools.formatLore("crops-harvested", "{crops}", oldCropsMinedFormatted);
String newLine = toolStats.configTools.formatLore("crops-harvested", "{crops}", newCropsMinedFormatted);
if (oldLine == null || newLine == null) {
return;
}
List<String> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
meta.setLore(newLore);
}
playerTool.setItemMeta(meta);

View File

@@ -64,7 +64,7 @@ public class CraftItem implements Listener {
if (event.isShiftClick()) {
String configMessage = toolStats.config.getString("messages.shift-click-warning.crafting");
if (configMessage != null) {
if (configMessage.length() != 0) {
if (!configMessage.isEmpty()) {
event.getWhoClicked().sendMessage(ChatColor.translateAlternateColorCodes('&', configMessage));
}
}
@@ -122,21 +122,20 @@ public class CraftItem implements Listener {
}
// do we add the lore based on the config?
if (toolStats.configTools.checkConfig(itemStack.getType(), "created-date")) {
String createdOnRaw = toolStats.configTools.getLoreFromConfig("created.created-on", true);
if (createdOnRaw == null) {
toolStats.logger.warning("There is no lore message for messages.created.created-on!");
String date = toolStats.numberFormat.formatDate(finalDate);
String newLine = toolStats.configTools.formatLore("created.created-on", "{date}", date);
if (newLine == null) {
return null;
}
lore.add(createdOnRaw.replace("{date}", toolStats.numberFormat.formatDate(finalDate)));
lore.add(newLine);
meta.setLore(lore);
}
if (toolStats.configTools.checkConfig(itemStack.getType(), "created-by")) {
String createdByRaw = toolStats.configTools.getLoreFromConfig("created.created-by", true);
if (createdByRaw == null) {
toolStats.logger.warning("There is no lore message for messages.created.created-by!");
String newLine = toolStats.configTools.formatLore("created.created-by", "{player}", owner.getName());
if (newLine == null) {
return null;
}
lore.add(createdByRaw.replace("{player}", owner.getName()));
lore.add(newLine);
meta.setLore(lore);
}
newItem.setItemMeta(meta);

View File

@@ -87,6 +87,11 @@ public class CreativeEvent implements Listener {
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);

View File

@@ -39,7 +39,7 @@ public class EntityDamage implements Listener {
private final ToolStats toolStats;
public final Set<UUID> trackedMobs = new HashSet<>();
private final List<EntityDamageEvent.DamageCause> ignoredCauses = Arrays.asList(EntityDamageEvent.DamageCause.SUICIDE, EntityDamageEvent.DamageCause.VOID, EntityDamageEvent.DamageCause.CUSTOM);
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;
@@ -241,13 +241,18 @@ public class EntityDamage implements Listener {
toolStats.logger.warning(itemStack + " does not have valid player-kills set! Resting to zero. This should NEVER happen.");
}
playerKills++;
container.set(toolStats.swordPlayerKills, PersistentDataType.INTEGER, playerKills);
container.set(toolStats.swordPlayerKills, PersistentDataType.INTEGER, playerKills + 1);
// do we add the lore based on the config?
if (toolStats.configTools.checkConfig(itemStack.getType(), "player-kills")) {
String playerKillsFormatted = toolStats.numberFormat.formatInt(playerKills);
List<String> newLore = toolStats.itemLore.addItemLore(meta, "{kills}", playerKillsFormatted, "kills.player");
String oldPlayerKillsFormatted = toolStats.numberFormat.formatInt(playerKills);
String newPlayerKillsFormatted = toolStats.numberFormat.formatInt(playerKills + 1);
String oldLine = toolStats.configTools.formatLore("kills.player", "{kills}", oldPlayerKillsFormatted);
String newLine = toolStats.configTools.formatLore("kills.player", "{kills}", newPlayerKillsFormatted);
if (oldLine == null || newLine == null) {
return;
}
List<String> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
meta.setLore(newLore);
}
itemStack.setItemMeta(meta);
@@ -275,13 +280,18 @@ public class EntityDamage implements Listener {
toolStats.logger.warning(itemStack + " does not have valid mob-kills set! Resting to zero. This should NEVER happen.");
}
mobKills++;
container.set(toolStats.swordMobKills, PersistentDataType.INTEGER, mobKills);
container.set(toolStats.swordMobKills, PersistentDataType.INTEGER, mobKills + 1);
// do we add the lore based on the config?
if (toolStats.configTools.checkConfig(itemStack.getType(), "mob-kills")) {
String mobKillsFormatted = toolStats.numberFormat.formatInt(mobKills);
List<String> newLore = toolStats.itemLore.addItemLore(meta, "{kills}", mobKillsFormatted, "kills.mob");
String oldMobKillsFormatted = toolStats.numberFormat.formatInt(mobKills);
String newMobKillsFormatted = toolStats.numberFormat.formatInt(mobKills + 1);
String oldLine = toolStats.configTools.formatLore("kills.mob", "{kills}", oldMobKillsFormatted);
String newLine = toolStats.configTools.formatLore("kills.mob", "{kills}", newMobKillsFormatted);
if (oldLine == null || newLine == null) {
return;
}
List<String> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
meta.setLore(newLore);
}
itemStack.setItemMeta(meta);
@@ -294,6 +304,10 @@ public class EntityDamage implements Listener {
* @param damage How much damage is being added.
*/
private void updateDamage(ItemStack itemStack, double damage) {
// ignore if the damage is zero or negative
if (damage < 0) {
return;
}
ItemMeta meta = itemStack.getItemMeta();
if (meta == null) {
toolStats.logger.warning(itemStack + " does NOT have any meta! Unable to update stats.");
@@ -310,13 +324,17 @@ public class EntityDamage implements Listener {
toolStats.logger.warning(itemStack + " does not have valid damage-taken set! Resting to zero. This should NEVER happen.");
}
damageTaken = damageTaken + damage;
container.set(toolStats.armorDamage, PersistentDataType.DOUBLE, damageTaken);
container.set(toolStats.armorDamageInt, PersistentDataType.INTEGER, damageTaken.intValue());
container.set(toolStats.armorDamage, PersistentDataType.DOUBLE, damageTaken + damage);
if (toolStats.config.getBoolean("enabled.armor-damage")) {
String damageTakenFormatted = toolStats.numberFormat.formatDouble(damageTaken);
List<String> newLore = toolStats.itemLore.addItemLore(meta, "{damage}", damageTakenFormatted, "damage-taken");
String oldDamageFormatted = toolStats.numberFormat.formatDouble(damageTaken);
String newDamageFormatted = toolStats.numberFormat.formatDouble(damageTaken + damage);
String oldLine = toolStats.configTools.formatLore("damage-taken", "{damage}", oldDamageFormatted);
String newLine = toolStats.configTools.formatLore("damage-taken", "{damage}", newDamageFormatted);
if (oldLine == null || newLine == null) {
return;
}
List<String> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
meta.setLore(newLore);
}
itemStack.setItemMeta(meta);
@@ -345,13 +363,18 @@ public class EntityDamage implements Listener {
toolStats.logger.warning(newTrident + " does not have valid mob-kills set! Resting to zero. This should NEVER happen.");
}
mobKills++;
container.set(toolStats.swordMobKills, PersistentDataType.INTEGER, mobKills);
container.set(toolStats.swordMobKills, PersistentDataType.INTEGER, mobKills + 1);
// do we add the lore based on the config?
if (toolStats.configTools.checkConfig(newTrident.getType(), "mob-kills")) {
String mobKillsFormatted = toolStats.numberFormat.formatInt(mobKills);
List<String> newLore = toolStats.itemLore.addItemLore(meta, "{kills}", mobKillsFormatted, "kills.mob");
String oldMobKillsFormatted = toolStats.numberFormat.formatInt(mobKills);
String newMobKillsFormatted = toolStats.numberFormat.formatInt(mobKills + 1);
String oldLine = toolStats.configTools.formatLore("kills.mob", "{kills}", oldMobKillsFormatted);
String newLine = toolStats.configTools.formatLore("kills.mob", "{kills}", newMobKillsFormatted);
if (oldLine == null || newLine == null) {
return null;
}
List<String> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
meta.setLore(newLore);
}
newTrident.setItemMeta(meta);
@@ -381,13 +404,18 @@ public class EntityDamage implements Listener {
toolStats.logger.warning(newTrident + " does not have valid player-kills set! Resting to zero. This should NEVER happen.");
}
playerKills++;
container.set(toolStats.swordPlayerKills, PersistentDataType.INTEGER, playerKills);
container.set(toolStats.swordPlayerKills, PersistentDataType.INTEGER, playerKills + 1);
// do we add the lore based on the config?
if (toolStats.configTools.checkConfig(newTrident.getType(), "player-kills")) {
String playerKillsFormatted = toolStats.numberFormat.formatInt(playerKills);
List<String> newLore = toolStats.itemLore.addItemLore(meta, "{kills}", playerKillsFormatted, "kills.player");
String oldPlayerKillsFormatted = toolStats.numberFormat.formatInt(playerKills);
String newPlayerKillsFormatted = toolStats.numberFormat.formatInt(playerKills + 1);
String oldLine = toolStats.configTools.formatLore("kills.player", "{kills}", oldPlayerKillsFormatted);
String newLine = toolStats.configTools.formatLore("kills.player", "{kills}", newPlayerKillsFormatted);
if (oldLine == null || newLine == null) {
return null;
}
List<String> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
meta.setLore(newLore);
}
newTrident.setItemMeta(meta);

View File

@@ -86,7 +86,8 @@ public class EntityDeath implements Listener {
container.set(toolStats.originType, PersistentDataType.INTEGER, 1);
if (toolStats.config.getBoolean("enabled.dropped-by")) {
List<String> newLore = toolStats.itemLore.addItemLore(meta, "{name}", mob, "dropped-by");
String newLine = toolStats.configTools.formatLore("dropped-by", "{name}", mob);
List<String> newLore = toolStats.itemLore.addItemLore(meta, newLine);
meta.setLore(newLore);
}
newItem.setItemMeta(meta);

View File

@@ -20,7 +20,6 @@ package lol.hyper.toolstats.events;
import lol.hyper.toolstats.ToolStats;
import lol.hyper.toolstats.tools.UUIDDataType;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryOpenEvent;
@@ -83,14 +82,6 @@ public class InventoryOpen implements Listener {
container.set(toolStats.hash, PersistentDataType.STRING, hash);
}
}
// add origin tag
if (!container.has(toolStats.originType, PersistentDataType.INTEGER)) {
itemMeta = toolStats.itemLore.getOrigin(itemMeta, itemStack.getType() == Material.ELYTRA);
if (itemMeta == null) {
continue;
}
}
ItemMeta clone = itemMeta.clone();
BukkitRunnable runnable = new BukkitRunnable() {
@Override

View File

@@ -32,6 +32,7 @@ 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.Date;
import java.util.List;
@@ -58,25 +59,8 @@ public class PlayerFish implements Listener {
if (player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.SPECTATOR) {
return;
}
// make sure the player is holding a fishing rod
// player can fish with their offhand
PlayerInventory inventory = player.getInventory();
boolean isMainHand = inventory.getItemInMainHand().getType() == Material.FISHING_ROD;
boolean isOffHand = inventory.getItemInOffHand().getType() == Material.FISHING_ROD;
ItemStack fishingRod = null;
if (isMainHand) {
fishingRod = inventory.getItemInMainHand();
}
if (isOffHand) {
fishingRod = inventory.getItemInOffHand();
}
// if the player is hold fishing rods in both hands
// default to main hand since that takes priority
if (isMainHand && isOffHand) {
fishingRod = inventory.getItemInMainHand();
}
ItemStack fishingRod = getItemStack(player);
// player swapped items?
if (fishingRod == null) {
return;
@@ -99,6 +83,26 @@ public class PlayerFish implements Listener {
}
}
private static @Nullable ItemStack getItemStack(Player player) {
PlayerInventory inventory = player.getInventory();
boolean isMainHand = inventory.getItemInMainHand().getType() == Material.FISHING_ROD;
boolean isOffHand = inventory.getItemInOffHand().getType() == Material.FISHING_ROD;
ItemStack fishingRod = null;
if (isMainHand) {
fishingRod = inventory.getItemInMainHand();
}
if (isOffHand) {
fishingRod = inventory.getItemInOffHand();
}
// if the player is hold fishing rods in both hands
// default to main hand since that takes priority
if (isMainHand && isOffHand) {
fishingRod = inventory.getItemInMainHand();
}
return fishingRod;
}
/**
* Update a fishing rod's fish count.
*
@@ -121,12 +125,17 @@ public class PlayerFish implements Listener {
toolStats.logger.warning(fishingRod + " does not have valid fish-caught set! Resting to zero. This should NEVER happen.");
}
fishCaught++;
container.set(toolStats.fishingRodCaught, PersistentDataType.INTEGER, fishCaught);
container.set(toolStats.fishingRodCaught, PersistentDataType.INTEGER, fishCaught + 1);
if (toolStats.config.getBoolean("enabled.fish-caught")) {
String fishCaughtFormatted = toolStats.numberFormat.formatInt(fishCaught);
List<String> newLore = toolStats.itemLore.addItemLore(meta, "{fish}", fishCaughtFormatted, "fished.fish-caught");
String oldFishFormatted = toolStats.numberFormat.formatInt(fishCaught);
String newFishFormatted = toolStats.numberFormat.formatInt(fishCaught + 1);
String oldLine = toolStats.configTools.formatLore("fished.fish-caught", "{fish}", oldFishFormatted);
String newLine = toolStats.configTools.formatLore("fished.fish-caught", "{fish}", newFishFormatted);
if (oldLine == null || newLine == null) {
return;
}
List<String> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
meta.setLore(newLore);
}
fishingRod.setItemMeta(meta);

View File

@@ -19,7 +19,6 @@ package lol.hyper.toolstats.events;
import lol.hyper.toolstats.ToolStats;
import lol.hyper.toolstats.tools.UUIDDataType;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
@@ -77,14 +76,6 @@ public class PlayerJoin implements Listener {
String hash = toolStats.hashMaker.makeHash(itemStack.getType(), owner, timestamp);
container.set(toolStats.hash, PersistentDataType.STRING, hash);
}
// add origin tag
if (!container.has(toolStats.originType, PersistentDataType.INTEGER)) {
itemMeta = toolStats.itemLore.getOrigin(itemMeta, itemStack.getType() == Material.ELYTRA);
if (itemMeta == null) {
continue;
}
}
ItemMeta clone = itemMeta.clone();
BukkitRunnable runnable = new BukkitRunnable() {
@Override

View File

@@ -0,0 +1,107 @@
/*
* 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.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.persistence.PersistentDataType;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class PlayerMove implements Listener {
private final ToolStats toolStats;
private final Map<Player, Long> playerStartFlight = new HashMap<>();
public PlayerMove(ToolStats toolStats) {
this.toolStats = toolStats;
}
@EventHandler(priority = EventPriority.MONITOR)
public void onCraft(PlayerMoveEvent event) {
Player player = event.getPlayer();
// player starts to fly
if (player.isGliding()) {
// if they are flying, and we don't have them tracked, add them
if (!playerStartFlight.containsKey(player)) {
playerStartFlight.put(player, System.currentTimeMillis());
}
} else {
// player is not flying
if (playerStartFlight.containsKey(player)) {
trackFlight(player, playerStartFlight.get(player));
playerStartFlight.remove(player);
}
}
}
private void trackFlight(Player player, long startTime) {
ItemStack chest = player.getInventory().getChestplate();
// make sure their chest piece is an elytra
if (chest == null || chest.getType() != Material.ELYTRA) {
return;
}
ItemMeta meta = chest.getItemMeta();
if (meta == null) {
toolStats.logger.warning(chest + " does NOT have any meta! Unable to update stats.");
return;
}
// read the current stats from the item
// if they don't exist, then start from 0
Long flightTime = 0L;
PersistentDataContainer container = meta.getPersistentDataContainer();
if (container.has(toolStats.flightTime, PersistentDataType.LONG)) {
flightTime = container.get(toolStats.flightTime, PersistentDataType.LONG);
}
if (flightTime == null) {
flightTime = 0L;
toolStats.logger.warning(flightTime + " does not have valid flight-time set! Resting to zero. This should NEVER happen.");
}
// get the duration of the flight
long duration = (System.currentTimeMillis() - startTime);
double newDuration = flightTime + duration;
container.set(toolStats.flightTime, PersistentDataType.LONG, flightTime + duration);
// do we add the lore based on the config?
if (toolStats.config.getBoolean("enabled.flight-time")) {
String oldFlightFormatted = toolStats.numberFormat.formatDouble((double) flightTime / 1000);
String newFlightFormatted = toolStats.numberFormat.formatDouble(newDuration / 1000);
String oldLine = toolStats.configTools.formatLore("flight-time", "{time}", oldFlightFormatted);
String newLine = toolStats.configTools.formatLore("flight-time", "{time}", newFlightFormatted);
if (oldLine == null || newLine == null) {
return;
}
List<String> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
meta.setLore(newLore);
}
chest.setItemMeta(meta);
}
}

View File

@@ -32,6 +32,7 @@ import org.bukkit.inventory.PlayerInventory;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.persistence.PersistentDataType;
import org.jetbrains.annotations.Nullable;
import java.util.List;
@@ -57,25 +58,7 @@ public class SheepShear implements Listener {
return;
}
// make sure the player is holding shears
// player can shear with their offhand
PlayerInventory inventory = player.getInventory();
boolean isMainHand = inventory.getItemInMainHand().getType() == Material.SHEARS;
boolean isOffHand = inventory.getItemInOffHand().getType() == Material.SHEARS;
ItemStack shears = null;
if (isMainHand) {
shears = inventory.getItemInMainHand();
}
if (isOffHand) {
shears = inventory.getItemInOffHand();
}
// if the player is hold fishing rods in both hands
// default to main hand since that takes priority
if (isMainHand && isOffHand) {
shears = inventory.getItemInMainHand();
}
ItemStack shears = getShears(player);
// player swapped items?
if (shears == null) {
return;
@@ -92,6 +75,26 @@ public class SheepShear implements Listener {
addLore(finalShears);
}
private static @Nullable ItemStack getShears(Player player) {
PlayerInventory inventory = player.getInventory();
boolean isMainHand = inventory.getItemInMainHand().getType() == Material.SHEARS;
boolean isOffHand = inventory.getItemInOffHand().getType() == Material.SHEARS;
ItemStack shears = null;
if (isMainHand) {
shears = inventory.getItemInMainHand();
}
if (isOffHand) {
shears = inventory.getItemInOffHand();
}
// if the player is hold shears in both hands
// default to main hand since that takes priority
if (isMainHand && isOffHand) {
shears = inventory.getItemInMainHand();
}
return shears;
}
/**
* Adds tags to shears.
*
@@ -114,12 +117,17 @@ public class SheepShear implements Listener {
toolStats.logger.warning(newShears + " does not have valid sheared set! Resting to zero. This should NEVER happen.");
}
sheepSheared++;
container.set(toolStats.shearsSheared, PersistentDataType.INTEGER, sheepSheared);
container.set(toolStats.shearsSheared, PersistentDataType.INTEGER, sheepSheared + 1);
if (toolStats.config.getBoolean("enabled.sheep-sheared")) {
String sheepShearedFormatted = toolStats.numberFormat.formatInt(sheepSheared);
List<String> newLore = toolStats.itemLore.addItemLore(meta, "{sheep}", sheepShearedFormatted, "sheep-sheared");
String oldSheepFormatted = toolStats.numberFormat.formatInt(sheepSheared);
String newSheepFormatted = toolStats.numberFormat.formatInt(sheepSheared + 1);
String oldLine = toolStats.configTools.formatLore("sheep-sheared", "{sheep}", oldSheepFormatted);
String newLine = toolStats.configTools.formatLore("sheep-sheared", "{sheep}", newSheepFormatted);
if (oldLine == null || newLine == null) {
return;
}
List<String> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
meta.setLore(newLore);
}
newShears.setItemMeta(meta);

View File

@@ -31,6 +31,7 @@ import org.bukkit.inventory.PlayerInventory;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.persistence.PersistentDataType;
import org.jetbrains.annotations.Nullable;
import java.util.List;
@@ -56,6 +57,17 @@ public class ShootBow implements Listener {
}
PlayerInventory inventory = player.getInventory();
ItemStack heldBow = getBow(inventory);
// player swapped
if (heldBow == null) {
return;
}
updateArrowsShot(heldBow);
}
private static @Nullable ItemStack getBow(PlayerInventory inventory) {
boolean isMainHand = inventory.getItemInMainHand().getType() == Material.BOW || inventory.getItemInMainHand().getType() == Material.CROSSBOW;
boolean isOffHand = inventory.getItemInOffHand().getType() == Material.BOW || inventory.getItemInMainHand().getType() == Material.CROSSBOW;
ItemStack heldBow = null;
@@ -71,13 +83,7 @@ public class ShootBow implements Listener {
if (isMainHand && isOffHand) {
heldBow = inventory.getItemInMainHand();
}
// player swapped
if (heldBow == null) {
return;
}
updateArrowsShot(heldBow);
return heldBow;
}
private void updateArrowsShot(ItemStack bow) {
@@ -99,13 +105,18 @@ public class ShootBow implements Listener {
toolStats.logger.warning(arrowsShot + " does not have valid arrows-shot set! Resting to zero. This should NEVER happen.");
}
arrowsShot++;
container.set(toolStats.arrowsShot, PersistentDataType.INTEGER, arrowsShot);
container.set(toolStats.arrowsShot, PersistentDataType.INTEGER, arrowsShot + 1);
// do we add the lore based on the config?
if (toolStats.config.getBoolean("enabled.arrows-shot")) {
String arrowsShotFormatted = toolStats.numberFormat.formatInt(arrowsShot);
List<String> newLore = toolStats.itemLore.addItemLore(meta, "{arrows}", arrowsShotFormatted, "arrows-shot");
String oldArrowsFormatted = toolStats.numberFormat.formatInt(arrowsShot);
String newArrowsFormatted = toolStats.numberFormat.formatInt(arrowsShot + 1);
String oldLine = toolStats.configTools.formatLore("arrows-shot", "{arrows}", oldArrowsFormatted);
String newLine = toolStats.configTools.formatLore("arrows-shot", "{arrows}", newArrowsFormatted);
if (oldLine == null || newLine == null) {
return;
}
List<String> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
meta.setLore(newLore);
}
bow.setItemMeta(meta);

View File

@@ -55,6 +55,7 @@ public class ItemChecker {
validItems.add(Material.BOW);
validItems.add(Material.FISHING_ROD);
validItems.add(Material.CROSSBOW);
validItems.add(Material.ELYTRA);
// combine the lists
validItems.addAll(armorItems);

View File

@@ -34,49 +34,49 @@ public class ItemLore {
}
/**
* Adds/updates lore for an item.
* Updates existing lore on an item.
*
* @param placeholder The placeholder from the config. ex: {kills}
* @param placeholderValue The value to replace the placeholder.
* @param configLorePath The path to the config message.
* @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<String> addItemLore(ItemMeta itemMeta, String placeholder, String placeholderValue, String configLorePath) {
String configLore = toolStats.configTools.getLoreFromConfig(configLorePath, false);
String configLoreRaw = toolStats.configTools.getLoreFromConfig(configLorePath, true);
if (configLore == null || configLoreRaw == null) {
toolStats.logger.warning("There is no lore message for messages." + configLorePath + "!");
toolStats.logger.warning("Unable to update lore for item.");
return itemMeta.getLore();
}
List<String> newLore;
// replace the placeholder with the value
// ex: {kills} -> a number
String newLine = configLoreRaw.replace(placeholder, placeholderValue);
public List<String> updateItemLore(ItemMeta itemMeta, String oldLine, String newLine) {
List<String> itemLore;
oldLine = toolStats.configTools.removeColor(oldLine);
if (itemMeta.hasLore()) {
newLore = itemMeta.getLore();
itemLore = itemMeta.getLore();
// keep track of line index
// this doesn't mess the lore of existing items
for (int x = 0; x < newLore.size(); x++) {
for (int x = 0; x < itemLore.size(); x++) {
// check to see if the line matches the config value
// this means we update this line only!
String line = newLore.get(x);
if (line.contains(configLore)) {
newLore.set(x, newLine);
return newLore;
String line = toolStats.configTools.removeColor(itemLore.get(x));
if (line.equals(oldLine)) {
itemLore.set(x, newLine);
return itemLore;
}
}
// if the item has lore, but we didn't find the line
newLore.add(newLine);
itemLore.add(newLine);
} else {
// if the item has no lore, create a new list and add the line
newLore = new ArrayList<>();
newLore.add(newLine);
itemLore = new ArrayList<>();
itemLore.add(newLine);
}
return newLore;
return itemLore;
}
public List<String> addItemLore(ItemMeta itemMeta, String newLine) {
List<String> itemLore;
if (itemMeta.hasLore()) {
itemLore = itemMeta.getLore();
itemLore.add(newLine);
} else {
itemLore = new ArrayList<>();
itemLore.add(newLine);
}
return itemLore;
}
/**
@@ -106,8 +106,8 @@ public class ItemLore {
// set the lore based on the origin
switch (origin) {
case 2: {
dateCreatedLore = toolStats.configTools.getLoreFromConfig("looted.looted-on", true);
itemOwnerLore = toolStats.configTools.getLoreFromConfig("looted.looted-by", true);
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!");
@@ -122,8 +122,8 @@ public class ItemLore {
break;
}
case 3: {
dateCreatedLore = toolStats.configTools.getLoreFromConfig("traded.traded-on", true);
itemOwnerLore = toolStats.configTools.getLoreFromConfig("traded.traded-by", true);
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!");
@@ -138,8 +138,8 @@ public class ItemLore {
break;
}
case 4: {
dateCreatedLore = toolStats.configTools.getLoreFromConfig("looted.found-on", true);
itemOwnerLore = toolStats.configTools.getLoreFromConfig("looted.found-by", true);
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!");
@@ -154,8 +154,8 @@ public class ItemLore {
break;
}
case 5: {
dateCreatedLore = toolStats.configTools.getLoreFromConfig("fished.caught-on", true);
itemOwnerLore = toolStats.configTools.getLoreFromConfig("fished.caught-by", true);
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!");
@@ -170,8 +170,8 @@ public class ItemLore {
break;
}
case 6: {
dateCreatedLore = toolStats.configTools.getLoreFromConfig("spawned-in.spawned-on", true);
itemOwnerLore = toolStats.configTools.getLoreFromConfig("spawned-in.spawned-by", true);
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!");
@@ -203,63 +203,4 @@ public class ItemLore {
newLore.add(itemOwnerLore.replace("{player}", playerName));
return newLore;
}
/**
* Determine an item's origin based on lore.
*
* @param itemMeta The item's meta.
* @param elytra If they item is an elytra.
* @return The new item meta with the new origin tag. Returns null if origin cannot be determined.
*/
public ItemMeta getOrigin(ItemMeta itemMeta, boolean elytra) {
List<String> lore;
if (!itemMeta.hasLore()) {
return null;
}
lore = itemMeta.getLore();
Integer origin = null;
String createdBy = toolStats.configTools.getLoreFromConfig("created.created-by", false);
String createdOn = toolStats.configTools.getLoreFromConfig("created.created-on", false);
String caughtBy = toolStats.configTools.getLoreFromConfig("fished.caught-by", false);
String lootedBy = toolStats.configTools.getLoreFromConfig("looted.looted-by", false);
String foundBy = toolStats.configTools.getLoreFromConfig("looted.found-by", false);
String tradedBy = toolStats.configTools.getLoreFromConfig("traded.traded-by", false);
for (String line : lore) {
// this is the worst code I have ever written
if (createdBy != null && line.contains(createdBy)) {
origin = 0;
}
if (createdOn != null && line.contains(createdOn)) {
origin = 0;
}
if (caughtBy != null && line.contains(caughtBy)) {
origin = 5;
}
if (lootedBy != null && line.contains(lootedBy)) {
origin = 2;
}
// because the config changed, "found-by" was being used for ALL looted items
// this includes elytras, so we have to check for this mistake
if (foundBy != null && line.contains(foundBy)) {
if (elytra) {
origin = 4;
} else {
origin = 5;
}
}
if (tradedBy != null && line.contains(tradedBy)) {
origin = 3;
}
}
if (origin == null) {
return null;
}
PersistentDataContainer container = itemMeta.getPersistentDataContainer();
container.set(toolStats.originType, PersistentDataType.INTEGER, origin);
return itemMeta;
}
}

View File

@@ -21,12 +21,15 @@ import lol.hyper.toolstats.ToolStats;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class ConfigTools {
private final ToolStats toolStats;
private final Pattern COLOR_CODES = Pattern.compile("(?i)&[0-9A-FK-ORX]");
public static final Pattern COLOR_CODES = Pattern.compile("[&§]([0-9a-fk-or])");
public static final Pattern CONFIG_HEX_PATTERN = Pattern.compile("[&§]#([A-Fa-f0-9]{6})");
public static final Pattern MINECRAFT_HEX_PATTERN = Pattern.compile("§x(?:§[a-fA-F0-9]){6}|§[a-fA-F0-9]");
public ConfigTools(ToolStats toolStats) {
this.toolStats = toolStats;
@@ -107,56 +110,47 @@ public class ConfigTools {
}
/**
* Gets the lore message from the config.
* Format a string to be ready for lore usage.
*
* @param configName The config name, "messages." is already in front.
* @param raw If you want the raw message with the formatting codes and placeholders.
* @return The lore message.
* @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 String getLoreFromConfig(String configName, boolean raw) {
public String formatLore(String configName, String placeHolder, Object value) {
String lore = toolStats.config.getString("messages." + configName);
if (lore == null) {
return null;
}
if (raw) {
return ChatColor.translateAlternateColorCodes('&', lore);
} else {
// remove all color codes
// this is used to compare the current lore on the item
// Example: [§7Arrows shot: §8] is on the lore
// this will return [Arrows shot: ] so we can match it
lore = COLOR_CODES.matcher(lore).replaceAll("");
if (lore.contains("{player}")) {
lore = lore.replace("{player}", "");
// set the placeholder to the value
lore = lore.replace(placeHolder, String.valueOf(value));
Matcher hexMatcher = CONFIG_HEX_PATTERN.matcher(lore);
while (hexMatcher.find()) {
String hexCode = hexMatcher.group(1);
lore = lore.replaceAll(hexMatcher.group(), net.md_5.bungee.api.ChatColor.of("#" + hexCode).toString());
}
if (lore.contains("{date}")) {
lore = lore.replace("{date}", "");
Matcher colorMatcher = COLOR_CODES.matcher(lore);
while (colorMatcher.find()) {
String colorCode = colorMatcher.group(1);
lore = lore.replaceAll("&" + colorCode, ChatColor.getByChar(colorCode).toString());
}
if (lore.contains("{name}")) {
lore = lore.replace("{name}", "");
return ChatColor.translateAlternateColorCodes('§', lore);
}
if (lore.contains("{kills}")) {
lore = lore.replace("{kills}", "");
}
if (lore.contains("{blocks}")) {
lore = lore.replace("{blocks}", "");
}
if (lore.contains("{sheep}")) {
lore = lore.replace("{sheep}", "");
}
if (lore.contains("{damage}")) {
lore = lore.replace("{damage}", "");
}
if (lore.contains("{fish}")) {
lore = lore.replace("{fish}", "");
}
if (lore.contains("{crops}")) {
lore = lore.replace("{crops}", "");
}
if (lore.contains("{arrows}")) {
lore = lore.replace("{arrows}", "");
}
}
return lore;
/**
* Remove all color codes from a message.
*
* @param message The message.
* @return The message without color codes.
*/
public String removeColor(String message) {
message = MINECRAFT_HEX_PATTERN.matcher(message).replaceAll("");
message = COLOR_CODES.matcher(message).replaceAll("");
message = CONFIG_HEX_PATTERN.matcher(message).replaceAll("");
return message;
}
}

View File

@@ -36,6 +36,7 @@ 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;
public class ConfigUpdater {
@@ -49,9 +50,16 @@ public class ConfigUpdater {
int version = toolStats.config.getInt("config-version");
// this will be a switch in the future
// Upgrade 5 to 6
if (version == 5) {
Version6 version6 = new Version6(toolStats);
version6.update();
}
// Upgrade 6 to 7
if (version == 6) {
Version7 version7 = new Version7(toolStats);
version7.update();
}
}
}

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-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 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 5 has been saved as config-6.yml");
}
}

View File

@@ -81,6 +81,7 @@ enabled:
dropped-by: true
elytra-tag: true
arrows-shot: true
flight-time: true
messages:
created:
@@ -110,6 +111,7 @@ messages:
dropped-by: "&7Dropped by: &8{name}" # name will be player/mob name
damage-taken: "&7Damage taken: &8{damage}"
arrows-shot: "&7Arrows shot: &8{arrows}"
flight-time: "&7Flight time: &8{time}"
# Display this message if the player shift click trades/crafts items. It's not really easy to get every single item
# that is crafted. The tag will only be added to the first item. If you don't want this message, simply replace them both with ""
shift-click-warning:
@@ -134,4 +136,4 @@ number-formats:
# This has no use currently, but can be used for future features for dupe detection.
generate-hash-for-items: true
config-version: 6
config-version: 7