mirror of
https://github.com/hyperdefined/ToolStats.git
synced 2025-12-06 06:41:44 +00:00
add dropped-by
This commit is contained in:
@@ -93,6 +93,10 @@ public final class ToolStats extends JavaPlugin {
|
|||||||
* Key for arrows shot.
|
* Key for arrows shot.
|
||||||
*/
|
*/
|
||||||
public final NamespacedKey arrowsShot = new NamespacedKey(this, "arrows-shot");
|
public final NamespacedKey arrowsShot = new NamespacedKey(this, "arrows-shot");
|
||||||
|
/**
|
||||||
|
* Key for arrows shot.
|
||||||
|
*/
|
||||||
|
public final NamespacedKey droppedBy = new NamespacedKey(this, "dropped-by");
|
||||||
/**
|
/**
|
||||||
* Key for tracking flight time.
|
* Key for tracking flight time.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -266,6 +266,17 @@ public class CommandToolStats implements TabExecutor {
|
|||||||
player.getInventory().setItem(slot, finalItem);
|
player.getInventory().setItem(slot, finalItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (container.has(toolStats.droppedBy, PersistentDataType.STRING)) {
|
||||||
|
if (toolStats.config.getBoolean("enabled.dropped-by")) {
|
||||||
|
if (container.has(toolStats.droppedBy)) {
|
||||||
|
String droppedBy = container.get(toolStats.droppedBy, PersistentDataType.STRING);
|
||||||
|
lore.add(toolStats.configTools.formatLore("dropped-by", "{name}", droppedBy));
|
||||||
|
} else {
|
||||||
|
player.sendMessage(Component.text("Unable to set 'dropped-by', as this item has no record of it."));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (container.has(toolStats.itemOwner, new UUIDDataType())) {
|
if (container.has(toolStats.itemOwner, new UUIDDataType())) {
|
||||||
UUID owner = container.get(toolStats.itemOwner, new UUIDDataType());
|
UUID owner = container.get(toolStats.itemOwner, new UUIDDataType());
|
||||||
String ownerName = null;
|
String ownerName = null;
|
||||||
@@ -329,6 +340,12 @@ public class CommandToolStats implements TabExecutor {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case 1: {
|
||||||
|
if (toolStats.config.getBoolean("enabled.dropped-on")) {
|
||||||
|
lore.add(toolStats.configTools.formatLore("dropped-on", "{date}", date));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
case 2: {
|
case 2: {
|
||||||
if (toolStats.configTools.checkConfig(original.getType(), "looted-on")) {
|
if (toolStats.configTools.checkConfig(original.getType(), "looted-on")) {
|
||||||
lore.add(toolStats.configTools.formatLore("looted.looted-on", "{date}", date));
|
lore.add(toolStats.configTools.formatLore("looted.looted-on", "{date}", date));
|
||||||
|
|||||||
@@ -30,6 +30,8 @@ import org.bukkit.inventory.meta.ItemMeta;
|
|||||||
import org.bukkit.persistence.PersistentDataContainer;
|
import org.bukkit.persistence.PersistentDataContainer;
|
||||||
import org.bukkit.persistence.PersistentDataType;
|
import org.bukkit.persistence.PersistentDataType;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@@ -84,19 +86,44 @@ public class EntityDeath implements Listener {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!toolStats.config.getBoolean("enabled.dropped-by")) {
|
long timeCreated = System.currentTimeMillis();
|
||||||
return null;
|
Date finalDate;
|
||||||
|
if (toolStats.config.getBoolean("normalize-time-creation")) {
|
||||||
|
finalDate = toolStats.numberFormat.normalizeTime(timeCreated);
|
||||||
|
timeCreated = finalDate.getTime();
|
||||||
|
} else {
|
||||||
|
finalDate = new Date(timeCreated);
|
||||||
}
|
}
|
||||||
|
|
||||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
PersistentDataContainer container = meta.getPersistentDataContainer();
|
||||||
container.set(toolStats.originType, PersistentDataType.INTEGER, 1);
|
|
||||||
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();
|
||||||
}
|
}
|
||||||
Component newLine = toolStats.configTools.formatLore("dropped-by", "{name}", mobName);
|
|
||||||
List<Component> newLore = toolStats.itemLore.addItemLore(meta, newLine);
|
List<Component> lore;
|
||||||
meta.lore(newLore);
|
if (meta.hasLore()) {
|
||||||
|
lore = meta.lore();
|
||||||
|
} else {
|
||||||
|
lore = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (toolStats.config.getBoolean("enabled.dropped-on")) {
|
||||||
|
container.set(toolStats.originType, PersistentDataType.INTEGER, 1);
|
||||||
|
container.set(toolStats.timeCreated, PersistentDataType.LONG, timeCreated);
|
||||||
|
String date = toolStats.numberFormat.formatDate(finalDate);
|
||||||
|
Component droppedOn = toolStats.configTools.formatLore("dropped-on", "{date}", date);
|
||||||
|
lore.add(droppedOn);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (toolStats.config.getBoolean("enabled.dropped-by")) {
|
||||||
|
container.set(toolStats.originType, PersistentDataType.INTEGER, 1);
|
||||||
|
container.set(toolStats.droppedBy, PersistentDataType.STRING, mobName);
|
||||||
|
Component droppedBy = toolStats.configTools.formatLore("dropped-by", "{name}", mobName);
|
||||||
|
lore.add(droppedBy);
|
||||||
|
}
|
||||||
|
|
||||||
|
meta.lore(lore);
|
||||||
newItem.setItemMeta(meta);
|
newItem.setItemMeta(meta);
|
||||||
return newItem;
|
return newItem;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,6 +80,13 @@ public class Version12 {
|
|||||||
toolStats.config.set("enabled.traded-tag", null);
|
toolStats.config.set("enabled.traded-tag", null);
|
||||||
toolStats.config.set("enabled.spawned-in", null);
|
toolStats.config.set("enabled.spawned-in", null);
|
||||||
|
|
||||||
|
toolStats.logger.info("Adding enabled.dropped-on");
|
||||||
|
boolean droppedBy = toolStats.config.getBoolean("enabled.dropped-by");
|
||||||
|
toolStats.config.set("enabled.dropped-on", droppedBy);
|
||||||
|
|
||||||
|
toolStats.logger.info("Adding messages.dropped-on");
|
||||||
|
toolStats.config.set("messages.dropped-on", "&7Dropped on: &8{date}");
|
||||||
|
|
||||||
|
|
||||||
// rename crafted to crafted here
|
// rename crafted to crafted here
|
||||||
// copy the old ones first
|
// copy the old ones first
|
||||||
|
|||||||
@@ -208,6 +208,7 @@ enabled:
|
|||||||
sheep-sheared: true
|
sheep-sheared: true
|
||||||
armor-damage: true
|
armor-damage: true
|
||||||
dropped-by: true
|
dropped-by: true
|
||||||
|
dropped-on: true
|
||||||
elytra-tag: true
|
elytra-tag: true
|
||||||
arrows-shot: true
|
arrows-shot: true
|
||||||
flight-time: true
|
flight-time: true
|
||||||
@@ -238,7 +239,8 @@ messages:
|
|||||||
blocks-mined: "&7Blocks mined: &8{blocks}"
|
blocks-mined: "&7Blocks mined: &8{blocks}"
|
||||||
crops-harvested: "&7Crops harvested: &8{crops}"
|
crops-harvested: "&7Crops harvested: &8{crops}"
|
||||||
sheep-sheared: "&7Sheep sheared: &8{sheep}"
|
sheep-sheared: "&7Sheep sheared: &8{sheep}"
|
||||||
dropped-by: "&7Dropped by: &8{name}" # name will be player/mob name
|
dropped-by: "&7Dropped by: &8{name}" # name will be mob name
|
||||||
|
dropped-on: "&7Dropped on: &8{date}"
|
||||||
damage-taken: "&7Damage taken: &8{damage}"
|
damage-taken: "&7Damage taken: &8{damage}"
|
||||||
arrows-shot: "&7Arrows shot: &8{arrows}"
|
arrows-shot: "&7Arrows shot: &8{arrows}"
|
||||||
flight-time: "&7Flight time: &8{years}y {months}m {days}d {hours}h {minutes}m {seconds}s"
|
flight-time: "&7Flight time: &8{years}y {months}m {days}d {hours}h {minutes}m {seconds}s"
|
||||||
|
|||||||
Reference in New Issue
Block a user