Generating a 10x10 glass box?

Discussion in 'Plugin Development' started by HighOnSwiftness, Mar 28, 2014.

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

    HighOnSwiftness

    I was just wondering how to make it so if you right click a player, they get teleported into a generated glass box that's 30 blocks up in the air. Thank you!
     
  2. Offline

    2MBKindiegames

    This is probably what you're looking for:
    Code:java
    1. @EventHandler
    2. public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
    3. if (event.getRightClicked() instanceof Player) {
    4. Player clicked = (Player) event.getRightClicked();
    5. Location loc = clicked.getLocation().clone();
    6. loc.add(0, 30, 0);
    7.  
    8. boolean done = false;
    9. Block pasteBlock;
    10. int xPos = 0;
    11. int yPos = 0;
    12. int zPos = 0;
    13.  
    14. while (done == false) {
    15. pasteBlock = loc.getWorld().getBlockAt(loc.getBlockX()+xPos, loc.getBlockY()+yPos, loc.getBlockZ()+zPos);
    16. pasteBlock.setType(Material.AIR);
    17.  
    18. if (yPos == 0 || yPos == 10) {
    19. pasteBlock = loc.getWorld().getBlockAt(loc.getBlockX()+xPos, loc.getBlockY()+yPos, loc.getBlockZ()+zPos);
    20. pasteBlock.setType(Material.GLASS);
    21. } else if (xPos == 0 || xPos == 10) {
    22. pasteBlock = loc.getWorld().getBlockAt(loc.getBlockX()+xPos, loc.getBlockY()+yPos, loc.getBlockZ()+zPos);
    23. pasteBlock.setType(Material.GLASS);
    24. } else if (zPos == 0 || zPos == 10) {
    25. pasteBlock = loc.getWorld().getBlockAt(loc.getBlockX()+xPos, loc.getBlockY()+yPos, loc.getBlockZ()+zPos);
    26. pasteBlock.setType(Material.GLASS);
    27. }
    28.  
    29. xPos++;
    30. if (xPos > 10) {
    31. xPos = 0;
    32. zPos++;
    33.  
    34. if (zPos > 10) {
    35. zPos = 0;
    36. yPos++;
    37.  
    38. if (yPos > 10) {
    39. done = true;
    40. }
    41. }
    42. }
    43. }
    44.  
    45. Location teleport = loc.clone();
    46. teleport.add(5, 2, 5);
    47. clicked.teleport(teleport);
    48. }
    49. }
     
  3. Offline

    HighOnSwiftness

    2MBKindiegames Yeah, I think it is. But, do you think you could add some comments? You don't have to, I'm just wondering if you could for the hell of it :p

    Oh jesus, I forgot. How do I make it disappear? 2MBKindiegames

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

    willeb96

    Code:java
    1. @EventHandler
    2. public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
    3. if (event.getRightClicked() instanceof Player) {
    4. // Get the clicked players location and add 30 blocks on the Y-axis to it
    5. Player clicked = (Player) event.getRightClicked();
    6. Location loc = clicked.getLocation().clone();
    7. loc.add(0, 30, 0);
    8.  
    9. // Initalize some variables used to generate the glass block
    10. boolean done = false;
    11. Block pasteBlock;
    12. int xPos = 0;
    13. int yPos = 0;
    14. int zPos = 0;
    15.  
    16. while (done == false) {
    17. pasteBlock = loc.getWorld().getBlockAt(loc.getBlockX()+xPos, loc.getBlockY()+yPos, loc.getBlockZ()+zPos);
    18. pasteBlock.setType(Material.AIR);
    19.  
    20. // Checks to determine whether a block is part of the outer wall or not
    21. if (yPos == 0 || yPos == 10) {
    22. pasteBlock = loc.getWorld().getBlockAt(loc.getBlockX()+xPos, loc.getBlockY()+yPos, loc.getBlockZ()+zPos);
    23. pasteBlock.setType(Material.GLASS);
    24. } else if (xPos == 0 || xPos == 10) {
    25. pasteBlock = loc.getWorld().getBlockAt(loc.getBlockX()+xPos, loc.getBlockY()+yPos, loc.getBlockZ()+zPos);
    26. pasteBlock.setType(Material.GLASS);
    27. } else if (zPos == 0 || zPos == 10) {
    28. pasteBlock = loc.getWorld().getBlockAt(loc.getBlockX()+xPos, loc.getBlockY()+yPos, loc.getBlockZ()+zPos);
    29. pasteBlock.setType(Material.GLASS);
    30. }
    31.  
    32. // Increment coordinates of the block to do next
    33. xPos++;
    34. if (xPos > 10) {
    35. xPos = 0;
    36. zPos++;
    37.  
    38. if (zPos > 10) {
    39. zPos = 0;
    40. yPos++;
    41.  
    42. if (yPos > 10) {
    43. done = true;
    44. }
    45. }
    46. }
    47. }
    48.  
    49. // Teleport the player
    50. Location teleport = loc.clone();
    51. teleport.add(5, 2, 5);
    52. clicked.teleport(teleport);
    53. }
    54. }
     
  5. Offline

    2MBKindiegames

    I'll add some code wich makes it dissapear

    Here you go:
    Code:java
    1. //Creates a List
    2. ArrayList<Location> blockList = new ArrayList<Location>();
    3.  
    4.  
    5. public void onDisable(){
    6. //Set all changed blocks back to air
    7. Block block;
    8. for (int i = 0; i < blockList.size(); i++) {
    9. block = blockList.get(i).getBlock();
    10. block.setType(Material.AIR);
    11. }
    12. blockList.clear();
    13. }
    14.  
    15. @EventHandler
    16. public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
    17. if (event.getRightClicked() instanceof Player) {
    18. // Get the clicked players location and add 30 blocks on the Y-axis to it
    19. Player clicked = (Player) event.getRightClicked();
    20. Location loc = clicked.getLocation().clone();
    21. loc.add(0, 30, 0);
    22.  
    23. // Initalize some variables used to generate the glass block
    24. boolean done = false;
    25. Block pasteBlock;
    26. int xPos = 0;
    27. int yPos = 0;
    28. int zPos = 0;
    29.  
    30. while (done == false) {
    31. pasteBlock = loc.getWorld().getBlockAt(loc.getBlockX()+xPos, loc.getBlockY()+yPos, loc.getBlockZ()+zPos);
    32. pasteBlock.setType(Material.AIR);
    33. //Adds the location to the list
    34. blockList.add(pasteBlock.getLocation());
    35.  
    36. // Checks to determine whether a block is part of the outer wall or not
    37. if (yPos == 0 || yPos == 10) {
    38. pasteBlock = loc.getWorld().getBlockAt(loc.getBlockX()+xPos, loc.getBlockY()+yPos, loc.getBlockZ()+zPos);
    39. pasteBlock.setType(Material.GLASS);
    40. } else if (xPos == 0 || xPos == 10) {
    41. pasteBlock = loc.getWorld().getBlockAt(loc.getBlockX()+xPos, loc.getBlockY()+yPos, loc.getBlockZ()+zPos);
    42. pasteBlock.setType(Material.GLASS);
    43. } else if (zPos == 0 || zPos == 10) {
    44. pasteBlock = loc.getWorld().getBlockAt(loc.getBlockX()+xPos, loc.getBlockY()+yPos, loc.getBlockZ()+zPos);
    45. pasteBlock.setType(Material.GLASS);
    46. }
    47.  
    48. // Increment coordinates of the block to do next
    49. xPos++;
    50. if (xPos > 10) {
    51. xPos = 0;
    52. zPos++;
    53.  
    54. if (zPos > 10) {
    55. zPos = 0;
    56. yPos++;
    57.  
    58. if (yPos > 10) {
    59. done = true;
    60. }
    61. }
    62. }
    63. }
    64.  
    65. // Teleport the player
    66. Location teleport = loc.clone();
    67. teleport.add(5, 2, 5);
    68. clicked.teleport(teleport);
    69. }
    70. }


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

    HighOnSwiftness

    2MBKindiegames So, wouldn't that mean if I edited the map it would make it disappear too?
     
  7. Offline

    2MBKindiegames

    Yes, if you disable the plugin, the blocks get deleted
     
Thread Status:
Not open for further replies.

Share This Page