Glow Items

Discussion in 'Spigot Plugin Development' started by Dori_mon, Jun 24, 2016.

  1. Hello,
    Can someone help me add glow to the ItemStack named sword()?
    This is the code:


    Code (Text):
    package me.Dori_mon.CustomEnchants;

    import java.util.ArrayList;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.java.JavaPlugin;

    public class Main extends JavaPlugin implements Listener {
       
        public void onEnable() {
            System.out.println(">> CustomEnchants has been Enabled! <<");
            System.out.println(">> Plugin by Dori_mon <<");
            getConfig().options().copyDefaults(true);
            saveConfig();
        }
       
        public void onDisable() {
            System.out.println("<< CustomEnchants has been Disabled! >>");
            System.out.println("<< Plugin by Dori_mon >>");
        }
       
       
        public ItemStack sword() {
            ItemStack is = new ItemStack(Material.DIAMOND_SWORD);
            ItemMeta meta = is.getItemMeta();
            String swordName = getConfig().getString("Sword-Name");
            swordName = ChatColor.translateAlternateColorCodes('&', swordName);
            meta.setDisplayName(swordName);
            ArrayList<String> lore = new ArrayList<String>();
            lore.add(ChatColor.GRAY + "Blindness");
            meta.setLore(lore);
            is.setItemMeta(meta);
            return is;
        }
       
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            Player p = (Player) sender;
            if (label.equalsIgnoreCase("sword")) {
                if (args.length == 0) {
                    p.sendMessage("/sword blindness <player>");
                } else if (args.length == 1) {
                    if (args[0].equalsIgnoreCase("Blindness")) {
                        if (sender instanceof Player) {
                            p.getInventory().addItem(sword());
                        }
                    }
                } else if (args.length == 2) {
                    if (args[0].equalsIgnoreCase("Blindness")) {
                        Player p2 = Bukkit.getPlayer(args[1]);
                        p2.getInventory().addItem(sword());
                    }
                }
            }
            return false;
        }

    }
     
     
    • Winner Winner x 1
  2. Code (Text):
      public static ItemStack addGlow(ItemStack item){
        net.minecraft.server.v1_8_R3.ItemStack nmsStack = CraftItemStack.asNMSCopy(item);
        NBTTagCompound tag = null;
        if (!nmsStack.hasTag()) {
         tag = new NBTTagCompound ();
         nmsStack.setTag(tag);
        }
        if (tag == null) tag = nmsStack.getTag();
        NBTTagList ench = new NBTTagList();
        tag.set("ench", ench);
        nmsStack.setTag(tag);
        return CraftItemStack.asCraftMirror(nmsStack);
      }
    To use it you must do "addGlow(Your ItemStack)"