How does Bukkit manage map ID's?

Discussion in 'Plugin Development' started by kiwhen, Sep 9, 2013.

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

    kiwhen

    I've been looking into the map API and custom renderers, which is pretty cool. There is one last thing that I don't fully understand, and that is how Bukkit manages the map ID's. As far as I can tell, there are no methods for adding or deleting IDs, and there is a finite number of IDs available (~33 thousand of them).

    Now - when I call createMap(), a new MapView is created for the world, which is probably tied to the coordinates where the map was initialized. I would assume that maps created in the same area would then re-use the first map's ID, so that the image shown is essentially the same. I'm not quite sure wether this is the case or not, since the markers are supposed to be different for each player in an SMP scenario. But again, this could probably be solved using slightly different "rendering" methods (but the same ID) for each player, which I know to be possible.

    Anyway - how does this ID system work? If I hand out maps with a given ID, they will show the same image, more or less. Is the ID based on coordinates? If so, how can I be sure that Bukkit won't give out my custom map ID's for random players who are trying to make a regular map?

    And more importantly, does Bukkit ever unload or delete map ID's, or will I eventually reach a point where all ID's are in use, and the world crashes?

    I'm thinking that I could "reserve" ID number 1, and just apply my custom renderer to that. But again, would Bukkit ever give that particular map to someone else, or does it bother to check if that ID is already in use? I mean, my custom map is technically also tied to coordinates in that world, around 0,0.

    Just to explain what I'm actually doing; on loading, my plugin grabs an ID, clears the renderers and apply my custom one. Whenever players receive this particular map, I simply call into existence a map with that fixed ID I used when loading. This totally works, but I would still like to know how Bukkit feels about this sort of thing.
     
  2. Offline

    kiwhen

    *sneeze*
     
  3. Offline

    DarkBladee12

    First of all maps are not tied to any coordinates since you can use "Bukkit.createMap(World world)", so they map IDs are tied to a world and the MapRenderer does the part for rendering the current environment onto the map that has this renderer. However I didn't find out yet how the ID system works, but I know that Bukkit would never create a new map with an already existing ID, because that would be nonsense. I'm not sure but I think that Bukkit never unloads the map IDs maybe the world will crash when it reached the limit of over 33 thousand, but be honest do you think that a server comes to a point where over 33 thousand map IDs have been generated (without the use of a plugin)? And no Bukkit would never distribute a map with an ID of an already existent map, so you can reserve certain IDs for your plugin, but be sure that your reserved ID isn't already existent! So you could probably check if the plugin already reserved some IDs if yes just add your renderers to the map with that ID and if not generate a new map and save the ID then add your renderers to that map. I hope I could help ;)

    Sorry that I made a new post, but the forum doesn't let me edit my previous post correctly <.< So I actually found out how map IDs are generated and they're handled by nms and not Bukkit itself. So here's what I found in the nms classes of which I think it's the method which generates an ID and creates the file for the map with that ID:

    Code:java
    1.  
    2. // From the class WorldMapCollection.java ([URL]https://github.com/Bukkit/mc-dev/blob/master/net/minecraft/server/WorldMapCollection.java[/URL])
    3. public int a(String s) {
    4. Short oshort = (Short) this.d.get(s);
    5.  
    6. if (oshort == null) {
    7. oshort = Short.valueOf((short) 0);
    8. } else {
    9. oshort = Short.valueOf((short) (oshort.shortValue() + 1));
    10. }
    11.  
    12. this.d.put(s, oshort);
    13. if (this.a == null) {
    14. return oshort.shortValue();
    15. } else {
    16. try {
    17. File file1 = this.a.getDataFile("idcounts");
    18.  
    19. if (file1 != null) {
    20. NBTTagCompound nbttagcompound = new NBTTagCompound();
    21. Iterator iterator = this.d.keySet().iterator();
    22.  
    23. while (iterator.hasNext()) {
    24. String s1 = (String) iterator.next();
    25. short short1 = ((Short) this.d.get(s1)).shortValue();
    26.  
    27. nbttagcompound.setShort(s1, short1);
    28. }
    29.  
    30. DataOutputStream dataoutputstream = new DataOutputStream(new FileOutputStream(file1));
    31.  
    32. NBTCompressedStreamTools.a(nbttagcompound, (DataOutput) dataoutputstream);
    33. dataoutputstream.close();
    34. }
    35. } catch (Exception exception) {
    36. exception.printStackTrace();
    37. }
    38.  
    39. return oshort.shortValue();
    40. }
    41. }


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
Thread Status:
Not open for further replies.

Share This Page