Skip to content

Commit d2f4ac4

Browse files
committed
8.7.1
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
1 parent 0c1c08e commit d2f4ac4

File tree

4 files changed

+25
-17
lines changed

4 files changed

+25
-17
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.github.cryptomorin</groupId>
88
<artifactId>XSeries</artifactId>
9-
<version>8.7.0</version>
9+
<version>8.7.1</version>
1010

1111
<name>XSeries</name>
1212
<description>A set of utilities for Minecraft plugins</description>

src/main/java/com/cryptomorin/xseries/SkullUtils.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import java.lang.invoke.MethodHandle;
3737
import java.lang.invoke.MethodHandles;
3838
import java.lang.reflect.Field;
39+
import java.lang.reflect.Method;
3940
import java.util.Base64;
4041
import java.util.Objects;
4142
import java.util.UUID;
@@ -51,7 +52,7 @@
5152
* </ul>
5253
*
5354
* @author Crypto Morin
54-
* @version 3.1.1
55+
* @version 3.1.2
5556
* @see XMaterial
5657
* @see ReflectionUtils
5758
* @see SkullCacheListener
@@ -61,7 +62,6 @@ public class SkullUtils {
6162
private static final String VALUE_PROPERTY = "{\"textures\":{\"SKIN\":{\"url\":\"";
6263
private static final boolean SUPPORTS_UUID = XMaterial.supports(12);
6364
private static final String TEXTURES = "https://textures.minecraft.net/texture/";
64-
//private static final Pattern BASE64 = Pattern.compile("(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)?");
6565

6666
static {
6767
MethodHandles.Lookup lookup = MethodHandles.lookup();
@@ -71,9 +71,16 @@ public class SkullUtils {
7171
Class<?> CraftMetaSkull = ReflectionUtils.getCraftClass("inventory.CraftMetaSkull");
7272
Field profile = CraftMetaSkull.getDeclaredField("profile");
7373
profile.setAccessible(true);
74-
75-
profileSetter = lookup.unreflectSetter(profile);
7674
profileGetter = lookup.unreflectGetter(profile);
75+
76+
try {
77+
// https://github.com/CryptoMorin/XSeries/issues/169
78+
Method setProfile = CraftMetaSkull.getDeclaredMethod("setProfile", GameProfile.class);
79+
setProfile.setAccessible(true);
80+
profileSetter = lookup.unreflect(setProfile);
81+
} catch (NoSuchMethodException e) {
82+
profileSetter = lookup.unreflectSetter(profile);
83+
}
7784
} catch (NoSuchFieldException | IllegalAccessException e) {
7885
e.printStackTrace();
7986
}

src/main/java/com/cryptomorin/xseries/XItemStack.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
* ItemStack: https://hub.spigotmc.org/javadocs/spigot/org/bukkit/inventory/ItemStack.html
7575
*
7676
* @author Crypto Morin
77-
* @version 7.0.0
77+
* @version 7.1.0
7878
* @see XMaterial
7979
* @see XPotion
8080
* @see SkullUtils
@@ -196,23 +196,21 @@ public static void serialize(@Nonnull ItemStack item, @Nonnull ConfigurationSect
196196
config.set("color", color.getRed() + ", " + color.getGreen() + ", " + color.getBlue());
197197
} else if (meta instanceof PotionMeta) {
198198
if (supports(9)) {
199-
200199
PotionMeta potion = (PotionMeta) meta;
201200
List<PotionEffect> customEffects = potion.getCustomEffects();
202201
List<String> effects = new ArrayList<>(customEffects.size());
203202
for (PotionEffect effect : customEffects) {
204203
effects.add(effect.getType().getName() + ", " + effect.getDuration() + ", " + effect.getAmplifier());
205204
}
206205

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

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

213212
} else {
214-
215-
//check for water bottles in 1.8
213+
// Check for water bottles in 1.8
216214
if (item.getDurability() != 0) {
217215
Potion potion = Potion.fromItemStack(item);
218216
config.set("level", potion.getLevel());
@@ -288,7 +286,7 @@ public static void serialize(@Nonnull ItemStack item, @Nonnull ConfigurationSect
288286
} else if (supports(17)) {
289287
if (meta instanceof AxolotlBucketMeta) {
290288
AxolotlBucketMeta bucket = (AxolotlBucketMeta) meta;
291-
if (bucket.hasVariant()) config.set("variant", bucket.getVariant().toString());
289+
if (bucket.hasVariant()) config.set("color", bucket.getVariant().toString());
292290
}
293291
} else if (supports(16)) {
294292
if (meta instanceof CompassMeta) {
@@ -478,7 +476,7 @@ public static ItemStack edit(@Nonnull ItemStack item, @Nonnull ConfigurationSect
478476
if (supports(9)) {
479477
PotionMeta potion = (PotionMeta) meta;
480478

481-
for (String effects : config.getStringList("custom-effects")) {
479+
for (String effects : config.getStringList("effects")) {
482480
XPotion.Effect effect = XPotion.parseEffect(effects);
483481
if (effect.hasChance()) potion.addCustomEffect(effect.getEffect(), true);
484482
}
@@ -521,7 +519,7 @@ public static ItemStack edit(@Nonnull ItemStack item, @Nonnull ConfigurationSect
521519
spawner.update(true);
522520
bsm.setBlockState(spawner);
523521
} else if (supports(11) && state instanceof ShulkerBox) {
524-
ConfigurationSection shulkerSection = config.getConfigurationSection("shulker");
522+
ConfigurationSection shulkerSection = config.getConfigurationSection("contents");
525523
if (shulkerSection != null) {
526524
ShulkerBox box = (ShulkerBox) state;
527525
for (String key : shulkerSection.getKeys(false)) {
@@ -637,7 +635,7 @@ public static ItemStack edit(@Nonnull ItemStack item, @Nonnull ConfigurationSect
637635
} else if (supports(17)) {
638636
if (meta instanceof AxolotlBucketMeta) {
639637
AxolotlBucketMeta bucket = (AxolotlBucketMeta) meta;
640-
String variantStr = config.getString("variant");
638+
String variantStr = config.getString("color");
641639
if (variantStr != null) {
642640
Axolotl.Variant variant = Enums.getIfPresent(Axolotl.Variant.class, variantStr.toUpperCase(Locale.ENGLISH)).or(Axolotl.Variant.BLUE);
643641
bucket.setVariant(variant);

src/main/java/com/cryptomorin/xseries/XTag.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727

2828
import java.util.*;
2929

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

3332
public static final @NonNull XTag<XMaterial> AIR;
@@ -2010,11 +2009,15 @@ private static XMaterial[] findAllCorals(boolean alive, boolean block, boolean f
20102009
* Checks if this Material is an obtainable item. "Obtainable items" are simply materials that can be displayed in your GUI.
20112010
* 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()}
20122011
*
2013-
* @return true if this material is an item.
2012+
* @return true if this material is an item, otherwise false if it's not an item or the item is not supported.
20142013
* @since 1.13
20152014
*/
20162015
public static boolean isItem(XMaterial material) {
2017-
if (XMaterial.supports(13)) return material.parseMaterial().isItem();
2016+
if (XMaterial.supports(13)) {
2017+
Material mat = material.parseMaterial();
2018+
return mat != null && mat.isItem();
2019+
}
2020+
20182021
switch (material) { // All the materials that are NOT an item (only 1.12 materials)
20192022
case ATTACHED_MELON_STEM:
20202023
case ATTACHED_PUMPKIN_STEM:

0 commit comments

Comments
 (0)