check for vault money sign

Discussion in 'Plugin Development' started by HenkDeKipGaming, May 25, 2015.

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

    HenkDeKipGaming

    hey everyone,
    i'm thinking of a way to make kinda like a sign shop thing xD
    i just need to know how to check the amount of money that someone has :)
    so i got this code:
    Code:
    @EventHandler
                             public void onPlayerInteract94(PlayerInteractEvent e) {
                             if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
                             if ((e.getClickedBlock().getState() instanceof Sign)) {
                               Sign s = (Sign)e.getClickedBlock().getState();
                               if (s.getLine(1).equalsIgnoreCase("§6Rank 2")) {
                                  
                                   //check for amount of money
                                   // take away the right amount of money
                                   // do other stuff
                               }
                             }
                             }
    
    
    By the way, the money is from vault.
     
  2. Offline

    Zombie_Striker

    @HenkDeKipGaming
    • Why are you inverting the if statment, only then to return? Say if it's equal to RightCLICKBLOCK
    • Look at Vault's Docs, Vault's API, and all the methods it has.
    • Format your code.
     
  3. Offline

    HenkDeKipGaming

    thanks i'll try that :)
     
  4. Offline

    HenkDeKipGaming

    @Zombie_Striker Hey, i tried this:

    Code:
    public static Economy econ = null;
                           
                           //spawnpoint setting
                             @EventHandler
                             public void onPlayerInteract94(PlayerInteractEvent e) {
                             if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
                             if ((e.getClickedBlock().getState() instanceof Sign)) {
                               Sign s = (Sign)e.getClickedBlock().getState();
                               if (s.getLine(1).equalsIgnoreCase("§6Rank 2")) {
                                   
                                 
                                   
                                   @SuppressWarnings("deprecation")
                                    EconomyResponse r = econ.withdrawPlayer(e.getPlayer().getName(), 10);
                                   if (r.transactionSuccess()) {
                                      Location Location = e.getPlayer().getLocation();
                                      e.getPlayer().setBedSpawnLocation(Location, true);
                                        e.getPlayer().sendMessage("Your spawnpoint has been set");
                                           
                                   }
                                   else {
                                           e.getPlayer().sendMessage(ChatColor.RED + "You can't afford this kit :(");
                                           
                                   }
                                 
                                 
                                 
                                     
                               }
                             }
    
    and it doesn't do anything... what to do?
     
  5. Offline

    Zombie_Striker

    • Is econ Null?
    • Did you register a Listener?
    • Why is it still inverted?
    • What part of this does not work?
     
  6. Offline

    HenkDeKipGaming

    I did not register a listener, and there are no errors.. but it does nothing when i click the sign
     
  7. Offline

    Zombie_Striker

  8. Offline

    CoolGamerXD

    @HenkDeKipGaming It wont work if you did not register events. To register events, In your main class you have to add method in onEnable()
    Code:java
    1. public void onEnable() {
    2. Bukkit.getServer().getPluginManager().registerEvents(new [Event's class name](this), this);
    3. // If you have single class you will do (this, this)
     
  9. Nothing wrong with doing this really, it's a matter of personal preference. Personally I prefer to do this where it makes sense to in order to reduce the nested nature of it :) In my opinion the following:

    Code:
    @EventHandler
    public void onInteract(PlayerInteractEvent e) {
        if(e.getAction() == Action.RIGHT_CLICK_BLOCK) {
            if((e.getClickedBlock().getState()) instanceof Sign) {
                Sign s = (Sign) e.getClickedBlock().getState();
                if(s.getLine(1).equalsIgnoreCase("whatever") {
                    // Do stuff here
                }
            }
        }
    }
    Isn't quite as nice as the following, due to the excessive indentation:

    Code:
    @EventHander
    public void onInteract(PlayerInteractEvent e) {
        if(e.getAction() != Action.RIGHT_CLICK_BLOCK)
            return;
    
        if(!(e.getClickedBlock().getState() instanceof Sign))
            return;
    
        Sign s = (Sign) e.getClickedBlock().getState();
        // etc.
    }

    @HenkDeKipGaming The above advice is correct either way: You need to learn more about Java, and then more about the API that you are using, before trying to make plugins, otherwise you'll just run into simple mistakes that you are unable to solve. I recommend the Oracle tutorials, or a good Java book :)
     
  10. Offline

    HenkDeKipGaming

  11. Offline

    Irantwomiles

    I was the same way but you got to work one step at a time.
     
  12. Offline

    HenkDeKipGaming

    I'll do that :) I just started and i'm allready making Minigame plugins... that's not how it works haha.
    i first gotta learn xD
     
  13. Offline

    Irantwomiles

    im not sure about you but I had basic Java knowledge before starting and I kept learning as I went along. Just don't quit cause it will get frustrating at times.
     
Thread Status:
Not open for further replies.

Share This Page