Solved Need some help

Discussion in 'Spigot Plugin Development' started by alex3413, Jun 8, 2016.

  1. This is my code everything is working, besides checking if the player has not played before when someone joins the server and they have not played before it doesn't add them to the welcome HashMap please help
     
    #1 alex3413, Jun 8, 2016
    Last edited: Jun 8, 2016
  2. In your hashmap it should be new HashMap<String, String> welcome = new HashMap<>(); this goes with the array
    Did you register events in main class?
     
  3. Can you add me on skype?
     
  4. MiniDigger

    Supporter

    wow, all those suppressed warnings...

    IIRC OfflinePlayer#hasPlayedBefore is only supposed to work for offline players. So that you can check if a player with a given name was at some time connected to the server. the problem now is that when you check it in the PlayerJoinEvent the player is on the server thus he hasPlayedBefore you checked it.
    Try using AsyncPlayerPreLoginEvent and construct a offline plaer based on the name and then use hasPlayedBefore to do your stuff.
     
  5. dont hate for me saying this but another way of initialising any array, hashmap or similar (which would be considered a less lazy way of doing it too, because programming is starting to inherit some lazy techniques) would be like so:

    HashMap<String, String> welcome = new HashMap<String, String>();

    it also just looks a tad more pleasant to the eye (for me anyway)

    On another note, what is the point of the hashmap welcome? why not just use a Player obbject (keeping in mind that you will want to remove the player object if they happen to leave before they are welcomed)
     
  6. MiniDigger

    Supporter

    well, you seem to be the only one to think so ^^
    IDEA even hides the String,String on the constructor call, because it is completely unnecessary.
    you don't even need to store the whole player object, a simple string would be enough.
     
  7. Well i sort of learnt around the fact that if you dont tell the computer to do it then the computer wont do it sort of way so it comes second nature to me :p oh well.

    My bad, i thought they were going to use the player object to send a message to the player, read over it again and indeed it is only the name that is needed.
     
  8. I solved it! :D thanks guys
     
  9. Solved PREFIX, edit the title and change the prefix, adding a solved message after you just said its solved is completely pointless as the people that have clicked on the link have already read the question and the answers to catch up ready to reply with more information.