1.20.2 support

This commit is contained in:
Jules 2023-09-30 13:11:30 +02:00
parent 760f7f6b0b
commit b8e02c945f
3 changed files with 16 additions and 51 deletions

View File

@ -1,7 +1,5 @@
package net.Indyuce.mmocore.api.player.profess; package net.Indyuce.mmocore.api.player.profess;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
import io.lumine.mythic.lib.MythicLib; import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.UtilityMethods; import io.lumine.mythic.lib.UtilityMethods;
import io.lumine.mythic.lib.api.MMOLineConfig; import io.lumine.mythic.lib.api.MMOLineConfig;
@ -21,18 +19,18 @@ import net.Indyuce.mmocore.api.player.profess.event.EventTrigger;
import net.Indyuce.mmocore.api.player.profess.resource.ManaDisplayOptions; import net.Indyuce.mmocore.api.player.profess.resource.ManaDisplayOptions;
import net.Indyuce.mmocore.api.player.profess.resource.PlayerResource; import net.Indyuce.mmocore.api.player.profess.resource.PlayerResource;
import net.Indyuce.mmocore.api.player.profess.resource.ResourceRegeneration; import net.Indyuce.mmocore.api.player.profess.resource.ResourceRegeneration;
import net.Indyuce.mmocore.skill.binding.SkillSlot;
import net.Indyuce.mmocore.api.util.MMOCoreUtils; import net.Indyuce.mmocore.api.util.MMOCoreUtils;
import net.Indyuce.mmocore.api.util.math.formula.LinearValue; import net.Indyuce.mmocore.api.util.math.formula.LinearValue;
import net.Indyuce.mmocore.experience.EXPSource; import net.Indyuce.mmocore.experience.EXPSource;
import net.Indyuce.mmocore.experience.ExpCurve; import net.Indyuce.mmocore.experience.ExpCurve;
import net.Indyuce.mmocore.experience.ExperienceObject;
import net.Indyuce.mmocore.experience.droptable.ExperienceTable; import net.Indyuce.mmocore.experience.droptable.ExperienceTable;
import net.Indyuce.mmocore.loot.chest.particle.CastingParticle; import net.Indyuce.mmocore.loot.chest.particle.CastingParticle;
import net.Indyuce.mmocore.player.stats.StatInfo; import net.Indyuce.mmocore.player.stats.StatInfo;
import net.Indyuce.mmocore.skill.ClassSkill; import net.Indyuce.mmocore.skill.ClassSkill;
import net.Indyuce.mmocore.skill.RegisteredSkill; import net.Indyuce.mmocore.skill.RegisteredSkill;
import net.Indyuce.mmocore.skill.binding.SkillSlot;
import net.Indyuce.mmocore.skill.cast.ComboMap; import net.Indyuce.mmocore.skill.cast.ComboMap;
import net.Indyuce.mmocore.experience.ExperienceObject;
import net.Indyuce.mmocore.skilltree.tree.SkillTree; import net.Indyuce.mmocore.skilltree.tree.SkillTree;
import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;
@ -45,7 +43,6 @@ import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.lang.reflect.Field;
import java.util.*; import java.util.*;
import java.util.logging.Level; import java.util.logging.Level;
@ -90,19 +87,11 @@ public class PlayerClass extends PostLoadObject implements ExperienceObject {
name = MythicLib.plugin.parseColors(config.getString("display.name", "INVALID DISPLAY NAME")); name = MythicLib.plugin.parseColors(config.getString("display.name", "INVALID DISPLAY NAME"));
icon = MMOCoreUtils.readIcon(config.getString("display.item", "BARRIER")); icon = MMOCoreUtils.readIcon(config.getString("display.item", "BARRIER"));
if (config.contains("display.texture") && icon.getType() == VersionMaterial.PLAYER_HEAD.toMaterial()) if (config.contains("display.texture") && icon.getType() == VersionMaterial.PLAYER_HEAD.toMaterial()) {
try { ItemMeta meta = icon.getItemMeta();
ItemMeta meta = icon.getItemMeta(); UtilityMethods.setTextureValue(meta, config.getString("display.texture"));
Field profileField = meta.getClass().getDeclaredField("profile"); icon.setItemMeta(meta);
profileField.setAccessible(true); }
GameProfile gp = new GameProfile(UUID.randomUUID(), null);
gp.getProperties().put("textures", new Property("textures", config.getString("display.texture")));
profileField.set(meta, gp);
icon.setItemMeta(meta);
} catch (IllegalArgumentException | IllegalAccessException | NoSuchFieldException
| SecurityException exception) {
throw new IllegalArgumentException("Could not apply playerhead texture: " + exception.getMessage());
}
for (String string : config.getStringList("display.lore")) for (String string : config.getStringList("display.lore"))
description.add(ChatColor.GRAY + MythicLib.plugin.parseColors(string)); description.add(ChatColor.GRAY + MythicLib.plugin.parseColors(string));
@ -375,9 +364,9 @@ public class PlayerClass extends PostLoadObject implements ExperienceObject {
/** /**
* @return A list of passive skills which correspond to class * @return A list of passive skills which correspond to class
* scripts wrapped in a format recognized by MythicLib. * scripts wrapped in a format recognized by MythicLib.
* Class scripts are handled just like * Class scripts are handled just like
* passive skills * passive skills
*/ */
@NotNull @NotNull
public List<PassiveSkill> getScripts() { public List<PassiveSkill> getScripts() {

View File

@ -1,14 +1,11 @@
package net.Indyuce.mmocore.gui.api.item; package net.Indyuce.mmocore.gui.api.item;
import com.mojang.authlib.GameProfile; import io.lumine.mythic.lib.UtilityMethods;
import com.mojang.authlib.properties.Property;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.gui.api.GeneratedInventory; import net.Indyuce.mmocore.gui.api.GeneratedInventory;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -17,11 +14,8 @@ import org.bukkit.inventory.meta.SkullMeta;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.lang.reflect.Field;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID;
import java.util.logging.Level;
public abstract class InventoryItem<T extends GeneratedInventory> { public abstract class InventoryItem<T extends GeneratedInventory> {
private final String id, function; private final String id, function;
@ -153,7 +147,8 @@ public abstract class InventoryItem<T extends GeneratedInventory> {
final ItemStack item = new ItemStack(material); final ItemStack item = new ItemStack(material);
final ItemMeta meta = item.getItemMeta(); final ItemMeta meta = item.getItemMeta();
meta.setCustomModelData(modelData); meta.setCustomModelData(modelData);
if (texture != null && meta instanceof SkullMeta) applyTexture(texture, (SkullMeta) meta); if (texture != null && meta instanceof SkullMeta)
UtilityMethods.setTextureValue(meta, texture);
if (hasName()) meta.setDisplayName(placeholders.apply(effectivePlayer, getName())); if (hasName()) meta.setDisplayName(placeholders.apply(effectivePlayer, getName()));
@ -182,19 +177,6 @@ public abstract class InventoryItem<T extends GeneratedInventory> {
return inv.getPlayer(); return inv.getPlayer();
} }
private void applyTexture(String value, SkullMeta meta) {
try {
GameProfile profile = new GameProfile(UUID.randomUUID(), null);
profile.getProperties().put("textures", new Property("textures", value));
Field profileField = meta.getClass().getDeclaredField("profile");
profileField.setAccessible(true);
profileField.set(meta, profile);
} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException exception) {
MMOCore.log(Level.WARNING, "Could not apply item texture value of " + getId());
}
}
public Placeholders getPlaceholders(T inv) { public Placeholders getPlaceholders(T inv) {
return getPlaceholders(inv, 0); return getPlaceholders(inv, 0);
} }

View File

@ -1,8 +1,7 @@
package net.Indyuce.mmocore.util.item; package net.Indyuce.mmocore.util.item;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
import io.lumine.mythic.lib.MythicLib; import io.lumine.mythic.lib.MythicLib;
import io.lumine.mythic.lib.UtilityMethods;
import io.lumine.mythic.lib.api.item.ItemTag; import io.lumine.mythic.lib.api.item.ItemTag;
import io.lumine.mythic.lib.api.item.NBTItem; import io.lumine.mythic.lib.api.item.NBTItem;
import io.lumine.mythic.lib.version.VersionMaterial; import io.lumine.mythic.lib.version.VersionMaterial;
@ -13,7 +12,6 @@ import org.bukkit.inventory.meta.Damageable;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.lang.reflect.Field;
import java.util.*; import java.util.*;
import java.util.logging.Level; import java.util.logging.Level;
@ -45,12 +43,8 @@ public abstract class AbstractItemBuilder {
if (item.getType() == VersionMaterial.PLAYER_HEAD.toMaterial() && configItem.getTexture() != null) if (item.getType() == VersionMaterial.PLAYER_HEAD.toMaterial() && configItem.getTexture() != null)
try { try {
Field profileField = meta.getClass().getDeclaredField("profile"); UtilityMethods.setTextureValue(meta, configItem.getTexture());
profileField.setAccessible(true); } catch (IllegalArgumentException exception) {
GameProfile profile = new GameProfile(UUID.randomUUID(), null);
profile.getProperties().put("textures", new Property("textures", configItem.getTexture()));
profileField.set(meta, profile);
} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException exception) {
MMOCore.log(Level.WARNING, "Could not load texture of config item called '" + configItem.getId() + "'"); MMOCore.log(Level.WARNING, "Could not load texture of config item called '" + configItem.getId() + "'");
} }