Skip to content

Commit

Permalink
Fix player head meta on versions below 1.13
Browse files Browse the repository at this point in the history
  • Loading branch information
mdcfe committed Aug 24, 2019
1 parent 2c33fb6 commit 5f9eb22
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions Essentials/src/com/earth2me/essentials/MetaItemStack.java
Expand Up @@ -8,10 +8,12 @@
import com.earth2me.essentials.utils.MaterialUtil;
import com.earth2me.essentials.utils.NumberUtil;
import com.google.common.base.Joiner;
import java.lang.reflect.Method;
import java.util.*;
import java.util.logging.Level;
import java.util.regex.Pattern;
import net.ess3.api.IEssentials;
import net.ess3.nms.refl.ReflUtil;

import org.apache.commons.lang.ArrayUtils;
import org.bukkit.Color;
import org.bukkit.DyeColor;
import org.bukkit.FireworkEffect;
Expand All @@ -26,11 +28,6 @@
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;

import java.lang.reflect.Method;
import java.util.*;
import java.util.logging.Level;
import java.util.regex.Pattern;

import static com.earth2me.essentials.I18n.tl;


Expand Down Expand Up @@ -177,9 +174,7 @@ public void addStringMeta(final CommandSource sender, final boolean allowUnsafe,
} else if (split.length > 1 && (split[0].equalsIgnoreCase("player") || split[0].equalsIgnoreCase("owner")) && hasMetaPermission(sender, "head", false, true, ess)) {
if (MaterialUtil.isPlayerHead(stack.getType(), stack.getDurability())) {
final String owner = split[1];
final SkullMeta meta = (SkullMeta) stack.getItemMeta();
meta.setOwningPlayer(ess.getServer().getOfflinePlayer(owner));
stack.setItemMeta(meta);
setSkullOwner(ess, stack, owner);
} else {
throw new Exception(tl("onlyPlayerSkulls"));
}
Expand Down Expand Up @@ -584,4 +579,23 @@ private void setUnbreakable(ItemStack is, boolean unbreakable) {
t.printStackTrace();
}
}

private static boolean useNewSkullMethod = true;

private static void setSkullOwner(final IEssentials ess, final ItemStack stack, final String owner) {
if (!(stack.getItemMeta() instanceof SkullMeta)) return;

SkullMeta meta = (SkullMeta) stack.getItemMeta();
if (useNewSkullMethod) {
try {
meta.setOwningPlayer(ess.getServer().getOfflinePlayer(owner));
return;

This comment has been minimized.

Copy link
@mdcfe

mdcfe Aug 28, 2019

Author Member

Missing stack#setItemMeta call.

} catch (NoSuchMethodError e) {
useNewSkullMethod = false;
}
}

meta.setOwner(owner);
stack.setItemMeta(meta);
}
}

0 comments on commit 5f9eb22

Please sign in to comment.