Help disabling players pushing minecarts

Discussion in 'Spigot Plugin Development' started by zackatack108, Jun 26, 2016.

  1. Okay so I'm having issues with my plugin that I want to disable players being able to push a minecart around.

    Here's my Code
    Code (Text):
    public class Main extends JavaPlugin implements Listener{
       
        public void onEnable(){
            getLogger().info(" has been enabled.");
                   
            getServer().getPluginManager().registerEvents(this, this);
        }
       
        public void onDisable(){
           
        }
       
        @EventHandler
        public void onCollision(VehicleEntityCollisionEvent event){
            if(event.getEntity().getWorld().getName().equalsIgnoreCase("Creative")){
                event.setCancelled(true);
                System.out.println("Test");        
            }
        }  
    }
    So from testing I found that the VehicleEntityCollisonEvent only happens when the player is riding the Minecart which is not the case I want. Any Ideas on how to get it so players can't push the cart at all?
     
  2. bumping because I really need help with this.
     
  3. Try VehicleCollisionEvent, which is called when an entity and vehicle collide.
     
    • Optimistic Optimistic x 1
  4. Doesn't appear to be triggering when I walk into a minecart. plus it looks Like I can't cancel the collision so you can't push it which is what I want
     
  5. You need to register your listener in your onEnable.
     
  6. I did register it
     
  7. Okay maybe this will help with trying to figure out what's going on. So when I have two minecarts running on a track with canceled set to true the carts won't bounce off of each other. When I have it set to False the carts bounce off of each other. In both situations the player is still able to push the carts which is the part I want to disable.

    Also when the cart is moving around and I'm on the track the cart bounces off of me in both situations.
     
  8. Try using #setCollisionCancelled instead of or in addition to #setCancelled (sitll using VehicleEntityCollisionEvent)