Make console break block, and registre it?

Discussion in 'Plugin Development' started by Zhadowseb, May 6, 2016.

Thread Status:
Not open for further replies.
  1. Hello!

    So i am creating a plugin, where when a player opens a chest at a given location, the chest will break when it's emptied, what i'm looking for is an event that registres when i do .breakNaturally();

    Hope you can help ^^

    Zhadowseb
     
  2. Offline

    timtower Administrator Administrator Moderator

  3. Offline

    timtower Administrator Administrator Moderator

  4. @timtower Thank you!

    @timtower okay so i looked at it, and i don't understand it ;P i pretty new to coding ;)

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

    timtower Administrator Administrator Moderator

    @Zhadowseb Make an instance of the event that you want to be thrown.
    Call that method with the instance as parameter.
     
  6. @timtower

    How would i do that? Sry i'm trying to learn ;)
     
  7. Offline

    timtower Administrator Administrator Moderator

    @Zhadowseb Call the constructor?
    And what are you trying to learn? Working with Bukkit or Java?
    If you are trying to learn Java then I suggest that you move away from Bukkit before you know some basics about it.
     
  8. @timtower

    I'm not sure how to do that, because i tried with the BlockBreakEvent, and that takes a Player, which i don't require, so how do i do it then?
     
  9. Offline

    timtower Administrator Administrator Moderator

    @Zhadowseb Then you need to look for an event that does suit your needs.
     
  10. @Zhadowseb After looking into Block#breakNaturally() code, there is NO EVENT called.
    I would suggest you making a custom event and calling it after you use breakNaturally();
     
  11. Offline

    timtower Administrator Administrator Moderator

    @Zhadowseb Then find an event that suits your needs.
    Why do you want to throw an event?
    What kind of plugins should listen to such events?
     
  12. @timtower

    I'm creating a crates plugin, that makes the crate despawn, and then respawn after a certain amount of time, the thing is tho, the crate will be broken by the server, instead of a player which you know. Therefore i need such an event ;)
     
  13. Offline

    timtower Administrator Administrator Moderator

    @Zhadowseb And why would you need to throw an event then? Who needs to know about it besides your plugin?
     
  14. @timtower Instead of asking questions, could you help me, and tell me how i could do it in other ways?
     
  15. Offline

    timtower Administrator Administrator Moderator

    @Zhadowseb I am trying to find out why you need to throw the event. Because to me it doesn't seem like it that you need to.
     
  16. @timtower Actually, there's no event that suits his needings.
    @Zhadowseb Events are used to interact with bukkit api or other plugins, if you don't need to interact with any of them, then simply avoid using events. What you are trying is to call a method when you do Block#breakNaturally() right? Then simply call that method after you run that code, example:

    Code:
    public class MyMain extends JavaPlugin {
      public void doAction(boolean lock, Block block) {
        //Some Code
        if (isChest(block) && shouldBreak(block) && !lock) {
          block.breakNaturally();
          onBlockBreak(block);
        }
      }
    
      public void onBlockBreak(Block block) {
        //Handle block breaking.
      }
    }
     
  17. Offline

    timtower Administrator Administrator Moderator

    Even more reason to ask why he needs the event.
     
    Juancomaster1998 likes this.
  18. @Juancomaster1998 That looks awesome! but i have to ask, what is the isChest and shouldBreak, because eclipse is giving me errors, asking me to create a method for them?

    @timtower What i meant was, that the questions you asked me was no helping understand, you asked me why i needed an event, which i didn't i didn't need, what @Juancomaster1998 did was explain why i didn't need it and why which was really helpfull because i can't answear you question why i need an event because i don't know.
     
  19. @Zhadowseb
    those methods where just illustrative, there it should be your code, and after you invoke the breakNaturally() bukkit method, invoke the method where you handle block breaking.
    Note: Invoke equals calling.

    I would really recommend you having some java knowledge before starting with bukkit, you could read java docs (it's really useful, but way boring), or look some videos in internet, like pogostick ones.
     
  20. @Juancomaster1998 Yea i actually did watch some of his videos, i watch a guy called appljuize too, he taught me a little java before actually learning me bukkit, but thank you very much for the help ;)

    @timtower Thank you to you to for trying to help me, i'm sorry if i offended you :)
     
Thread Status:
Not open for further replies.

Share This Page