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.
@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?
@Puzikovs 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 Code:java package me.ialistannen.enchantmentcap; import org.bukkit.Bukkit;import org.bukkit.enchantments.Enchantment;import org.bukkit.event.EventHandler;import org.bukkit.event.Listener;import org.bukkit.event.enchantment.EnchantItemEvent;import org.bukkit.plugin.java.JavaPlugin; import java.util.HashMap;import java.util.Map;import java.util.regex.Matcher;import java.util.regex.Pattern; /*** Limits the maximum enchantment level you can get*/public class EnchantmentCap extends JavaPlugin implements Listener { // Enchantment defines static hash code private Map<Enchantment, Integer> enchantmentMaxMap; private static final Pattern SPLITTER_PATTERN = Pattern.compile("(.+?);([0-9])", Pattern.CASE_INSENSITIVE); @Override public void onEnable() { saveDefaultConfig(); createMap(); Bukkit.getPluginManager().registerEvents(this, this); } private void createMap() { enchantmentMaxMap = new HashMap<>(); for (String line : getConfig().getStringList("enchantments")) { Matcher matcher = SPLITTER_PATTERN.matcher(line.trim()); if (!matcher.matches()) { getLogger().warning("Wrong format: '" + line + "'"); continue; } String enchantmentName = matcher.group(1).trim(); // must be an int, as the pattern matched ("[0-9]") int level = Integer.parseInt(matcher.group(2)); Enchantment enchantment = Enchantment.getByName(enchantmentName); if (enchantment == null) { getLogger().warning("Unknown enchantment: '" + enchantmentName + "'"); continue; } enchantmentMaxMap.put(enchantment, level); } } /** * Prevents the enchanting with too high levels * * @param event The {@link EnchantItemEvent} */ @EventHandler public void onEnchant(EnchantItemEvent event) { if(event.getEnchanter().hasPermission(getConfig().getString("bypass_permission"))) { return; } event.getEnchantsToAdd().entrySet().stream() .filter(entry -> enchantmentMaxMap.containsKey(entry.getKey())) .forEach(entry -> { int maxLevel = enchantmentMaxMap.get(entry.getKey()); if (entry.getValue() > maxLevel) { entry.setValue(maxLevel); } }); }}
@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?
@Puzikovs Ops automatically have all permisions, so also the bypass. Only limits enchantin in an enchanting table.
@I Al Istannen God i am stupid sometimes.... It works just fine, thanks a lot Mr ^^ You might as well drop it on bukkit plugins because this is a really good thing!
@Puzikovs No problem, glad it works We all have our moments... The default spawn protection has given me a few headaches too I am probably too lazy to do this 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
@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?
@Puzikovs You may, but I will maybe not do it. I won't promise anything, as I know myself good enough School starts again at Monday and I will enter the "Oberstufe" so I have no idea how my timetable will look And what I do there counts in the final mark, which I am not really a fan of... Good luck with your server though, hope you find the time and players to enjoy it!
@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 ^^