Need helping setting up a config.

Discussion in 'Plugin Development' started by JackoDEJ, Apr 25, 2018.

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

    JackoDEJ

    Hey guys! This is day 3 of me developing my first plugin. My plugin is coming along well and all that it does is that whenever a player breaks a block (for this instance stone), it will give the player coal at 10%. I have done other things like breaking tall grass will get the player different seed variety, or breaking log will get the player sticks, etc...

    What I would like is a way for the user to config there own block to break, the reward, and the percentage. Sort of like this:

    1:
    - Block: 'Stone'
    - Drop: 'Coal'
    - Chance: '10'
     
    Last edited by a moderator: Apr 25, 2018
  2. Offline

    timtower Administrator Administrator Moderator

    @JackoDEJ I would suggest to use this:
    Code:
    Drops:
      STONE:
        COAL: 10
        IRON: 1
      DIRT:
        DIAMOND: 50
        COBBLESTONE: 50
     
  3. Offline

    JackoDEJ

    Alright, thanks.
    How exactly will I get the config and my java to communicate?

    Here is an example of my code.
    Code:
        @EventHandler
        public void onBlockBreak(BlockBreakEvent e) {
            Block b = e.getBlock();
            Player p = e.getPlayer();
            Random ran = new Random();
            int choice = ran.nextInt(100) + 1;
            if (b.getType() == Material.STONE) {
                if(choice < 10) {
                p.getInventory().addItem(new ItemStack(Material.COAL));
                p.sendMessage(ChatColor.GOLD + "You have got 1 Coal!");
            } else {
                p.getInventory().addItem(new ItemStack(Material.AIR));
            }   
        }
     
  4. Offline

    timtower Administrator Administrator Moderator

    @JackoDEJ Highly depends on your current config.
     
  5. Offline

    JackoDEJ

    Here is my new config.

    Code:
    Drops:
      STONE:
        COAL: 10
      LOG:
        STICK: 50
      TALL_GRASS:
        PUMPKIN_SEEDS:15
        MELON_SEEDS: 15
        BEETROOT SEEDS: 15
    (Has spaces but did not paste)
     
    Last edited by a moderator: Apr 25, 2018
  6. Offline

    timtower Administrator Administrator Moderator

    @JackoDEJ First step is finding the correct ConfigurationSection, and handle it when the section does not exist.
     
  7. Offline

    JackoDEJ

    Uhhh, haha. I am not fully picking up what you're putting down. What would you suggest?
     
  8. Offline

    timtower Administrator Administrator Moderator

    @JackoDEJ You have the Drops section, you need to get the correct subsection for the broken block.
     
  9. Offline

    JackoDEJ

    I am sorry, but I am not understanding. I would prefer to learn from example code if that's ok.
     
  10. Offline

    timtower Administrator Administrator Moderator

  11. Offline

    JackoDEJ

    Well, that's very helpful. You may be familiar with all of these terms, but I am on day 3. I am not experienced in a lot like you. :(
     
  12. Offline

    timtower Administrator Administrator Moderator

    3 days in Bukkit or 3 days in Java?
     
  13. Offline

    JackoDEJ

    Both. I am using Bukkit to also get me used to Java. I know the common phrase for someone like me will be "Go learn Java." :(

    Just answer me this, please. I think I got this sort of correct.
    Here is my config:

    1:
    - Block: 'Stone'
    - Drop: 'Coal'
    - Chance: '10'

    And would a line similar to this call for the "Stone" block.

    p.getInventory().addItem(new ItemStack(Material.getConfig().getString("1.Block")));

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Apr 25, 2018
  14. Offline

    timtower Administrator Administrator Moderator

    Because Bukkit adds a lot of new things, won't get far running when you can't even walk yet.
    You need loops and checks, can't do it in a single line.
     
  15. Offline

    JackoDEJ

    I am at more of a limping stage haha. Alright, thank you for your help.
     
Thread Status:
Not open for further replies.

Share This Page