mirror of
https://github.com/hyperdefined/ToolStats.git
synced 2025-12-06 06:41:44 +00:00
Compare commits
28 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
50b5823daf | ||
|
|
c87d0ca3bf | ||
|
|
d1a16ff2e6 | ||
|
|
9134da31f4 | ||
|
|
0cf85edda6 | ||
|
|
7fe0234785 | ||
|
|
6385814b52 | ||
|
|
603e1ac1fd | ||
|
|
86dc5f421a | ||
|
|
7d9be0cfd1 | ||
|
|
f7bacec617 | ||
|
|
227723fe10 | ||
|
|
785333e8d1 | ||
|
|
bc784b8d46 | ||
|
|
f5ddada892 | ||
|
|
a43155b0c5 | ||
|
|
e327d132e2 | ||
|
|
f09f2d3703 | ||
|
|
e9782c2985 | ||
|
|
b596310bfe | ||
|
|
6d1f0fe561 | ||
|
|
fb0d179d37 | ||
|
|
e8ab578eef | ||
|
|
57be2371e1 | ||
|
|
f3732a4eea | ||
|
|
7e13159056 | ||
|
|
7cdb8d55b5 | ||
|
|
368e59b1e1 |
@@ -6,6 +6,7 @@
|
||||
<a href="https://github.com/hyperdefined/ToolStats/releases"><img src="https://img.shields.io/github/downloads/hyperdefined/ToolStats/total?logo=github" alt="Downloads"></a>
|
||||
<img src="https://img.shields.io/badge/made%20with-love%20&%20fluff-red" alt="Made with love & fluff">
|
||||
<a href="https://ko-fi.com/hyperdefined"><img src="https://img.shields.io/badge/Donate-Ko--fi-red" alt="Donate via Ko-fi"></a>
|
||||
<img alt="Discord" src="https://img.shields.io/discord/1267600843356639413?style=flat&logo=discord&label=Discord">
|
||||
<a href="https://www.gnu.org/licenses/gpl-3.0"><img src="https://img.shields.io/badge/License-GPLv3-blue.svg" alt="License: GPL v3"></a>
|
||||
<a href="https://wakatime.com/badge/user/992a7647-176a-477c-8086-e1abfba87ff4/project/0200f07a-f303-4103-a5f2-34b38c9c1fa4"><img src="https://wakatime.com/badge/user/992a7647-176a-477c-8086-e1abfba87ff4/project/0200f07a-f303-4103-a5f2-34b38c9c1fa4.svg" alt="wakatime"></a>
|
||||
</p>
|
||||
@@ -42,5 +43,8 @@ If item lore is ever incorrect/missing, you can run `/toolstats reset`. This com
|
||||
## Documentation
|
||||
Visit the [wiki](https://github.com/hyperdefined/ToolStats/wiki) for help.
|
||||
|
||||
## Support
|
||||
You can join the [Discord](https://discord.gg/rJuQXVcJz8) for support.
|
||||
|
||||
## License
|
||||
This plugin is released under GNU General Public License v3. See [LICENSE](https://github.com/hyperdefined/ToolStats/blob/master/LICENSE).
|
||||
|
||||
12
pom.xml
12
pom.xml
@@ -23,7 +23,7 @@
|
||||
|
||||
<groupId>lol.hyper</groupId>
|
||||
<artifactId>toolstats</artifactId>
|
||||
<version>1.7.3</version>
|
||||
<version>1.8.3</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>ToolStats</name>
|
||||
@@ -123,7 +123,7 @@
|
||||
<dependency>
|
||||
<groupId>org.bstats</groupId>
|
||||
<artifactId>bstats-bukkit</artifactId>
|
||||
<version>3.0.2</version>
|
||||
<version>3.1.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@@ -141,7 +141,7 @@
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-platform-bukkit</artifactId>
|
||||
<version>4.3.3</version>
|
||||
<version>4.3.4</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@@ -150,5 +150,11 @@
|
||||
<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>
|
||||
|
||||
@@ -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 = 8;
|
||||
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);
|
||||
|
||||
|
||||
@@ -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()));
|
||||
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))));
|
||||
}
|
||||
}
|
||||
finalMeta.setLore(lore);
|
||||
finalItem.setItemMeta(finalMeta);
|
||||
int slot = player.getInventory().getHeldItemSlot();
|
||||
player.getInventory().setItem(slot, finalItem);
|
||||
return;
|
||||
Long flightTime = null;
|
||||
Long timeCreated = null;
|
||||
if (container.has(toolStats.timeCreated, PersistentDataType.LONG)) {
|
||||
timeCreated = container.get(toolStats.timeCreated, PersistentDataType.LONG);
|
||||
}
|
||||
if (container.has(toolStats.flightTime, PersistentDataType.LONG)) {
|
||||
flightTime = container.get(toolStats.flightTime, PersistentDataType.LONG);
|
||||
}
|
||||
|
||||
if (flightTime != null) {
|
||||
if (toolStats.config.getBoolean("enabled.flight-time")) {
|
||||
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);
|
||||
}
|
||||
|
||||
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)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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, EntityDamageEvent.DamageCause.KILL);
|
||||
private final List<String> ignoredDamageCauses = Arrays.asList("SUICIDE", "VOID", "CUSTOM", "KILL");
|
||||
|
||||
public EntityDamage(ToolStats toolStats) {
|
||||
this.toolStats = toolStats;
|
||||
@@ -57,8 +57,8 @@ public class EntityDamage implements Listener {
|
||||
LivingEntity mobBeingAttacked = (LivingEntity) event.getEntity();
|
||||
|
||||
// ignore void and /kill damage
|
||||
EntityDamageEvent.DamageCause cause = event.getCause();
|
||||
if (ignoredCauses.contains(cause)) {
|
||||
String cause = event.getCause().toString().toUpperCase();
|
||||
if (ignoredDamageCauses.contains(cause)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -166,8 +166,8 @@ public class EntityDamage implements Listener {
|
||||
}
|
||||
|
||||
// ignore void and /kill damage
|
||||
EntityDamageEvent.DamageCause cause = event.getCause();
|
||||
if (ignoredCauses.contains(cause)) {
|
||||
String cause = event.getCause().toString().toUpperCase();
|
||||
if (ignoredDamageCauses.contains(cause)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -196,8 +196,8 @@ public class EntityDamage implements Listener {
|
||||
}
|
||||
|
||||
// ignore void and /kill damage
|
||||
EntityDamageEvent.DamageCause cause = event.getCause();
|
||||
if (ignoredCauses.contains(cause)) {
|
||||
String cause = event.getCause().toString().toUpperCase();
|
||||
if (ignoredDamageCauses.contains(cause)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
@@ -314,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);
|
||||
@@ -349,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);
|
||||
@@ -385,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);
|
||||
|
||||
@@ -29,7 +29,8 @@ 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 {
|
||||
|
||||
@@ -53,13 +54,13 @@ public class EntityDeath implements Listener {
|
||||
ItemMeta droppedItemMeta = droppedItem.getItemMeta();
|
||||
if (droppedItemMeta != null) {
|
||||
PersistentDataContainer container = droppedItemMeta.getPersistentDataContainer();
|
||||
if (container.has(toolStats.timeCreated, PersistentDataType.LONG)) {
|
||||
if (container.has(toolStats.originType, PersistentDataType.INTEGER)) {
|
||||
continue; // ignore any items that have our tags
|
||||
}
|
||||
|
||||
}
|
||||
if (toolStats.itemChecker.isValidItem(droppedItem.getType())) {
|
||||
ItemStack newItem = addLore(droppedItem, livingEntity.getName());
|
||||
ItemStack newItem = addLore(droppedItem, livingEntity);
|
||||
if (newItem != null) {
|
||||
event.getDrops().set(i, newItem);
|
||||
}
|
||||
@@ -73,9 +74,9 @@ public class EntityDeath implements Listener {
|
||||
* Adds "drop by" tag to item.
|
||||
*
|
||||
* @param oldItem The item to add lore to.
|
||||
* @param mob The mob or player name.
|
||||
* @param entity The mob dying.
|
||||
*/
|
||||
private ItemStack addLore(ItemStack oldItem, String mob) {
|
||||
private ItemStack addLore(ItemStack oldItem, LivingEntity entity) {
|
||||
ItemStack newItem = oldItem.clone();
|
||||
ItemMeta meta = newItem.getItemMeta();
|
||||
if (meta == null) {
|
||||
@@ -86,7 +87,12 @@ 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 mobName = toolStats.config.getString("messages.mob." + entity.getType());
|
||||
if (mobName == null) {
|
||||
mobName = entity.getName();
|
||||
}
|
||||
String newLine = toolStats.configTools.formatLore("dropped-by", "{name}", mobName);
|
||||
List<String> newLore = toolStats.itemLore.addItemLore(meta, newLine);
|
||||
meta.setLore(newLore);
|
||||
}
|
||||
newItem.setItemMeta(meta);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
107
src/main/java/lol/hyper/toolstats/events/PlayerMove.java
Normal file
107
src/main/java/lol/hyper/toolstats/events/PlayerMove.java
Normal 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);
|
||||
}
|
||||
}
|
||||
@@ -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,8 +58,23 @@ public class SheepShear implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
// make sure the player is holding shears
|
||||
// player can shear with their offhand
|
||||
ItemStack shears = getShears(player);
|
||||
// player swapped items?
|
||||
if (shears == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// make sure the sheep is not sheared
|
||||
Sheep sheep = (Sheep) entity;
|
||||
if (sheep.isSheared()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// update the stats
|
||||
addLore(shears);
|
||||
}
|
||||
|
||||
private static @Nullable ItemStack getShears(Player player) {
|
||||
PlayerInventory inventory = player.getInventory();
|
||||
boolean isMainHand = inventory.getItemInMainHand().getType() == Material.SHEARS;
|
||||
boolean isOffHand = inventory.getItemInOffHand().getType() == Material.SHEARS;
|
||||
@@ -70,26 +86,12 @@ public class SheepShear implements Listener {
|
||||
shears = inventory.getItemInOffHand();
|
||||
}
|
||||
|
||||
// if the player is hold fishing rods in both hands
|
||||
// if the player is hold shears in both hands
|
||||
// default to main hand since that takes priority
|
||||
if (isMainHand && isOffHand) {
|
||||
shears = inventory.getItemInMainHand();
|
||||
}
|
||||
|
||||
// player swapped items?
|
||||
if (shears == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Sheep sheep = (Sheep) entity;
|
||||
// make sure the sheep is not sheared
|
||||
if (sheep.isSheared()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// update the stats
|
||||
ItemStack finalShears = shears;
|
||||
addLore(finalShears);
|
||||
return shears;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -114,12 +116,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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -47,6 +47,9 @@ public class ItemChecker {
|
||||
if (lowerCase.contains("_helmet") || lowerCase.contains("_chestplate") || lowerCase.contains("_leggings") || lowerCase.contains("_boots")) {
|
||||
armorItems.add(material);
|
||||
}
|
||||
if (lowerCase.equalsIgnoreCase("mace")) {
|
||||
meleeItems.add(material);
|
||||
}
|
||||
}
|
||||
|
||||
// hardcode these
|
||||
@@ -55,6 +58,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);
|
||||
|
||||
@@ -18,9 +18,6 @@
|
||||
package lol.hyper.toolstats.tools;
|
||||
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.meta.Damageable;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
@@ -37,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 = ChatColor.stripColor(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;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -109,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!");
|
||||
@@ -125,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!");
|
||||
@@ -141,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!");
|
||||
@@ -157,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!");
|
||||
@@ -173,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!");
|
||||
@@ -206,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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
@@ -96,6 +99,9 @@ public class ConfigTools {
|
||||
case "fishing-rod": {
|
||||
return toolStats.config.getBoolean("enabled." + configName + ".fishing-rod");
|
||||
}
|
||||
case "mace": {
|
||||
return toolStats.config.getBoolean("enabled." + configName + ".mace");
|
||||
}
|
||||
case "helmet":
|
||||
case "chestplate":
|
||||
case "leggings":
|
||||
@@ -107,56 +113,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}", "");
|
||||
}
|
||||
if (lore.contains("{date}")) {
|
||||
lore = lore.replace("{date}", "");
|
||||
}
|
||||
if (lore.contains("{name}")) {
|
||||
lore = lore.replace("{name}", "");
|
||||
}
|
||||
if (lore.contains("{kills}")) {
|
||||
lore = lore.replace("{kills}", "");
|
||||
}
|
||||
if (lore.contains("{blocks}")) {
|
||||
lore = lore.replace("{blocks}", "");
|
||||
}
|
||||
if (lore.contains("{sheep}")) {
|
||||
lore = lore.replace("{sheep}", "");
|
||||
}
|
||||
if (lore.contains("{damage}")) {
|
||||
lore = lore.replace("{damage}", "");
|
||||
}
|
||||
if (lore.contains("{fish}")) {
|
||||
lore = lore.replace("{fish}", "");
|
||||
}
|
||||
if (lore.contains("{crops}")) {
|
||||
lore = lore.replace("{crops}", "");
|
||||
}
|
||||
if (lore.contains("{arrows}")) {
|
||||
lore = lore.replace("{arrows}", "");
|
||||
}
|
||||
|
||||
// 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());
|
||||
}
|
||||
return lore;
|
||||
|
||||
Matcher colorMatcher = COLOR_CODES.matcher(lore);
|
||||
while (colorMatcher.find()) {
|
||||
String colorCode = colorMatcher.group(1);
|
||||
lore = lore.replaceAll("&" + colorCode, ChatColor.getByChar(colorCode).toString());
|
||||
}
|
||||
|
||||
return ChatColor.translateAlternateColorCodes('§', 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,8 @@ package lol.hyper.toolstats.tools.config;
|
||||
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import lol.hyper.toolstats.tools.config.versions.Version6;
|
||||
import lol.hyper.toolstats.tools.config.versions.Version7;
|
||||
import lol.hyper.toolstats.tools.config.versions.Version8;
|
||||
|
||||
public class ConfigUpdater {
|
||||
|
||||
@@ -48,10 +50,25 @@ public class ConfigUpdater {
|
||||
public void updateConfig() {
|
||||
int version = toolStats.config.getInt("config-version");
|
||||
|
||||
// this will be a switch in the future
|
||||
if (version == 5) {
|
||||
Version6 version6 = new Version6(toolStats);
|
||||
version6.update();
|
||||
switch(version) {
|
||||
case 5: {
|
||||
// Version 5 to 6
|
||||
Version6 version6 = new Version6(toolStats);
|
||||
version6.update();
|
||||
break;
|
||||
}
|
||||
case 6: {
|
||||
// Version 6 to 7
|
||||
Version7 version7 = new Version7(toolStats);
|
||||
version7.update();
|
||||
break;
|
||||
}
|
||||
case 7: {
|
||||
// Version 7 to 8
|
||||
Version8 version8 = new Version8(toolStats);
|
||||
version8.update();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* This file is part of ToolStats.
|
||||
*
|
||||
* ToolStats is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* ToolStats is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with ToolStats. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package lol.hyper.toolstats.tools.config.versions;
|
||||
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class Version7 {
|
||||
|
||||
private final ToolStats toolStats;
|
||||
|
||||
/**
|
||||
* Used for updating from version 6 to 7.
|
||||
*
|
||||
* @param toolStats ToolStats instance.
|
||||
*/
|
||||
public Version7(ToolStats toolStats) {
|
||||
this.toolStats = toolStats;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform the config update.
|
||||
*/
|
||||
public void update() {
|
||||
// save the old config first
|
||||
try {
|
||||
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config-6.yml");
|
||||
} catch (IOException exception) {
|
||||
toolStats.logger.severe("Unable to save config-6.yml!");
|
||||
throw new RuntimeException(exception);
|
||||
}
|
||||
|
||||
// we make this super verbose so that admins can see what's being added
|
||||
toolStats.logger.info("Updating config.yml to version 7.");
|
||||
toolStats.config.set("config-version", 7);
|
||||
|
||||
toolStats.logger.info("Adding messages.flight-time to config.yml.");
|
||||
toolStats.config.set("messages.flight-time", "&7Flight time: &8{time}");
|
||||
|
||||
toolStats.logger.info("Adding enabled.flight-time to config.yml.");
|
||||
toolStats.config.set("enabled.flight-time", true);
|
||||
|
||||
// save the config and reload it
|
||||
try {
|
||||
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config.yml");
|
||||
} catch (IOException exception) {
|
||||
toolStats.logger.severe("Unable to save config.yml!");
|
||||
throw new RuntimeException(exception);
|
||||
}
|
||||
toolStats.loadConfig();
|
||||
toolStats.logger.info("Config has been updated to version 7. A copy of version 6 has been saved as config-6.yml");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* This file is part of ToolStats.
|
||||
*
|
||||
* ToolStats is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* ToolStats is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with ToolStats. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package lol.hyper.toolstats.tools.config.versions;
|
||||
|
||||
import lol.hyper.toolstats.ToolStats;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Version8 {
|
||||
|
||||
private final ToolStats toolStats;
|
||||
|
||||
/**
|
||||
* Used for updating from version 7 to 8.
|
||||
*
|
||||
* @param toolStats ToolStats instance.
|
||||
*/
|
||||
public Version8(ToolStats toolStats) {
|
||||
this.toolStats = toolStats;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform the config update.
|
||||
*/
|
||||
public void update() {
|
||||
// save the old config first
|
||||
try {
|
||||
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config-7.yml");
|
||||
} catch (IOException exception) {
|
||||
toolStats.logger.severe("Unable to save config-7.yml!");
|
||||
throw new RuntimeException(exception);
|
||||
}
|
||||
|
||||
// we make this super verbose so that admins can see what's being added
|
||||
toolStats.logger.info("Updating config.yml to version 8.");
|
||||
toolStats.config.set("config-version", 8);
|
||||
|
||||
// Add example to setting mob names
|
||||
toolStats.logger.info("Adding example for messages.mob.ZOMBIE");
|
||||
toolStats.config.set("messages.mob.ZOMBIE", "Zombie");
|
||||
|
||||
// Add mace to enabled sections
|
||||
toolStats.logger.info("Adding entry for enabled.created-by.mace");
|
||||
toolStats.config.set("enabled.created-by.mace", true);
|
||||
|
||||
toolStats.logger.info("Adding entry for enabled.created-date.mace");
|
||||
toolStats.config.set("enabled.created-date.mace", true);
|
||||
|
||||
toolStats.logger.info("Adding entry for enabled.player-kills.mace");
|
||||
toolStats.config.set("enabled.player-kills.mace", true);
|
||||
|
||||
toolStats.logger.info("Adding entry for enabled.mob-kills.mace");
|
||||
toolStats.config.set("enabled.mob-kills.mace", true);
|
||||
|
||||
List<String> mobComments = new ArrayList<>();
|
||||
mobComments.add("Set display name for mobs. See: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/entity/EntityType.html");
|
||||
toolStats.config.setComments("messages.mob", mobComments);
|
||||
|
||||
// save the config and reload it
|
||||
try {
|
||||
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config.yml");
|
||||
} catch (IOException exception) {
|
||||
toolStats.logger.severe("Unable to save config.yml!");
|
||||
throw new RuntimeException(exception);
|
||||
}
|
||||
toolStats.loadConfig();
|
||||
toolStats.logger.info("Config has been updated to version 8. A copy of version 7 has been saved as config-7.yml");
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ enabled:
|
||||
shears: true
|
||||
bow: true
|
||||
armor: true
|
||||
mace: true
|
||||
# Will show time the item is created
|
||||
created-date:
|
||||
pickaxe: true
|
||||
@@ -19,6 +20,7 @@ enabled:
|
||||
shears: true
|
||||
bow: true
|
||||
armor: true
|
||||
mace: true
|
||||
# Will show "Fished by <player>"
|
||||
fished-tag:
|
||||
pickaxe: true
|
||||
@@ -54,11 +56,13 @@ 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
|
||||
@@ -75,12 +79,14 @@ enabled:
|
||||
shears: true
|
||||
bow: true
|
||||
armor: true
|
||||
mace: true
|
||||
fish-caught: true
|
||||
sheep-sheared: true
|
||||
armor-damage: true
|
||||
dropped-by: true
|
||||
elytra-tag: true
|
||||
arrows-shot: true
|
||||
flight-time: true
|
||||
|
||||
messages:
|
||||
created:
|
||||
@@ -110,11 +116,15 @@ 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:
|
||||
crafting: "&cCrafting items via shift clicking does not fully apply tags to each item. This is a limitation with the Bukkit API."
|
||||
trading: "&cTrading items via shift clicking does not fully apply tags to each item. This is a limitation with the Bukkit API."
|
||||
# Set display name for mobs. See: https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/entity/EntityType.html
|
||||
mobs:
|
||||
ZOMBIE: "Zombie"
|
||||
|
||||
# Change the default formatting for dates.
|
||||
# See: https://www.digitalocean.com/community/tutorials/java-simpledateformat-java-date-format
|
||||
@@ -134,4 +144,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
|
||||
Reference in New Issue
Block a user