Solved weird bug, no eror, event registered

Discussion in 'Plugin Development' started by Lionhard, Dec 29, 2013.

Thread Status:
Not open for further replies.
  1. Hello, could you please help me? I have a points plugin and want to give a player points when he breaks certain blocks. I putted the events into the main class, so it is a bit easier and registered the events with pm.registerEvents(this, this);
    The code looks like:

    Code:java
    1. @EventHandler
    2. public void onBreakBlock(BlockBreakEvent event){
    3. Block block = event.getBlock();
    4. Player player = event.getPlayer();
    5. if(this.getConfig().getBoolean("earnings.blocks.breaking.enabled")){
    6. Set<String> allBlockNames = this.getConfig().getConfigurationSection("earnings.blocks.breaking.blocks").getKeys(false);
    7. for(String blockName : allBlockNames){
    8. if(block.equals(Material.valueOf(this.getConfig().getString("earnings.blocks.breaking.blocks."+ blockName + ".name")))){
    9. player.sendMessage(blockName);
    10. int pointsForBlock = this.getConfig().getInt("earnings.blocks.breaking.blocks." + blockName + ".points");
    11. pointsEarnedByBlockBreaking += pointsForBlock;
    12. int playerPoints = playersConfig.getInt(player.getName() + ".points");
    13. playerPoints += pointsForBlock;
    14. playersConfig.set(player.getName() + ".points", playerPoints);
    15. try {
    16. playersConfig.save(playersFile);
    17. } catch (IOException e) {
    18. e.printStackTrace();
    19. }
    20. blocksBreaked += 1;
    21. if(blocksBreaked == this.getConfig().getInt("earnings.blocks.breaking.blocksBreakedToNotify")){
    22. player.sendMessage(ChatColor.translateAlternateColorCodes('&', messages.getString("blockBreakingPointsNotification"))
    23. .replace("%pointsEarned%", Integer.toString(pointsEarnedByBlockBreaking)
    24. .replace("%blocksBreaked%", Integer.toString(blocksBreaked))));
    25. blocksBreaked = 0;
    26. pointsEarnedByBlockBreaking = 0;
    27. }
    28. }
    29. }
    30. }
    31. }




    and the config like:
    Code:
    earnings:
      killing:
        players:
          enabled: true
          points: 2
        enemies:
          enabled: true
          points: 1
      blocks:
        breaking:
          blocksBreakedToNotify: 20 # A notification that the player has got points will at every 20 (or as you set it) breaked blocks.
          enabled: true
          blocks:
            obsidian:
              name: OBSIDIAN
              points: 12
            diamond:
              name: DIAMOND_ORE
              points: 9
            gold:
              name: GOLD_ORE
              points: 7
            redstone:
              name: REDSTONE_ORE
              points: 6
            lapis_lazuli:
              name: LAPIS_ORE
              points: 6
            iron:
              name: IRON_ORE
              points: 4
            coal:
              name: COAL_ORE
              points: 2
            stone:
              name: STONE
              points: 1

    just look at the block breaking part in the config.

    Do you know why nothing happens? No errors, no reward no messageshown up. There was a error earlier, but that was because my config.yml had name: LAPISLAZULI_ORE and it should be LAPIS_ORE. That was also good, now I know that it gets the names right. but it just wont work. :/

    Thank you very much in advance, Lionhard98.

    P.S.: PLEASE HELP! ;)
     
  2. Offline

    timtower Administrator Administrator Moderator

    Lionhard Try block.getType()==Material.valueofstuff
    You are trying to compare a Block with a Material
     
    Lionhard likes this.
  3. timtower ok thanks!

    timtower and you are again awesome, working perfectly! ;)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
    timtower likes this.
Thread Status:
Not open for further replies.

Share This Page