Solved Set a block to a chest with items in it..

Discussion in 'Plugin Development' started by Techno, Mar 23, 2014.

Thread Status:
Not open for further replies.
  1. Soo, what I want to do is: Have a block, you right click it, it sets it to a chest with 16 diamonds in it..

    Code:
    Code:java
    1.  
    2. // Private's
    3. private World world;
    4. private Location loc;
    5. private Location b;
    6.  
    7. @EventHandler
    8. public void blockwork(PlayerInteractEvent e) {
    9. // Player for the event
    10. Player p = e.getPlayer();
    11.  
    12. // Getting the block
    13. if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
    14. if (e.getClickedBlock().getType() == Material.DIAMOND_BLOCK) {
    15. // Send surprise message!
    16. p.sendMessage("" + ChatColor.BLUE + ChatColor.ITALIC + "SUPRISE!");
    17.  
    18. // Get player location
    19. world = p.getWorld();
    20. loc = p.getLocation();
    21.  
    22. // Block
    23. b = (Location) e.getClickedBlock().getLocation();
    24.  
    25. // Change2
    26. Block bc = e.getClickedBlock();
    27.  
    28. Chest c = (Chest) bc;
    29. Block cb = (Block) c;
    30.  
    31.  
    32.  
    33. }
    34.  
    35. if (e.getClickedBlock().getType() == Material.BEDROCK) {
    36. // Send surprise message!
    37. p.sendMessage("" + ChatColor.RED + ChatColor.ITALIC + "TREE!");
    38.  
    39. // Get player location
    40. world = p.getWorld();
    41. loc = p.getLocation();
    42.  
    43. // Block
    44. b = (Location) e.getClickedBlock().getLocation();
    45.  
    46. // More
    47. Block change = e.getClickedBlock();
    48. change.setType(Material.AIR);
    49.  
    50. // Set block
    51. world.generateTree(b.add(0, 0, -1), TreeType.TREE);
    52.  
    53. // Teleport
    54. p.teleport(loc.add(0, 0, 0));
    55.  
    56. }
    57.  
    58. }
    59.  
    60. }
    61.  
     
  2. Offline

    rfsantos1996


    Code:java
    1. // on Interact Event
    2. if(e.getAction().equals(Action.RIGHT_CLICK_BLOCK) && e.getClickedBlock().getType().equals(Material.<MATERIAL THAT YOU WANT TO TURN INTO A CHEST>)) {
    3. Player p = e.getPlayer();
    4. e.getClickedBlock().setType(Material.CHEST);
    5. if(e.getClickedBlock().getState() instanceof Chest) {
    6. Chest chest = (Chest) e.getClickedBlock().getState();
    7. chest.getInventory().addItem(new ItemStack(Material.DIAMOND, 16));
    8. p.sendMessage("Here, have a chest with 16 diamonds!");
    9. }
    10. }
     
Thread Status:
Not open for further replies.

Share This Page