mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-02-22 08:25:12 +00:00
Fix player head meta on versions below 1.13
This commit is contained in:
parent
2c33fb6834
commit
5f9eb22d23
1 changed files with 24 additions and 10 deletions
|
@ -8,10 +8,12 @@ import com.earth2me.essentials.utils.FormatUtil;
|
||||||
import com.earth2me.essentials.utils.MaterialUtil;
|
import com.earth2me.essentials.utils.MaterialUtil;
|
||||||
import com.earth2me.essentials.utils.NumberUtil;
|
import com.earth2me.essentials.utils.NumberUtil;
|
||||||
import com.google.common.base.Joiner;
|
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.api.IEssentials;
|
||||||
import net.ess3.nms.refl.ReflUtil;
|
import net.ess3.nms.refl.ReflUtil;
|
||||||
|
|
||||||
import org.apache.commons.lang.ArrayUtils;
|
|
||||||
import org.bukkit.Color;
|
import org.bukkit.Color;
|
||||||
import org.bukkit.DyeColor;
|
import org.bukkit.DyeColor;
|
||||||
import org.bukkit.FireworkEffect;
|
import org.bukkit.FireworkEffect;
|
||||||
|
@ -26,11 +28,6 @@ import org.bukkit.potion.Potion;
|
||||||
import org.bukkit.potion.PotionEffect;
|
import org.bukkit.potion.PotionEffect;
|
||||||
import org.bukkit.potion.PotionEffectType;
|
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;
|
import static com.earth2me.essentials.I18n.tl;
|
||||||
|
|
||||||
|
|
||||||
|
@ -177,9 +174,7 @@ public class MetaItemStack {
|
||||||
} else if (split.length > 1 && (split[0].equalsIgnoreCase("player") || split[0].equalsIgnoreCase("owner")) && hasMetaPermission(sender, "head", false, true, ess)) {
|
} 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())) {
|
if (MaterialUtil.isPlayerHead(stack.getType(), stack.getDurability())) {
|
||||||
final String owner = split[1];
|
final String owner = split[1];
|
||||||
final SkullMeta meta = (SkullMeta) stack.getItemMeta();
|
setSkullOwner(ess, stack, owner);
|
||||||
meta.setOwningPlayer(ess.getServer().getOfflinePlayer(owner));
|
|
||||||
stack.setItemMeta(meta);
|
|
||||||
} else {
|
} else {
|
||||||
throw new Exception(tl("onlyPlayerSkulls"));
|
throw new Exception(tl("onlyPlayerSkulls"));
|
||||||
}
|
}
|
||||||
|
@ -584,4 +579,23 @@ public class MetaItemStack {
|
||||||
t.printStackTrace();
|
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;
|
||||||
|
} catch (NoSuchMethodError e) {
|
||||||
|
useNewSkullMethod = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
meta.setOwner(owner);
|
||||||
|
stack.setItemMeta(meta);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue