mirror of
https://github.com/hyperdefined/ToolStats.git
synced 2025-12-07 21:25:00 +00:00
Compare commits
12 Commits
1.9
...
1.9.2-hotf
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
eeb6038b66 | ||
|
|
5e3e9f0825 | ||
|
|
11ee83773e | ||
|
|
9f5da738dd | ||
|
|
434f0dfe30 | ||
|
|
06a3bb2498 | ||
|
|
5624c02ee2 | ||
|
|
3e1c2dcbc3 | ||
|
|
8a1759b6b1 | ||
|
|
b4be9eb741 | ||
|
|
7a18649474 | ||
|
|
32f1e78630 |
2
pom.xml
2
pom.xml
@@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
<groupId>lol.hyper</groupId>
|
<groupId>lol.hyper</groupId>
|
||||||
<artifactId>toolstats</artifactId>
|
<artifactId>toolstats</artifactId>
|
||||||
<version>1.9</version>
|
<version>1.9.2-hotfix</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>ToolStats</name>
|
<name>ToolStats</name>
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ public final class ToolStats extends JavaPlugin {
|
|||||||
*/
|
*/
|
||||||
public final NamespacedKey originType = new NamespacedKey(this, "origin");
|
public final NamespacedKey originType = new NamespacedKey(this, "origin");
|
||||||
|
|
||||||
public final int CONFIG_VERSION = 9;
|
public final int CONFIG_VERSION = 10;
|
||||||
public final Logger logger = this.getLogger();
|
public final Logger logger = this.getLogger();
|
||||||
public final File configFile = new File(this.getDataFolder(), "config.yml");
|
public final File configFile = new File(this.getDataFolder(), "config.yml");
|
||||||
public boolean tokens = false;
|
public boolean tokens = false;
|
||||||
|
|||||||
@@ -184,39 +184,84 @@ public class AnvilEvent implements Listener {
|
|||||||
ItemStack newItem = toolStats.itemChecker.addToken(firstSlotItem, targetToken);
|
ItemStack newItem = toolStats.itemChecker.addToken(firstSlotItem, targetToken);
|
||||||
switch (targetToken) {
|
switch (targetToken) {
|
||||||
case "crops-mined": {
|
case "crops-mined": {
|
||||||
|
if (toolStats.config.getBoolean("enabled.crops-harvested")) {
|
||||||
newItem.setItemMeta(toolStats.itemLore.updateCropsMined(newItem, 0));
|
newItem.setItemMeta(toolStats.itemLore.updateCropsMined(newItem, 0));
|
||||||
|
} else {
|
||||||
|
event.setResult(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "blocks-mined": {
|
case "blocks-mined": {
|
||||||
|
if (toolStats.configTools.checkConfig(newItem.getType(), "blocks-mined")) {
|
||||||
newItem.setItemMeta(toolStats.itemLore.updateBlocksMined(newItem, 0));
|
newItem.setItemMeta(toolStats.itemLore.updateBlocksMined(newItem, 0));
|
||||||
|
} else {
|
||||||
|
event.setResult(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "damage-taken": {
|
case "damage-taken": {
|
||||||
|
if (toolStats.config.getBoolean("enabled.armor-damage")) {
|
||||||
newItem.setItemMeta(toolStats.itemLore.updateDamage(newItem, 0.0, false));
|
newItem.setItemMeta(toolStats.itemLore.updateDamage(newItem, 0.0, false));
|
||||||
|
} else {
|
||||||
|
event.setResult(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "mob-kills": {
|
case "mob-kills": {
|
||||||
|
if (toolStats.configTools.checkConfig(newItem.getType(), "mob-kills")) {
|
||||||
newItem.setItemMeta(toolStats.itemLore.updateMobKills(newItem, 0));
|
newItem.setItemMeta(toolStats.itemLore.updateMobKills(newItem, 0));
|
||||||
|
} else {
|
||||||
|
event.setResult(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "player-kills": {
|
case "player-kills": {
|
||||||
|
if (toolStats.configTools.checkConfig(newItem.getType(), "player-kills")) {
|
||||||
newItem.setItemMeta(toolStats.itemLore.updatePlayerKills(newItem, 0));
|
newItem.setItemMeta(toolStats.itemLore.updatePlayerKills(newItem, 0));
|
||||||
|
} else {
|
||||||
|
event.setResult(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "arrows-shot": {
|
case "arrows-shot": {
|
||||||
|
if (toolStats.config.getBoolean("enabled.arrows-shot")) {
|
||||||
newItem.setItemMeta(toolStats.itemLore.updateArrowsShot(newItem, 0));
|
newItem.setItemMeta(toolStats.itemLore.updateArrowsShot(newItem, 0));
|
||||||
|
} else {
|
||||||
|
event.setResult(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "sheep-sheared": {
|
case "sheep-sheared": {
|
||||||
|
if (toolStats.config.getBoolean("enabled.sheep-sheared")) {
|
||||||
newItem.setItemMeta(toolStats.itemLore.updateSheepSheared(newItem, 0));
|
newItem.setItemMeta(toolStats.itemLore.updateSheepSheared(newItem, 0));
|
||||||
|
} else {
|
||||||
|
event.setResult(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "flight-time": {
|
case "flight-time": {
|
||||||
|
if (toolStats.config.getBoolean("enabled.flight-time")) {
|
||||||
newItem.setItemMeta(toolStats.itemLore.updateFlightTime(newItem, 0));
|
newItem.setItemMeta(toolStats.itemLore.updateFlightTime(newItem, 0));
|
||||||
|
} else {
|
||||||
|
event.setResult(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "fish-caught": {
|
case "fish-caught": {
|
||||||
|
if (toolStats.config.getBoolean("enabled.fish-caught")) {
|
||||||
newItem.setItemMeta(toolStats.itemLore.updateFishCaught(newItem, 0));
|
newItem.setItemMeta(toolStats.itemLore.updateFishCaught(newItem, 0));
|
||||||
|
} else {
|
||||||
|
event.setResult(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ public class CraftItem implements Listener {
|
|||||||
// if the slot was empty before we crafted, this means we just made it
|
// if the slot was empty before we crafted, this means we just made it
|
||||||
if (oldSlotItem == null) {
|
if (oldSlotItem == null) {
|
||||||
// add the lore
|
// add the lore
|
||||||
ItemStack newItem = addLore(newSlotItem, player);
|
ItemStack newItem = addCraftOrigin(newSlotItem, player);
|
||||||
if (newItem != null) {
|
if (newItem != null) {
|
||||||
player.getInventory().setItem(i, newItem);
|
player.getInventory().setItem(i, newItem);
|
||||||
}
|
}
|
||||||
@@ -97,7 +97,7 @@ public class CraftItem implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// the player did not shift click
|
// the player did not shift click
|
||||||
ItemStack newItem = addLore(craftedItem, player);
|
ItemStack newItem = addCraftOrigin(craftedItem, player);
|
||||||
if (newItem != null) {
|
if (newItem != null) {
|
||||||
// set the result
|
// set the result
|
||||||
event.setCurrentItem(newItem);
|
event.setCurrentItem(newItem);
|
||||||
@@ -111,7 +111,7 @@ public class CraftItem implements Listener {
|
|||||||
* @param owner The player crafting.
|
* @param owner The player crafting.
|
||||||
* @return A copy of the item with the tags + lore.
|
* @return A copy of the item with the tags + lore.
|
||||||
*/
|
*/
|
||||||
private ItemStack addLore(ItemStack itemStack, Player owner) {
|
private ItemStack addCraftOrigin(ItemStack itemStack, Player owner) {
|
||||||
// clone the item
|
// clone the item
|
||||||
ItemStack newItem = itemStack.clone();
|
ItemStack newItem = itemStack.clone();
|
||||||
ItemMeta meta = newItem.getItemMeta();
|
ItemMeta meta = newItem.getItemMeta();
|
||||||
@@ -130,25 +130,19 @@ public class CraftItem implements Listener {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// only make the hash if it's enabled
|
|
||||||
if (toolStats.config.getBoolean("generate-hash-for-items")) {
|
|
||||||
String hash = toolStats.hashMaker.makeHash(newItem.getType(), owner.getUniqueId(), timeCreated);
|
|
||||||
container.set(toolStats.hash, PersistentDataType.STRING, hash);
|
|
||||||
}
|
|
||||||
|
|
||||||
container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated);
|
|
||||||
container.set(toolStats.itemOwner, new UUIDDataType(), owner.getUniqueId());
|
|
||||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 0);
|
|
||||||
|
|
||||||
List<Component> lore;
|
|
||||||
// get the current lore the item
|
// get the current lore the item
|
||||||
|
List<Component> lore;
|
||||||
if (meta.hasLore()) {
|
if (meta.hasLore()) {
|
||||||
lore = meta.lore();
|
lore = meta.lore();
|
||||||
} else {
|
} else {
|
||||||
lore = new ArrayList<>();
|
lore = new ArrayList<>();
|
||||||
}
|
}
|
||||||
// do we add the lore based on the config?
|
|
||||||
|
// if creation date is enabled, add it
|
||||||
if (toolStats.configTools.checkConfig(itemStack.getType(), "created-date")) {
|
if (toolStats.configTools.checkConfig(itemStack.getType(), "created-date")) {
|
||||||
|
container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated);
|
||||||
|
container.set(toolStats.originType, PersistentDataType.INTEGER, 0);
|
||||||
|
|
||||||
String date = toolStats.numberFormat.formatDate(finalDate);
|
String date = toolStats.numberFormat.formatDate(finalDate);
|
||||||
Component newLine = toolStats.configTools.formatLore("created.created-on", "{date}", date);
|
Component newLine = toolStats.configTools.formatLore("created.created-on", "{date}", date);
|
||||||
if (newLine == null) {
|
if (newLine == null) {
|
||||||
@@ -157,7 +151,12 @@ public class CraftItem implements Listener {
|
|||||||
lore.add(newLine);
|
lore.add(newLine);
|
||||||
meta.lore(lore);
|
meta.lore(lore);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if creation owner is enabled, add it
|
||||||
if (toolStats.configTools.checkConfig(itemStack.getType(), "created-by")) {
|
if (toolStats.configTools.checkConfig(itemStack.getType(), "created-by")) {
|
||||||
|
container.set(toolStats.itemOwner, new UUIDDataType(), owner.getUniqueId());
|
||||||
|
container.set(toolStats.originType, PersistentDataType.INTEGER, 0);
|
||||||
|
|
||||||
Component newLine = toolStats.configTools.formatLore("created.created-by", "{player}", owner.getName());
|
Component newLine = toolStats.configTools.formatLore("created.created-by", "{player}", owner.getName());
|
||||||
if (newLine == null) {
|
if (newLine == null) {
|
||||||
return null;
|
return null;
|
||||||
@@ -165,6 +164,12 @@ public class CraftItem implements Listener {
|
|||||||
lore.add(newLine);
|
lore.add(newLine);
|
||||||
meta.lore(lore);
|
meta.lore(lore);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if hash is enabled, add it
|
||||||
|
if (toolStats.config.getBoolean("generate-hash-for-items")) {
|
||||||
|
String hash = toolStats.hashMaker.makeHash(newItem.getType(), owner.getUniqueId(), timeCreated);
|
||||||
|
container.set(toolStats.hash, PersistentDataType.STRING, hash);
|
||||||
|
}
|
||||||
newItem.setItemMeta(meta);
|
newItem.setItemMeta(meta);
|
||||||
return newItem;
|
return newItem;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,50 +65,53 @@ public class CreativeEvent implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// add the tags to the item
|
// add the tags to the item
|
||||||
ItemStack newItem = addLore(spawnedItem, player);
|
ItemStack newItem = addCreativeOrigin(spawnedItem, player);
|
||||||
if (newItem != null) {
|
if (newItem != null) {
|
||||||
event.setCursor(newItem);
|
event.setCursor(newItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds tags to newly spawned items in creative.
|
* Adds spawned in tags to item.
|
||||||
*
|
*
|
||||||
* @param spawnedItem The item.
|
* @param itemStack The item add item to.
|
||||||
|
* @param owner The player spawning in.
|
||||||
|
* @return A copy of the item with the tags + lore.
|
||||||
*/
|
*/
|
||||||
private ItemStack addLore(ItemStack spawnedItem, Player owner) {
|
private ItemStack addCreativeOrigin(ItemStack itemStack, Player owner) {
|
||||||
ItemStack newSpawnedItem = spawnedItem.clone();
|
ItemStack newSpawnedItem = itemStack.clone();
|
||||||
ItemMeta meta = newSpawnedItem.getItemMeta();
|
ItemMeta meta = newSpawnedItem.getItemMeta();
|
||||||
if (meta == null) {
|
if (meta == null) {
|
||||||
toolStats.logger.warning(newSpawnedItem + " does NOT have any meta! Unable to update stats.");
|
toolStats.logger.warning(itemStack + " does NOT have any meta! Unable to update stats.");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
// get the current time
|
||||||
long timeCreated = System.currentTimeMillis();
|
long timeCreated = System.currentTimeMillis();
|
||||||
Date finalDate = new Date(timeCreated);
|
Date finalDate = new Date(timeCreated);
|
||||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||||
|
|
||||||
// if the item already has an origin set, don't add it again
|
// if the item already has the tag
|
||||||
if (container.has(toolStats.originType, PersistentDataType.INTEGER)) {
|
// this is to prevent duplicate tags
|
||||||
|
if (container.has(toolStats.timeCreated, PersistentDataType.LONG) || container.has(toolStats.itemOwner, PersistentDataType.LONG)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// only make the hash if it's enabled
|
// if hash is enabled, add it
|
||||||
if (toolStats.config.getBoolean("generate-hash-for-items")) {
|
if (toolStats.config.getBoolean("generate-hash-for-items")) {
|
||||||
String hash = toolStats.hashMaker.makeHash(spawnedItem.getType(), owner.getUniqueId(), timeCreated);
|
String hash = toolStats.hashMaker.makeHash(newSpawnedItem.getType(), owner.getUniqueId(), timeCreated);
|
||||||
container.set(toolStats.hash, PersistentDataType.STRING, hash);
|
container.set(toolStats.hash, PersistentDataType.STRING, hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if spawned in is enabled, add it
|
||||||
|
if (toolStats.configTools.checkConfig(newSpawnedItem.getType(), "spawned-in")) {
|
||||||
container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated);
|
container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated);
|
||||||
container.set(toolStats.itemOwner, new UUIDDataType(), owner.getUniqueId());
|
container.set(toolStats.itemOwner, new UUIDDataType(), owner.getUniqueId());
|
||||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 6);
|
container.set(toolStats.originType, PersistentDataType.INTEGER, 6);
|
||||||
|
|
||||||
if (toolStats.configTools.checkConfig(newSpawnedItem.getType(), "spawned-in")) {
|
|
||||||
String formattedDate = toolStats.numberFormat.formatDate(finalDate);
|
String formattedDate = toolStats.numberFormat.formatDate(finalDate);
|
||||||
List<Component> newLore = toolStats.itemLore.addNewOwner(meta, owner.getName(), formattedDate);
|
List<Component> newLore = toolStats.itemLore.addNewOwner(meta, owner.getName(), formattedDate);
|
||||||
meta.lore(newLore);
|
meta.lore(newLore);
|
||||||
}
|
}
|
||||||
|
|
||||||
newSpawnedItem.setItemMeta(meta);
|
newSpawnedItem.setItemMeta(meta);
|
||||||
return newSpawnedItem;
|
return newSpawnedItem;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,10 +84,12 @@ public class EntityDeath implements Listener {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!toolStats.config.getBoolean("enabled.dropped-by")) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 1);
|
container.set(toolStats.originType, PersistentDataType.INTEGER, 1);
|
||||||
|
|
||||||
if (toolStats.config.getBoolean("enabled.dropped-by")) {
|
|
||||||
String mobName = toolStats.config.getString("messages.mob." + entity.getType());
|
String mobName = toolStats.config.getString("messages.mob." + entity.getType());
|
||||||
if (mobName == null) {
|
if (mobName == null) {
|
||||||
mobName = entity.getName();
|
mobName = entity.getName();
|
||||||
@@ -95,7 +97,6 @@ public class EntityDeath implements Listener {
|
|||||||
Component newLine = toolStats.configTools.formatLore("dropped-by", "{name}", mobName);
|
Component newLine = toolStats.configTools.formatLore("dropped-by", "{name}", mobName);
|
||||||
List<Component> newLore = toolStats.itemLore.addItemLore(meta, newLine);
|
List<Component> newLore = toolStats.itemLore.addItemLore(meta, newLine);
|
||||||
meta.lore(newLore);
|
meta.lore(newLore);
|
||||||
}
|
|
||||||
newItem.setItemMeta(meta);
|
newItem.setItemMeta(meta);
|
||||||
return newItem;
|
return newItem;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ public class GenerateLoot implements Listener {
|
|||||||
* @param owner The player that found the item.
|
* @param owner The player that found the item.
|
||||||
* @return The item with the lore.
|
* @return The item with the lore.
|
||||||
*/
|
*/
|
||||||
private ItemStack addLore(ItemStack itemStack, Player owner) {
|
private ItemStack addLootedOrigin(ItemStack itemStack, Player owner) {
|
||||||
ItemStack newItem = itemStack.clone();
|
ItemStack newItem = itemStack.clone();
|
||||||
ItemMeta meta = itemStack.getItemMeta();
|
ItemMeta meta = itemStack.getItemMeta();
|
||||||
if (meta == null) {
|
if (meta == null) {
|
||||||
@@ -102,6 +102,10 @@ public class GenerateLoot implements Listener {
|
|||||||
Date finalDate = new Date(timeCreated);
|
Date finalDate = new Date(timeCreated);
|
||||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||||
|
|
||||||
|
if (!toolStats.configTools.checkConfig(newItem.getType(), "looted-tag")) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
if (container.has(toolStats.timeCreated, PersistentDataType.LONG) || container.has(toolStats.itemOwner, PersistentDataType.LONG)) {
|
if (container.has(toolStats.timeCreated, PersistentDataType.LONG) || container.has(toolStats.itemOwner, PersistentDataType.LONG)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -115,12 +119,9 @@ public class GenerateLoot implements Listener {
|
|||||||
container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated);
|
container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated);
|
||||||
container.set(toolStats.itemOwner, new UUIDDataType(), owner.getUniqueId());
|
container.set(toolStats.itemOwner, new UUIDDataType(), owner.getUniqueId());
|
||||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 2);
|
container.set(toolStats.originType, PersistentDataType.INTEGER, 2);
|
||||||
|
|
||||||
if (toolStats.configTools.checkConfig(newItem.getType(), "looted-tag")) {
|
|
||||||
String formattedDate = toolStats.numberFormat.formatDate(finalDate);
|
String formattedDate = toolStats.numberFormat.formatDate(finalDate);
|
||||||
List<Component> newLore = toolStats.itemLore.addNewOwner(meta, owner.getName(), formattedDate);
|
List<Component> newLore = toolStats.itemLore.addNewOwner(meta, owner.getName(), formattedDate);
|
||||||
meta.lore(newLore);
|
meta.lore(newLore);
|
||||||
}
|
|
||||||
newItem.setItemMeta(meta);
|
newItem.setItemMeta(meta);
|
||||||
return newItem;
|
return newItem;
|
||||||
}
|
}
|
||||||
@@ -139,7 +140,7 @@ public class GenerateLoot implements Listener {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (toolStats.itemChecker.isValidItem(itemStack.getType())) {
|
if (toolStats.itemChecker.isValidItem(itemStack.getType())) {
|
||||||
ItemStack newItem = addLore(itemStack, player);
|
ItemStack newItem = addLootedOrigin(itemStack, player);
|
||||||
if (newItem != null) {
|
if (newItem != null) {
|
||||||
loot.set(i, newItem);
|
loot.set(i, newItem);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,8 +19,7 @@ package lol.hyper.toolstats.events;
|
|||||||
|
|
||||||
import lol.hyper.toolstats.ToolStats;
|
import lol.hyper.toolstats.ToolStats;
|
||||||
import lol.hyper.toolstats.tools.UUIDDataType;
|
import lol.hyper.toolstats.tools.UUIDDataType;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.inventory.InventoryOpenEvent;
|
import org.bukkit.event.inventory.InventoryOpenEvent;
|
||||||
@@ -47,7 +46,7 @@ public class InventoryOpen implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Inventory inventory = event.getInventory();
|
Inventory inventory = event.getInventory();
|
||||||
Location location = event.getInventory().getLocation();
|
Player player = (Player) event.getPlayer();
|
||||||
for (ItemStack itemStack : inventory) {
|
for (ItemStack itemStack : inventory) {
|
||||||
if (itemStack == null) {
|
if (itemStack == null) {
|
||||||
continue;
|
continue;
|
||||||
@@ -75,31 +74,35 @@ public class InventoryOpen implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// generate a hash if the item doesn't have one (if it's enabled in the config)
|
// generate a hash if the item doesn't have one (and enabled)
|
||||||
|
// if hashes are disabled and the item has one, remove it.
|
||||||
if (toolStats.config.getBoolean("generate-hash-for-items")) {
|
if (toolStats.config.getBoolean("generate-hash-for-items")) {
|
||||||
if (!container.has(toolStats.hash, PersistentDataType.STRING)) {
|
if (!container.has(toolStats.hash, PersistentDataType.STRING)) {
|
||||||
// make sure the item has an owner
|
UUID owner = null;
|
||||||
if (!container.has(toolStats.itemOwner, new UUIDDataType())) {
|
// get the current owner if there is one.
|
||||||
continue;
|
if (container.has(toolStats.itemOwner, new UUIDDataType())) {
|
||||||
|
owner = container.get(toolStats.itemOwner, new UUIDDataType());
|
||||||
}
|
}
|
||||||
UUID owner = container.get(toolStats.itemOwner, new UUIDDataType());
|
// if there is no owner, use the player holding it
|
||||||
if (owner == null) {
|
if (owner == null) {
|
||||||
continue;
|
owner = player.getUniqueId();
|
||||||
}
|
}
|
||||||
Long timestamp = container.get(toolStats.timeCreated, PersistentDataType.LONG);
|
Long timestamp = container.get(toolStats.timeCreated, PersistentDataType.LONG);
|
||||||
if (timestamp == null) {
|
if (timestamp == null) {
|
||||||
continue;
|
// if there is no time created, use now
|
||||||
|
timestamp = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
String hash = toolStats.hashMaker.makeHash(itemStack.getType(), owner, timestamp);
|
String hash = toolStats.hashMaker.makeHash(itemStack.getType(), owner, timestamp);
|
||||||
container.set(toolStats.hash, PersistentDataType.STRING, hash);
|
container.set(toolStats.hash, PersistentDataType.STRING, hash);
|
||||||
|
itemStack.setItemMeta(itemMeta);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// if hashes are disabled but the item has one, remove it.
|
||||||
|
if (container.has(toolStats.hash, PersistentDataType.STRING)) {
|
||||||
|
container.remove(toolStats.hash);
|
||||||
|
itemStack.setItemMeta(itemMeta);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
ItemMeta clone = itemMeta.clone();
|
|
||||||
if (location != null) {
|
|
||||||
Bukkit.getRegionScheduler().runDelayed(toolStats, location, scheduledTask -> itemStack.setItemMeta(clone), 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,10 @@ import lol.hyper.toolstats.tools.UUIDDataType;
|
|||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.*;
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.entity.EntityType;
|
||||||
|
import org.bukkit.entity.Item;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
@@ -64,7 +67,7 @@ public class PickupItem implements Listener {
|
|||||||
if (itemStack.getType() == Material.ELYTRA) {
|
if (itemStack.getType() == Material.ELYTRA) {
|
||||||
// the elytra has the new key, set the lore to it
|
// the elytra has the new key, set the lore to it
|
||||||
if (container.has(toolStats.newElytra, PersistentDataType.INTEGER)) {
|
if (container.has(toolStats.newElytra, PersistentDataType.INTEGER)) {
|
||||||
ItemStack newElytra = addLore(itemStack, (Player) event.getEntity());
|
ItemStack newElytra = addElytraOrigin(itemStack, (Player) event.getEntity());
|
||||||
if (newElytra != null) {
|
if (newElytra != null) {
|
||||||
item.setItemStack(newElytra);
|
item.setItemStack(newElytra);
|
||||||
}
|
}
|
||||||
@@ -80,7 +83,7 @@ public class PickupItem implements Listener {
|
|||||||
* @param itemStack The elytra to add lore to.
|
* @param itemStack The elytra to add lore to.
|
||||||
* @param owner The player who found it.
|
* @param owner The player who found it.
|
||||||
*/
|
*/
|
||||||
private ItemStack addLore(ItemStack itemStack, Player owner) {
|
private ItemStack addElytraOrigin(ItemStack itemStack, Player owner) {
|
||||||
ItemStack finalItem = itemStack.clone();
|
ItemStack finalItem = itemStack.clone();
|
||||||
ItemMeta meta = finalItem.getItemMeta();
|
ItemMeta meta = finalItem.getItemMeta();
|
||||||
if (meta == null) {
|
if (meta == null) {
|
||||||
@@ -90,6 +93,10 @@ public class PickupItem implements Listener {
|
|||||||
Date finalDate = new Date(timeCreated);
|
Date finalDate = new Date(timeCreated);
|
||||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||||
|
|
||||||
|
if (!toolStats.config.getBoolean("enabled.elytra-tag")) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// only make the hash if it's enabled
|
// only make the hash if it's enabled
|
||||||
if (toolStats.config.getBoolean("generate-hash-for-items")) {
|
if (toolStats.config.getBoolean("generate-hash-for-items")) {
|
||||||
String hash = toolStats.hashMaker.makeHash(finalItem.getType(), owner.getUniqueId(), timeCreated);
|
String hash = toolStats.hashMaker.makeHash(finalItem.getType(), owner.getUniqueId(), timeCreated);
|
||||||
@@ -100,12 +107,9 @@ public class PickupItem implements Listener {
|
|||||||
container.set(toolStats.itemOwner, new UUIDDataType(), owner.getUniqueId());
|
container.set(toolStats.itemOwner, new UUIDDataType(), owner.getUniqueId());
|
||||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 4);
|
container.set(toolStats.originType, PersistentDataType.INTEGER, 4);
|
||||||
container.remove(toolStats.newElytra);
|
container.remove(toolStats.newElytra);
|
||||||
|
|
||||||
if (toolStats.config.getBoolean("enabled.elytra-tag")) {
|
|
||||||
String formattedDate = toolStats.numberFormat.formatDate(finalDate);
|
String formattedDate = toolStats.numberFormat.formatDate(finalDate);
|
||||||
List<Component> newLore = toolStats.itemLore.addNewOwner(meta, owner.getName(), formattedDate);
|
List<Component> newLore = toolStats.itemLore.addNewOwner(meta, owner.getName(), formattedDate);
|
||||||
meta.lore(newLore);
|
meta.lore(newLore);
|
||||||
}
|
|
||||||
finalItem.setItemMeta(meta);
|
finalItem.setItemMeta(meta);
|
||||||
return finalItem;
|
return finalItem;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,10 +72,11 @@ public class PlayerFish implements Listener {
|
|||||||
PlayerInventory inventory = player.getInventory();
|
PlayerInventory inventory = player.getInventory();
|
||||||
boolean isMain = inventory.getItemInMainHand().getType() == Material.FISHING_ROD;
|
boolean isMain = inventory.getItemInMainHand().getType() == Material.FISHING_ROD;
|
||||||
boolean isOffHand = inventory.getItemInOffHand().getType() == Material.FISHING_ROD;
|
boolean isOffHand = inventory.getItemInOffHand().getType() == Material.FISHING_ROD;
|
||||||
if (isMain) {
|
if (isMain && isOffHand) {
|
||||||
inventory.getItemInMainHand().setItemMeta(newFishingRod);
|
inventory.getItemInMainHand().setItemMeta(newFishingRod);
|
||||||
}
|
} else if (isMain) {
|
||||||
if (isOffHand) {
|
inventory.getItemInMainHand().setItemMeta(newFishingRod);
|
||||||
|
} else if (isOffHand) {
|
||||||
inventory.getItemInOffHand().setItemMeta(newFishingRod);
|
inventory.getItemInOffHand().setItemMeta(newFishingRod);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -111,22 +112,26 @@ public class PlayerFish implements Listener {
|
|||||||
Date finalDate = new Date(timeCreated);
|
Date finalDate = new Date(timeCreated);
|
||||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||||
|
|
||||||
|
if (!toolStats.configTools.checkConfig(newItem.getType(), "fished-tag")) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
if (container.has(toolStats.timeCreated, PersistentDataType.LONG) || container.has(toolStats.itemOwner, PersistentDataType.LONG)) {
|
if (container.has(toolStats.timeCreated, PersistentDataType.LONG) || container.has(toolStats.itemOwner, PersistentDataType.LONG)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// only make the hash if it's enabled
|
||||||
|
if (toolStats.config.getBoolean("generate-hash-for-items")) {
|
||||||
String hash = toolStats.hashMaker.makeHash(newItem.getType(), owner.getUniqueId(), timeCreated);
|
String hash = toolStats.hashMaker.makeHash(newItem.getType(), owner.getUniqueId(), timeCreated);
|
||||||
|
|
||||||
container.set(toolStats.hash, PersistentDataType.STRING, hash);
|
container.set(toolStats.hash, PersistentDataType.STRING, hash);
|
||||||
|
}
|
||||||
|
|
||||||
container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated);
|
container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated);
|
||||||
container.set(toolStats.itemOwner, new UUIDDataType(), owner.getUniqueId());
|
container.set(toolStats.itemOwner, new UUIDDataType(), owner.getUniqueId());
|
||||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 5);
|
container.set(toolStats.originType, PersistentDataType.INTEGER, 5);
|
||||||
|
|
||||||
if (toolStats.configTools.checkConfig(newItem.getType(), "fished-tag")) {
|
|
||||||
String formattedDate = toolStats.numberFormat.formatDate(finalDate);
|
String formattedDate = toolStats.numberFormat.formatDate(finalDate);
|
||||||
List<Component> newLore = toolStats.itemLore.addNewOwner(meta, owner.getName(), formattedDate);
|
List<Component> newLore = toolStats.itemLore.addNewOwner(meta, owner.getName(), formattedDate);
|
||||||
meta.lore(newLore);
|
meta.lore(newLore);
|
||||||
}
|
|
||||||
newItem.setItemMeta(meta);
|
newItem.setItemMeta(meta);
|
||||||
return newItem;
|
return newItem;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,24 +72,33 @@ public class PlayerJoin implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// generate a hash if the item doesn't have one
|
// generate a hash if the item doesn't have one
|
||||||
|
if (toolStats.config.getBoolean("generate-hash-for-items")) {
|
||||||
if (!container.has(toolStats.hash, PersistentDataType.STRING)) {
|
if (!container.has(toolStats.hash, PersistentDataType.STRING)) {
|
||||||
// make sure the item has an owner
|
UUID owner = null;
|
||||||
if (!container.has(toolStats.itemOwner, new UUIDDataType())) {
|
// get the current owner if there is one.
|
||||||
continue;
|
if (container.has(toolStats.itemOwner, new UUIDDataType())) {
|
||||||
|
owner = container.get(toolStats.itemOwner, new UUIDDataType());
|
||||||
}
|
}
|
||||||
UUID owner = container.get(toolStats.itemOwner, new UUIDDataType());
|
// if there is no owner, use the player holding it
|
||||||
if (owner == null) {
|
if (owner == null) {
|
||||||
continue;
|
owner = player.getUniqueId();
|
||||||
}
|
}
|
||||||
Long timestamp = container.get(toolStats.timeCreated, PersistentDataType.LONG);
|
Long timestamp = container.get(toolStats.timeCreated, PersistentDataType.LONG);
|
||||||
if (timestamp == null) {
|
if (timestamp == null) {
|
||||||
continue;
|
// if there is no time created, use now
|
||||||
|
timestamp = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
String hash = toolStats.hashMaker.makeHash(itemStack.getType(), owner, timestamp);
|
String hash = toolStats.hashMaker.makeHash(itemStack.getType(), owner, timestamp);
|
||||||
container.set(toolStats.hash, PersistentDataType.STRING, hash);
|
container.set(toolStats.hash, PersistentDataType.STRING, hash);
|
||||||
|
itemStack.setItemMeta(itemMeta);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// if hashes are disabled but the item has one, remove it.
|
||||||
|
if (container.has(toolStats.hash, PersistentDataType.STRING)) {
|
||||||
|
container.remove(toolStats.hash);
|
||||||
|
itemStack.setItemMeta(itemMeta);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ItemMeta clone = itemMeta.clone();
|
|
||||||
player.getScheduler().runDelayed(toolStats, scheduledTask -> itemStack.setItemMeta(clone), null, 1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,16 +65,17 @@ public class SheepShear implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// update the stats
|
// update the stats
|
||||||
ItemMeta newItem = toolStats.itemLore.updateSheepSheared(heldShears, 1);
|
ItemMeta newShears = toolStats.itemLore.updateSheepSheared(heldShears, 1);
|
||||||
if (newItem != null) {
|
if (newShears != null) {
|
||||||
PlayerInventory inventory = player.getInventory();
|
PlayerInventory inventory = player.getInventory();
|
||||||
boolean isMain = inventory.getItemInMainHand().getType() == Material.SHEARS;
|
boolean isMain = inventory.getItemInMainHand().getType() == Material.SHEARS;
|
||||||
boolean isOffHand = inventory.getItemInOffHand().getType() == Material.SHEARS;
|
boolean isOffHand = inventory.getItemInOffHand().getType() == Material.SHEARS;
|
||||||
if (isMain) {
|
if (isMain && isOffHand) {
|
||||||
inventory.getItemInMainHand().setItemMeta(newItem);
|
inventory.getItemInMainHand().setItemMeta(newShears);
|
||||||
}
|
} else if (isMain) {
|
||||||
if (isOffHand) {
|
inventory.getItemInMainHand().setItemMeta(newShears);
|
||||||
inventory.getItemInOffHand().setItemMeta(newItem);
|
} else if (isOffHand) {
|
||||||
|
inventory.getItemInOffHand().setItemMeta(newShears);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,16 +56,17 @@ public class ShootBow implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemMeta newItem = toolStats.itemLore.updateArrowsShot(heldBow, 1);
|
ItemMeta newBow = toolStats.itemLore.updateArrowsShot(heldBow, 1);
|
||||||
if (newItem != null) {
|
if (newBow != null) {
|
||||||
PlayerInventory inventory = player.getInventory();
|
PlayerInventory inventory = player.getInventory();
|
||||||
boolean isMain = inventory.getItemInMainHand().getType() == Material.BOW || inventory.getItemInMainHand().getType() == Material.CROSSBOW;
|
boolean isMain = inventory.getItemInMainHand().getType() == Material.BOW || inventory.getItemInMainHand().getType() == Material.CROSSBOW;
|
||||||
boolean isOffHand = inventory.getItemInOffHand().getType() == Material.BOW || inventory.getItemInOffHand().getType() == Material.CROSSBOW;
|
boolean isOffHand = inventory.getItemInOffHand().getType() == Material.BOW || inventory.getItemInOffHand().getType() == Material.CROSSBOW;
|
||||||
if (isMain) {
|
if (isMain && isOffHand) {
|
||||||
inventory.getItemInMainHand().setItemMeta(newItem);
|
inventory.getItemInMainHand().setItemMeta(newBow);
|
||||||
}
|
} else if (isMain) {
|
||||||
if (isOffHand) {
|
inventory.getItemInMainHand().setItemMeta(newBow);
|
||||||
inventory.getItemInOffHand().setItemMeta(newItem);
|
} else if (isOffHand) {
|
||||||
|
inventory.getItemInOffHand().setItemMeta(newBow);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ public class VillagerTrade implements Listener {
|
|||||||
// if the slot was empty before we traded, this means we just traded it
|
// if the slot was empty before we traded, this means we just traded it
|
||||||
if (oldSlotItem == null) {
|
if (oldSlotItem == null) {
|
||||||
// add the lore
|
// add the lore
|
||||||
ItemStack newItem = addLore(newSlotItem, player);
|
ItemStack newItem = addTradeOrigin(newSlotItem, player);
|
||||||
if (newItem != null) {
|
if (newItem != null) {
|
||||||
player.getInventory().setItem(i, newItem);
|
player.getInventory().setItem(i, newItem);
|
||||||
}
|
}
|
||||||
@@ -104,7 +104,7 @@ public class VillagerTrade implements Listener {
|
|||||||
}, null, 1);
|
}, null, 1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ItemStack newItem = addLore(tradedItem, player);
|
ItemStack newItem = addTradeOrigin(tradedItem, player);
|
||||||
if (newItem != null) {
|
if (newItem != null) {
|
||||||
// set the new item
|
// set the new item
|
||||||
inventory.setItem(event.getSlot(), newItem);
|
inventory.setItem(event.getSlot(), newItem);
|
||||||
@@ -118,7 +118,7 @@ public class VillagerTrade implements Listener {
|
|||||||
* @param owner The player who traded.
|
* @param owner The player who traded.
|
||||||
* @return The item with lore.
|
* @return The item with lore.
|
||||||
*/
|
*/
|
||||||
private ItemStack addLore(ItemStack oldItem, Player owner) {
|
private ItemStack addTradeOrigin(ItemStack oldItem, Player owner) {
|
||||||
ItemStack newItem = oldItem.clone();
|
ItemStack newItem = oldItem.clone();
|
||||||
ItemMeta meta = newItem.getItemMeta();
|
ItemMeta meta = newItem.getItemMeta();
|
||||||
if (meta == null) {
|
if (meta == null) {
|
||||||
@@ -133,6 +133,10 @@ public class VillagerTrade implements Listener {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!toolStats.configTools.checkConfig(newItem.getType(), "traded-tag")) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// only make the hash if it's enabled
|
// only make the hash if it's enabled
|
||||||
if (toolStats.config.getBoolean("generate-hash-for-items")) {
|
if (toolStats.config.getBoolean("generate-hash-for-items")) {
|
||||||
String hash = toolStats.hashMaker.makeHash(newItem.getType(), owner.getUniqueId(), timeCreated);
|
String hash = toolStats.hashMaker.makeHash(newItem.getType(), owner.getUniqueId(), timeCreated);
|
||||||
@@ -142,12 +146,9 @@ public class VillagerTrade implements Listener {
|
|||||||
container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated);
|
container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated);
|
||||||
container.set(toolStats.itemOwner, new UUIDDataType(), owner.getUniqueId());
|
container.set(toolStats.itemOwner, new UUIDDataType(), owner.getUniqueId());
|
||||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 3);
|
container.set(toolStats.originType, PersistentDataType.INTEGER, 3);
|
||||||
|
|
||||||
if (toolStats.configTools.checkConfig(newItem.getType(), "traded-tag")) {
|
|
||||||
String formattedDate = toolStats.numberFormat.formatDate(finalDate);
|
String formattedDate = toolStats.numberFormat.formatDate(finalDate);
|
||||||
List<Component> newLore = toolStats.itemLore.addNewOwner(meta, owner.getName(), formattedDate);
|
List<Component> newLore = toolStats.itemLore.addNewOwner(meta, owner.getName(), formattedDate);
|
||||||
meta.lore(newLore);
|
meta.lore(newLore);
|
||||||
}
|
|
||||||
newItem.setItemMeta(meta);
|
newItem.setItemMeta(meta);
|
||||||
return newItem;
|
return newItem;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -220,6 +220,9 @@ public class ItemChecker {
|
|||||||
// if the player is holding a bow in their main hand, use that one
|
// if the player is holding a bow in their main hand, use that one
|
||||||
// if the bow is in their offhand instead, use that one after checking main hand
|
// if the bow is in their offhand instead, use that one after checking main hand
|
||||||
// Minecraft prioritizes main hand if the player holds in both hands
|
// Minecraft prioritizes main hand if the player holds in both hands
|
||||||
|
if (isMain && isOffHand) {
|
||||||
|
return main;
|
||||||
|
}
|
||||||
if (isMain) {
|
if (isMain) {
|
||||||
return main;
|
return main;
|
||||||
}
|
}
|
||||||
@@ -246,6 +249,9 @@ public class ItemChecker {
|
|||||||
// if the player is holding shears in their main hand, use that one
|
// if the player is holding shears in their main hand, use that one
|
||||||
// if the shears are in their offhand instead, use that one after checking main hand
|
// if the shears are in their offhand instead, use that one after checking main hand
|
||||||
// Minecraft prioritizes main hand if the player holds in both hands
|
// Minecraft prioritizes main hand if the player holds in both hands
|
||||||
|
if (isMain && isOffHand) {
|
||||||
|
return main;
|
||||||
|
}
|
||||||
if (isMain) {
|
if (isMain) {
|
||||||
return main;
|
return main;
|
||||||
}
|
}
|
||||||
@@ -272,6 +278,9 @@ public class ItemChecker {
|
|||||||
// if the player is holding a fishing rod in their main hand, use that one
|
// if the player is holding a fishing rod in their main hand, use that one
|
||||||
// if the fishing rod is in their offhand instead, use that one after checking main hand
|
// if the fishing rod is in their offhand instead, use that one after checking main hand
|
||||||
// Minecraft prioritizes main hand if the player holds in both hands
|
// Minecraft prioritizes main hand if the player holds in both hands
|
||||||
|
if (isMain && isOffHand) {
|
||||||
|
return main;
|
||||||
|
}
|
||||||
if (isMain) {
|
if (isMain) {
|
||||||
return main;
|
return main;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,6 +88,19 @@ public class ItemLore {
|
|||||||
return itemLore;
|
return itemLore;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a given lore from an item.
|
||||||
|
*
|
||||||
|
* @param inputLore The item's lore.
|
||||||
|
* @param toRemove The line to remove.
|
||||||
|
* @return The lore with the line removed.
|
||||||
|
*/
|
||||||
|
public List<Component> removeLore(List<Component> inputLore, Component toRemove) {
|
||||||
|
List<Component> newLore = new ArrayList<>(inputLore);
|
||||||
|
newLore.removeIf(line -> PlainTextComponentSerializer.plainText().serialize(line).equals(PlainTextComponentSerializer.plainText().serialize(toRemove)));
|
||||||
|
return newLore;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds new ownership to an item.
|
* Adds new ownership to an item.
|
||||||
*
|
*
|
||||||
@@ -229,6 +242,26 @@ public class ItemLore {
|
|||||||
// if they don't exist, then start from 0
|
// if they don't exist, then start from 0
|
||||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||||
|
|
||||||
|
// if it's disabled, don't update the stats
|
||||||
|
// check to see if the item has the stats, remove them if it does
|
||||||
|
if (!toolStats.config.getBoolean("enabled.crops-harvested")) {
|
||||||
|
if (container.has(toolStats.cropsHarvested)) {
|
||||||
|
Integer cropsMined = container.get(toolStats.cropsHarvested, PersistentDataType.INTEGER);
|
||||||
|
if (cropsMined == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
container.remove(toolStats.cropsHarvested);
|
||||||
|
if (meta.hasLore()) {
|
||||||
|
String oldCropsMinedFormatted = toolStats.numberFormat.formatInt(cropsMined);
|
||||||
|
Component lineToRemove = toolStats.configTools.formatLore("crops-harvested", "{crops}", oldCropsMinedFormatted);
|
||||||
|
List<Component> newLore = removeLore(meta.lore(), lineToRemove);
|
||||||
|
meta.lore(newLore);
|
||||||
|
}
|
||||||
|
return meta;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// check for tokens
|
// check for tokens
|
||||||
boolean validToken = toolStats.itemChecker.checkTokens(container, "crops-mined");
|
boolean validToken = toolStats.itemChecker.checkTokens(container, "crops-mined");
|
||||||
// check for tokens
|
// check for tokens
|
||||||
@@ -265,9 +298,6 @@ public class ItemLore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
container.set(toolStats.cropsHarvested, PersistentDataType.INTEGER, cropsMined + add);
|
container.set(toolStats.cropsHarvested, PersistentDataType.INTEGER, cropsMined + add);
|
||||||
|
|
||||||
// do we add the lore based on the config?
|
|
||||||
if (toolStats.configTools.checkConfig(clone.getType(), "blocks-mined")) {
|
|
||||||
String oldCropsMinedFormatted = toolStats.numberFormat.formatInt(cropsMined);
|
String oldCropsMinedFormatted = toolStats.numberFormat.formatInt(cropsMined);
|
||||||
String newCropsMinedFormatted = toolStats.numberFormat.formatInt(cropsMined + add);
|
String newCropsMinedFormatted = toolStats.numberFormat.formatInt(cropsMined + add);
|
||||||
Component oldLine = toolStats.configTools.formatLore("crops-harvested", "{crops}", oldCropsMinedFormatted);
|
Component oldLine = toolStats.configTools.formatLore("crops-harvested", "{crops}", oldCropsMinedFormatted);
|
||||||
@@ -277,7 +307,6 @@ public class ItemLore {
|
|||||||
}
|
}
|
||||||
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
||||||
meta.lore(newLore);
|
meta.lore(newLore);
|
||||||
}
|
|
||||||
return meta;
|
return meta;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -295,6 +324,27 @@ public class ItemLore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||||
|
|
||||||
|
// if it's disabled, don't update the stats
|
||||||
|
// check to see if the item has the stats, remove them if it does
|
||||||
|
if (!toolStats.configTools.checkConfig(clone.getType(), "blocks-mined")) {
|
||||||
|
if (container.has(toolStats.blocksMined)) {
|
||||||
|
Integer blocksMined = container.get(toolStats.blocksMined, PersistentDataType.INTEGER);
|
||||||
|
if (blocksMined == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
container.remove(toolStats.blocksMined);
|
||||||
|
if (meta.hasLore()) {
|
||||||
|
String oldBlocksMinedFormatted = toolStats.numberFormat.formatInt(blocksMined);
|
||||||
|
Component lineToRemove = toolStats.configTools.formatLore("blocks-mined", "{blocks}", oldBlocksMinedFormatted);
|
||||||
|
List<Component> newLore = removeLore(meta.lore(), lineToRemove);
|
||||||
|
meta.lore(newLore);
|
||||||
|
}
|
||||||
|
return meta;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
boolean validToken = toolStats.itemChecker.checkTokens(container, "blocks-mined");
|
boolean validToken = toolStats.itemChecker.checkTokens(container, "blocks-mined");
|
||||||
// check for tokens
|
// check for tokens
|
||||||
if (toolStats.config.getBoolean("tokens.enabled")) {
|
if (toolStats.config.getBoolean("tokens.enabled")) {
|
||||||
@@ -332,9 +382,6 @@ public class ItemLore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
container.set(toolStats.blocksMined, PersistentDataType.INTEGER, blocksMined + add);
|
container.set(toolStats.blocksMined, PersistentDataType.INTEGER, blocksMined + add);
|
||||||
|
|
||||||
// do we add the lore based on the config?
|
|
||||||
if (toolStats.configTools.checkConfig(clone.getType(), "blocks-mined")) {
|
|
||||||
String oldBlocksMinedFormatted = toolStats.numberFormat.formatInt(blocksMined);
|
String oldBlocksMinedFormatted = toolStats.numberFormat.formatInt(blocksMined);
|
||||||
String newBlocksMinedFormatted = toolStats.numberFormat.formatInt(blocksMined + add);
|
String newBlocksMinedFormatted = toolStats.numberFormat.formatInt(blocksMined + add);
|
||||||
Component oldLine = toolStats.configTools.formatLore("blocks-mined", "{blocks}", oldBlocksMinedFormatted);
|
Component oldLine = toolStats.configTools.formatLore("blocks-mined", "{blocks}", oldBlocksMinedFormatted);
|
||||||
@@ -344,7 +391,6 @@ public class ItemLore {
|
|||||||
}
|
}
|
||||||
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
||||||
meta.lore(newLore);
|
meta.lore(newLore);
|
||||||
}
|
|
||||||
return meta;
|
return meta;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -362,6 +408,27 @@ public class ItemLore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||||
|
|
||||||
|
// if it's disabled, don't update the stats
|
||||||
|
// check to see if the item has the stats, remove them if it does
|
||||||
|
if (!toolStats.configTools.checkConfig(clone.getType(), "player-kills")) {
|
||||||
|
if (container.has(toolStats.playerKills)) {
|
||||||
|
Integer playerKills = container.get(toolStats.playerKills, PersistentDataType.INTEGER);
|
||||||
|
if (playerKills == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
container.remove(toolStats.playerKills);
|
||||||
|
if (meta.hasLore()) {
|
||||||
|
String oldPlayerKillsFormatted = toolStats.numberFormat.formatInt(playerKills);
|
||||||
|
Component lineToRemove = toolStats.configTools.formatLore("player-kills", "{kills}", oldPlayerKillsFormatted);
|
||||||
|
List<Component> newLore = removeLore(meta.lore(), lineToRemove);
|
||||||
|
meta.lore(newLore);
|
||||||
|
}
|
||||||
|
return meta;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// check for tokens
|
// check for tokens
|
||||||
boolean validToken = toolStats.itemChecker.checkTokens(container, "player-kills");
|
boolean validToken = toolStats.itemChecker.checkTokens(container, "player-kills");
|
||||||
// check for tokens
|
// check for tokens
|
||||||
@@ -398,9 +465,6 @@ public class ItemLore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
container.set(toolStats.playerKills, PersistentDataType.INTEGER, playerKills + add);
|
container.set(toolStats.playerKills, PersistentDataType.INTEGER, playerKills + add);
|
||||||
|
|
||||||
// do we add the lore based on the config?
|
|
||||||
if (toolStats.configTools.checkConfig(clone.getType(), "player-kills")) {
|
|
||||||
String oldPlayerKillsFormatted = toolStats.numberFormat.formatInt(playerKills);
|
String oldPlayerKillsFormatted = toolStats.numberFormat.formatInt(playerKills);
|
||||||
String newPlayerKillsFormatted = toolStats.numberFormat.formatInt(playerKills + add);
|
String newPlayerKillsFormatted = toolStats.numberFormat.formatInt(playerKills + add);
|
||||||
Component oldLine = toolStats.configTools.formatLore("kills.player", "{kills}", oldPlayerKillsFormatted);
|
Component oldLine = toolStats.configTools.formatLore("kills.player", "{kills}", oldPlayerKillsFormatted);
|
||||||
@@ -410,7 +474,6 @@ public class ItemLore {
|
|||||||
}
|
}
|
||||||
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
||||||
meta.lore(newLore);
|
meta.lore(newLore);
|
||||||
}
|
|
||||||
return meta;
|
return meta;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -428,6 +491,27 @@ public class ItemLore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||||
|
|
||||||
|
// if it's disabled, don't update the stats
|
||||||
|
// check to see if the item has the stats, remove them if it does
|
||||||
|
if (!toolStats.configTools.checkConfig(clone.getType(), "mob-kills")) {
|
||||||
|
if (container.has(toolStats.mobKills)) {
|
||||||
|
Integer mobKills = container.get(toolStats.mobKills, PersistentDataType.INTEGER);
|
||||||
|
if (mobKills == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
container.remove(toolStats.mobKills);
|
||||||
|
if (meta.hasLore()) {
|
||||||
|
String oldMobKillsFormatted = toolStats.numberFormat.formatInt(mobKills);
|
||||||
|
Component lineToRemove = toolStats.configTools.formatLore("mob-kills", "{kills}", oldMobKillsFormatted);
|
||||||
|
List<Component> newLore = removeLore(meta.lore(), lineToRemove);
|
||||||
|
meta.lore(newLore);
|
||||||
|
}
|
||||||
|
return meta;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// check for tokens
|
// check for tokens
|
||||||
boolean validToken = toolStats.itemChecker.checkTokens(container, "mob-kills");
|
boolean validToken = toolStats.itemChecker.checkTokens(container, "mob-kills");
|
||||||
// check for tokens
|
// check for tokens
|
||||||
@@ -464,9 +548,6 @@ public class ItemLore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
container.set(toolStats.mobKills, PersistentDataType.INTEGER, mobKills + add);
|
container.set(toolStats.mobKills, PersistentDataType.INTEGER, mobKills + add);
|
||||||
|
|
||||||
// do we add the lore based on the config?
|
|
||||||
if (toolStats.configTools.checkConfig(clone.getType(), "mob-kills")) {
|
|
||||||
String oldMobKillsFormatted = toolStats.numberFormat.formatInt(mobKills);
|
String oldMobKillsFormatted = toolStats.numberFormat.formatInt(mobKills);
|
||||||
String newMobKillsFormatted = toolStats.numberFormat.formatInt(mobKills + add);
|
String newMobKillsFormatted = toolStats.numberFormat.formatInt(mobKills + add);
|
||||||
Component oldLine = toolStats.configTools.formatLore("kills.mob", "{kills}", oldMobKillsFormatted);
|
Component oldLine = toolStats.configTools.formatLore("kills.mob", "{kills}", oldMobKillsFormatted);
|
||||||
@@ -476,7 +557,6 @@ public class ItemLore {
|
|||||||
}
|
}
|
||||||
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
||||||
meta.lore(newLore);
|
meta.lore(newLore);
|
||||||
}
|
|
||||||
return meta;
|
return meta;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -502,6 +582,27 @@ public class ItemLore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||||
|
|
||||||
|
// if it's disabled, don't update the stats
|
||||||
|
// check to see if the item has the stats, remove them if it does
|
||||||
|
if (!toolStats.config.getBoolean("enabled.armor-damage")) {
|
||||||
|
if (container.has(toolStats.armorDamage)) {
|
||||||
|
Double armorDamage = container.get(toolStats.armorDamage, PersistentDataType.DOUBLE);
|
||||||
|
if (armorDamage == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
container.remove(toolStats.armorDamage);
|
||||||
|
if (meta.hasLore()) {
|
||||||
|
String oldDamageTakenFormatted = toolStats.numberFormat.formatDouble(armorDamage);
|
||||||
|
Component lineToRemove = toolStats.configTools.formatLore("damage-taken", "{damage}", oldDamageTakenFormatted);
|
||||||
|
List<Component> newLore = removeLore(meta.lore(), lineToRemove);
|
||||||
|
meta.lore(newLore);
|
||||||
|
}
|
||||||
|
return meta;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// check for tokens
|
// check for tokens
|
||||||
boolean validToken = toolStats.itemChecker.checkTokens(container, "damage-taken");
|
boolean validToken = toolStats.itemChecker.checkTokens(container, "damage-taken");
|
||||||
// check for tokens
|
// check for tokens
|
||||||
@@ -538,8 +639,6 @@ public class ItemLore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
container.set(toolStats.armorDamage, PersistentDataType.DOUBLE, damageTaken + damage);
|
container.set(toolStats.armorDamage, PersistentDataType.DOUBLE, damageTaken + damage);
|
||||||
|
|
||||||
if (toolStats.config.getBoolean("enabled.armor-damage")) {
|
|
||||||
String oldDamageFormatted = toolStats.numberFormat.formatDouble(damageTaken);
|
String oldDamageFormatted = toolStats.numberFormat.formatDouble(damageTaken);
|
||||||
String newDamageFormatted = toolStats.numberFormat.formatDouble(damageTaken + damage);
|
String newDamageFormatted = toolStats.numberFormat.formatDouble(damageTaken + damage);
|
||||||
Component oldLine = toolStats.configTools.formatLore("damage-taken", "{damage}", oldDamageFormatted);
|
Component oldLine = toolStats.configTools.formatLore("damage-taken", "{damage}", oldDamageFormatted);
|
||||||
@@ -549,7 +648,6 @@ public class ItemLore {
|
|||||||
}
|
}
|
||||||
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
||||||
meta.lore(newLore);
|
meta.lore(newLore);
|
||||||
}
|
|
||||||
return meta;
|
return meta;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -567,6 +665,27 @@ public class ItemLore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||||
|
|
||||||
|
// if it's disabled, don't update the stats
|
||||||
|
// check to see if the item has the stats, remove them if it does
|
||||||
|
if (!toolStats.config.getBoolean("enabled.flight-time")) {
|
||||||
|
if (container.has(toolStats.flightTime)) {
|
||||||
|
Long flightTime = container.get(toolStats.flightTime, PersistentDataType.LONG);
|
||||||
|
if (flightTime == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
container.remove(toolStats.flightTime);
|
||||||
|
if (meta.hasLore()) {
|
||||||
|
String oldFlightTimeFormatted = toolStats.numberFormat.formatDouble(flightTime);
|
||||||
|
Component lineToRemove = toolStats.configTools.formatLore("flight-time", "{time}", oldFlightTimeFormatted);
|
||||||
|
List<Component> newLore = removeLore(meta.lore(), lineToRemove);
|
||||||
|
meta.lore(newLore);
|
||||||
|
}
|
||||||
|
return meta;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// check for tokens
|
// check for tokens
|
||||||
boolean validToken = toolStats.itemChecker.checkTokens(container, "flight-time");
|
boolean validToken = toolStats.itemChecker.checkTokens(container, "flight-time");
|
||||||
// check for tokens
|
// check for tokens
|
||||||
@@ -605,9 +724,6 @@ public class ItemLore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
container.set(toolStats.flightTime, PersistentDataType.LONG, 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 oldFlightFormatted = toolStats.numberFormat.formatDouble((double) flightTime / 1000);
|
||||||
String newFlightFormatted = toolStats.numberFormat.formatDouble((double) (flightTime + duration) / 1000);
|
String newFlightFormatted = toolStats.numberFormat.formatDouble((double) (flightTime + duration) / 1000);
|
||||||
Component oldLine = toolStats.configTools.formatLore("flight-time", "{time}", oldFlightFormatted);
|
Component oldLine = toolStats.configTools.formatLore("flight-time", "{time}", oldFlightFormatted);
|
||||||
@@ -617,7 +733,6 @@ public class ItemLore {
|
|||||||
}
|
}
|
||||||
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
||||||
meta.lore(newLore);
|
meta.lore(newLore);
|
||||||
}
|
|
||||||
return meta;
|
return meta;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -635,6 +750,27 @@ public class ItemLore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||||
|
|
||||||
|
// if it's disabled, don't update the stats
|
||||||
|
// check to see if the item has the stats, remove them if it does
|
||||||
|
if (!toolStats.config.getBoolean("enabled.sheep-sheared")) {
|
||||||
|
if (container.has(toolStats.sheepSheared)) {
|
||||||
|
Integer sheepSheared = container.get(toolStats.sheepSheared, PersistentDataType.INTEGER);
|
||||||
|
if (sheepSheared == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
container.remove(toolStats.sheepSheared);
|
||||||
|
if (meta.hasLore()) {
|
||||||
|
String oldSheepShearedFormatted = toolStats.numberFormat.formatDouble(sheepSheared);
|
||||||
|
Component lineToRemove = toolStats.configTools.formatLore("sheep-sheared", "{sheep}", oldSheepShearedFormatted);
|
||||||
|
List<Component> newLore = removeLore(meta.lore(), lineToRemove);
|
||||||
|
meta.lore(newLore);
|
||||||
|
}
|
||||||
|
return meta;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// check for tokens
|
// check for tokens
|
||||||
boolean validToken = toolStats.itemChecker.checkTokens(container, "sheep-sheared");
|
boolean validToken = toolStats.itemChecker.checkTokens(container, "sheep-sheared");
|
||||||
// check for tokens
|
// check for tokens
|
||||||
@@ -671,8 +807,6 @@ public class ItemLore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
container.set(toolStats.sheepSheared, PersistentDataType.INTEGER, sheepSheared + add);
|
container.set(toolStats.sheepSheared, PersistentDataType.INTEGER, sheepSheared + add);
|
||||||
|
|
||||||
if (toolStats.config.getBoolean("enabled.sheep-sheared")) {
|
|
||||||
String oldSheepFormatted = toolStats.numberFormat.formatInt(sheepSheared);
|
String oldSheepFormatted = toolStats.numberFormat.formatInt(sheepSheared);
|
||||||
String newSheepFormatted = toolStats.numberFormat.formatInt(sheepSheared + add);
|
String newSheepFormatted = toolStats.numberFormat.formatInt(sheepSheared + add);
|
||||||
Component oldLine = toolStats.configTools.formatLore("sheep-sheared", "{sheep}", oldSheepFormatted);
|
Component oldLine = toolStats.configTools.formatLore("sheep-sheared", "{sheep}", oldSheepFormatted);
|
||||||
@@ -682,7 +816,6 @@ public class ItemLore {
|
|||||||
}
|
}
|
||||||
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
||||||
meta.lore(newLore);
|
meta.lore(newLore);
|
||||||
}
|
|
||||||
return meta;
|
return meta;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -700,6 +833,27 @@ public class ItemLore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||||
|
|
||||||
|
// if it's disabled, don't update the stats
|
||||||
|
// check to see if the item has the stats, remove them if it does
|
||||||
|
if (!toolStats.config.getBoolean("enabled.arrows-shot")) {
|
||||||
|
if (container.has(toolStats.arrowsShot)) {
|
||||||
|
Integer arrowsShot = container.get(toolStats.arrowsShot, PersistentDataType.INTEGER);
|
||||||
|
if (arrowsShot == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
container.remove(toolStats.arrowsShot);
|
||||||
|
if (meta.hasLore()) {
|
||||||
|
String oldArrowsShotFormatted = toolStats.numberFormat.formatDouble(arrowsShot);
|
||||||
|
Component lineToRemove = toolStats.configTools.formatLore("arrows-shot", "{arrows}", oldArrowsShotFormatted);
|
||||||
|
List<Component> newLore = removeLore(meta.lore(), lineToRemove);
|
||||||
|
meta.lore(newLore);
|
||||||
|
}
|
||||||
|
return meta;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// check for tokens
|
// check for tokens
|
||||||
boolean validToken = toolStats.itemChecker.checkTokens(container, "arrows-shot");
|
boolean validToken = toolStats.itemChecker.checkTokens(container, "arrows-shot");
|
||||||
// check for tokens
|
// check for tokens
|
||||||
@@ -738,9 +892,6 @@ public class ItemLore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
container.set(toolStats.arrowsShot, PersistentDataType.INTEGER, arrowsShot + add);
|
container.set(toolStats.arrowsShot, PersistentDataType.INTEGER, arrowsShot + add);
|
||||||
|
|
||||||
// do we add the lore based on the config?
|
|
||||||
if (toolStats.config.getBoolean("enabled.arrows-shot")) {
|
|
||||||
String oldArrowsFormatted = toolStats.numberFormat.formatInt(arrowsShot);
|
String oldArrowsFormatted = toolStats.numberFormat.formatInt(arrowsShot);
|
||||||
String newArrowsFormatted = toolStats.numberFormat.formatInt(arrowsShot + add);
|
String newArrowsFormatted = toolStats.numberFormat.formatInt(arrowsShot + add);
|
||||||
Component oldLine = toolStats.configTools.formatLore("arrows-shot", "{arrows}", oldArrowsFormatted);
|
Component oldLine = toolStats.configTools.formatLore("arrows-shot", "{arrows}", oldArrowsFormatted);
|
||||||
@@ -750,7 +901,6 @@ public class ItemLore {
|
|||||||
}
|
}
|
||||||
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
||||||
meta.lore(newLore);
|
meta.lore(newLore);
|
||||||
}
|
|
||||||
return meta;
|
return meta;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -768,6 +918,27 @@ public class ItemLore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||||
|
|
||||||
|
// if it's disabled, don't update the stats
|
||||||
|
// check to see if the item has the stats, remove them if it does
|
||||||
|
if (!toolStats.config.getBoolean("enabled.fish-caught")) {
|
||||||
|
if (container.has(toolStats.fishCaught)) {
|
||||||
|
Integer fishCaught = container.get(toolStats.fishCaught, PersistentDataType.INTEGER);
|
||||||
|
if (fishCaught == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
container.remove(toolStats.fishCaught);
|
||||||
|
if (meta.hasLore()) {
|
||||||
|
String oldFishCaught = toolStats.numberFormat.formatDouble(fishCaught);
|
||||||
|
Component lineToRemove = toolStats.configTools.formatLore("fished.fish-caught", "{fish}", oldFishCaught);
|
||||||
|
List<Component> newLore = removeLore(meta.lore(), lineToRemove);
|
||||||
|
meta.lore(newLore);
|
||||||
|
}
|
||||||
|
return meta;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// check for tokens
|
// check for tokens
|
||||||
boolean validToken = toolStats.itemChecker.checkTokens(container, "fish-caught");
|
boolean validToken = toolStats.itemChecker.checkTokens(container, "fish-caught");
|
||||||
// check for tokens
|
// check for tokens
|
||||||
@@ -804,8 +975,6 @@ public class ItemLore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
container.set(toolStats.fishCaught, PersistentDataType.INTEGER, fishCaught + add);
|
container.set(toolStats.fishCaught, PersistentDataType.INTEGER, fishCaught + add);
|
||||||
|
|
||||||
if (toolStats.config.getBoolean("enabled.fish-caught")) {
|
|
||||||
String oldFishFormatted = toolStats.numberFormat.formatInt(fishCaught);
|
String oldFishFormatted = toolStats.numberFormat.formatInt(fishCaught);
|
||||||
String newFishFormatted = toolStats.numberFormat.formatInt(fishCaught + add);
|
String newFishFormatted = toolStats.numberFormat.formatInt(fishCaught + add);
|
||||||
Component oldLine = toolStats.configTools.formatLore("fished.fish-caught", "{fish}", oldFishFormatted);
|
Component oldLine = toolStats.configTools.formatLore("fished.fish-caught", "{fish}", oldFishFormatted);
|
||||||
@@ -815,7 +984,6 @@ public class ItemLore {
|
|||||||
}
|
}
|
||||||
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
List<Component> newLore = toolStats.itemLore.updateItemLore(meta, oldLine, newLine);
|
||||||
meta.lore(newLore);
|
meta.lore(newLore);
|
||||||
}
|
|
||||||
return meta;
|
return meta;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ public class ConfigTools {
|
|||||||
*
|
*
|
||||||
* @param material The item type to check.
|
* @param material The item type to check.
|
||||||
* @param configName The config we are checking under.
|
* @param configName The config we are checking under.
|
||||||
* @return If we want to allow lore or not.
|
* @return If we want to add data or not.
|
||||||
*/
|
*/
|
||||||
public boolean checkConfig(Material material, String configName) {
|
public boolean checkConfig(Material material, String configName) {
|
||||||
String itemName = material.toString().toLowerCase();
|
String itemName = material.toString().toLowerCase();
|
||||||
|
|||||||
@@ -18,10 +18,7 @@
|
|||||||
package lol.hyper.toolstats.tools.config;
|
package lol.hyper.toolstats.tools.config;
|
||||||
|
|
||||||
import lol.hyper.toolstats.ToolStats;
|
import lol.hyper.toolstats.ToolStats;
|
||||||
import lol.hyper.toolstats.tools.config.versions.Version6;
|
import lol.hyper.toolstats.tools.config.versions.*;
|
||||||
import lol.hyper.toolstats.tools.config.versions.Version7;
|
|
||||||
import lol.hyper.toolstats.tools.config.versions.Version8;
|
|
||||||
import lol.hyper.toolstats.tools.config.versions.Version9;
|
|
||||||
|
|
||||||
public class ConfigUpdater {
|
public class ConfigUpdater {
|
||||||
|
|
||||||
@@ -34,31 +31,30 @@ public class ConfigUpdater {
|
|||||||
public void updateConfig() {
|
public void updateConfig() {
|
||||||
int version = toolStats.config.getInt("config-version");
|
int version = toolStats.config.getInt("config-version");
|
||||||
|
|
||||||
switch(version) {
|
|
||||||
case 5: {
|
|
||||||
// Version 5 to 6
|
// Version 5 to 6
|
||||||
|
if (version == 5) {
|
||||||
Version6 version6 = new Version6(toolStats);
|
Version6 version6 = new Version6(toolStats);
|
||||||
version6.update();
|
version6.update();
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
case 6: {
|
|
||||||
// Version 6 to 7
|
// Version 6 to 7
|
||||||
|
if (version == 6) {
|
||||||
Version7 version7 = new Version7(toolStats);
|
Version7 version7 = new Version7(toolStats);
|
||||||
version7.update();
|
version7.update();
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
case 7: {
|
|
||||||
// Version 7 to 8
|
// Version 7 to 8
|
||||||
|
if (version == 7) {
|
||||||
Version8 version8 = new Version8(toolStats);
|
Version8 version8 = new Version8(toolStats);
|
||||||
version8.update();
|
version8.update();
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
case 8: {
|
|
||||||
// Version 8 to 9
|
// Version 8 to 9
|
||||||
|
if (version == 8) {
|
||||||
Version9 version9 = new Version9(toolStats);
|
Version9 version9 = new Version9(toolStats);
|
||||||
version9.update();
|
version9.update();
|
||||||
break;
|
}
|
||||||
}
|
// Version 9 to 10
|
||||||
|
if (version == 9) {
|
||||||
|
Version10 version10 = new Version10(toolStats);
|
||||||
|
version10.update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,81 @@
|
|||||||
|
/*
|
||||||
|
* 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 Version10 {
|
||||||
|
|
||||||
|
private final ToolStats toolStats;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used for updating from version 9 to 10.
|
||||||
|
*
|
||||||
|
* @param toolStats ToolStats instance.
|
||||||
|
*/
|
||||||
|
public Version10(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-9.yml");
|
||||||
|
} catch (IOException exception) {
|
||||||
|
toolStats.logger.severe("Unable to save config-9.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 10.");
|
||||||
|
toolStats.config.set("config-version", 10);
|
||||||
|
|
||||||
|
// Add missing values I forgot...
|
||||||
|
toolStats.logger.info("Adding entry for enabled.created-by.fishing-rod");
|
||||||
|
toolStats.config.set("enabled.created-by.fishing-rod", true);
|
||||||
|
toolStats.logger.info("Adding entry for enabled.created-date.fishing-rod");
|
||||||
|
toolStats.config.set("enabled.created-date.fishing-rod", true);
|
||||||
|
toolStats.logger.info("Adding entry for enabled.fished-tag.fishing-rod");
|
||||||
|
toolStats.config.set("enabled.fished-tag.fishing-rod", true);
|
||||||
|
toolStats.logger.info("Adding entry for enabled.looted-tag.fishing-rod");
|
||||||
|
toolStats.config.set("enabled.looted-tag.fishing-rod", true);
|
||||||
|
toolStats.logger.info("Adding entry for enabled.traded-tag.fishing-rod");
|
||||||
|
toolStats.config.set("enabled.traded-tag.fishing-rod", true);
|
||||||
|
toolStats.logger.info("Adding entry for enabled.spawned-in.fishing-rod");
|
||||||
|
toolStats.config.set("enabled.spawned-in.fishing-rod", true);
|
||||||
|
|
||||||
|
toolStats.logger.info("Adding entry for enabled.crops-harvested");
|
||||||
|
toolStats.config.set("enabled.crops-harvested", 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 10. A copy of version 9 has been saved as config-9.yml");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -67,6 +67,7 @@ enabled:
|
|||||||
bow: true
|
bow: true
|
||||||
armor: true
|
armor: true
|
||||||
mace: true
|
mace: true
|
||||||
|
fishing-rod: true
|
||||||
# Will show time the item is created
|
# Will show time the item is created
|
||||||
created-date:
|
created-date:
|
||||||
pickaxe: true
|
pickaxe: true
|
||||||
@@ -78,6 +79,7 @@ enabled:
|
|||||||
bow: true
|
bow: true
|
||||||
armor: true
|
armor: true
|
||||||
mace: true
|
mace: true
|
||||||
|
fishing-rod: true
|
||||||
# Will show "Fished by <player>"
|
# Will show "Fished by <player>"
|
||||||
fished-tag:
|
fished-tag:
|
||||||
pickaxe: true
|
pickaxe: true
|
||||||
@@ -88,6 +90,7 @@ enabled:
|
|||||||
shears: true
|
shears: true
|
||||||
bow: true
|
bow: true
|
||||||
armor: true
|
armor: true
|
||||||
|
fishing-rod: true
|
||||||
# Will show "Found by <player>"
|
# Will show "Found by <player>"
|
||||||
looted-tag:
|
looted-tag:
|
||||||
pickaxe: true
|
pickaxe: true
|
||||||
@@ -98,6 +101,7 @@ enabled:
|
|||||||
shears: true
|
shears: true
|
||||||
bow: true
|
bow: true
|
||||||
armor: true
|
armor: true
|
||||||
|
fishing-rod: true
|
||||||
# Will show "Trade by <player>"
|
# Will show "Trade by <player>"
|
||||||
traded-tag:
|
traded-tag:
|
||||||
pickaxe: true
|
pickaxe: true
|
||||||
@@ -108,6 +112,7 @@ enabled:
|
|||||||
shears: true
|
shears: true
|
||||||
bow: true
|
bow: true
|
||||||
armor: true
|
armor: true
|
||||||
|
fishing-rod: true
|
||||||
player-kills:
|
player-kills:
|
||||||
sword: true
|
sword: true
|
||||||
axe: true
|
axe: true
|
||||||
@@ -137,6 +142,7 @@ enabled:
|
|||||||
bow: true
|
bow: true
|
||||||
armor: true
|
armor: true
|
||||||
mace: true
|
mace: true
|
||||||
|
fishing-rod: true
|
||||||
fish-caught: true
|
fish-caught: true
|
||||||
sheep-sheared: true
|
sheep-sheared: true
|
||||||
armor-damage: true
|
armor-damage: true
|
||||||
@@ -144,6 +150,7 @@ enabled:
|
|||||||
elytra-tag: true
|
elytra-tag: true
|
||||||
arrows-shot: true
|
arrows-shot: true
|
||||||
flight-time: true
|
flight-time: true
|
||||||
|
crops-harvested: true
|
||||||
|
|
||||||
messages:
|
messages:
|
||||||
created:
|
created:
|
||||||
@@ -194,6 +201,6 @@ number-formats:
|
|||||||
# When any tool is created, it will generate a hash for the item.
|
# When any tool is created, it will generate a hash for the item.
|
||||||
# This hash is not on the item lore, only stored in the NBT data.
|
# This hash is not on the item lore, only stored in the NBT data.
|
||||||
# This has no use currently, but can be used for future features for dupe detection.
|
# This has no use currently, but can be used for future features for dupe detection.
|
||||||
generate-hash-for-items: true
|
generate-hash-for-items: false
|
||||||
|
|
||||||
config-version: 9
|
config-version: 10
|
||||||
Reference in New Issue
Block a user