Cuboid areas

Discussion in 'Plugin Development' started by Baummann, Jun 15, 2011.

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

    Baummann

    How would I make selectable cuboid areas? And how to read/save them from/in a file?
    And how would I check if a player enter/leaves it?
     
  2. Offline

    Jako

    Currently I'm working on a way of cuboiding, What I'm am experimenting with is you pass in 2 blocks, you get the difference between the two points, and that will tell you the length, width, and height, then you use 3 for-loops to systematically go through each direction, pulling out each block. So the first for-loop loops through the all the height values, then the for-loop for the width is inside that, which then has a for-loop for the length inside of it. If done right, it should go through every block in the selection. Then you would get every block that isn't air and save it.
    To save it each block, you could use relative x, y, and z values. You could use a format like this x:y:z:id;x:y:z:id;. So basically you say block1 is the starting position, where certainBlock is relatively (2, 2, -2) and its blockType or id is "1" (stone). Which in the format would be "2:2:-2:1;". So, you would first save the starting block first, so you would have something like "60:180:52:29" If you had multiple blocks you would have something like this: "60:180:52:29;3:1:-7:17;4:5:-2:1". You would then just save that to a file. Then to remove it from the file, you could use a file.split(";") which will return an array of all the blocks as "3:1:-7:17" then you would do another split on that, passing in ":" and that would give you an array where array[0] = x, array[1] = y, array[2] = z, and array[3] = id, which then you could pull that info back into a block.
    I have no idea if this would be the best way to store the information, but I think it is a pretty decent way. I haven't fully made my cuboid operation work, but I've been a bit busy with other things. Use this as an idea, and if I can help further, I would love to.

    If you wanted to save just the selection, I would save just block1 and block2, I'd use the same format, so like "60:180:52:29;80:200:53:72". Or you could use a config file to store it. (If you want to try that, I can help with that)

    Now with the player enter/leave, you could find the minimum of the x/y/z and the maximum of the x/y/z and just check if they are within those ranges of all the x/y/z.

    Code:
    if ((player.getLocation.getX() > 5) && (player.getLocation.getX() < 20))
    {
        if ((player.getLocation.getY() > 60) && (player.getLocation.getY() < 80))
        {
            if ((player.getLocation.getZ() > 623) && (player.getLocation.getZ() < 637))
            {
                //Do whatever you want, because they are within the given selection
            }
        }
    }
    Hope this helps and wasn't too confusing, you could try looking in worldedit's source code for an example.

    -Jako
     
  3. WorldEdit can be used as a pretty good reference for checking and calculating.
    CuboidRegion is where most of the region-based calculation takes place.
    To save the area itself, simply store the coordinates of the 2 given points.
     
  4. Offline

    nickguletskii

    This isn't a very efficient way of coordinate storing. A 1d array is enough. We also need the size of the region and its starting point.
    The position of the block in a 1D array is defined by a formula:
    x*(Y*Z) + y*Z + z
    Where x, y, z are coordinates of the block and X, Y, Z - size of the area.
    Now, to restore the coordinates of the block, we use this:
    z = i%Z
    y = ((i-z)/Z)%X
    x = (((i-z)/Z)-y)/Y
    i here is the position of the block in the 1D array.
    I haven't checked, but this looks right.

    EDIT: Fixed the formulas.
     
  5. Offline

    Baummann

    I looked into cuboid's source and it looks like this:

    Code:
    package nl.robinvandervliet.CuboidPlugin;
    
    import java.util.HashMap;
    import org.bukkit.block.Block;
    import org.bukkit.entity.Player;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.event.player.PlayerListener;
    import org.bukkit.inventory.ItemStack;
    
    public class CuboidPluginPlayerListener extends PlayerListener
    {
      public static CuboidPlugin plugin;
    
      public CuboidPluginPlayerListener(CuboidPlugin instance)
      {
        plugin = instance;
      }
    
      public void onPlayerInteract(PlayerInteractEvent event)
      {
        if (event.getAction().equals(Action.RIGHT_CLICK_BLOCK))
        {
          if (event.getPlayer().getItemInHand().getTypeId() == plugin.cuboidtool)
          {
            if (plugin.checkpermissions(event.getPlayer(), "cuboidplugin.select"))
            {
              if (CuboidPlugin.selected.get(event.getPlayer().getName() + "_mode") == null)
              {
                CuboidPlugin.selected.put(event.getPlayer().getName() + "_mode", Integer.valueOf(1));
                CuboidPlugin.selected.put(event.getPlayer().getName() + "_x1", Integer.valueOf(event.getClickedBlock().getX()));
                CuboidPlugin.selected.put(event.getPlayer().getName() + "_y1", Integer.valueOf(event.getClickedBlock().getY()));
                CuboidPlugin.selected.put(event.getPlayer().getName() + "_z1", Integer.valueOf(event.getClickedBlock().getZ()));
                CuboidPlugin.selected.put(event.getPlayer().getName() + "_x2", null);
                CuboidPlugin.selected.put(event.getPlayer().getName() + "_y2", null);
                CuboidPlugin.selected.put(event.getPlayer().getName() + "_z2", null);
                event.getPlayer().sendMessage("§7First point selected. (" + event.getClickedBlock().getX() + ", " + event.getClickedBlock().getY() + ", " + event.getClickedBlock().getZ() + ")");
              }
              else if (((Integer)CuboidPlugin.selected.get(event.getPlayer().getName() + "_mode")).intValue() == 1)
              {
                CuboidPlugin.selected.put(event.getPlayer().getName() + "_mode", Integer.valueOf(2));
                CuboidPlugin.selected.put(event.getPlayer().getName() + "_x2", Integer.valueOf(event.getClickedBlock().getX()));
                CuboidPlugin.selected.put(event.getPlayer().getName() + "_y2", Integer.valueOf(event.getClickedBlock().getY()));
                CuboidPlugin.selected.put(event.getPlayer().getName() + "_z2", Integer.valueOf(event.getClickedBlock().getZ()));
                event.getPlayer().sendMessage("§7Second point selected. (" + event.getClickedBlock().getX() + ", " + event.getClickedBlock().getY() + ", " + event.getClickedBlock().getZ() + ")");
              }
              else if (((Integer)CuboidPlugin.selected.get(event.getPlayer().getName() + "_mode")).intValue() == 2)
              {
                CuboidPlugin.selected.put(event.getPlayer().getName() + "_mode", Integer.valueOf(1));
                CuboidPlugin.selected.put(event.getPlayer().getName() + "_x1", Integer.valueOf(event.getClickedBlock().getX()));
                CuboidPlugin.selected.put(event.getPlayer().getName() + "_y1", Integer.valueOf(event.getClickedBlock().getY()));
                CuboidPlugin.selected.put(event.getPlayer().getName() + "_z1", Integer.valueOf(event.getClickedBlock().getZ()));
                CuboidPlugin.selected.put(event.getPlayer().getName() + "_x2", null);
                CuboidPlugin.selected.put(event.getPlayer().getName() + "_y2", null);
                CuboidPlugin.selected.put(event.getPlayer().getName() + "_z2", null);
                event.getPlayer().sendMessage("§7First point selected. (" + event.getClickedBlock().getX() + "," + event.getClickedBlock().getY() + "," + event.getClickedBlock().getZ() + ")");
              }
            }
          }
        }
      }
    }
    And this:

    Code:
      public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args)
      {
        if (command.getName().equalsIgnoreCase("cuboid"))
        {
          if (!(sender instanceof Player))
          {
            log.info("This command cannot be used in the console.");
            return true;
          }
    
          Player player = (Player)sender;
    
          if (checkpermissions(player, "cuboidplugin.cuboid"))
          {
            if ((selected.get(player.getName() + "_mode") != null) && (((Integer)selected.get(player.getName() + "_mode")).intValue() == 2))
            {
              if (args.length >= 1)
              {
                try
                {
                  int id = 0;
                  int data = 0;
    
                  if (args[0].contains(":"))
                  {
                    String[] split = args[0].split(":");
    
                    id = Integer.parseInt(split[0]);
                    data = Integer.parseInt(split[1]);
                  }
                  else
                  {
                    id = Integer.parseInt(args[0]);
                    data = 0;
                  }
    
                  if (is_block(id))
                  {
                    int i = 0;
    
                    for (int forx = Math.min(((Integer)selected.get(player.getName() + "_x1")).intValue(), ((Integer)selected.get(player.getName() + "_x2")).intValue()); forx <= Math.max(((Integer)selected.get(player.getName() + "_x1")).intValue(), ((Integer)selected.get(player.getName() + "_x2")).intValue()); forx++)
                    {
                      for (int fory = Math.min(((Integer)selected.get(player.getName() + "_y1")).intValue(), ((Integer)selected.get(player.getName() + "_y2")).intValue()); fory <= Math.max(((Integer)selected.get(player.getName() + "_y1")).intValue(), ((Integer)selected.get(player.getName() + "_y2")).intValue()); fory++)
                      {
                        for (int forz = Math.min(((Integer)selected.get(player.getName() + "_z1")).intValue(), ((Integer)selected.get(player.getName() + "_z2")).intValue()); forz <= Math.max(((Integer)selected.get(player.getName() + "_z1")).intValue(), ((Integer)selected.get(player.getName() + "_z2")).intValue()); forz++)
                        {
                          i++;
                        }
                      }
                    }
    
                    if (this.cuboidmaxblocks <= 0)
                    {
                      i = this.cuboidmaxblocks;
                    }
    
                    if (i <= this.cuboidmaxblocks)
                    {
                      for (int forx = Math.min(((Integer)selected.get(player.getName() + "_x1")).intValue(), ((Integer)selected.get(player.getName() + "_x2")).intValue()); forx <= Math.max(((Integer)selected.get(player.getName() + "_x1")).intValue(), ((Integer)selected.get(player.getName() + "_x2")).intValue()); forx++)
                      {
                        for (int fory = Math.min(((Integer)selected.get(player.getName() + "_y1")).intValue(), ((Integer)selected.get(player.getName() + "_y2")).intValue()); fory <= Math.max(((Integer)selected.get(player.getName() + "_y1")).intValue(), ((Integer)selected.get(player.getName() + "_y2")).intValue()); fory++)
                        {
                          for (int forz = Math.min(((Integer)selected.get(player.getName() + "_z1")).intValue(), ((Integer)selected.get(player.getName() + "_z2")).intValue()); forz <= Math.max(((Integer)selected.get(player.getName() + "_z1")).intValue(), ((Integer)selected.get(player.getName() + "_z2")).intValue()); forz++)
                          {
                            player.getWorld().getBlockAt(forx, fory, forz).setTypeId(id);
                            player.getWorld().getBlockAt(forx, fory, forz).setData((byte)data);
                          }
                        }
                      }
    
                      player.sendMessage("§7Area cuboided with " + Material.getMaterial(id).name().toLowerCase().replace("_", " ") + "!");
                      if (!this.cuboidlogging.equals(Boolean.valueOf(true))) break label1515;
                      log.info(player.getName() + " cuboided a area with " + Material.getMaterial(id).name().toLowerCase().replace("_", " ") + "!"); break label1515;
                    }
    
                    player.sendMessage("§cOver server maximum."); break label1515;
                  }
    
                  player.sendMessage("§cUnknown block.");
                }
                catch (NumberFormatException n)
                {
                  player.sendMessage("§cUnknown block.");
                }
              }
              else
              {
                player.sendMessage("§cNo id choosed.");
              }
            }
            else
            {
              player.sendMessage("§cNo cuboid selected.");
            }
          }
          else
          {
            player.sendMessage("§cCannot use cuboid. You don't have permissions!");
          }
          label1515: return true;
        }
        if (command.getName().equalsIgnoreCase("replace"))
        {
          if (!(sender instanceof Player))
          {
            log.info("This command cannot be used in the console.");
            return true;
          }
    
          Player player = (Player)sender;
    
          if (checkpermissions(player, "cuboidplugin.replace"))
          {
            if ((selected.get(player.getName() + "_mode") != null) && (((Integer)selected.get(player.getName() + "_mode")).intValue() == 2))
            {
              if (args.length >= 2)
              {
                try
                {
                  int id1 = 0;
                  int data1 = 0;
    
                  if (args[0].contains(":"))
                  {
                    String[] split1 = args[0].split(":");
    
                    id1 = Integer.parseInt(split1[0]);
                    data1 = Integer.parseInt(split1[1]);
                  }
                  else
                  {
                    id1 = Integer.parseInt(args[0]);
                    data1 = 0;
                  }
    
                  int id2 = 0;
                  int data2 = 0;
    
                  if (args[1].contains(":"))
                  {
                    String[] split2 = args[1].split(":");
    
                    id2 = Integer.parseInt(split2[0]);
                    data2 = Integer.parseInt(split2[1]);
                  }
                  else
                  {
                    id2 = Integer.parseInt(args[1]);
                    data2 = 0;
                  }
    
                  if ((is_block(id1)) && (is_block(id2)))
                  {
                    int i = 0;
    
                    for (int forx = Math.min(((Integer)selected.get(player.getName() + "_x1")).intValue(), ((Integer)selected.get(player.getName() + "_x2")).intValue()); forx <= Math.max(((Integer)selected.get(player.getName() + "_x1")).intValue(), ((Integer)selected.get(player.getName() + "_x2")).intValue()); forx++)
                    {
                      for (int fory = Math.min(((Integer)selected.get(player.getName() + "_y1")).intValue(), ((Integer)selected.get(player.getName() + "_y2")).intValue()); fory <= Math.max(((Integer)selected.get(player.getName() + "_y1")).intValue(), ((Integer)selected.get(player.getName() + "_y2")).intValue()); fory++)
                      {
                        for (int forz = Math.min(((Integer)selected.get(player.getName() + "_z1")).intValue(), ((Integer)selected.get(player.getName() + "_z2")).intValue()); forz <= Math.max(((Integer)selected.get(player.getName() + "_z1")).intValue(), ((Integer)selected.get(player.getName() + "_z2")).intValue()); forz++)
                        {
                          i++;
                        }
                      }
                    }
    
                    if (this.cuboidmaxblocks <= 0)
                    {
                      i = this.cuboidmaxblocks;
                    }
    
                    if (i <= this.cuboidmaxblocks)
                    {
                      for (int forx = Math.min(((Integer)selected.get(player.getName() + "_x1")).intValue(), ((Integer)selected.get(player.getName() + "_x2")).intValue()); forx <= Math.max(((Integer)selected.get(player.getName() + "_x1")).intValue(), ((Integer)selected.get(player.getName() + "_x2")).intValue()); forx++)
                      {
                        for (int fory = Math.min(((Integer)selected.get(player.getName() + "_y1")).intValue(), ((Integer)selected.get(player.getName() + "_y2")).intValue()); fory <= Math.max(((Integer)selected.get(player.getName() + "_y1")).intValue(), ((Integer)selected.get(player.getName() + "_y2")).intValue()); fory++)
                        {
                          for (int forz = Math.min(((Integer)selected.get(player.getName() + "_z1")).intValue(), ((Integer)selected.get(player.getName() + "_z2")).intValue()); forz <= Math.max(((Integer)selected.get(player.getName() + "_z1")).intValue(), ((Integer)selected.get(player.getName() + "_z2")).intValue()); forz++)
                          {
                            if (args[0].contains(":"))
                            {
                              if ((player.getWorld().getBlockAt(forx, fory, forz).getTypeId() != id1) || (player.getWorld().getBlockAt(forx, fory, forz).getData() != data1))
                                continue;
                              player.getWorld().getBlockAt(forx, fory, forz).setTypeId(id2);
                              player.getWorld().getBlockAt(forx, fory, forz).setData((byte)data2);
                            }
                            else
                            {
                              if (player.getWorld().getBlockAt(forx, fory, forz).getTypeId() != id1)
                                continue;
                              player.getWorld().getBlockAt(forx, fory, forz).setTypeId(id2);
                              player.getWorld().getBlockAt(forx, fory, forz).setData((byte)data2);
                            }
                          }
                        }
    
                      }
    
                      player.sendMessage("§7Area replaced from " + Material.getMaterial(id1).name().toLowerCase().replace("_", " ") + " to " + Material.getMaterial(id2).name().toLowerCase().replace("_", " ") + "!");
                      if (!this.cuboidlogging.equals(Boolean.valueOf(true))) break label3316;
                      log.info(player.getName() + " replaced a area from " + Material.getMaterial(id1).name().toLowerCase().replace("_", " ") + " to " + Material.getMaterial(id2).name().toLowerCase().replace("_", " ") + "!"); break label3316;
                    }
    
                    player.sendMessage("§cOver server maximum."); break label3316;
                  }
    
                  player.sendMessage("§cUnknown block.");
                }
                catch (NumberFormatException n)
                {
                  player.sendMessage("§cUnknown block.");
                }
              }
              else
              {
                player.sendMessage("§cNo id choosed.");
              }
            }
            else
            {
              player.sendMessage("§cNo cuboid selected.");
            }
          }
          else
          {
            player.sendMessage("§cCannot use replace. You don't have permissions!");
          }
          label3316: return true;
        }
        if (command.getName().equalsIgnoreCase("walls"))
        {
          if (!(sender instanceof Player))
          {
            log.info("This command cannot be used in the console.");
            return true;
          }
    
          Player player = (Player)sender;
    
          if (checkpermissions(player, "cuboidplugin.walls"))
          {
            if ((selected.get(player.getName() + "_mode") != null) && (((Integer)selected.get(player.getName() + "_mode")).intValue() == 2))
            {
              if (args.length >= 1)
              {
                try
                {
                  int id = 0;
                  int data = 0;
    
                  if (args[0].contains(":"))
                  {
                    String[] split = args[0].split(":");
    
                    id = Integer.parseInt(split[0]);
                    data = Integer.parseInt(split[1]);
                  }
                  else
                  {
                    id = Integer.parseInt(args[0]);
                    data = 0;
                  }
    
                  if (is_block(id))
                  {
                    int i = 0;
    
                    for (int forx = Math.min(((Integer)selected.get(player.getName() + "_x1")).intValue(), ((Integer)selected.get(player.getName() + "_x2")).intValue()); forx <= Math.max(((Integer)selected.get(player.getName() + "_x1")).intValue(), ((Integer)selected.get(player.getName() + "_x2")).intValue()); forx++)
                    {
                      for (int fory = Math.min(((Integer)selected.get(player.getName() + "_y1")).intValue(), ((Integer)selected.get(player.getName() + "_y2")).intValue()); fory <= Math.max(((Integer)selected.get(player.getName() + "_y1")).intValue(), ((Integer)selected.get(player.getName() + "_y2")).intValue()); fory++)
                      {
                        for (int forz = Math.min(((Integer)selected.get(player.getName() + "_z1")).intValue(), ((Integer)selected.get(player.getName() + "_z2")).intValue()); forz <= Math.max(((Integer)selected.get(player.getName() + "_z1")).intValue(), ((Integer)selected.get(player.getName() + "_z2")).intValue()); forz++)
                        {
                          i++;
                        }
                      }
                    }
    
                    if (this.cuboidmaxblocks <= 0)
                    {
                      i = this.cuboidmaxblocks;
                    }
    
                    if (i <= this.cuboidmaxblocks)
                    {
                      for (int forx = Math.min(((Integer)selected.get(player.getName() + "_x1")).intValue(), ((Integer)selected.get(player.getName() + "_x2")).intValue()); forx <= Math.max(((Integer)selected.get(player.getName() + "_x1")).intValue(), ((Integer)selected.get(player.getName() + "_x2")).intValue()); forx++)
                      {
                        for (int fory = Math.min(((Integer)selected.get(player.getName() + "_y1")).intValue(), ((Integer)selected.get(player.getName() + "_y2")).intValue()); fory <= Math.max(((Integer)selected.get(player.getName() + "_y1")).intValue(), ((Integer)selected.get(player.getName() + "_y2")).intValue()); fory++)
                        {
                          for (int forz = Math.min(((Integer)selected.get(player.getName() + "_z1")).intValue(), ((Integer)selected.get(player.getName() + "_z2")).intValue()); forz <= Math.max(((Integer)selected.get(player.getName() + "_z1")).intValue(), ((Integer)selected.get(player.getName() + "_z2")).intValue()); forz++)
                          {
                            if ((forx != Math.min(((Integer)selected.get(player.getName() + "_x1")).intValue(), ((Integer)selected.get(player.getName() + "_x2")).intValue())) && (forx != Math.max(((Integer)selected.get(player.getName() + "_x1")).intValue(), ((Integer)selected.get(player.getName() + "_x2")).intValue())) && (forz != Math.min(((Integer)selected.get(player.getName() + "_z1")).intValue(), ((Integer)selected.get(player.getName() + "_z2")).intValue())) && (forz != Math.max(((Integer)selected.get(player.getName() + "_z1")).intValue(), ((Integer)selected.get(player.getName() + "_z2")).intValue())))
                              continue;
                            player.getWorld().getBlockAt(forx, fory, forz).setTypeId(id);
                            player.getWorld().getBlockAt(forx, fory, forz).setData((byte)data);
                          }
                        }
    
                      }
    
                      player.sendMessage("§7Created walls in area from " + Material.getMaterial(id).name().toLowerCase().replace("_", " ") + "!");
                      if (!this.cuboidlogging.equals(Boolean.valueOf(true))) break label5170;
                      log.info(player.getName() + " created walls in area from " + Material.getMaterial(id).name().toLowerCase().replace("_", " ") + "!"); break label5170;
                    }
    
                    player.sendMessage("§cOver server maximum."); break label5170;
                  }
    
                  player.sendMessage("§cUnknown block.");
                }
                catch (NumberFormatException n)
                {
                  player.sendMessage("§cUnknown block.");
                }
              }
              else
              {
                player.sendMessage("§cNo id choosed.");
              }
            }
            else
            {
              player.sendMessage("§cNo cuboid selected.");
            }
          }
          else
          {
            player.sendMessage("§cCannot use walls. You don't have permissions!");
          }
          label5170: return true;
        }
        if (command.getName().equalsIgnoreCase("box"))
        {
          if (!(sender instanceof Player))
          {
            log.info("This command cannot be used in the console.");
            return true;
          }
    
          Player player = (Player)sender;
    
          if (checkpermissions(player, "cuboidplugin.box"))
          {
            if ((selected.get(player.getName() + "_mode") != null) && (((Integer)selected.get(player.getName() + "_mode")).intValue() == 2))
            {
              if (args.length >= 1)
              {
                try
                {
                  int id = 0;
                  int data = 0;
    
                  if (args[0].contains(":"))
                  {
                    String[] split = args[0].split(":");
    
                    id = Integer.parseInt(split[0]);
                    data = Integer.parseInt(split[1]);
                  }
                  else
                  {
                    id = Integer.parseInt(args[0]);
                    data = 0;
                  }
    
                  if (is_block(id))
                  {
                    int i = 0;
    
                    for (int forx = Math.min(((Integer)selected.get(player.getName() + "_x1")).intValue(), ((Integer)selected.get(player.getName() + "_x2")).intValue()); forx <= Math.max(((Integer)selected.get(player.getName() + "_x1")).intValue(), ((Integer)selected.get(player.getName() + "_x2")).intValue()); forx++)
                    {
                      for (int fory = Math.min(((Integer)selected.get(player.getName() + "_y1")).intValue(), ((Integer)selected.get(player.getName() + "_y2")).intValue()); fory <= Math.max(((Integer)selected.get(player.getName() + "_y1")).intValue(), ((Integer)selected.get(player.getName() + "_y2")).intValue()); fory++)
                      {
                        for (int forz = Math.min(((Integer)selected.get(player.getName() + "_z1")).intValue(), ((Integer)selected.get(player.getName() + "_z2")).intValue()); forz <= Math.max(((Integer)selected.get(player.getName() + "_z1")).intValue(), ((Integer)selected.get(player.getName() + "_z2")).intValue()); forz++)
                        {
                          i++;
                        }
                      }
                    }
    
                    if (this.cuboidmaxblocks <= 0)
                    {
                      i = this.cuboidmaxblocks;
                    }
    
                    if (i <= this.cuboidmaxblocks)
                    {
                      for (int forx = Math.min(((Integer)selected.get(player.getName() + "_x1")).intValue(), ((Integer)selected.get(player.getName() + "_x2")).intValue()); forx <= Math.max(((Integer)selected.get(player.getName() + "_x1")).intValue(), ((Integer)selected.get(player.getName() + "_x2")).intValue()); forx++)
                      {
                        for (int fory = Math.min(((Integer)selected.get(player.getName() + "_y1")).intValue(), ((Integer)selected.get(player.getName() + "_y2")).intValue()); fory <= Math.max(((Integer)selected.get(player.getName() + "_y1")).intValue(), ((Integer)selected.get(player.getName() + "_y2")).intValue()); fory++)
                        {
                          for (int forz = Math.min(((Integer)selected.get(player.getName() + "_z1")).intValue(), ((Integer)selected.get(player.getName() + "_z2")).intValue()); forz <= Math.max(((Integer)selected.get(player.getName() + "_z1")).intValue(), ((Integer)selected.get(player.getName() + "_z2")).intValue()); forz++)
                          {
                            if ((forx != Math.min(((Integer)selected.get(player.getName() + "_x1")).intValue(), ((Integer)selected.get(player.getName() + "_x2")).intValue())) && (forx != Math.max(((Integer)selected.get(player.getName() + "_x1")).intValue(), ((Integer)selected.get(player.getName() + "_x2")).intValue())) && (fory != Math.min(((Integer)selected.get(player.getName() + "_y1")).intValue(), ((Integer)selected.get(player.getName() + "_y2")).intValue())) && (fory != Math.max(((Integer)selected.get(player.getName() + "_y1")).intValue(), ((Integer)selected.get(player.getName() + "_y2")).intValue())) && (forz != Math.min(((Integer)selected.get(player.getName() + "_z1")).intValue(), ((Integer)selected.get(player.getName() + "_z2")).intValue())) && (forz != Math.max(((Integer)selected.get(player.getName() + "_z1")).intValue(), ((Integer)selected.get(player.getName() + "_z2")).intValue())))
                              continue;
                            player.getWorld().getBlockAt(forx, fory, forz).setTypeId(id);
                            player.getWorld().getBlockAt(forx, fory, forz).setData((byte)data);
                          }
                        }
    
                      }
    
                      player.sendMessage("§7Created a box in area from " + Material.getMaterial(id).name().toLowerCase().replace("_", " ") + "!");
                      if (!this.cuboidlogging.equals(Boolean.valueOf(true))) break label7192;
                      log.info(player.getName() + " created a box in area from " + Material.getMaterial(id).name().toLowerCase().replace("_", " ") + "!"); break label7192;
                    }
    
                    player.sendMessage("§cOver server maximum."); break label7192;
                  }
    
                  player.sendMessage("§cUnknown block.");
                }
                catch (NumberFormatException n)
                {
                  player.sendMessage("§cUnknown block.");
                }
              }
              else
              {
                player.sendMessage("§cNo id choosed.");
              }
            }
            else
            {
              player.sendMessage("§cNo cuboid selected.");
            }
          }
          else
          {
            player.sendMessage("§cCannot use box. You don't have permissions!");
          }
          label7192: return true;
        }
        if (command.getName().equalsIgnoreCase("size"))
        {
          if (!(sender instanceof Player))
          {
            log.info("This command cannot be used in the console.");
            return true;
          }
    
          Player player = (Player)sender;
    
          if (checkpermissions(player, "cuboidplugin.size"))
          {
            if ((selected.get(player.getName() + "_mode") != null) && (((Integer)selected.get(player.getName() + "_mode")).intValue() == 2))
            {
              int i = 0;
    
              for (int forx = Math.min(((Integer)selected.get(player.getName() + "_x1")).intValue(), ((Integer)selected.get(player.getName() + "_x2")).intValue()); forx <= Math.max(((Integer)selected.get(player.getName() + "_x1")).intValue(), ((Integer)selected.get(player.getName() + "_x2")).intValue()); forx++)
              {
                for (int fory = Math.min(((Integer)selected.get(player.getName() + "_y1")).intValue(), ((Integer)selected.get(player.getName() + "_y2")).intValue()); fory <= Math.max(((Integer)selected.get(player.getName() + "_y1")).intValue(), ((Integer)selected.get(player.getName() + "_y2")).intValue()); fory++)
                {
                  for (int forz = Math.min(((Integer)selected.get(player.getName() + "_z1")).intValue(), ((Integer)selected.get(player.getName() + "_z2")).intValue()); forz <= Math.max(((Integer)selected.get(player.getName() + "_z1")).intValue(), ((Integer)selected.get(player.getName() + "_z2")).intValue()); forz++)
                  {
                    i++;
                  }
                }
              }
    
              player.sendMessage("§7This selection has " + i + " blocks!");
              if (this.cuboidlogging.equals(Boolean.valueOf(true)))
              {
                log.info(player.getName() + " got the size of a selection with " + i + " blocks!");
              }
            }
            else
            {
              player.sendMessage("§cNo cuboid selected.");
            }
          }
          else
          {
            player.sendMessage("§cCannot use size. You don't have permissions!");
          }
          return true;
        }
        return false;
      }
    }
    Now I just need to save the locations. And figure out how to do somethign when a player enters the cuboid.
     
  6. Offline

    nickguletskii

    That doesn't look like the code to load/save them.
     
  7. Try using Regios
     
  8. Offline

    Baummann

    I never said that I want a plugin I said I want to make a plugin :p which looks like this:
    1st Select area
    2nd Type /area protect
    3rd If a player except you enters the cuboid he gets kicked/teleported out
     
  9. Offline

    nickguletskii

    Ooooh, I got it... You want to save the list of the regions, yeah? Then it is easy - make a class called a Region (implements Serializable) and a HashSet/ArrayList of it. Save/load using SnakeYML.
     
  10. Offline

    Wizehh

    I need help with this too :/
     
  11. Offline

    BillyGalbreath

    Don't use player.get location().getX() or you'll run into issues. Instead use .getBlockX()
     
  12. Offline

    messageofdeath

    I made this Cuboid Vector based system that works perfectly. It has parsing as well already done as well. to String and to Vector/Cuboid

    http://pastebin.com/mcXCijCh
     
  13. Offline

    Wizehh

    I have a cuboid system that works perfectly; however, on reload/restart, the arraylist is cleared.
    messageofdeath Does yours fix this problemo'?
     
  14. Offline

    dillyg10

    A cuboid is two vectors: So we'll have an example here

    Vector a, Vector b;

    Now, you need a max, and a min...
    a is the min, b is the max.

    Okay! So, how to select this? Well let's say you have a /select command that gives you an apple to select a region, just make a player listener to listen for... left click, and if it's left click set a to the location, otherwise if it's right click set b to the location.

    That's simple, how to check if a player is in a region...

    if (p.getLocation().toVector().isInAxisAlignedBB(a,b)) { //Then the player is in the region }

    To save it...

    config.set("region.vector1",a);
    config.set("region.vector2",b);

    Now, to find the min and the max (which you will want to do)

    if (a.getY() < b.getY()) a = min;
    else b = min;
    (horrible sudo code)

    There you go, cuboids are basic, if you have questions don't hesitate to ask!
     
Thread Status:
Not open for further replies.

Share This Page