Solved Issue setting a player's gamemode?

Discussion in 'Spigot Plugin Development' started by Aubameyang, Apr 14, 2017.

Thread Status:
Not open for further replies.
  1. I'm saving the player's game mode in a hashmap. And when I go to restore the players game mode, it just doesn't set it.

    I've debugged it, and it returns the game mode correctly.
    Code (Text):

    p.sendMessage(gameMode.get(p.getUniqueId()) + ""); // Returns the correct gamemode name in caps ie CREATIVE
    p.setGameMode(gameMode.get(p.getUniqueId())); // Should work, console doesnt throw any errors or anything
     
    Edit: What I have works, I was setting their game mode in another class when debugging a long time ago, rip
     
    #1 Aubameyang, Apr 14, 2017
    Last edited: Apr 14, 2017
  2. That should work lol if all else fails you can always go like this

    Code (Text):
    if (gameMode.get(p.getUniqueId).equalsIgnoreCase("CREATIVE")){
           p.setGameMode(Gamemode.CREATIVE);
    }
    Do it for all

    Its not very efficient but it works
     
  3. I was wondering that. Is it because it doesn't have the "GameMode." but that wouldn't make sense as I'm storing his game mode so I should be able to just set it ;-;
     
  4. Why are you storing it in a hashmap, doesn't player.getGamemode(); exist or something?
     
  5. have you tried
    Code (Text):
    System.out.println();
    the stored value in the hashmap to see if it saves correctly? The class Gamemode may not be serializable to be stored in a hashmap.

    You can try storing it as a String instead and using that in a switch statement/if statements to change the gamemode so your HashMap will be
    Code (Text):

    new HashMap<UUID,String>
    //instead of
    new HashMap<UUID,GameMode>
     
    If this fails, if this is running on a command, replace this...
    Code (Text):

    Player p=(Player)sender;
    //with
    Player p=Bukkit.getPlayer(sender.getUniqueId());
     
    Just might be an issue of casting. This is unlikely however.
     
  6. If this isn't solved yet,
    Code (Text):
    p.setGameMode(GameMode.valueOf(gameMode.get(p.getUniqueId())));
     
    • Like Like x 1
  7. Saving PlayerData before they join my arena and restoring it
    That's true maybe game modes can't be stored, but i can't imagine a reason why it wouldn't be able to. And I also thought of using the String which would work fine but figured using game modes would be easiest :p
    But I'm technically storing GameMode.CREATIVE so Im not sure how that'd work.

    I'm not on my computer right now, if all else fails, Ill probably just using a string for the game mode type and use GameMode.valueof()
     
  8. Yeah i saw that you stored the gamemode after i posted that reply, but i honestly think u must use GameMode.valueOf, can't think of any other way :p
     
    • Like Like x 1
  9. Yeah that is what I'm thinking as of now
     
Thread Status:
Not open for further replies.