Creating a hollow square programmatically

Discussion in 'Plugin Development' started by BrennyMullan, Dec 14, 2014.

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

    BrennyMullan

    I am trying to create a hollow square much like the //walls command from WorldEdit based on 2 Locations.

    Say i have 2 Locations like so

    Code:
    Location loc = new Location(Bukkit.getWorld("world"), 1863, 70, 86);
    Location loc2 = new Location(Bukkit.getWorld("world"), 1873, 70, 96);
    Those 2 Locations correspond to a 10x10 square, is there anyway in my plugin i can create walls around that selection which will be 10 blocks high without having to create a bunch of for loops for each axix.
     
  2. Offline

    teej107

    You will have to use a for-loop on each axis. One way or another. There are multiple that I have in mind.
     
  3. Offline

    DeadlyScone

    I would look here:
    http://wiki.bukkit.org/Plugin_Tutorial

    And scroll down to block manipulation and have a looksie. Unfortunately I don't think there is a way to do this without doing what teej said.

    Thy being said, that link shows how to make a solid cuboid but I am sure you understand the concept enough.
     
  4. Offline

    BrennyMullan

    Thanks for the help, i went with this

    Code:
    public void generateCube(Location loc, int length) {
    
                int x1 = loc.getBlockX();
                int y1 = loc.getBlockY();
                int z1 = loc.getBlockZ();
            
                int x2 = x1 + length;
                int y2 = y1 + length;
                int z2 = z1 + length;
            
                World world = loc.getWorld();
            
                for (int xPoint = x1; xPoint <= x2; xPoint++) {
                    for (int yPoint = y1; yPoint <= y2; yPoint++) {
                            Block currentBlock = world.getBlockAt(xPoint, yPoint, z1);
                            currentBlock.setType(Material.GLASS);
                    }
                }
                for (int xPoint = x1; xPoint <= x2; xPoint++) {
                    for (int yPoint = y1; yPoint <= y2; yPoint++) {
                            Block currentBlock = world.getBlockAt(xPoint, yPoint, z2);
                            currentBlock.setType(Material.GLASS);
                    }
                }
                for (int zPoint = z1; zPoint <= z2; zPoint++) {
                    for (int yPoint = y1; yPoint <= y2; yPoint++) {
                            Block currentBlock = world.getBlockAt(x1, yPoint, zPoint);
                            currentBlock.setType(Material.GLASS);
                    }
                }
                for (int zPoint = z1; zPoint <= z2; zPoint++) {
                    for (int yPoint = y1; yPoint <= y2; yPoint++) {
                            Block currentBlock = world.getBlockAt(x2, yPoint, zPoint);
                            currentBlock.setType(Material.GLASS);
                    }
                }
            }
    Not sure if this is the most efficient way but it does the job

    Is there a way to stop the fake blocks disappearing when right clicking? i have tried the player interact event but its not registered as a real interact when the fake block disappears.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 29, 2016
  5. Offline

    DeadlyScone

  6. Offline

    BrennyMullan

    @DeadlyScone The blocks that are spawned in using the sendBlockChange
     
  7. Offline

    Skionz

    @BrennyMullan That creates a client side block. Why not just create a real block?
     
  8. Offline

    BrennyMullan

    @Skionz Its a combat type of plugin, once they run out of spawn and get combat tagged, if they try run back in the wall appears(only the combat tagged player can see, sending block changes) but they can right click the blocks and they dissapear
     
  9. Offline

    Skionz

    @BrennyMullan Ah, I'm not sure. You could create a scheduler but there is probably a better way.
     
  10. Offline

    DeadlyScone

    @BrennyMullan
    Well, if it wasn't client side I wouldn''ve suggested checking the player interact event and checking if the player clicked within the 2 location points(similar to creating the cuboid,but just checking if it's within) then callng the method again to generate the cuboid if that's the case.

    Here is an idea that might work.
    I suppose you could create a hashmap containing <String, Boolean> if the player leaves the spawn add that players name and set the bool to true, then if they click within the bounds of the cuboid (severside it will be air block btw) then run the generate cuboid method again.
     
  11. Offline

    BrennyMullan

    @Skionz Yeah i tried that, having the cuboid regen every second so if its broken it comes back right away but running it every second would probably be expensive

    @DeadlyScone Thats a good idea, i already have a map to check if they are in the "show walls bounds" that are around spawn, if they are and they are combat tagged then the walls will come up when they enter, The problem with the playerinteract event is the event doesn't get called when you right click air without an item in your hand, so they would still be able to right click the fake blocks and make them dissapear
     
  12. Offline

    DeadlyScone

    @BrennyMullan
    that event gets fired when a player interacts with an object or air according to bukkit jd. Did you print a debug message before any code to test this?
     
  13. Offline

    BrennyMullan

    @DeadlyScone Yeah but Bukkit decided to cancel the event now if its clicking air without an item in hand, i did test it just to make sure.
     
Thread Status:
Not open for further replies.

Share This Page