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

On block interact

Comments in 'Plugin Development' started by rinkuno, Jul 30, 2016.

  1. rinkuno
    Offline

    rinkuno Active Member

    Joined:
    Oct 8, 2014
    Posts:
    59
    Minecraft User:
    rinku
    So need a code for when u hit a block or break or place

    And says a Certan message
    Last edited: Jul 31, 2016
  2. rinkuno
    Offline

    rinkuno Active Member

    Joined:
    Oct 8, 2014
    Posts:
    59
    Minecraft User:
    rinku
  3. Extreme_Heat
    Offline

    Extreme_Heat Active Member

    Joined:
    Apr 19, 2016
    Posts:
    76
    Minecraft User:
    Extreme_Heat
    Create event handlers in your plugin and use BlockBreakEvent and BlockPlaceEvent.

    You can then get the player using the $eventObject->getPlayer() function as you would with any other event.
  4. rinkuno
    Offline

    rinkuno Active Member

    Joined:
    Oct 8, 2014
    Posts:
    59
    Minecraft User:
    rinku
    Expand and I need the code I'm not good with events but it know php
  5. Extreme_Heat
    Offline

    Extreme_Heat Active Member

    Joined:
    Apr 19, 2016
    Posts:
    76
    Minecraft User:
    Extreme_Heat
    Sample untested code:

    Code:
    <?php
    
    use pocketmine\plugin\PluginBase;
    use pocketmine\event\Listener;
    use pocketmine\event\block\BlockBreakEvent;
    use pocketmine\event\block\BlockPlaceEvent;
    
    
    class PluginMain extends PluginBase implements Listener {
        public function onEnable() {
            $this->getServer()->getPluginManager()->registerEvents($this, $this);
        }
    
        public function onBlockBreakEvent(BlockBreakEvent $event) {
            $event->setCancelled(true);
            // do whatever else you need...
        }
    
        public function onBlockPlaceEvent(BlockPlaceEvent $event) {
            $event->setCancelled(true);
            // do whatever else you need...
        }
    }
  6. MCPEPIG
    Offline

    MCPEPIG Notable Member

    Joined:
    Jun 22, 2014
    Posts:
    349
    Minecraft User:
    MCPEPIG
    What happened to the namespace.
    andre_the_gamer likes this.
  7. Extreme_Heat
    Offline

    Extreme_Heat Active Member

    Joined:
    Apr 19, 2016
    Posts:
    76
    Minecraft User:
    Extreme_Heat
    The code was not meant to be a thing you just copy and paste and expect to work. The namespace depends on whatever the OP is using, I only added the "<?php" initializer for the sake of completeness.
    SOFe likes this.
  8. andre_the_gamer
    Offline

    andre_the_gamer Active Member

    Joined:
    Feb 5, 2015
    Posts:
    112
    Minecraft User:
    Andre_The_Gamer
    Yea but, if you "were" wanting to help someone you could of at least done it right. Even if it wasn't mean't to be copied | pasted! :)
  9. Extreme_Heat
    Offline

    Extreme_Heat Active Member

    Joined:
    Apr 19, 2016
    Posts:
    76
    Minecraft User:
    Extreme_Heat
    Except that it is syntactically done correctly...? That's like saying "I need help building this room in my house, can you help me with the blueprints?", me giving them the blueprints to the room along with half of the house and then the guy complaining saying "if you were going to give me the blueprints with the house, you might as well have given the whole thing." My job was to give you the blueprints to the room, which I did, but don't complain about me not giving the blueprints to the whole house. That wasn't my job, it was just something I threw in there to be nice/complete/whatever. Feels weird the fact that I need to even be explaining this...
    SOFe and 17bhata like this.
  10. rinkuno
    Offline

    rinkuno Active Member

    Joined:
    Oct 8, 2014
    Posts:
    59
    Minecraft User:
    rinku
    Well worse news I can't give a player a message when block broke And placed
  11. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    Use PHP instead of CODE brackets and the true in $event->setCancelled(true) is useless
    its better if you do only $event->setCancelled() to cancel the event
  12. rinkuno
    Offline

    rinkuno Active Member

    Joined:
    Oct 8, 2014
    Posts:
    59
    Minecraft User:
    rinku
    Ain't workin
  13. JackboyPlay
    Offline

    JackboyPlay Active Member

    Joined:
    Apr 25, 2015
    Posts:
    507
    Minecraft User:
    JackboyPlay
    Have you added $event->getPlayer()->sendMessage("HA GAY"); ?
  14. rinkuno
    Offline

    rinkuno Active Member

    Joined:
    Oct 8, 2014
    Posts:
    59
    Minecraft User:
    rinku
    Not workin still
  15. rinkuno
    Offline

    rinkuno Active Member

    Joined:
    Oct 8, 2014
    Posts:
    59
    Minecraft User:
    rinku
    Still won't work
  16. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    That's the same. Yes, "true" is the default value, but if you take a look at a plugin later, you'll find it easier to understand if you see the "true".
    Any errors? Show us your code.
  17. rinkuno
    Offline

    rinkuno Active Member

    Joined:
    Oct 8, 2014
    Posts:
    59
    Minecraft User:
    rinku
    Just restarted my server boom magic it worked
  18. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    Actually it seems that the OP is just asking for PlayerInteractEvent? Since you want it to include whenever you touch a block, including when you touch a block with hand?
    Better analogy: You don't submit a generic door design with the doorplate explicitly saying "Room 101, Miniluv" on it.

    Using the same logic, what happened to the "of your class" behind "the namespace" in your post, if you want every single thing to be included when it is already implied? It seems that we need a bit more common sense? (See my signature)

Share This Page

Advertisement