How do i get someones gamemode in an IF Statement

Discussion in 'Plugin Development' started by thomashomsy, Aug 3, 2014.

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

    thomashomsy

    Hi as i am Fairly New to coding i'm trying to make a Basic command called /admin that will put them in gm 1, invisible to anyone and off the tab, but when done again puts them in gm 0 on the tab and not invisible.
    Please could u post some Code Below which could help

    Thanks for Helping

    -Thomas

     
  2. I won't give you code because then you wouldn't learn as much than if I would explain how to do it and you try to make it. If that doesn't work, you can post your code and we can help you. The player class has a method called hidePlayer(Player), so create a for loop with every player (bukkit.getOnlinePlayers()) and call the hide player method with as argument the person who performed the command. Than just perform the method setGameMode(GameMode.CREATIVE) at the player that performed the command.
     
  3. Offline

    ZodiacTheories

    thomashomsy

    For the gamemode, I believe the Player class has a getGamemode() method which returns the gamemode of the player. There is also a setGamemode() method which sets their gamemode. To set their gamemode, do player.setGamemode(Gamemode.GAMEMODE);

    If you don't what the admin visible when typing a command and pressing tab to see the options, you can use the PlayerChatTabCompleteEvent. To make them invisible, you could loop through all the players online with a for loop, then vanish the admin from the players by using forlooponlineplayersvariable.hidePlayer(admin);

    Hopefully this helped

    Zodiac
     
  4. Offline

    shohouku

    Code:java
    1. Player p = e.getPlayer();
    2. if(p.getGameMode.equals(GameMode.CREATIVE) { }
    3.  


    I don't know about anyone else but I learnt Java through visualizing codes.
     
  5. Offline

    ItsLeoFTW


    Code:java
    1. Player p = e.getPlayer();
    2. if (p.getGameMode() == GameMode.CREATIVE) {
    3. //do stuff
    4. }


    this should work, just put your own code in instead of "//do stuff"
     
  6. Offline

    GeorgeeeHD

    thomashomsy ill give u all the code for OP on dojo xD
     
  7. Offline

    BJCxMC

    Did you still need the code? I actually have this already written for my plugin.
     
    Marten Mooij likes this.
  8. Offline

    Marten Mooij

    IRRELEVANT (Sorry): Here have a like because your "reply" made me laugh.
     
  9. Offline

    BJCxMC

    What's funny about it? Just trying to help him out.
     
  10. Offline

    thomashomsy

    nah m8
     
Thread Status:
Not open for further replies.

Share This Page