Help with saving block Locations and BlockData

Discussion in 'Plugin Development' started by CSEden, Feb 27, 2021.

  1. Offline

    CSEden

    So I am working on a plugin that makes some technical stuff easier to do in minecraft. The goal of the plugin is going to be that it will function something like gnembon's carpet mod. So I have gotten a lot of features in but I have some problems. What I do is I generate a hollow sphere at the players origin, I then save the locations of each block and their corresponding BlockData so I later on can remove the sphere. I use
    sendBlockChange to send blocks to a certain player only (because they should only be able to see the sphere). I can generate the sphere, save the locations and BlockData, but when I try to load another sphere with that data to remove it it seems to have no effect. Any help is aprechiated :)

    Here is the code of the process:
    Code:
    List<Location> SavedBlockLocation = new ArrayList<Location>();
    List<Material> SavedBlockData = new ArrayList<Material>();
    
    if (command.getName().equalsIgnoreCase("despawnzone")) {
           for (Location l : generateSphere(player, player.getLocation(),30 , true)) {
                  SavedBlockLocation.add(player.getWorld().getBlockAt(l).getLocation());
                  SavedBlockData.add(player.getWorld().getBlockAt(l).getType());
                  player.sendBlockChange(l, Material.RED_STAINED_GLASS.createBlockData());
            }
    }
    
    if (command.getName().equalsIgnoreCase("despawnzone_stop")) {
            int count = 0;
            for (Location i : SavedBlockLocation) {
                   try {
                        player.sendBlockChange(i, SavedBlockData.get(count).createBlockData());
                        count++;
                   } catch (Exception e) {
                         player.sendMessage(e.toString());
                  }
          }
    }
    
    generateSphere returns a List of locations where the blocks should be placed.
     

Share This Page