Map packets

Discussion in 'Plugin Development' started by Nogtail, Nov 27, 2013.

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

    Nogtail

    I would like to show different players different versions of the same map and am a bit confused on how I would go about doing this.

    Thanks :)

    EDIT: This is about the map item, sorry for the confusion.
     
  2. Nogtail Be prepared for something really tricky! Use protocolLib, else you won't survive.

    Basically you need to modify the outgoing packets, or send new ones when the player joins. The first option is the less-laggy one client side but needs your plugin to depend on ProtocolLib.

    Here is a list of all possible Packets:
    http://wiki.vg/Protocol#Multi_Block_Change
    http://wiki.vg/Protocol#Chunk_Data
    http://wiki.vg/Protocol#Block_Change
    http://wiki.vg/Protocol#Map_Chunk_Bulk <- This is the one you will probably need.

    Since I have never worked with those packets I will try to explain how to do it but if it doesn't work then I won't be able to help :/

    If you take a look at how orebfuscator does this you see it listens for the outgoing Packets.MAP_CHUNK and Packets.MAP_CHUNK_BULK. (https://github.com/lishid/Orebfusca...lishid/orebfuscator/hook/ProtocolLibHook.java)

    You will have to do the same. Then it looks like it uses a the Calculations class to obfuscate the chunk. (https://github.com/lishid/Orebfusca...id/orebfuscator/obfuscation/Calculations.java)
    As you probably see it's pretty "advanced" stuff. I would send the author if he can help you with this since I'm not very common with this kind of packet manipulation. Taking a good look at orebfuscator will be a good to learn more about the map format/packet manipulation.
     
  3. Offline

    Nogtail

    Sorry, I ment as in the map item, I should have been more clear. The resources you have linked have given me a bit of info (http://wiki.vg/Protocol#Maps) but wondering if you know anything about this, thanks :)
     
  4. Offline

    desht

    You can do this with the Bukkit Map API, no need for any NMS hackery. Basically, when you construct your custom map renderer, pass true to the superclass constructor, e.g.

    PHP:
    public class MyRenderer {
       public 
    MyRenderer() {
          
    super(true);
       } 
     
        public 
    void render(MapView mapMapCanvas canvasPlayer player) {
            
    // ...map rendering code here...
        

    }
    That super(true) indicates that you want a per-player rendering context, i.e. a separate MapCanvas object will be maintained by CraftBukkit for each player. This means every player can see a different image on the same map.
     
    fromgate likes this.
  5. Offline

    Nogtail

    Will this work if the map is on an item frame? Haven't looked at the code for item frames so not sure how they handle maps.
     
  6. Offline

    desht

  7. Offline

    Nogtail

    Thanks a lot for all the help :)
     
  8. Offline

    Nogtail

  9. Offline

    desht

    Nogtail to keep track of which map you're using, you could persist its ID, either in your main config.yml, or perhaps in another file. This (untested code) example just uses the main plugin config.

    PHP:
    short mapId plugin.getConfig().getShort("mapId", -1);
    MapView view;
    if (
    mapId == -1) {
      
    view Bukkit.createMap(world);
      
    plugin.getConfig().set("mapId"view.getId());
      
    plugin.saveConfig();
    } else {
      
    view Bukkit.getMap(mapId);
      
    // ...you should really check for null here and get a new map if so...
    }
    ItemStack mapItem = new ItemStack(Material.MAP1view.getId());
    frame.setItem(mapItem);
     
Thread Status:
Not open for further replies.

Share This Page