Changing game mode not working...

Discussion in 'Plugin Development' started by ImDeJay, Jan 27, 2013.

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

    ImDeJay

    k, ive browsed around didnt find what i was looking for.

    I am working on my AntiFlyPVP plugin, and everything is working fine except changing the game mode.

    i want to be able to, when a player attacks another player, take them out of fly mode and creative.

    taking them out of fly mode works just fine, but i cant take them out of creative.

    is entitydamagebyentityevent bypassed while in creative mode?

    here's my code.

    Code:java
    1. @EventHandler
    2. public void playerHit(EntityDamageByEntityEvent event){
    3.  
    4. if(event.getDamager() instanceof Player && event.getEntity() instanceof Player){
    5.  
    6. final Player attacker = (Player) event.getDamager();
    7. final Player victim = (Player) event.getEntity();
    8.  
    9. attacker.setAllowFlight(false);
    10. victim.setAllowFlight(false);
    11.  
    12. attacker.setGameMode(GameMode.SURVIVAL);
    13. victim.setGameMode(GameMode.SURVIVAL);
    14.  
    15. }
    16.  
    17.  
    18. }[/code]
    19.  
    20. why is it not setting their game mode to survival?
     
  2. Offline

    Th3Controller

    Do
    Code:
    attacker.getPlayer().setGameMode(GameMode.SURVIVAL);
    You'll need to get the player then set gamemode.
     
  3. Offline

    RainoBoy97

    while you are in creative, and attacks another creative mode player, i dont think this method gets called because its EntityDAMAGEByEntityEvent :p
     
  4. Offline

    ImDeJay

    that still doesnt work.

    wonder what event would be called then

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  5. Offline

    Th3Controller

    Player's are considered entities too.
     
  6. Offline

    danthonywalker

    Are you registering the event in the onEnable method?
     
  7. Offline

    welsar55

    tryed to do somthing like this in a old plugin i did not find anything th3 its DAMAGE not hit
     
  8. Offline

    RainoBoy97

    I know, but in creative they dont take damage, so im not sure if this event gets called then :p
     
  9. Offline

    Th3Controller

    They prove a point, try an interact event.

    Also when you manage to get it working, add projectile checking also.
     
    BH72 likes this.
Thread Status:
Not open for further replies.

Share This Page