Saving UUIDs

Discussion in 'Spigot Plugin Development' started by martin0leung, Jul 8, 2015.

Thread Status:
Not open for further replies.
  1. For some reason, I disabled the server and the server has 1 UUID on the HashMap, it saves 3, then when I reload the server, it saves double that, then double that???? What is happening? Here is my Saving.
    Code (Text):
                    for(Entry<UUID, Boolean> Speed : DM.SpeedMap().entrySet()) {
                        userData.set(Speed.getKey().toString() + ".speed", Speed.getValue());
                    }    
     
    • Optimistic Optimistic x 1
  2. What do you mean? I don't understand what you meant by 1 then 3 then double that. The HashMap gets more values?
     
    • Agree Agree x 1
  3. @Bolt
    On my file, at the start, I only have my own UUID, but then, if I reload, It just adds a lot of fake UUIDs that don't exist in Minecraft. Why?
     
  4. Post the whole code in here.
     
    • Agree Agree x 1
    • Winner Winner x 1
  5. Agreed.
    It would be helpful to both you and us if you posted your whole code here. Quite frankly, I haven't understood what you were trying to accomplish here.
     
    • Like Like x 1
  6. @MarinD99 @xXVevzZXx
    What code? I have a lot of code.
    This is my loading:
    Code (Text):
                    for(String UUIDs : userData.getKeys(true)) {
                        UUID id = DM.StoID(UUIDs);
                        boolean speed = userData.getBoolean(UUIDs + ".speed");
                        DM.putSpeed(id, speed);
                    }
     
  7. Ok let me ask you a few things here, does this help us? (Thats shoild be a no...)

    What is DM
    What is putSpeed
    What is userData
    What is stoID

    This is why we need to see the whole class, we cant magically see what all of your code is with a snippet, please supply the class (es) that relate to this and then we can help you

    Plus supplying the whole class means that we are more likely to find you problem (most people post a snippet... and the problem isnt even in the snippet of code they have supplied, which makes the thread pointless)
     
    • Agree Agree x 3
  8. @LeePMC
    DM(this is my class) = DataManger, Code inside it:
    putSpeed:
    Code (Text):
        public static void putSpeed(UUID id, boolean value) {
            if(String.valueOf(value).equals("true")) {
                Speed.put(id, value);
                return;
            } else if(String.valueOf(value).equals("false")) {
                Speed.put(id, value);
                return;
            } else return;
        }
    stoID:
    Code (Text):
        @SuppressWarnings("deprecation")
        public static UUID StoID(String s) {
            return Bukkit.getOfflinePlayer(s).getUniqueId();
        }
    ------------------------------------
    On my SLAPI
    userData:
    Code (Text):
                userData = YamlConfiguration.loadConfiguration(ursFile);
     
    • Useful Useful x 1
  9. all i can say about this is

    1. why the hell are you using String.valueOf(value).equals("true") when you could just go if (value)

    since its adding more and more every time you reload... its probably because you are using .put which means that if Speed has changed since the reload, it will at it into the hash map and not remove the others, check if the UUID is already in the hash map, and if it is set that value instead of putting a new one in (i think put is supposed to replace it but some say it doesn't so just check to be sure)
     
    • Agree Agree x 2
  10. @LeePMC
    Okay, I changed the SString.valueOf(value).equals("true") Part, but I don't understand what you wrote other than that, I made a command which allows me to see the UUIDs in the HashMap, but somehow it keeps on adding more non-existing UUIDs into the HashMap... Why is it doing that?
     
    • Useful Useful x 1
  11. its not adding more 'non existent' UUID's its adding the same UUID with a different speed
     
  12. @LeePMC
    Erm... Actaully, It is adding non existent UUIDs, I checked the UUIDs to see who they are and why its happening, and they are non-existent.

    They are all different UUIDs and only mine which exists.
     
    • Like Like x 1
    • Informative Informative x 1
  13. This method is functionally the same as:
    PHP:
    public static void putSpeed(UUID id, boolean value) {
        Speed.put(id, value);
    }
     
    • Winner Winner x 1
  14. @St3venAU
    OMG I FNA OF YOUR VIDEOS!!!
    And I changed that, I didn't know why I did that :p
    I hope you make more Over-Engineering Episodes :) I have been watching since the your first episode! :)
     
    • Like Like x 1
    • Funny Funny x 1
  15. Why not just UUID uuid = UUID.fromString(String);?
     
  16. @MajorSkillage
    Does that work with OfflinePlayers?
     
  17. Bukkit.getOfflinePlayer(String) returns a player by their name, not by their UUID, therefor it will give you a completely random UUID on reload :/. Do what @MajorSkillage said and it should solve your issue.
     
  18. @megamichiel
    Oh Thanks!!! But I do not know how to convert a string which is a UUID to a actually UUID.
     
  19. An offline player's UUID is the exact same as if they were a player.

    EDIT: Sorry was tried when I typed this I really meant
    An offline player's UUID is the exact same as that same offline player except as a player's UUID.
     
    #20 HotProtato, Jul 17, 2015
    Last edited: Jul 18, 2015
Thread Status:
Not open for further replies.