Skip to content

Commit

Permalink
8.7.1
Browse files Browse the repository at this point in the history
ItemStack
Changed the names of a few options to more abstract name for future items.

SkullUtils
Fixed an issue where using ItemStack#equals or ItemStack#isSimilar caused a NPE when used between two custom skulls.

XTag
Fixed isItem() for outdated versions above 1.13
  • Loading branch information
CryptoMorin committed Mar 31, 2022
1 parent 0c1c08e commit d2f4ac4
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 17 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.github.cryptomorin</groupId>
<artifactId>XSeries</artifactId>
<version>8.7.0</version>
<version>8.7.1</version>

<name>XSeries</name>
<description>A set of utilities for Minecraft plugins</description>
Expand Down
15 changes: 11 additions & 4 deletions src/main/java/com/cryptomorin/xseries/SkullUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Base64;
import java.util.Objects;
import java.util.UUID;
Expand All @@ -51,7 +52,7 @@
* </ul>
*
* @author Crypto Morin
* @version 3.1.1
* @version 3.1.2
* @see XMaterial
* @see ReflectionUtils
* @see SkullCacheListener
Expand All @@ -61,7 +62,6 @@ public class SkullUtils {
private static final String VALUE_PROPERTY = "{\"textures\":{\"SKIN\":{\"url\":\"";
private static final boolean SUPPORTS_UUID = XMaterial.supports(12);
private static final String TEXTURES = "https://textures.minecraft.net/texture/";
//private static final Pattern BASE64 = Pattern.compile("(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)?");

static {
MethodHandles.Lookup lookup = MethodHandles.lookup();
Expand All @@ -71,9 +71,16 @@ public class SkullUtils {
Class<?> CraftMetaSkull = ReflectionUtils.getCraftClass("inventory.CraftMetaSkull");
Field profile = CraftMetaSkull.getDeclaredField("profile");
profile.setAccessible(true);

profileSetter = lookup.unreflectSetter(profile);
profileGetter = lookup.unreflectGetter(profile);

try {
// https://github.com/CryptoMorin/XSeries/issues/169
Method setProfile = CraftMetaSkull.getDeclaredMethod("setProfile", GameProfile.class);
setProfile.setAccessible(true);
profileSetter = lookup.unreflect(setProfile);
} catch (NoSuchMethodException e) {
profileSetter = lookup.unreflectSetter(profile);
}
} catch (NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
}
Expand Down
16 changes: 7 additions & 9 deletions src/main/java/com/cryptomorin/xseries/XItemStack.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
* ItemStack: https://hub.spigotmc.org/javadocs/spigot/org/bukkit/inventory/ItemStack.html
*
* @author Crypto Morin
* @version 7.0.0
* @version 7.1.0
* @see XMaterial
* @see XPotion
* @see SkullUtils
Expand Down Expand Up @@ -196,23 +196,21 @@ public static void serialize(@Nonnull ItemStack item, @Nonnull ConfigurationSect
config.set("color", color.getRed() + ", " + color.getGreen() + ", " + color.getBlue());
} else if (meta instanceof PotionMeta) {
if (supports(9)) {

PotionMeta potion = (PotionMeta) meta;
List<PotionEffect> customEffects = potion.getCustomEffects();
List<String> effects = new ArrayList<>(customEffects.size());
for (PotionEffect effect : customEffects) {
effects.add(effect.getType().getName() + ", " + effect.getDuration() + ", " + effect.getAmplifier());
}

config.set("custom-effects", effects);
config.set("effects", effects);
PotionData potionData = potion.getBasePotionData();
config.set("base-effect", potionData.getType().name() + ", " + potionData.isExtended() + ", " + potionData.isUpgraded());

if (potion.hasColor()) config.set("color", potion.getColor().asRGB());

} else {

//check for water bottles in 1.8
// Check for water bottles in 1.8
if (item.getDurability() != 0) {
Potion potion = Potion.fromItemStack(item);
config.set("level", potion.getLevel());
Expand Down Expand Up @@ -288,7 +286,7 @@ public static void serialize(@Nonnull ItemStack item, @Nonnull ConfigurationSect
} else if (supports(17)) {
if (meta instanceof AxolotlBucketMeta) {
AxolotlBucketMeta bucket = (AxolotlBucketMeta) meta;
if (bucket.hasVariant()) config.set("variant", bucket.getVariant().toString());
if (bucket.hasVariant()) config.set("color", bucket.getVariant().toString());
}
} else if (supports(16)) {
if (meta instanceof CompassMeta) {
Expand Down Expand Up @@ -478,7 +476,7 @@ public static ItemStack edit(@Nonnull ItemStack item, @Nonnull ConfigurationSect
if (supports(9)) {
PotionMeta potion = (PotionMeta) meta;

for (String effects : config.getStringList("custom-effects")) {
for (String effects : config.getStringList("effects")) {
XPotion.Effect effect = XPotion.parseEffect(effects);
if (effect.hasChance()) potion.addCustomEffect(effect.getEffect(), true);
}
Expand Down Expand Up @@ -521,7 +519,7 @@ public static ItemStack edit(@Nonnull ItemStack item, @Nonnull ConfigurationSect
spawner.update(true);
bsm.setBlockState(spawner);
} else if (supports(11) && state instanceof ShulkerBox) {
ConfigurationSection shulkerSection = config.getConfigurationSection("shulker");
ConfigurationSection shulkerSection = config.getConfigurationSection("contents");
if (shulkerSection != null) {
ShulkerBox box = (ShulkerBox) state;
for (String key : shulkerSection.getKeys(false)) {
Expand Down Expand Up @@ -637,7 +635,7 @@ public static ItemStack edit(@Nonnull ItemStack item, @Nonnull ConfigurationSect
} else if (supports(17)) {
if (meta instanceof AxolotlBucketMeta) {
AxolotlBucketMeta bucket = (AxolotlBucketMeta) meta;
String variantStr = config.getString("variant");
String variantStr = config.getString("color");
if (variantStr != null) {
Axolotl.Variant variant = Enums.getIfPresent(Axolotl.Variant.class, variantStr.toUpperCase(Locale.ENGLISH)).or(Axolotl.Variant.BLUE);
bucket.setVariant(variant);
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/com/cryptomorin/xseries/XTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

import java.util.*;

@SuppressWarnings("NotNullFieldNotInitialized")
public final class XTag<@NonNull T extends Enum<T>> {

public static final @NonNull XTag<XMaterial> AIR;
Expand Down Expand Up @@ -2010,11 +2009,15 @@ private static XMaterial[] findAllCorals(boolean alive, boolean block, boolean f
* Checks if this Material is an obtainable item. "Obtainable items" are simply materials that can be displayed in your GUI.
* This method is mainly designed to support pre-1.13, servers using 1.13 and above will directly have their materials checked with {@link Material#isItem()}
*
* @return true if this material is an item.
* @return true if this material is an item, otherwise false if it's not an item or the item is not supported.
* @since 1.13
*/
public static boolean isItem(XMaterial material) {
if (XMaterial.supports(13)) return material.parseMaterial().isItem();
if (XMaterial.supports(13)) {
Material mat = material.parseMaterial();
return mat != null && mat.isItem();
}

switch (material) { // All the materials that are NOT an item (only 1.12 materials)
case ATTACHED_MELON_STEM:
case ATTACHED_PUMPKIN_STEM:
Expand Down

0 comments on commit d2f4ac4

Please sign in to comment.