[Sothatsit's Useful Snippets] - Block Letters, MobBarAPI, AutoRespawn + More!

Discussion in 'Resources' started by SoThatsIt, Feb 1, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    Regablith

    That bump though
     
  2. Offline

    ChipDev

    Awesome, you always have use for atleast one ;)
     
  3. Offline

    DevRosemberg

    That will never actually work properly as you're never actually setting the wave's color.
     
  4. Offline

    T0pAz7

    EnchantGlow doesn't work.
     
  5. Offline

    Bammerbom

  6. Offline

    T0pAz7

    I had to fix some things to make it work. For example if it was registered, then don't register again and a way to remove the enchantment.

    Code:
    package com.zyria.utils;
    
    import org.bukkit.enchantments.Enchantment;
    import org.bukkit.enchantments.EnchantmentTarget;
    import org.bukkit.enchantments.EnchantmentWrapper;
    import org.bukkit.inventory.ItemStack;
    
    import java.lang.reflect.Field;
    
    public class EnchantGlow extends EnchantmentWrapper
    {
        private static Enchantment glow;
    
        public EnchantGlow(int id)
        {
            super(id);
        }
    
        @Override
        public boolean canEnchantItem(ItemStack item)
        {
            return false;
        }
    
        @Override
        public boolean conflictsWith(Enchantment other)
        {
            return false;
        }
    
        @Override
        public EnchantmentTarget getItemTarget()
        {
            return null;
        }
    
        @Override
        public int getMaxLevel()
        {
            return 10;
        }
    
        @Override
        public String getName()
        {
            return "Glow";
        }
    
        @Override
        public int getStartLevel()
        {
            return 1;
        }
    
        public static Enchantment getGlow()
        {
            if (glow != null) return glow;
    
            if(Enchantment.getByName("Glow") != null)
                return Enchantment.getByName("Glow");
    
            try
            {
                Field f = Enchantment.class.getDeclaredField("acceptingNew");
                f.setAccessible(true);
                f.set(null, true);
            }
            catch (Exception e)
            {
                e.printStackTrace();
            }
    
            glow = new EnchantGlow(255);
            Enchantment.registerEnchantment(glow);
            return glow;
        }
    
        public static ItemStack addGlow(ItemStack item)
        {
            Enchantment glow = getGlow();
    
            if(!item.containsEnchantment(glow))
                item.addUnsafeEnchantment(glow, 1);
    
            return item;
        }
    
        public static ItemStack removeGlow(ItemStack item)
        {
            Enchantment glow = getGlow();
    
            if(item.containsEnchantment(glow))
                item.removeEnchantment(glow);
    
            return item;
        }
    }
     
Thread Status:
Not open for further replies.

Share This Page