Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Map;
- import java.util.HashMap;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.enchantments.Enchantment;
- import org.bukkit.event.enchantment.EnchantItemEvent;
- public class PlayerEnchantLock implements Listener
- {
- // Map to set the limit on the enchants.
- Map<Enchantment, Integer> enchantLockList = new HashMap<Enchantment, Integer>();
- // Set enchant locks here in the constructor
- public PlayerEnchantLock()
- {
- enchantLockList.put(Enchantment.PROTECTION_ENVIRONMENTAL, 2); // Protection
- enchantLockList.put(Enchantment.PROTECTION_FIRE, 4); // Fire Protection
- enchantLockList.put(Enchantment.PROTECTION_FALL, 4); // Feather Failing
- enchantLockList.put(Enchantment.PROTECTION_EXPLOSIONS, 4); // Blast Protection
- enchantLockList.put(Enchantment.PROTECTION_PROJECTILE, 4); // Projectile Protection
- enchantLockList.put(Enchantment.OXYGEN, 3); // Respiration
- enchantLockList.put(Enchantment.WATER_WORKER, 1); // Aqua Affinity
- enchantLockList.put(Enchantment.THORNS, 3); // Thorns
- enchantLockList.put(Enchantment.DAMAGE_ALL, 3); // Sharpness
- enchantLockList.put(Enchantment.DAMAGE_UNDEAD, 5); // Smite
- enchantLockList.put(Enchantment.DAMAGE_ARTHROPODS, 5); // Bane of Arthropods
- enchantLockList.put(Enchantment.KNOCKBACK, 0); // Knockback
- enchantLockList.put(Enchantment.FIRE_ASPECT, 0); // Fire Aspect
- enchantLockList.put(Enchantment.LOOT_BONUS_MOBS, 3); // Looting
- enchantLockList.put(Enchantment.DIG_SPEED, 5); // Efficiency
- enchantLockList.put(Enchantment.SILK_TOUCH, 1); // Silk Touch
- enchantLockList.put(Enchantment.DURABILITY, 3); // Unbreaking
- enchantLockList.put(Enchantment.LOOT_BONUS_BLOCKS, 3); // Fortune
- enchantLockList.put(Enchantment.ARROW_DAMAGE, 3); // Power
- enchantLockList.put(Enchantment.ARROW_KNOCKBACK, 0); // Punch
- enchantLockList.put(Enchantment.ARROW_FIRE, 1); // Flame
- enchantLockList.put(Enchantment.ARROW_INFINITE, 1); // Infinite
- enchantLockList.put(Enchantment.LUCK, 3); // Luck
- enchantLockList.put(Enchantment.LURE, 3); // Lure
- }
- // Event that will lock the enchant levels from an enchant table.
- @EventHandler
- public void onEnchantLock(EnchantItemEvent event)
- {
- Map<Enchantment, Integer> validEnchant = new HashMap<Enchantment, Integer>();
- for (Enchantment key : event.getEnchantsToAdd().keySet())
- {
- int LevelToSet = 0;
- if (enchantLockList.containsKey(key))
- {
- if (enchantLockList.get(key) != 0)
- {
- if (event.getEnchantsToAdd().get(key) > enchantLockList.get(key))
- LevelToSet = enchantLockList.get(key);
- else
- LevelToSet = event.getEnchantsToAdd().get(key);
- validEnchant.put(key, LevelToSet);
- }
- }
- }
- event.getEnchantsToAdd().clear();
- for (Enchantment key : validEnchant.keySet())
- event.getEnchantsToAdd().put(key, validEnchant.get(key));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement