Giter VIP home page Giter VIP logo

advancedevents's Introduction

AdvancedEvents

This is a PocketMine-MP plugin that allows you to comfortably working with the events using a new piece of PHP 8 power — attributes.

Inspired by qPexLegendary's CoolEventListener.

Examples

Below is a simple example of a plugin with an event listener using the AdvancedEvents.

<?php

use AdvancedEvents_virion\src\jurasciix\advancedEvents\AdvancedEvents;use AdvancedEvents_virion\src\jurasciix\advancedEvents\attribute\EventHandler;use pocketmine\event\block\BlockBreakEvent;use pocketmine\event\block\BlockPlaceEvent;use pocketmine\event\EventPriority;use pocketmine\event\player\PlayerJoinEvent;use pocketmine\plugin\PluginBase;

// There is no need to implement the \pocketmine\event\Listener interface.
// Implementation makes sense only if you need to inform the code reviewer that class contains event handlers.
class Example extends PluginBase /*implements Listener*/ {

    protected function onEnable(): void {
        // Register this class as a listener on behalf of this plugin.
        AdvancedEvents::registerEventListener($this, $this);
    }

    // The method that handles certain events is detected by the EventHandler attribute, unlike PM-MP.
    // In other words, this attribute is required for each method that handles events.
    #[EventHandler(priority: EventPriority::LOWEST)]
    private function onPlayerJoin(PlayerJoinEvent $event): void {
        $event->getPlayer()->sendMessage("Welcome!");
    }
    
    // You can combine the handling of several events at once
    #[EventHandler]
    private function onBlockPlaceOrBreak(BlockPlaceEvent|BlockBreakEvent $event): void {
        // Cancel the event and send a message to the player who initiated the event.
        $event->cancel();
        $event->getPlayer()->sendPopup("Pls don't do that.");
    }
}

advancedevents's People

Contributors

jurasciix avatar poggit-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

advancedevents's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.