mirror of
https://github.com/hyperdefined/ToolStats.git
synced 2025-12-06 06:41:44 +00:00
don't change player drop items
This commit is contained in:
@@ -7,5 +7,4 @@ A simple plugin to track cool stats for your tools and armor!
|
|||||||
* ~~Track armor damage.~~
|
* ~~Track armor damage.~~
|
||||||
* ~~Track fish caught.~~
|
* ~~Track fish caught.~~
|
||||||
* ~~Track sheep sheared.~~
|
* ~~Track sheep sheared.~~
|
||||||
* If player kills player, tag their tools and armor with "Dropped by"
|
|
||||||
* Properly handle combing of tools. Stats should combine together.
|
* Properly handle combing of tools. Stats should combine together.
|
||||||
@@ -26,25 +26,12 @@ public class EntityDeath implements Listener {
|
|||||||
@EventHandler
|
@EventHandler
|
||||||
public void onDeath(EntityDeathEvent event) {
|
public void onDeath(EntityDeathEvent event) {
|
||||||
LivingEntity livingEntity = event.getEntity();
|
LivingEntity livingEntity = event.getEntity();
|
||||||
|
if (livingEntity instanceof Player) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
UUID livingEntityUUID = event.getEntity().getUniqueId();
|
UUID livingEntityUUID = event.getEntity().getUniqueId();
|
||||||
if (toolStats.mobKill.trackedMobs.contains(livingEntityUUID)) {
|
if (toolStats.mobKill.trackedMobs.contains(livingEntityUUID)) {
|
||||||
for (ItemStack current : event.getDrops()) {
|
for (ItemStack current : event.getDrops()) {
|
||||||
ItemMeta meta = current.getItemMeta();
|
|
||||||
boolean hasKey = false;
|
|
||||||
// check if the mob has one of our keys
|
|
||||||
// this will prevent the "dropped by" tag from being added
|
|
||||||
if (meta != null) {
|
|
||||||
PersistentDataContainer container = meta.getPersistentDataContainer();
|
|
||||||
for (NamespacedKey key : container.getKeys()) {
|
|
||||||
if (toolStats.keys.contains(key)) {
|
|
||||||
hasKey = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (hasKey && !(livingEntity instanceof Player)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
String name = current.getType().toString().toLowerCase(Locale.ROOT);
|
String name = current.getType().toString().toLowerCase(Locale.ROOT);
|
||||||
for (String item : toolStats.craftItem.validItems) {
|
for (String item : toolStats.craftItem.validItems) {
|
||||||
if (name.contains(item)) {
|
if (name.contains(item)) {
|
||||||
@@ -61,15 +48,25 @@ public class EntityDeath implements Listener {
|
|||||||
if (meta == null) {
|
if (meta == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
boolean hasTag = false;
|
||||||
List<String> lore;
|
List<String> lore;
|
||||||
if (meta.hasLore()) {
|
if (meta.hasLore()) {
|
||||||
lore = meta.getLore();
|
lore = meta.getLore();
|
||||||
assert lore != null;
|
assert lore != null;
|
||||||
|
for (int x = 0; x < lore.size(); x++) {
|
||||||
|
if (lore.get(x).contains("Dropped by")) {
|
||||||
|
// replace existing tag
|
||||||
|
lore.set(x, droppedLore.replace("X", mob));
|
||||||
|
hasTag = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// if the item has no lore, create a new list and add the string
|
// if the item has no lore, create a new list and add the string
|
||||||
lore = new ArrayList<>();
|
lore = new ArrayList<>();
|
||||||
}
|
}
|
||||||
lore.add(droppedLore.replace("X", mob));
|
if (!hasTag) {
|
||||||
|
lore.add(droppedLore.replace("X", mob));
|
||||||
|
}
|
||||||
meta.setLore(lore);
|
meta.setLore(lore);
|
||||||
itemStack.setItemMeta(meta);
|
itemStack.setItemMeta(meta);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user