mirror of
https://github.com/hyperdefined/ToolStats.git
synced 2025-12-06 06:41:44 +00:00
use the new GLIDER DataComponent
This commit is contained in:
@@ -169,7 +169,7 @@ public class AnvilEvent implements Listener {
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (firstSlotMaterial == Material.ELYTRA) {
|
if (toolStats.itemChecker.canGlide(clone)) {
|
||||||
addToken(event, tokenType, "flight-time", clone);
|
addToken(event, tokenType, "flight-time", clone);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,15 +53,23 @@ public class PlayerMove implements Listener {
|
|||||||
// player is not flying
|
// player is not flying
|
||||||
if (playerStartFlight.containsKey(player)) {
|
if (playerStartFlight.containsKey(player)) {
|
||||||
PlayerInventory inventory = player.getInventory();
|
PlayerInventory inventory = player.getInventory();
|
||||||
ItemStack chest = inventory.getChestplate();
|
// copy their current armor
|
||||||
// make sure the player is wearing an elytra
|
ItemStack[] armor = inventory.getArmorContents().clone();
|
||||||
if (chest != null && chest.getType() == Material.ELYTRA) {
|
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));
|
long duration = (System.currentTimeMillis() - playerStartFlight.get(player));
|
||||||
ItemMeta newItem = toolStats.itemLore.updateFlightTime(chest, duration);
|
ItemMeta newMeta = toolStats.itemLore.updateFlightTime(armorPiece, duration);
|
||||||
if (newItem != null) {
|
if (newMeta != null) {
|
||||||
inventory.getChestplate().setItemMeta(newItem);
|
armorPiece.setItemMeta(newMeta);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
inventory.setArmorContents(armor);
|
||||||
playerStartFlight.remove(player);
|
playerStartFlight.remove(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,8 @@
|
|||||||
|
|
||||||
package lol.hyper.toolstats.tools;
|
package lol.hyper.toolstats.tools;
|
||||||
|
|
||||||
|
import io.papermc.paper.datacomponent.DataComponentType;
|
||||||
|
import io.papermc.paper.datacomponent.DataComponentTypes;
|
||||||
import lol.hyper.toolstats.ToolStats;
|
import lol.hyper.toolstats.ToolStats;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
@@ -116,6 +118,22 @@ public class ItemChecker {
|
|||||||
return mineItems.contains(itemType);
|
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.
|
* Check a given item for a target token.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user