Can someone help me with coin system block

Discussion in 'Plugin Development' started by Dual_Fighter, Jun 30, 2014.

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

    Dual_Fighter

    I making a speedrun plugin and i need if u walk over a gold block than you get a coin and i cant get the coins from the config and i want if you walk over 1 that you get one coin not my whole chat gots spammed by You have a coin now.

    Code:java
    1. @EventHandler
    2. public void onMove(PlayerMoveEvent event)
    3. {
    4.  
    5. // Get player location
    6. Player p = event.getPlayer();
    7. // Get Material of block below the player
    8. Material block = p.getLocation().subtract(0, 1, 0).getBlock().getType();
    9. // check for single block
    10. // If you have a 'ArrayList<Material> object', do object.contains(block);
    11. if(block == Material.GOLD_BLOCK)
    12. {
    13.  
    14. getConfig().set(p.getName() + ".Coins: ", 1);
    15. saveConfig();
    16. p.sendMessage(ChatColor.BLUE + "You have one coin");
    17. p.sendMessage(ChatColor.GREEN + "You have now" + getConfig().get(".Coins") + "coins.");
    18.  
    19. }
    20. }
    21.  
     
  2. Offline

    minoneer

    1.: getConfig().getInt(p.getName() + ".Coins") should get you there.

    1.: Compare the "from" and the "to" location in you event and only give a coin, if it is not the same Block.
     
  3. Offline

    Niknea

    Dual_Fighter You keep reseting their coin back to one. Create a variable to get the amount of coins a player has, then add one to it.
     
  4. Offline

    Dual_Fighter

    Only need to know how to add a coin and not set the coins to 1
    Code:
    if(block == Material.GOLD_BLOCK)
                        {
     
                            getConfig().set(p.getName() , +1);
                            saveConfig();
                            p.sendMessage(ChatColor.BLUE + "You have one coin");
                            p.sendMessage(ChatColor.GREEN + "You have now " + getConfig().getInt(p.getName()) + " coins.");
     
  5. Offline

    nateracecar5

    Instead of doing
    Code:java
    1. getConfig().set(p.getName() , +1);
    2.  


    Do
    Code:java
    1. getConfig().set(p.getName(), getConfig().getInt(p.getName) + 1);
    2.  


    You can't do +1, because then you will just be setting the players name to the string of "+1". So what I did was grabbed the int, and added 1 to that int. Now it adds instead of sets. :)
     
  6. Offline

    Garris0n

    You can check the block x/z to make sure they're stepping into a new block.
     
  7. Offline

    Dual_Fighter

    Thanks that problem is solved a have only one and that is how do i get one message and not 8 per second

    Code:java
    1. if(block == Material.GOLD_BLOCK)
    2. {
    3.  
    4. getConfig().set(p.getName(), getConfig().getInt(p.getName()) + 1);
    5. saveConfig();
    6. p.sendMessage(ChatColor.BLUE + "You have recived 1 coin");
    7. p.setHealth(20);
    8. p.setFoodLevel(20);
    9.  
    10. }
     
Thread Status:
Not open for further replies.

Share This Page