Filled Enchant-cap

Discussion in 'Plugin Requests' started by Puzikovs, Sep 8, 2016.

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


    Plugin category: Enchantment small

    Minecraft version: 1.10.2

    Suggested name: EnchantmentLimiter

    What I want: Would be awesome it could be as simple as possible so it wouldnt take up much Server power, some of the plugins i found are bigger then this. But if someone can manage to give me something i need that is lightweight then please do share.

    What i need from this plugin is so that when people try to enchant any items using enchanting table, the best they could enchant on protection - would be protection 3. So protection 4 items couldnt be enchanted.

    Thats basically for my servers mechanics. Is it even possible?

    Seems like it is fairly easy to make since there isnt alot needed.

    Ideas for commands: Non needed

    Ideas for permissions: Would be grate if there could be a group to add so this could be bypassed.

    When I'd like it by: As soon as you can.

    Thank you.
    Last edited: Sep 8, 2016
  2. Offline

    I Al Istannen

    Does this work?

    Permission is defined in the config.

    Link: dropbox.
  3. Offline


    @I Al Istannen Im sorry to say i cant test it out right now, but i will as soon as i get home today.

    You already kind a made it? or you had something stored? :D
  4. Offline

    I Al Istannen

    No problem, take your time :)

    I made it. But this is all the code (74 lines with imports and comments), so it was quite easy ;)
    1. package me.ialistannen.enchantmentcap;
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.enchantments.Enchantment;
    5. import org.bukkit.event.EventHandler;
    6. import org.bukkit.event.Listener;
    7. import org.bukkit.event.enchantment.EnchantItemEvent;
    8. import;
    10. import java.util.HashMap;
    11. import java.util.Map;
    12. import java.util.regex.Matcher;
    13. import java.util.regex.Pattern;
    15. /**
    16. * Limits the maximum enchantment level you can get
    17. */
    18. public class EnchantmentCap extends JavaPlugin implements Listener {
    20. // Enchantment defines static hash code
    21. private Map<Enchantment, Integer> enchantmentMaxMap;
    23. private static final Pattern SPLITTER_PATTERN = Pattern.compile("(.+?);([0-9])", Pattern.CASE_INSENSITIVE);
    25. @Override
    26. public void onEnable() {
    27. saveDefaultConfig();
    28. createMap();
    29. Bukkit.getPluginManager().registerEvents(this, this);
    30. }
    32. private void createMap() {
    33. enchantmentMaxMap = new HashMap<>();
    35. for (String line : getConfig().getStringList("enchantments")) {
    36. Matcher matcher = SPLITTER_PATTERN.matcher(line.trim());
    37. if (!matcher.matches()) {
    38. getLogger().warning("Wrong format: '" + line + "'");
    39. continue;
    40. }
    42. String enchantmentName =;
    43. // must be an int, as the pattern matched ("[0-9]")
    44. int level = Integer.parseInt(;
    46. Enchantment enchantment = Enchantment.getByName(enchantmentName);
    47. if (enchantment == null) {
    48. getLogger().warning("Unknown enchantment: '" + enchantmentName + "'");
    49. continue;
    50. }
    52. enchantmentMaxMap.put(enchantment, level);
    53. }
    54. }
    56. /**
    57.   * Prevents the enchanting with too high levels
    58.   *
    59.   * @param event The {@link EnchantItemEvent}
    60.   */
    61. @EventHandler
    62. public void onEnchant(EnchantItemEvent event) {
    63. if(event.getEnchanter().hasPermission(getConfig().getString("bypass_permission"))) {
    64. return;
    65. }
    66. event.getEnchantsToAdd().entrySet().stream()
    67. .filter(entry -> enchantmentMaxMap.containsKey(entry.getKey()))
    68. .forEach(entry -> {
    69. int maxLevel = enchantmentMaxMap.get(entry.getKey());
    70. if (entry.getValue() > maxLevel) {
    71. entry.setValue(maxLevel);
    72. }
    73. });
    74. }
    75. }
  5. @I Al Istannen Rip those like 15% of Java 7 servers

    EDIT: *20.99%
  6. Offline

    I Al Istannen

    bwfcwalshy likes this.
  7. Offline


    @I Al Istannen Will op's be able to enchant prot 4? Since i will be using console to create specific prot 4 items, that will be given using another plugin, does this limit only the enchantment you can get by using enchantment table?
    Last edited by a moderator: Sep 8, 2016
  8. Offline

    I Al Istannen

    Ops automatically have all permisions, so also the bypass. Only limits enchantin in an enchanting table.
  9. Offline


  10. Offline

    I Al Istannen

    Me too :p
    Don't see why it shouldn't though, as long as you are running Java 8 ;)
  11. Offline


    @I Al Istannen Update: I am not able to open enchantment table unless i am op :D
  12. Offline

    I Al Istannen

    Try going away from spawn and out of any protected region.
  13. Offline


    @I Al Istannen God i am stupid sometimes.... :D It works just fine, thanks a lot Mr ^^
    You might as well drop it on bukkit plugins because this is a really good thing!
  14. Offline

    I Al Istannen

    No problem, glad it works :)

    We all have our moments... :p
    The default spawn protection has given me a few headaches too ;)

    I am probably too lazy to do this :D And I don't think it is requested that often, but mostly lazyness.

    It is in no way malicious though, if that is what you are afraid of. The code is above, feel free to compile it yourself :)
  15. Offline


    @I Al Istannen I dont have a huge server that i should be afraid of something actually.

    I havent worked with a minecraft server since 1.9 got release, when i went out of time and things to finish the server.

    WHat i had done before people actually enjoyed really much, but now i am planning to build everything and much more on 1.10.

    If i will be in need of any other small things, might i @TaG you?
  16. Offline

    I Al Istannen

    You may, but I will maybe not do it. I won't promise anything, as I know myself good enough :D

    School starts again at Monday and I will enter the "Oberstufe" so I have no idea how my timetable will look :p And what I do there counts in the final mark, which I am not really a fan of... :p

    Good luck with your server though, hope you find the time and players to enjoy it!
  17. Offline


    @I Al Istannen I think i will do just fine this time, will finish everything first, then check twice and fix up my own mistakes.

    Good luck with your school ^^
    I Al Istannen likes this.
Thread Status:
Not open for further replies.

Share This Page