简体   繁体   中英

getInt Function Doesn't Return Anything

I am currently trying to making a custom rules plugin (for minecraft) and I am trying to see if the player has something activated which I stored in the config file. It is in the listener class (which calls the config from the main). Here is my code:

@EventHandler
public void onEvent(AsyncPlayerChatEvent e) {

    Player player = e.getPlayer();


    if (config.getInt("EditingLine." + player.getName().toLowerCase()) == 1) {
        int line = 0;
        try {
            line = Integer.parseInt(e.getMessage());
        } catch (Exception b) {
            player.sendMessage(ChatColor.RED + "Invalid Number.");
            config.set("EditingLine." + player.getName().toLowerCase(), 0);
        }

        if (!(line == 0)) {
            config.set("EditingLine." + player.getName().toLowerCase(), 0);
            config.set("EditingText." + player.getName().toLowerCase(), 1);
            e.setCancelled(true);
            player.sendMessage(ChatColor.GRAY + "[" + ChatColor.GOLD + "Custom Rules" + ChatColor.GRAY + "]" + ChatColor.GREEN + " Enter the text you would now like on that line.");
        }
    }

}

The, config.getInt() function in the if then statement currently returns nothing. This may be happening because the config in the Listener Class is actually calling a custom made config, called 'playerdata.yml' and not the actual 'config.yml'. If there is any easier way to write this script, also let me know. I'm trying to make this as simple as I can.

通过将我的两个配置文件合并在一起,答案已得到解决。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM