Solved Check if user is in vehicle when he/she pressed a button

Discussion in 'Plugin Development' started by darkgreetingsnl, Apr 27, 2015.

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

    darkgreetingsnl

    Hello Devs,

    I am working on a custom Bukkit plugin and I wanna check if the user is in an vehicle when he/she pressed the button (Stone button). I have already some code but unfortunately it doesn't work.. Can someone tell me what is wrong with this code? (Btw, I use the vault API)

    Code:
        @EventHandler
        public void onPlayerInteract(PlayerInteractEvent event) {
            Player p = event.getPlayer();
            if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
                if(event.getClickedBlock().getType() == Material.STONE_BUTTON) {
                    p.sendMessage("true");
                    if(p.getVehicle().equals(EntityType.MINECART)) {
                        plugin.econ.withdrawPlayer(p, 75);
                        p.sendMessage(ChatColor.GREEN + "[GTA Parking Garage] You paid $75,- for an parking garage ticket");
                        p.sendMessage(ChatColor.GREEN + "[GTA Parking Garage] Your saldo is now: " + plugin.econ.getBalance(p));
                    }
                }
            }
        }
    EDIT:
    Yes I also tried isInsideVehicle
     
    Last edited: Apr 27, 2015
  2. Offline

    stormneo7

    Code:
    if(p.getVehicle().equals(EntityType.MINECART)) {
    You cannot compare an Entity to an EntityType. Try the following...
    Code:
    if(p.getVehicle() instanceof Minecart) {
     
  3. Offline

    darkgreetingsnl

    I solved that problem 1 min ago xd, but there is something with Vault. It doesn't withdraw the money from the player's saldo. Here is the code:
    Code:
        @EventHandler
        public void onPlayerInteract(PlayerInteractEvent event) {
            Player p = event.getPlayer();
            if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
                if(event.getClickedBlock().getType() == Material.STONE_BUTTON) {
                    if(p.isInsideVehicle()) {
                        p.sendMessage(ChatColor.GREEN + "[GTA Parking Garage] You paid $75,- for an parking garage ticket");
                        plugin.econ.withdrawPlayer(p, 75);
                    } else {
                        p.sendMessage("You are not in an vehicle right now.");
                    }
                }
            }
        }
     
  4. Offline

    mine-care

    @darkgreetingsnl does the player have those money because it seems you withdraw regardless of that fact also is an economy plugin running along with vauls? What Econ plugin you use?
     
  5. Offline

    darkgreetingsnl

  6. Offline

    mine-care

    I didn't know that and because in your previous post you reported a problem with vault I decided to throw a possible solution/cause.
    Also mark your thread as Solved to avoid such confusions.
     
  7. Offline

    darkgreetingsnl

    @mine-care
    Thank you for posting in this topic, I appreciate that. And I had already marked my topic as Solved (the vault topic) but I forgot this one. Sorry about that.
     
Thread Status:
Not open for further replies.

Share This Page