Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

[NEW API] $data["type"]

Comments in 'Plugin Development' started by Killman2, Jun 28, 2014.

  1. Killman2
    Offline

    Killman2 Active Member Plugin Developer

    Joined:
    May 5, 2014
    Posts:
    81
    Plugins:
    1
    Minecraft User:
    Killman2
    Hi! I am in the middle of developing a plugin and got stuck with switching $data["type"] without creating a new function. What I wanted to do is :

    PHP:
    public function onBlockBreakEvent(BlockBreakEvent $eventPlayer $player){
    if(
    $data["type"] == "break"){
    //my code
    }
    else
    {
    //mycode
    But there is no "$data" in the new API. So how do I switch the data type?
  2. jython234
    Offline

    jython234 Notable Member Plugin Developer

    Joined:
    Nov 4, 2013
    Posts:
    324
    Plugins:
    1
    Minecraft User:
    jython234
    Get the info from the $event variable.
    Like this: $event->getItem();
    Comedyman937 likes this.
  3. Killman2
    Offline

    Killman2 Active Member Plugin Developer

    Joined:
    May 5, 2014
    Posts:
    81
    Plugins:
    1
    Minecraft User:
    Killman2
    PHP:
    if($event["type"] == "break"){
    //code
    }
    Could I do that? And thanks for your reply.
  4. DA_Swagnemite
    Offline

    DA_Swagnemite Notable Member Plugin Developer

    Joined:
    Nov 17, 2013
    Posts:
    388
    Plugins:
    7
    Minecraft User:
    DA_SWAGNEMITE
  5. jython234
    Offline

    jython234 Notable Member Plugin Developer

    Joined:
    Nov 4, 2013
    Posts:
    324
    Plugins:
    1
    Minecraft User:
    jython234
    Edited my post :).
  6. xpyctum
    Offline

    xpyctum Active Member Plugin Developer

    Joined:
    Jan 13, 2014
    Posts:
    292
    Plugins:
    4
    Minecraft User:
    tylerdisney
    why do you use type?
  7. jython234
    Offline

    jython234 Notable Member Plugin Developer

    Joined:
    Nov 4, 2013
    Posts:
    324
    Plugins:
    1
    Minecraft User:
    jython234
    Wait, why are you checking if the block was broken, if the event itself was a block broken?
  8. xpyctum
    Offline

    xpyctum Active Member Plugin Developer

    Joined:
    Jan 13, 2014
    Posts:
    292
    Plugins:
    4
    Minecraft User:
    tylerdisney
    Is is already check by event
    PHP:
    public function onBlockBreak(BlockBreakEvent $eventPlayer $player){
    //mycode
  9. Killman2
    Offline

    Killman2 Active Member Plugin Developer

    Joined:
    May 5, 2014
    Posts:
    81
    Plugins:
    1
    Minecraft User:
    Killman2
    I'm making an AreaProtect plugin. And I need to do BlockPlace and Break in the same function.
  10. jython234
    Offline

    jython234 Notable Member Plugin Developer

    Joined:
    Nov 4, 2013
    Posts:
    324
    Plugins:
    1
    Minecraft User:
    jython234
    You can't, this is the new API, each function is for ONE event only.
    Comedyman937 likes this.
  11. xpyctum
    Offline

    xpyctum Active Member Plugin Developer

    Joined:
    Jan 13, 2014
    Posts:
    292
    Plugins:
    4
    Minecraft User:
    tylerdisney
    Read VK(private message)
  12. Killman2
    Offline

    Killman2 Active Member Plugin Developer

    Joined:
    May 5, 2014
    Posts:
    81
    Plugins:
    1
    Minecraft User:
    Killman2
    Oh, well, that is another thing that I don't like in 1.4 :eek::mad::(
  13. DA_Swagnemite
    Offline

    DA_Swagnemite Notable Member Plugin Developer

    Joined:
    Nov 17, 2013
    Posts:
    388
    Plugins:
    7
    Minecraft User:
    DA_SWAGNEMITE
    Youll get used to it. :p
    I had to completely reqrite two plugins about a month or two after each one was released. I personally was extremely mad when this was announced but now i've come to like the New API a lot. :D
    Killman2 likes this.
  14. xpyctum
    Offline

    xpyctum Active Member Plugin Developer

    Joined:
    Jan 13, 2014
    Posts:
    292
    Plugins:
    4
    Minecraft User:
    tylerdisney
    No, 1.4 is the better!
    New API is realy better then old
    And use
    PHP:
    public function onBlockBreak(BlockBreakEvent $eventPlayer $player){
    //mycode
    jython234, Killman2 and Comedyman937 like this.
  15. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Well, you can just redirect the events to the same function.

    And w*** *** **** is that Player $player? Your event will not be called if you have multiple parameters.

    Our famous quote:
    jython234 likes this.
  16. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    And look at the initial code. Your $data isn't defined, so how could you do that?
  17. jython234
    Offline

    jython234 Notable Member Plugin Developer

    Joined:
    Nov 4, 2013
    Posts:
    324
    Plugins:
    1
    Minecraft User:
    jython234
    Why would you need 2 events in the same function?
    PEMapModder likes this.
  18. Killman2
    Offline

    Killman2 Active Member Plugin Developer

    Joined:
    May 5, 2014
    Posts:
    81
    Plugins:
    1
    Minecraft User:
    Killman2
    Nevermind :) I already made it. Thanks for the help ;)
  19. jython234
    Offline

    jython234 Notable Member Plugin Developer

    Joined:
    Nov 4, 2013
    Posts:
    324
    Plugins:
    1
    Minecraft User:
    jython234
    :) glad I could help!
    Killman2 likes this.

Share This Page

Advertisement