Calling BlockPlaceEvent for Fun and Profit?

Discussion in 'Plugin Development' started by Steeveeo, Oct 30, 2011.

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

    Steeveeo

    Hello all, I'm working on a plugin that will let users load saved regions of blocks from a file, and while I have the other 90% of the plugin near-complete, I cannot figure out how this thing works.

    What I would like to do, is to get this to query the other plugins to see if this user can paste blocks in a certain region. Now, I realize the easiest and possibly best way to do this would be to call a BlockPlaceEvent to have the other plugins look over and make sure that it's a valid spot to place materials (i.e. Towny would not let a user load a paste within someone else's lot). However, I am utterly confused at how the constructor of this is setup and how I should go about doing this.

    The JavaDocs for Bukkit say that the constructor is as follows:

    BlockPlaceEvent(Block placedBlock, BlockState replacedBlockState, Block placedAgainst, ItemStack itemInHand, Player thePlayer, boolean canBuild)​

    Now, the way the system works is that I want to call this before overriding a block with my own data, meaning that "placedAgainst", "itemInHand", and "canBuild" would all be unknown, invalid, or irrelevant (canBuild is especially strange, since I want to figure that one out through this method).

    I have called and used artificial events like this with success before (Firetouch's netherrack ignition ability in ElixirMod called the event for Flint and Steel just fine), but this one is confusing, and apparently not an often-used thing as I can't dig anything up through searches.

    Anyone have an idea on how I would go about doing this? It would be greatly appreciated!
     
  2. BlockPlaceEvent e = new BlockPlaceEvent(b, bs, bside, player.getItemInHand(), player, true);
    getServer().getPluginManager().callEvent(e);
    if (!(e.isCancelled())) {
    // Do stuff
    }
     
  3. Offline

    Steeveeo

    Sorry, but that's not exactly helpful. I know what the variables are that it calls for, but in this specific situation, I'm not sure how to get that data, especially since it's placed by the server and not a player (it just has a player's name pinned on it).
     
  4. Well, when are you planning on calling it?
     
  5. Offline

    Steeveeo

    Right as the paste requirements complete, and through a loop in which all the data from a file is placed as blocks. I've got it all pasting just fine without the event check, but I would like it there for anti-griefing.
     
  6. Offline

    Afforess

    The first argument is where the new block is going to be. The second argument is the block state of where the new block is going to be. The 3rd argument is the block that was clicked. (This is not the same as the new block, the clicked block is usually a side or below where the new block will be). The 4th argument is the item in the players hand. The 5th argument is the player. The 6th argument is the default response to this action (you want it to be true, because by default, the block should be placed).

    Happy Halloween.
     
  7. Offline

    Steeveeo

    So should argument 1 just be the block I'm going to replace? Or how would I do that?
     
  8. Offline

    Afforess

    Yes.
     
  9. Offline

    Steeveeo

    Hmm, thanks, perhaps I can figure it out now. In the middle of an adventure map at the moment, though, so I'll get back to you on that.
     
Thread Status:
Not open for further replies.

Share This Page