Item amounts - configs

Discussion in 'Plugin Development' started by Coopah, Dec 26, 2014.

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

    Coopah

    So I'm working on a plugin and I'm trying to make it so you can implement a feature from the config. So what I'm having issues with is the item amounts. I have this code however when I break the block it doesn't drop any items?
    Code for the blockbreak event:
    Code:
     else if (b.getTypeId() == plugin.getConfig().getInt("Blocks.CustomBlock1.Item")) {
                           
                            e.setCancelled(true);
                           
                            b.setTypeId(plugin.getConfig().getInt("Blocks.Blockholder"));
                                                   
                            for(String item : plugin.getConfig().getStringList("Blocks.CustomBlock1.Drops")){
                                String[] breakdown = item.split(":");
                                int itemId = parse(breakdown[0]);
                                int itemAmount = parse(breakdown[1]);
                               
                                w.dropItem(b.getLocation(), new ItemStack(itemId, itemAmount));
                            }
                                Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
                                    public void run() {
                                        b.setTypeId(plugin.getConfig().getInt("Blocks.CustomBlock1.Item"));
                                        b.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, Material.COBBLESTONE);
                                    }
                                }, plugin.getConfig().getInt("Blocks.CustomBlock1.RespawnTimer"));
    Code for the parse:
    Code:
        public int parse(String in){
            int j = -1;
    
            try {
                j = Integer.parseInt(in);
            } catch(NumberFormatException ex) {
            }
            return j;
        }
    And my default config values:
    Code:
            config.addDefault("Blocks.CustomBlock1", "");
            config.addDefault("Blocks.CustomBlock1.Item", 20);
            config.addDefault("Blocks.CustomBlock1.Drops", '20:30');
            config.addDefault("Blocks.CustomBlock1.RespawnTimer", 20);
     
  2. Offline

    BlazingBroGamer

    @Coopah
    Question, are there any errors in the console? I suspect the drops string list. You need to set an array list of strings, not just a string.
     
  3. Offline

    nitrousspark

    @Coopah If there are no error's, it could be because of this:

    It is not recommended that you don't put anything in the catch statement. You should add some sort of message there like this:
    Code:
    System.out.printLn("Integer failed to parse! ##NAME OF CLASS FILE");
     
  4. Offline

    Coopah

    @nitrousspark @BlazingBroGamer
    No console errors, I added a system.out.printin and still the same error. Everything works but the item drops. What do you mean by a arraylist instead?
     
  5. Offline

    Coopah

  6. Offline

    Gamesareme

    @Coopah You can most likely work this out your self. Add a few System.out.printLn and see what numbers you are getting from the config. Using this, you can also see the number of the block ID. Then add a few more, and see how much of your code is running, if any.
     
  7. Offline

    Coopah

    @Gamesareme
    The entire thing is running it's just the config check isn't working. Like it thinks there is nothing there so it's dropping nothing.
     
  8. Offline

    1Rogue

    Why are you trying to manually create itemstacks yourself? You're able to write/read ItemStacks to and from the config itself directly. (And then you could just make your own ConfigurationSerializable class that holds extra information such as item drops).
     
  9. Offline

    Gamesareme

    @Coopah If that is case, then you should open up the config, in your plugins folder and make sure that the path you have in your code is there. Also, looking at the code you have above, you do not save it, or you do not at least in the snip-it you gave.
     
  10. Offline

    Coopah

    @Gamesareme
    It is the correct path. As for saving I don't think it would matter but I'll check.
    @1Rogue
    May I have a example or a better explanation of a ConfigurationSerializable class?
     
  11. Offline

    Gamesareme

    @Coopah After you make changes to the config, you need to save them.
     
  12. Offline

    1Rogue

Thread Status:
Not open for further replies.

Share This Page