Advertisement
Guest User

CoreClass.java

a guest
Jun 17th, 2021
43
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package io.github.thatsmusic99.skeletonhp;
  2.  
  3. import com.mojang.authlib.GameProfile;
  4. import org.bukkit.Bukkit;
  5. import org.bukkit.ChatColor;
  6. import org.bukkit.Material;
  7. import org.bukkit.command.Command;
  8. import org.bukkit.command.CommandSender;
  9. import org.bukkit.entity.Player;
  10. import org.bukkit.inventory.ItemStack;
  11. import org.bukkit.inventory.meta.SkullMeta;
  12. import org.bukkit.plugin.java.JavaPlugin;
  13.  
  14. import java.lang.reflect.Field;
  15. import java.util.Locale;
  16. import java.util.UUID;
  17.  
  18. public class CoreClass extends JavaPlugin {
  19.  
  20.     @Override
  21.     public void onEnable() {
  22.         getCommand("head").setExecutor(this);
  23.     }
  24.  
  25.     @Override
  26.     public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
  27.         if (args.length > 0 && sender instanceof Player) {
  28.             ItemStack skull = new ItemStack(Material.PLAYER_HEAD);
  29.             SkullMeta meta = (SkullMeta) skull.getItemMeta();
  30.  
  31.             switch (args[0].toLowerCase(Locale.ROOT)) {
  32.                 case "setowner":
  33.                     meta.setOwner("Thatsmusic99");
  34.                     break;
  35.                 case "setowning":
  36.                     meta.setOwningPlayer(Bukkit.getOfflinePlayer("Thatsmusic99"));
  37.                     break;
  38.                 case "headsplus":
  39.                     meta = setSkullOwner("Thatsmusic99", meta);
  40.                     break;
  41.                 default:
  42.                     return true;
  43.             }
  44.             meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', "&e:)"));
  45.             skull.setItemMeta(meta);
  46.             ((Player) sender).getInventory().addItem(skull);
  47.         }
  48.         return true;
  49.     }
  50.  
  51.     private SkullMeta setSkullOwner(String s, SkullMeta m) {
  52.         UUID uuid;
  53.         if (Bukkit.getPlayer(s) != null) {
  54.             uuid = Bukkit.getPlayer(s).getUniqueId();
  55.         } else {
  56.             uuid = UUID.nameUUIDFromBytes(s.getBytes());
  57.         }
  58.         GameProfile profile = new GameProfile(uuid, s);
  59.         try {
  60.             Field profileField = m.getClass().getDeclaredField("profile");
  61.             profileField.setAccessible(true);
  62.             profileField.set(m, profile);
  63.         } catch (NoSuchFieldException | IllegalAccessException e) {
  64.             e.printStackTrace();
  65.         }
  66.         return m;
  67.     }
  68. }
  69.  
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement