Help on custom Enchantment Levels

Discussion in 'Plugin Development' started by XexCruz, May 17, 2017.

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

    XexCruz

    Thanks to and shout out to ChefJava
    I cannot get enchantment levels to change to I to 1 or from V to 5 so roman numerals to numbers <

    Code not working <

    Here is what I typed out

    Code:
    package me.Diversive;
    
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.command.ConsoleCommandSender;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Main extends JavaPlugin {
      
        public void onEnable() {
            ConsoleCommandSender console = getServer().getConsoleSender();
            console.sendMessage(ChatColor.AQUA + " (!) BuffedX420 Enabled (!) ");
            }
            public void onDisable () {
            ConsoleCommandSender console = getServer().getConsoleSender();
            console.sendMessage(ChatColor.RED + " (!) BuffedX420 Disabled (!) ");
        }
        public boolean onCommand(CommandSender sender, Command command, String s, String[] args) {
            return false;
          
        }
            public int romanToInteger(String s) {
                if(s == null) {
                    return 0;
                }
    
                int length = s.length();
                int sum = 0;
                int pre = 0;
    
                for(int i = length - 1; i >= 0; i--){
                    int cur = romanTable(s.charAt(i));
    
                    if(i == length - 1){
                        sum = sum + cur;
                    }else{
                        if(cur < pre){
                            sum = sum - cur;
                        }else{
                            sum = sum + cur;
                        }
                    }
                    pre = cur;
                }
                return sum;
            }
            private int romanTable(char c){
                int num;
                switch(c){
                    case 'I':
                        num = 1;
                        break;
                    case 'V':
                        num = 5;
                        break;
                    case 'X':
                        num = 10;
                        break;
                    case 'L':
                        num = 50;
                        break;
                    case 'C':
                        num = 100;
                        break;
                    case 'D':
                        num = 500;
                        break;
                    case 'M':
                        num = 1000;
                        break;
                    default:
                        num = 0;
                        break;
                }
                return num;
            }
    }
    
    Thanks to who ever can help out means a lot <3
     
  2. Offline

    Zombie_Striker

    @XexCruz
    I'm assuming you are using this to decode your custom lore enchantments, as I don't see any other reason you would have roman numerals. In which case, it would be better to actually create real enchantments, as it will be displayed like all other enchantments, and you can use Encahntment.getLevel() to get the level as an int

    However, if you still don't want to use real enchantments, I can tell you it would be much better if you just do a switch statement and check for each individual roman numeral instead of creating a decoder.
     
Thread Status:
Not open for further replies.

Share This Page