Trample detection for Soil and Crops

Discussion in 'Plugin Development' started by Junrall, Jun 9, 2012.

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

    Junrall

    Trampling only occurs when the player or a mob jumps or falls on to soil or crops. Is there any way to check for this?
    Seems like all the "anti-trample" plugins only check to see if a soil or crops have been trampled when they have been walked on... which is useless since that way of trampling has been removed from Minecraft.
     
  2. I belive it's PlayerInteractEvent with getAction() == PHYSICAL.... I used this a long time ago but I don't know if it still triggers the same, it should tough.
     
  3. Offline

    Junrall

    Seems like i just tried that and it didn't work... I'll take a closer look.
     
  4. This is the *old* event I used and it worked:
    Code:
    public void onPlayerInteract(PlayerInteractEvent event)
                {
                    if(event.getAction() == Action.PHYSICAL)
                    {
                    	Block block = event.getClickedBlock();
                    	
                    	if(block == null)
                    		return;
                    	
                    	int blockType = block.getTypeId();
                    	
                    	if(blockType == Material.SOIL.getId())
                    	{
    	                	event.setUseInteractedBlock(org.bukkit.event.Event.Result.DENY);
    	                	event.setCancelled(true);
    	                	
                    		block.setTypeId(blockType);
                    		block.setData(block.getData());
                    	}
                    }
                }
    Unsure if the block re-setting to type & data was really required but anyway.

    But like I said, this was used a long time ago xD
     
    waremanu likes this.
  5. Offline

    Junrall

    Thanks for the code... Thats pretty much what I was doing... though, I did try just in case... and still crops and soil is trampled when players and critters jump onto them of fall on to them.

    I don't even think that onPlayerInteractEvent is called when things are trampled via a falling entity. With just event.setCancelled(true); by itself is used, crops and soil are still trampled.

    There has got to be a way to determine if soil/crops have been trampled by a falling entity.
     
  6. Why not print some stuff to be sure ?
    Code:
    public void onPlayerInteract(PlayerInteractEvent event)
    {
        System.out.print("[DEBUG] interact :: " + event.getAction() + " | " + event.getClickedBlock());
    }
     
  7. It could be on blockBreak but you'll have to test.
     
  8. Offline

    Junrall

    Lol, how can something that seems so easy be soooo elusive.:)
    I've tested all of the seemingly obvious events and still the answer evades me. Testing involved both sending verbose to the console and literally using a bare event.setCancelled(true); in each of the events made no difference.

    Ah well, this is one that will have to wait... I have other more important things to mess with... however, if anyone comes across a solution, please let me know.... I will do the same. And thank you for the quick responses :p
     
  9. Offline

    Iron_Crystal

    You said entity. Are you not using a player?
     
  10. Offline

    Junrall

    Woops! I meant player.... though, this is an issue with entities as well.
     
  11. It could be on blockPhysics? I remember a thread about a similar issue a while ago but can't remember the event.
     
  12. Offline

    Iron_Crystal

  13. Offline

    Njol

    Have you already tried EntityChangeBlockEvent?
     
  14. Offline

    Junrall

    Yeah, I saw that thread and even tried the Grief Prevention plugin that the thread had mentioned... and even that plugin does not address the trampling caused from players/entities dropping on soil and crops. Also, I have been unsuccessful with the PlayerInteractionEvent.
    Am I right in thinking that I can cancel any event within PlayerInteractionEvent with event.setCancelled(true)? ..or for that matter, any event? If so, then event.setCancelled(true) should cancel "drop trampling" (don't know what else to call it.)... right?
     
Thread Status:
Not open for further replies.

Share This Page