Skip to content

Commit

Permalink
Started working on migrating to XSkulls (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
PeachesMLG committed Jun 10, 2024
1 parent 6b5e1a0 commit 4f8fb8b
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 186 deletions.
7 changes: 5 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

group = "com.iridium"
version = "1.9.7"
version = "1.9.8"
description = "IridiumCore"

allprojects {
Expand All @@ -19,15 +19,18 @@ allprojects {
maven("https://repo.rosewooddev.io/repository/public/")
maven("https://repo.papermc.io/repository/maven-public/")
maven("https://nexus.iridiumdevelopment.net/repository/maven-releases/")
maven("https://libraries.minecraft.net")
}

dependencies {
// Dependencies that we want to shade in
implementation("com.github.cryptomorin:XSeries:11.0.0") { isTransitive = false }
implementation("com.github.cryptomorin:XSeries:11.0.0")

// Other dependencies that are not required or already available at runtime
compileOnly("org.jetbrains:annotations:24.1.0")
compileOnly("org.projectlombok:lombok:1.18.32")
// This is needed for XSkin, but isnt added to the XSeries jar, potentially a bug that will be fixed in a later release
compileOnly("com.mojang:authlib:1.5.25")

// Enable lombok annotation processing
annotationProcessor("org.projectlombok:lombok:1.18.32")
Expand Down
84 changes: 24 additions & 60 deletions plugin/src/main/java/com/iridium/iridiumcore/Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ public class Item {
public XMaterial material;
public int amount;
public String displayName;
public String skullData;
@Deprecated
public String headData;
@Deprecated
public String headOwner;
@Deprecated
public UUID headOwnerUUID;
public Integer model;
public List<String> lore;
Expand Down Expand Up @@ -62,93 +66,53 @@ public Item(XMaterial material, int slot, int amount, String displayName, List<S
*
* @param material The material of the item. Specifies the type
* @param slot The slot where this item should be in
* @param headData The data of the head for custom heads
* @param skullData The data of the head for custom heads
* @param amount The amount of this item. Should not be higher than the max stack size
* @param displayName The display name of the item with color codes
* @param lore The lore of the item, can be empty
*/
public Item(XMaterial material, int slot, String headData, int amount, String displayName, List<String> lore) {
public Item(XMaterial material, int slot, String skullData, int amount, String displayName, List<String> lore) {
this.material = material;
this.amount = amount;
this.lore = lore;
this.displayName = displayName;
this.slot = slot;
this.headData = headData;
this.skullData = skullData;
}

/**
* Creates a new item with the provided data.
* Used for creating player heads.
*
* @param material The material of the item. Specifies the type
* @param slot The slot where this item should be in
* @param amount The amount of this item. Should not be higher than the max stack size
* @param displayName The display name of the item with color codes
* @param headOwner The owner of the head
* @param lore The lore of the item, can be empty
*/
public Item(XMaterial material, int slot, int amount, String displayName, String headOwner, List<String> lore) {
this.material = material;
this.amount = amount;
this.lore = lore;
this.displayName = displayName;
this.headOwner = headOwner;
this.slot = slot;
}

/**
* Creates a new item with the provided data.
* Used for creating player heads in an inventory.
*
* @param material The material of the item. Specifies the type
* @param amount The amount of this item. Should not be higher than the max stack size
* @param displayName The display name of the item with color codes
* @param headOwner The owner of the head
* @param lore The lore of the item, can be empty
*/
public Item(XMaterial material, int amount, String displayName, String headOwner, List<String> lore) {
this.material = material;
this.amount = amount;
this.lore = lore;
this.displayName = displayName;
this.headOwner = headOwner;
}

/**
* Creates a new item with the provided data.
* Used for creating player heads in an inventory.
*
* @param material The material of the item. Specifies the type
* @param amount The amount of this item. Should not be higher than the max stack size
* @param displayName The display name of the item with color codes
* @param headOwner The owner of the head
* @param ownerUUID The UUID owner of the head
* @param model The Model of the item
* @param lore The lore of the item, can be empty
*/
public Item(XMaterial material, int amount, String displayName, String headOwner, UUID ownerUUID, List<String> lore) {
public Item(XMaterial material, int amount, String displayName, int model, List<String> lore) {
this.material = material;
this.amount = amount;
this.lore = lore;
this.displayName = displayName;
this.headOwnerUUID = ownerUUID;
this.headOwner = headOwner;
this.model = model;
}

/**
* Creates a new item with the provided data.
*
* @param material The material of the item. Specifies the type
* @param amount The amount of this item. Should not be higher than the max stack size
* @param displayName The display name of the item with color codes
* @param model The Model of the item
* @param lore The lore of the item, can be empty
* Migrates deprecated data over to the new methods
*/
public Item(XMaterial material, int amount, String displayName, int model, List<String> lore) {
this.material = material;
this.amount = amount;
this.lore = lore;
this.displayName = displayName;
this.model = model;
public void migrateData() {
if (headOwner != null && !headOwner.isEmpty()) {
skullData = headOwner;
headOwner = null;
}
if (headOwnerUUID != null) {
skullData = headOwnerUUID.toString();
headOwnerUUID = null;
}
if (headData != null && !headData.isEmpty()) {
skullData = headData;
headData = null;
}
}

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.iridium.iridiumcore.utils;

import com.cryptomorin.xseries.XMaterial;
import com.cryptomorin.xseries.XSkull;
import com.iridium.iridiumcore.IridiumCore;
import com.iridium.iridiumcore.Item;
import de.tr7zw.changeme.nbtapi.NBT;
import de.tr7zw.changeme.nbtapi.NBTItem;
import de.tr7zw.changeme.nbtapi.iface.ReadWriteNBT;
import de.tr7zw.changeme.nbtapi.utils.DataFixerUtil;
import org.bukkit.Material;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
Expand Down Expand Up @@ -37,7 +39,7 @@ public class ItemStackUtils {
*/
public static ItemStack makeItem(XMaterial material, int amount, String name, List<String> lore) {
ItemStack itemStack = material.parseItem();
if (itemStack == null) return null;
if (itemStack == null) return new ItemStack(Material.AIR);
itemStack.setAmount(amount);
ItemMeta itemMeta = itemStack.getItemMeta();
if (itemMeta != null) {
Expand All @@ -58,18 +60,9 @@ public static ItemStack makeItem(XMaterial material, int amount, String name, Li
*/
public static ItemStack makeItem(Item item, List<Placeholder> placeholders) {
ItemStack itemStack = makeItem(item.material, item.amount, StringUtils.processMultiplePlaceholders(item.displayName, placeholders), StringUtils.processMultiplePlaceholders(item.lore, placeholders));
if (item.material == XMaterial.PLAYER_HEAD && item.headData != null) {
return setHeadData(item.headData, itemStack);
} else if (item.material == XMaterial.PLAYER_HEAD && item.headOwner != null) {
UUID uuid;
if (item.headOwnerUUID == null) {
uuid = SkinUtils.getUUID(StringUtils.processMultiplePlaceholders(item.headOwner, placeholders));
} else {
uuid = item.headOwnerUUID;
}
return setHeadData(SkinUtils.getHeadData(uuid), itemStack);
} else if (item.model != null) {
return setModel(item.model, itemStack);

if (item.material == XMaterial.PLAYER_HEAD && item.skullData != null && !item.skullData.isEmpty()) {
XSkull.of(itemStack).profile(StringUtils.processMultiplePlaceholders(item.skullData, placeholders)).applyAsync();
}

return itemStack;
Expand Down
111 changes: 0 additions & 111 deletions plugin/src/main/java/com/iridium/iridiumcore/utils/SkinUtils.java

This file was deleted.

0 comments on commit 4f8fb8b

Please sign in to comment.