mirror of
https://github.com/hyperdefined/ToolStats.git
synced 2025-12-07 13:15:02 +00:00
update various things for origin NBT
This commit is contained in:
@@ -146,7 +146,7 @@ public class GenerateLoot implements Listener {
|
|||||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 2);
|
container.set(toolStats.originType, PersistentDataType.INTEGER, 2);
|
||||||
|
|
||||||
String formattedDate = toolStats.numberFormat.formatDate(finalDate);
|
String formattedDate = toolStats.numberFormat.formatDate(finalDate);
|
||||||
List<String> newLore = toolStats.itemLore.addNewOwner(meta, owner.getName(), formattedDate, "LOOTED");
|
List<String> newLore = toolStats.itemLore.addNewOwner(meta, owner.getName(), formattedDate);
|
||||||
|
|
||||||
if (toolStats.checkConfig(newItem, "looted-tag")) {
|
if (toolStats.checkConfig(newItem, "looted-tag")) {
|
||||||
meta.setLore(newLore);
|
meta.setLore(newLore);
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ public class PickupItem implements Listener {
|
|||||||
container.remove(toolStats.newElytra);
|
container.remove(toolStats.newElytra);
|
||||||
|
|
||||||
String formattedDate = toolStats.numberFormat.formatDate(finalDate);
|
String formattedDate = toolStats.numberFormat.formatDate(finalDate);
|
||||||
List<String> newLore = toolStats.itemLore.addNewOwner(meta, owner.getName(), formattedDate, "LOOTED");
|
List<String> newLore = toolStats.itemLore.addNewOwner(meta, owner.getName(), formattedDate);
|
||||||
|
|
||||||
if (toolStats.config.getBoolean("enabled.elytra-tag")) {
|
if (toolStats.config.getBoolean("enabled.elytra-tag")) {
|
||||||
meta.setLore(newLore);
|
meta.setLore(newLore);
|
||||||
|
|||||||
@@ -160,7 +160,7 @@ public class PlayerFish implements Listener {
|
|||||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 5);
|
container.set(toolStats.originType, PersistentDataType.INTEGER, 5);
|
||||||
|
|
||||||
String formattedDate = toolStats.numberFormat.formatDate(finalDate);
|
String formattedDate = toolStats.numberFormat.formatDate(finalDate);
|
||||||
List<String> newLore = toolStats.itemLore.addNewOwner(meta, owner.getName(), formattedDate, "FISHED");
|
List<String> newLore = toolStats.itemLore.addNewOwner(meta, owner.getName(), formattedDate);
|
||||||
|
|
||||||
if (toolStats.checkConfig(newItem, "fished-tag")) {
|
if (toolStats.checkConfig(newItem, "fished-tag")) {
|
||||||
meta.setLore(newLore);
|
meta.setLore(newLore);
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ public class VillagerTrade implements Listener {
|
|||||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 3);
|
container.set(toolStats.originType, PersistentDataType.INTEGER, 3);
|
||||||
|
|
||||||
String formattedDate = toolStats.numberFormat.formatDate(finalDate);
|
String formattedDate = toolStats.numberFormat.formatDate(finalDate);
|
||||||
List<String> newLore = toolStats.itemLore.addNewOwner(meta, owner.getName(), formattedDate, "TRADED");
|
List<String> newLore = toolStats.itemLore.addNewOwner(meta, owner.getName(), formattedDate);
|
||||||
|
|
||||||
if (toolStats.checkConfig(newItem, "traded-tag")) {
|
if (toolStats.checkConfig(newItem, "traded-tag")) {
|
||||||
meta.setLore(newLore);
|
meta.setLore(newLore);
|
||||||
|
|||||||
@@ -18,11 +18,13 @@
|
|||||||
package lol.hyper.toolstats.tools;
|
package lol.hyper.toolstats.tools;
|
||||||
|
|
||||||
import lol.hyper.toolstats.ToolStats;
|
import lol.hyper.toolstats.ToolStats;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
import org.bukkit.persistence.PersistentDataContainer;
|
||||||
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
public class ItemLore {
|
public class ItemLore {
|
||||||
|
|
||||||
@@ -87,38 +89,46 @@ public class ItemLore {
|
|||||||
* @param itemMeta The item meta.
|
* @param itemMeta The item meta.
|
||||||
* @param playerName The new owner of item.
|
* @param playerName The new owner of item.
|
||||||
* @param formattedDate The date of the ownership.
|
* @param formattedDate The date of the ownership.
|
||||||
* @param type The type of new ownership.
|
|
||||||
* @return The item's new lore.
|
* @return The item's new lore.
|
||||||
*/
|
*/
|
||||||
public List<String> addNewOwner(ItemMeta itemMeta, String playerName, String formattedDate, String type) {
|
public List<String> addNewOwner(ItemMeta itemMeta, String playerName, String formattedDate) {
|
||||||
String dateCreated = null;
|
String dateCreated = null;
|
||||||
String itemOwner = null;
|
String itemOwner = null;
|
||||||
switch (type) {
|
Integer origin = null;
|
||||||
case "LOOTED": {
|
PersistentDataContainer container = itemMeta.getPersistentDataContainer();
|
||||||
|
if (container.has(toolStats.originType, PersistentDataType.INTEGER)) {
|
||||||
|
origin = container.get(toolStats.originType, PersistentDataType.INTEGER);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (origin == null) {
|
||||||
|
origin = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (origin) {
|
||||||
|
case 2: {
|
||||||
|
dateCreated = toolStats.getLoreFromConfig("looted.looted-on", true);
|
||||||
|
itemOwner = toolStats.getLoreFromConfig("looted.looted-by", true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 3: {
|
||||||
|
dateCreated = toolStats.getLoreFromConfig("traded.traded-on", true);
|
||||||
|
itemOwner = toolStats.getLoreFromConfig("traded.traded-by", true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 4: {
|
||||||
dateCreated = toolStats.getLoreFromConfig("looted.found-on", true);
|
dateCreated = toolStats.getLoreFromConfig("looted.found-on", true);
|
||||||
itemOwner = toolStats.getLoreFromConfig("looted.found-by", true);
|
itemOwner = toolStats.getLoreFromConfig("looted.found-by", true);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "CREATED": {
|
case 5: {
|
||||||
dateCreated = toolStats.getLoreFromConfig("created.created-on", true);
|
|
||||||
itemOwner = toolStats.getLoreFromConfig("created.created-by", true);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "FISHED": {
|
|
||||||
dateCreated = toolStats.getLoreFromConfig("fished.caught-on", true);
|
dateCreated = toolStats.getLoreFromConfig("fished.caught-on", true);
|
||||||
itemOwner = toolStats.getLoreFromConfig("fished.caught-by", true);
|
itemOwner = toolStats.getLoreFromConfig("fished.caught-by", true);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "TRADED": {
|
|
||||||
dateCreated = toolStats.getLoreFromConfig("traded.traded-on", true);
|
|
||||||
itemOwner = toolStats.getLoreFromConfig("traded.traded-by", true);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dateCreated == null || itemOwner == null) {
|
if (dateCreated == null || itemOwner == null) {
|
||||||
toolStats.logger.warning("There is no lore message for messages." + type.toLowerCase(Locale.ENGLISH) + "!");
|
toolStats.logger.info("Unable to determine origin of item for " + itemMeta);
|
||||||
toolStats.logger.warning("Unable to update lore for item.");
|
|
||||||
return itemMeta.getLore();
|
return itemMeta.getLore();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,4 +143,19 @@ public class ItemLore {
|
|||||||
newLore.add(itemOwner.replace("{player}", playerName));
|
newLore.add(itemOwner.replace("{player}", playerName));
|
||||||
return newLore;
|
return newLore;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add origin to already existing items.
|
||||||
|
* @param itemStack The item to add origin to.
|
||||||
|
* @param origin The origin type.
|
||||||
|
*/
|
||||||
|
public void addOriginTag(ItemStack itemStack, int origin) {
|
||||||
|
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||||
|
if (itemMeta == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
PersistentDataContainer container = itemMeta.getPersistentDataContainer();
|
||||||
|
container.set(toolStats.originType, PersistentDataType.INTEGER, origin);
|
||||||
|
itemStack.setItemMeta(itemMeta);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user