Cancel player getting from Arrow

Discussion in 'Plugin Development' started by keizermark, Sep 8, 2014.

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

    keizermark

    I need to cancel that a player can get of a Arrow, but Whit this it dont work? When you spam shift sometimes you can get of.

    Code:
    public class Main extends JavaPlugin implements Listener {
     
        public void onEnable() {
            PluginManager pm = getServer().getPluginManager();
            pm.registerEvents(this, this);
        }
       
        public boolean CanExit = false;
        public Map<Player, Entity> chairList = new HashMap();
        public Map<Player, Location> chairLoc = new HashMap();
       
          @EventHandler
          public void onPlayerInteract(PlayerInteractEvent e) {
            Player p = e.getPlayer();
            if (e.getClickedBlock() != null) {
              Block block = e.getClickedBlock();
              if ((e.getAction() == Action.RIGHT_CLICK_BLOCK) && (!p.isInsideVehicle())) {
                  if (block.getType().name().equalsIgnoreCase("NETHER_BRICK_STAIRS")) {
                    World world = p.getWorld();
                    Entity Arrow = world.spawnEntity(p.getLocation(), EntityType.ARROW);
                    Arrow.teleport(block.getLocation().add(0.5D, 0.2D, 0.5D));
                    Arrow.setPassenger(p);
                    e.setCancelled(true);
                    chairLoc.put(p, Arrow.getLocation());
                    chairList.put(p, Arrow);
                    return;
                  }
              }
            }
          }
          @EventHandler
          public void onExit(PlayerToggleSneakEvent e) {
              if(chairList.containsKey(e.getPlayer())) {
                  if(chairLoc.containsKey(e.getPlayer())) {
                      if(CanExit == false) {
                          Player p = (Player) e.getPlayer();
                          Entity ArrowOld = chairList.get(p);
                          Location ArrowOldLoc = chairLoc.get(p);
                          ArrowOld.remove();
                          chairLoc.remove(p);
                          chairList.remove(p);
                         
                          Entity ArrowNew = p.getWorld().spawnEntity(ArrowOldLoc, EntityType.ARROW);
                          ArrowNew.setPassenger(p);
                          p.setSneaking(false);
                          p.setSneaking(true);
                          p.setSneaking(false);
                          chairLoc.put(p, ArrowNew.getLocation());
                          chairList.put(p, ArrowNew); 
                      } else if(CanExit) {
                          Player p = (Player) e.getPlayer();
                          Entity ArrowOld = chairList.get(p);
                          ArrowOld.remove();
                          chairLoc.remove(p);
                          chairList.remove(p);
                          p.setSneaking(false);
                      }
                  }
              }
             
          }
          @EventHandler
          public void onDespawn(ItemDespawnEvent event){
              if(event.getEntity().equals(EntityType.ARROW)){
                  event.setCancelled(true);
              }
          }
    }
    
     
  2. Offline

    jpjunho

    keizermark
    You can just use e.setCancelled() it will probably work better
    Why are you using one boolean to all players?
    And to check if a boolean is false don't use boolean == false use !boolean
     
  3. Offline

    keizermark

    jpjunho The boolean is true when all the players can exit. And changed to !CanExit. still doesnot work

    jpjunho nope e.setCancelled does nothing

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 14, 2016
  4. Offline

    jpjunho

  5. Offline

    keizermark

    jpjunho I know, that doesn't work
     
  6. Offline

    SmooshCakez

    Cancel the VehicleExitEvent.
     
  7. Offline

    keizermark

    SmooshCakez An arrow is n't a Vehicle. So that doesn't work.
     
  8. Offline

    Westini

    Everything is considered a vehicle after setting a passenger, as far as I know ;)
     
Thread Status:
Not open for further replies.

Share This Page