简体   繁体   English

getInt 函数不返回任何内容

[英]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. if then 语句中的 config.getInt() 函数当前不返回任何内容。 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'.这可能是因为 Listener 类中的配置实际上正在调用自定义配置,称为“playerdata.yml”而不是实际的“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.我正在努力使这尽可能简单。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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