use the new GLIDER DataComponent

This commit is contained in:
hyperdefined
2025-07-23 12:19:40 -04:00
parent 86cbdd58ff
commit 525df4bcf6
3 changed files with 34 additions and 8 deletions

View File

@@ -169,7 +169,7 @@ public class AnvilEvent implements Listener {
}
return;
}
if (firstSlotMaterial == Material.ELYTRA) {
if (toolStats.itemChecker.canGlide(clone)) {
addToken(event, tokenType, "flight-time", clone);
return;
}

View File

@@ -53,15 +53,23 @@ public class PlayerMove implements Listener {
// player is not flying
if (playerStartFlight.containsKey(player)) {
PlayerInventory inventory = player.getInventory();
ItemStack chest = inventory.getChestplate();
// make sure the player is wearing an elytra
if (chest != null && chest.getType() == Material.ELYTRA) {
long duration = (System.currentTimeMillis() - playerStartFlight.get(player));
ItemMeta newItem = toolStats.itemLore.updateFlightTime(chest, duration);
if (newItem != null) {
inventory.getChestplate().setItemMeta(newItem);
// copy their current armor
ItemStack[] armor = inventory.getArmorContents().clone();
for (ItemStack armorPiece : armor) {
// skip missing slots
if (armorPiece == null) {
continue;
}
// if the armor piece can glide, track the flight time
if (toolStats.itemChecker.canGlide(armorPiece)) {
long duration = (System.currentTimeMillis() - playerStartFlight.get(player));
ItemMeta newMeta = toolStats.itemLore.updateFlightTime(armorPiece, duration);
if (newMeta != null) {
armorPiece.setItemMeta(newMeta);
}
}
}
inventory.setArmorContents(armor);
playerStartFlight.remove(player);
}
}

View File

@@ -17,6 +17,8 @@
package lol.hyper.toolstats.tools;
import io.papermc.paper.datacomponent.DataComponentType;
import io.papermc.paper.datacomponent.DataComponentTypes;
import lol.hyper.toolstats.ToolStats;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
@@ -116,6 +118,22 @@ public class ItemChecker {
return mineItems.contains(itemType);
}
/**
* In newer versions of Minecraft, you can make items glide, which works
* like an Elytra.
*
* @param itemStack The item to check.
* @return True/false if the item can glide like an Elytra.
*/
public boolean canGlide(ItemStack itemStack) {
// if it's an elytra, we are good
if (itemStack.getType() == Material.ELYTRA) {
return true;
}
// otherwise if it has the GLIDER data
return itemStack.hasData(DataComponentTypes.GLIDER);
}
/**
* Check a given item for a target token.
*