Adventure Mode Click

Discussion in 'Plugin Development' started by Jamesthatguy, Jul 20, 2013.

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

    Jamesthatguy

    Hi, I need to make it so when someone clicks a certain block to break it, the event is cancelled just how it is in adventure mode. The catch is I am trying to make it so if certain blocks can be destroyed as if the player was in survival mode. I am not sure if there is a way to make it so the adventure mode click only applies to certain blocks so I am thinking the player's gamemode would have to be changed each time. If this is the case could someone tell me how to get rid of the gamemode change messages whenever a player's gamemode is changed? Any help is appreciated, thanks!
     
  2. Offline

    xTrollxDudex

    Jamesthatguy
    Player interact event
    if the action was left click block
    If event.getBlock().getType().equals(Material.BLOCK)
    event.setCancelled(true)
     
  3. Offline

    ZeusAllMighty11

    xTrollxDudex

    That doesn't stop the block from being breakable
     
  4. Offline

    xTrollxDudex

  5. Offline

    Jamesthatguy

    Yea that was the first thing I tried but it doesn't give the adventure mode cancel. For some reason it will only cancel when the block is actually broken.
     
  6. Offline

    Miner_Fil

    Try this,
    Code:java
    1. public void onBlockBreak(PlayerInteractEvent event)
    2. {
    3. Player player = event.getPlayer();
    4. if(event.getAction() != Action.LEFT_CLICK_BLOCK){
    5. if(event.getClickedBlock().getType() != Material.ANVIL){
    6. event.setCancelled(true);
    7. player.sendMessage("Oops, Seems like you can't break that Block!");
    8. }
    9. }
    10. }
     
  7. Offline

    Firefly

    You could cancel BlockDamageEvent
     
  8. Offline

    Jamesthatguy

    Firefly That results in the block break being cancelled instead of the click.

    Miner_Fil What with the negative in your statement? If the action is not a left click? That doesn't make much sense.
     
  9. Offline

    Firefly

    AFAIK BlockDamageEvent (not BlockBreakEvent) when cancelled will stop the player as soon as he punches the block.
     
  10. Offline

    xTrollxDudex

    Figure something out dude. I already have some pseudo code for you, now it's on you. I practically wrote code for you, did you even try it out before telling me that it won't work?
     
    microgeek likes this.
  11. Offline

    Jamesthatguy

    Firefly I tested it out and it doesn't work.
    xTrollxDudex
    I don't need people to write code for me, I need to know what method to use for this because as I stated before, yours was the first thing I tried and if it was that simple I wouldn't be here right now.
     
  12. Offline

    stonar96

    I donĀ“t think that there is a way to cancle the click, that it looks like the adventure-mode, because you would hit the block as long as the ping. When your are in adventure-mode, the click is cancled by the client. So the gamemode is a client effect.

    I think this wont work, because when you change the gamemode of the player when he click an the block it is too late, and the click is already cancled.

    (Sry for my bad english)
     
  13. Offline

    Jamesthatguy

    stonar96 Yea, i know that this is possible because I have seen it done but I am just not sure how. My guess is with changing gamemodes without the messages but I am not sure how you would get rid of the messages.
     
  14. Offline

    Cybermaxke

    You can't change the gamemode without the messages, that is client side.
     
  15. Offline

    xTrollxDudex

    I noted that bukkit probably changed some things up. They made interact and block damage work only for "clicking" which means if you hold it, the event wont fire....

    I think the only solution is with nms, hacking into the very code of net.minecraft.server itself to edit the properties of the block.

    I think chasechocolate knows spmething about this? I have no idea though.
     
Thread Status:
Not open for further replies.

Share This Page