What's wrong in this if check?

Discussion in 'Plugin Development' started by Edvio, Aug 2, 2016.

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

    Edvio

    I've been trying to fix this bug for ages now, but it still won't work, it always opens the first inventory (getRedeemINV())
    Code:
    Code:
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
            if (cmd.getName().equalsIgnoreCase("redeem")) {
                Player p = (Player)sender;
                YamlConfiguration config = new YamlConfiguration();
            if(config.getInt(String.valueOf(p.getUniqueId())) != 1 || !config.contains(String.valueOf(p.getUniqueId()))) {
                if(hasRank(p)) {
                p.openInventory(getRedeemINV());   
            p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&cMake sure you have inventory space before you redeem your items!"));
                }
            }else if(config.getInt(String.valueOf(p.getUniqueId())) == 1 || !hasRank(p)) {
                p.openInventory(getRedeemINVAlreadyClaimed());
            }
            }
            return false;
        }
                     
    
                      public void saveRedeemTrue(Player player) throws IOException {
                        YamlConfiguration config = new YamlConfiguration();
                        config.set(String.valueOf(player.getUniqueId()), 1);
                          File file = new File(new File(Main.instance.getDataFolder(), "data"), "redeemdata.yml");
                        config.save(file);
                        }
     
  2. Offline

    ArsenArsen

    You create a new configuration every time. You need to use getConfig for config.yml and FileConfiguration.load for non config.yml files.
     
  3. @Edvio
    Also, please format your code. Currently it is extremely hard to read. To format your code in eclipse, simply press Ctrl + Shift + F.
     
  4. Offline

    Edvio

    It works to put the uuid and the int in the config, but it doesn't work to get it
     
  5. Offline

    ArsenArsen

    Because you discard it later. Use getConfig.
     
  6. Offline

    Edvio

    It's not the main config.......
     
  7. Offline

    ArsenArsen

  8. Offline

    Edvio

  9. @Edvio Using console will throw an error, check before casting
     
Thread Status:
Not open for further replies.

Share This Page