Block Disappear

Discussion in 'Plugin Development' started by CrazymanJR, Sep 17, 2014.

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

    CrazymanJR

    I was wondering if somebody could help me code a plugin that removes a stone block after being placed for 3 seconds. I have no current code for this so far because i have no idea how to code something like this.
     
  2. Offline

    Bammerbom

    CrazymanJR
    Listen to BlockPlaceEvent, schedule a task of 60 tiks (3 seconds) and set the block to air.
     
  3. Offline

    CrazymanJR

    Bammerbom
    How would i get that it was a stone block that was placed? Would this work : if (event.getBlock().getType() == Material.STONE) {
     
  4. Offline

    Bammerbom

  5. Offline

    CrazymanJR

    Bammerbom
    I doubled checked it and i found possibly another way: if (event.getBlockPlaced().getType() == Material.STONE) {
    I don't know if this will work thou :p

    Bammerbom
    This is my current code so far, i need help with the part that says "don't know what to add here".

    Code:java
    1. @EventHandler
    2. public void onPlace(BlockPlaceEvent event) {
    3. if (event.getBlockPlaced().getType() == Material.STONE) {
    4. Bukkit.getScheduler().runTaskLater(plugin, new Runnable() {
    5. public void run() {
    6. //Don't know what to add here
    7. }
    8. }, 15 * 20L);
    9. }
    10. }


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

    simolus3

    Step 1: Make your BlockPlaceEvent final public void onPlace(final BlockPlaceEvent event)
    Step 2: Get the block in the run() void and set it to stone
    Code:java
    1. public void run() {
    2. event.getBlockPlaced().setType(Material.AIR);
    3. }
     
    Bammerbom likes this.
  7. Offline

    indyetoile

    CrazymanJR
    Code:java
    1. event.getBlockPlaced().setType(Material.AIR);


    Edit: Ninja'd by simolus3
     
    simolus3 likes this.
  8. Offline

    extended_clip



    Don't use
    Code:java
    1. if (event.getBlockPlaced().getType() == Material.STONE) {


    Use
    Code:java
    1. if (event.getBlockPlaced().getType().equals(Material.STONE)) {
     
  9. Offline

    teej107

    You don't need to make the method final, just the variable being passed in the parameters.
    It doesn't matter for enums.
     
  10. Offline

    CrazymanJR

    It worked :) Thanks for all the help guys
     
Thread Status:
Not open for further replies.

Share This Page