1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

MCMMO

Discussion in 'Help' started by Winchester, Aug 6, 2018.

  1. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    PHP:
    <?php
    namespace muqsit\mcmmo;

    use 
    pocketmine\event\Listener;
    use 
    pocketmine\event\player\PlayerInteractEvent;
    use 
    pocketmine\event\player\PlayerLoginEvent;
    use 
    pocketmine\event\player\PlayerQuitEvent;
    use 
    pocketmine\item\Tool;
    use 
    pocketmine\utils\TextFormat;

    class 
    EventListener implements Listener{

        
    /** @var Loader */
        
    private $plugin;

        
    /** @var int[] */
        
    private $last_interactions = [];

        public function 
    __construct(Loader $plugin){
            
    $this->plugin $plugin;
        }

        public function 
    onPlayerLogin(PlayerLoginEvent $event) : void{
            
    $player $event->getPlayer();
            
    $this->plugin->getDatabase()->load($player);
            
    $this->last_interactions[$player->getId()] = 0;
        }

        public function 
    onPlayerQuit(PlayerQuitEvent $event) : void{
            
    $player $event->getPlayer();
            
    $this->plugin->getDatabase()->save($playertrue);
            unset(
    $this->last_interactions[$player->getId()]);
        }

        public function 
    onPlayerInteract(PlayerInteractEvent $event) : void{
            
    $action $event->getAction();
            if(
    $action === PlayerInteractEvent::RIGHT_CLICK_BLOCK || $action === PlayerInteractEvent::RIGHT_CLICK_AIR){
                
    $item $event->getItem();
                if(
    $item instanceof Tool){
                    
    $player $event->getPlayer();
                    
    $pid $player->getId();
                    if(
    $this->last_interactions[$pid] !== $player->ticksLived){
                        
    $this->last_interactions[$pid] = $player->ticksLived;
                        
    $pid $player->getId();
                        
    $skill_manager $this->plugin->getSkillManager($player);
                        if(
    $skill_manager->canUseAbilities()){
                            
    $skill $skill_manager->getSkillByItem($item);
                            if(
    $skill !== null){
                                
    $player->sendMessage($skill_manager->activateAbility($skill->getId()) ? TextFormat::GREEN "**" strtoupper($skill->getAbilityName()) . TextFormat::GREEN " ACTIVATED**" :
                                    
    TextFormat::RED "Você está cansado demais para usar essa habilidade novamente. " TextFormat::YELLOW "(" $skill->getAbilityCooldownExpire() . "s)"
                                
    );
                            }
                        }
                    }
                }
            }
        }
    }
     
  2. Winchester

    Winchester Baby Zombie

    Messages:
    133


    apparently that error was solved, but now it appeared another = (



    [18:01:59] [Server thread/CRITICAL]: Não foi possível passar o evento 'pocketmine\event\player\PlayerInteractEvent' para 'mcMMO v1': Call to undefined method pocketmine\Player::getAsyncPool() em muqsit\mcmmo\EventListener
    [18:01:59] [Server thread/CRITICAL]: Error: "Call to undefined method pocketmine\Player::getAsyncPool()" (EXCEPTION) in "mcMMO-master/src/muqsit/mcmmo/skills/SkillManager" at line 212
    [18:01:59] [Server thread/DEBUG]: #0 mcMMO-master/src/muqsit/mcmmo/skills/SkillManager(178): muqsit\mcmmo\skills\SkillManager->scheduleSkillTasks(muqsit\mcmmo\skills\woodcutting\WoodcuttingSkill object)
    [18:01:59] [Server thread/DEBUG]: #1 mcMMO-master/src/muqsit/mcmmo/EventListener(49): muqsit\mcmmo\skills\SkillManager->activateAbility(integer 1)
    [18:01:59] [Server thread/DEBUG]: #2 src/pocketmine/plugin/MethodEventExecutor(38): muqsit\mcmmo\EventListener->onPlayerInteract(pocketmine\event\player\PlayerInteractEvent object)
    [18:01:59] [Server thread/DEBUG]: #3 src/pocketmine/plugin/RegisteredListener(98): pocketmine\plugin\MethodEventExecutor->execute(muqsit\mcmmo\EventListener object, pocketmine\event\player\PlayerInteractEvent object)
    [18:01:59] [Server thread/DEBUG]: #4 src/pocketmine/plugin/PluginManager(749): pocketmine\plugin\RegisteredListener->callEvent(pocketmine\event\player\PlayerInteractEvent object)
    [18:01:59] [Server thread/DEBUG]: #5 src/pocketmine/Player(2446): pocketmine\plugin\PluginManager->callEvent(pocketmine\event\player\PlayerInteractEvent object)
    [18:01:59] [Server thread/DEBUG]: #6 src/pocketmine/network/mcpe/PlayerNetworkSessionAdapter(132): pocketmine\Player->handleInventoryTransaction(pocketmine\network\mcpe\protocol\InventoryTransactionPacket object)
    [18:01:59] [Server thread/DEBUG]: #7 src/pocketmine/network/mcpe/protocol/InventoryTransactionPacket(155): pocketmine\network\mcpe\PlayerNetworkSessionAdapter->handleInventoryTransaction(pocketmine\network\mcpe\protocol\InventoryTransactionPacket object)
    [18:01:59] [Server thread/DEBUG]: #8 src/pocketmine/network/mcpe/PlayerNetworkSessionAdapter(92): pocketmine\network\mcpe\protocol\InventoryTransactionPacket->handle(pocketmine\network\mcpe\PlayerNetworkSessionAdapter object)
    [18:01:59] [Server thread/DEBUG]: #9 src/pocketmine/network/mcpe/protocol/BatchPacket(114): pocketmine\network\mcpe\PlayerNetworkSessionAdapter->handleDataPacket(pocketmine\network\mcpe\protocol\InventoryTransactionPacket object)
    [18:01:59] [Server thread/DEBUG]: #10 src/pocketmine/network/mcpe/PlayerNetworkSessionAdapter(92): pocketmine\network\mcpe\protocol\BatchPacket->handle(pocketmine\network\mcpe\PlayerNetworkSessionAdapter object)
    [18:01:59] [Server thread/DEBUG]: #11 src/pocketmine/Player(3033): pocketmine\network\mcpe\PlayerNetworkSessionAdapter->handleDataPacket(pocketmine\network\mcpe\protocol\BatchPacket object)
    [18:01:59] [Server thread/DEBUG]: #12 src/pocketmine/network/mcpe/RakLibInterface(158): pocketmine\Player->handleDataPacket(pocketmine\network\mcpe\protocol\BatchPacket object)
    [18:01:59] [Server thread/DEBUG]: #13 vendor/pocketmine/raklib/src/server/ServerHandler(98): pocketmine\network\mcpe\RakLibInterface->handleEncapsulated(string 192.168.15.10 56232, raklib\protocol\EncapsulatedPacket object, integer 0)
    [18:01:59] [Server thread/DEBUG]: #14 src/pocketmine/network/mcpe/RakLibInterface(103): raklib\server\ServerHandler->handlePacket()
    [18:01:59] [Server thread/DEBUG]: #15 src/pocketmine/network/Network(94): pocketmine\network\mcpe\RakLibInterface->process()
    [18:01:59] [Server thread/DEBUG]: #16 src/pocketmine/network/mcpe/RakLibInterface(80): pocketmine\network\Network->processInterface(pocketmine\network\mcpe\RakLibInterface object)
    [18:01:59] [Server thread/DEBUG]: #17 vendor/pocketmine/snooze/src/SleeperHandler(120): pocketmine\network\mcpe\RakLibInterface->pocketmine\network\mcpe\{closure}()
    [18:01:59] [Server thread/DEBUG]: #18 vendor/pocketmine/snooze/src/SleeperHandler(82): pocketmine\snooze\SleeperHandler->processNotifications()
    [18:01:59] [Server thread/DEBUG]: #19 src/pocketmine/Server(2257): pocketmine\snooze\SleeperHandler->sleepUntil(double 1533848519.646)
    [18:01:59] [Server thread/DEBUG]: #20 src/pocketmine/Server(2132): pocketmine\Server->tickProcessor()
    [18:01:59] [Server thread/DEBUG]: #21 src/pocketmine/Server(1713): pocketmine\Server->start()
    [18:01:59] [Server thread/DEBUG]: #22 src/pocketmine/PocketMine(237): pocketmine\Server->__construct(BaseClassLoader object, pocketmine\utils\MainLogger object, string C:\Black Hat Society\, string C:\Black Hat Society\plugins\)
    [18:01:59] [Server thread/DEBUG]: #23 C:/Black Hat Society/PocketMine-MP.phar(1): require(string phar://C:/Black Hat Society/PocketMine-MP.phar/src/pocketmine/PocketMine.php)
     
  3. Winchester

    Winchester Baby Zombie

    Messages:
    133
    PHP:
    <?php
    namespace muqsit\mcmmo\skills;
    use 
    muqsit\mcmmo\skills\acrobatics\AcrobaticsSkill;
    use 
    muqsit\mcmmo\skills\excavation\ExcavationSkill;
    use 
    muqsit\mcmmo\skills\tasks\AbilityCooldownNotifyTask;
    use 
    muqsit\mcmmo\skills\tasks\AbilityDeactivateNotifyTask;
    use 
    muqsit\mcmmo\skills\woodcutting\WoodcuttingSkill;
    use 
    muqsit\mcmmo\sounds\McMMOLevelUpSound;
    use 
    pocketmine\item\Item;
    use 
    pocketmine\Player;
    use 
    pocketmine\Server;
    use 
    pocketmine\utils\TextFormat;
    class 
    SkillManager{
        const 
    TASK_ABILITY_DEACTIVATE_NOTIFY 0;
        const 
    TASK_ABILITY_COOLDOWN_NOTIFY 1;
        
    /** @var string[] */
        
    private static $skills = [];
        
    /** @var string[] */
        
    private static $skill_names = [];
        
    /** @var int[] */
        
    private static $skill_identifiers = [];
        
    /** @var Skill[] */
        
    private $skill_tree = [];
        
    /** @var Player */
        
    private $player;
        
    /** @var int[] */
        
    private $taskIds = [];
        
    /** @var bool */
        
    private $can_use_abilities;
        public static function 
    registerSkill(string $classbool $override false) : void{
            
    $skillId $class::SKILL_ID;
            if(
    $skillId 0){
                throw new \
    Error("SkillId cannot be negative, got $skillId");
            }
            if(!isset(
    SkillManager::$skills[$skillId]) || $override){
                if(isset(
    SkillManager::$skills[$skillId])){
                    
    $oldskill SkillManager::$skills[$skillId];
                    
    $oldlistener $oldskill::getListenerClass();
                    if(
    $oldlistener !== null && is_subclass_of($oldskillSkillListener::class, true)){
                        
    //TODO: Unregister oldlistener
                    
    }
                    
    SkillManager::removeSkillIdentifiers($skillId);
                    unset(
    SkillManager::$skill_names[strtolower((new $oldskill())->getName())]);
                }
                
    SkillManager::$skills[$skillId] = $class;
                
    $listener $class::getListenerClass();
                if(
    $listener !== null){
                    if (!
    is_subclass_of($listenerSkillListener::class, true)) {
                        throw new \
    Error("$listener must be an instance of " SkillListener::class);
                    }
                    
    $server Server::getInstance();
                    
    $plugin $server->getPluginManager()->getPlugin("mcMMO");
                    
    $server->getPluginManager()->registerEvents(new $listener($plugin), $plugin);
                }
                
    $identifiers $class::getItemIdentifies();
                if(
    $identifiers !== null){
                    
    SkillManager::addSkillIdentifiers($skillId, ...$identifiers);
                }
                
    SkillManager::$skill_names[strtolower((new $class())->getName())] = $skillId;
                return;
            }
            throw new \
    Error("Attempted to override skill " SkillManager::$skills[$skillId]);
        }
        public static function 
    registerDefaults() : void{
            
    SkillManager::registerSkill(ExcavationSkill::class);
            
    SkillManager::registerSkill(WoodcuttingSkill::class);
            
    SkillManager::registerSkill(AcrobaticsSkill::class);
        }
        public static function 
    addSkillIdentifiers(int $skillIdint ...$itemIds) : void{
            foreach(
    $itemIds as $itemId){
                
    SkillManager::$skill_identifiers[$itemId] = $skillId;
            }
        }
        public static function 
    removeSkillIdentifiers(int $skillId) : void{
            foreach(
    array_keys(SkillManager::$skill_identifiers$skillIdtrue) as $itemId){
                unset(
    SkillManager::$skill_identifiers[$itemId]);
            }
        }
        public static function 
    getSkillIdByName(string $name) : ?int{
            return 
    SkillManager::$skill_names[strtolower($name)] ?? null;
        }
        public static function 
    getSkillClass(int $skillId) : ?string{
            return 
    SkillManager::$skills[$skillId] ?? null;
        }
        private static function 
    getSkillInstance(int $skillId, ...$args) : ?Skill{
            if(isset(
    SkillManager::$skills[$skillId])){
                
    $class SkillManager::$skills[$skillId];
                return new 
    $class(...$args);
            }
            return 
    null;
        }
        public function 
    __construct(Player $player, array $savedata){
            
    $this->player $player;
            
    $this->setCanUseAbilities($savedata["ability_use"] ?? true);
            
    $this->setSkillTree($savedata["skill_tree"] ?? []);
        }
        public function 
    getPlayer() : Player{
            return 
    $this->player;
        }
        public function 
    canUseAbilities() : bool{
            return 
    $this->can_use_abilities;
        }
        public function 
    setCanUseAbilities(bool $value true) : void{
            
    $this->can_use_abilities $value;
        }
        public function 
    getSkillTree(bool $clean false) : array{
            if(
    $clean){
                
    $skills $this->getSkillTree();
                foreach(
    $skills as &$skill){
                    
    $skill $skill->serialize();
                }
                return 
    $skills;
            }
            return 
    $this->skill_tree;
        }
        public function 
    toSaveData() : array{
            return [
                
    "ability_use" => $this->canUseAbilities(),
                
    "skill_tree" => $this->getSkillTree(true)
            ];
        }
        private function 
    setSkillTree(array $skill_tree) : void{
            foreach(
    $skill_tree as $skillId => $skillInfo){
                
    $this->skill_tree[$skillId] = $skill SkillManager::getSkillInstance($skillId$skillInfo);
                
    $this->scheduleSkillTasks($skill);
            }
        }
        public function 
    addSkillXp(int $skillIdint $xp) : void{
            
    $skill $this->getSkill($skillId);
            if(
    $skill->addXp($xp$increase)){
                
    $player $this->getPlayer();
                
    $player->sendMessage(TextFormat::YELLOW $skill->getName() . " skill increased by $increase. Total (" $skill->getLevel() . ")");
                
    $player->getLevel()->addSound(new McMMOLevelUpSound($player->x$player->y$player->z), [$player]);
            }
        }
        public function 
    activateAbility(int $skillId) : bool{
            
    $skill $this->getSkill($skillId);
            
    $player $this->getPlayer();
            if(
    $skill->activateAbility($player)){
                
    $this->scheduleSkillTasks($skill);
                return 
    true;
            }
            return 
    false;
        }
        public function 
    getSkill(int $skillId) : ?Skill{
            if(isset(
    $this->skill_tree[$skillId])){
                return 
    $this->skill_tree[$skillId];
            }
            
    $skill SkillManager::getSkillInstance($skillId);
            if(
    $skill !== null){
                return 
    $this->skill_tree[$skillId] = $skill;
            }
            return 
    null;
        }
        public function 
    getSkillByItem(Item $item) : ?Skill{
            if(isset(
    SkillManager::$skill_identifiers[$itemId $item->getId()])){
                return 
    $this->getSkill(SkillManager::$skill_identifiers[$itemId]);
            }
            return 
    null;
        }
        public function 
    merge(SkillManager $skill) : void{
            foreach(
    $skill->getSkillTree() as $skillId => $instance){
                
    $this->addXp($skillId$instance->getXp());
            }
        }
        public function 
    scheduleSkillTasks(Skill $skill) : void{
            
    $scheduler $this->getPlayer()->getServer()->getScheduler();
            
    $skillId $skill->getId();
            if(isset(
    $this->taskIds[SkillManager::TASK_ABILITY_DEACTIVATE_NOTIFY][$skillId])){
                
    $scheduler->cancelTask($this->taskIds[SkillManager::TASK_ABILITY_DEACTIVATE_NOTIFY][$skillId]);
            }
            
    $expire $skill->getAbilityExpire();
            if(
    $expire 0){
                
    $scheduler->scheduleDelayedTask($task = new AbilityDeactivateNotifyTask($this$skillId), $expire 20);
                
    $this->addIncompleteTask(SkillManager::TASK_ABILITY_DEACTIVATE_NOTIFY$skillId$task->getTaskId());
            }
            if(isset(
    $this->taskIds[SkillManager::TASK_ABILITY_COOLDOWN_NOTIFY][$skillId])){
                
    $scheduler->cancelTask($this->taskIds[SkillManager::TASK_ABILITY_COOLDOWN_NOTIFY][$skillId]);
            }
            
    $expire $skill->getAbilityCooldownExpire();
            if(
    $expire 0){
                
    $scheduler->scheduleDelayedTask($task = new AbilityCooldownNotifyTask($this$skillId), $expire 20);
                
    $this->addIncompleteTask(SkillManager::TASK_ABILITY_COOLDOWN_NOTIFY$skillId$task->getTaskId());
            }
        }
        public function 
    addIncompleteTask(int $idint $skillIdint $taskId) : void{
            
    $this->taskIds[$id][$skillId] = $taskId;
        }
        public function 
    setTaskAsCompleted(int $idint $skillId) : void{
            unset(
    $this->taskIds[$id][$skillId]);
        }
        public function 
    close(Server $server) : void{
            
    $scheduler $server->getScheduler();
            foreach(
    $this->taskIds as $taskIds){
                foreach(
    $taskIds as $taskId){
                    
    $scheduler->cancelTask($taskId);
                }
            }
            
    $this->taskIds = [];
        }
    }
     
  4. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    I can't find the error...
     
  5. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    Every instance of Server->getScheduler needs to be replaced with PluginBase->getScheduler. However, the plugin isn't currently set up to handle it appropriately. The plugin has a lot of things that need updating. Instead of asking for help for each individual problem, you could just request that somebody update the plugin altogether.
     
    Winchester likes this.
  6. Winchester

    Winchester Baby Zombie

    Messages:
    133
    [QUOTE = "corytortoise, post: 55662, member: 68"] Todo caso de Server-> getScheduler precisa ser substituído por PluginBase-> getScheduler. No entanto, o plug-in não está configurado para lidar com isso de maneira apropriada. O plugin tem muitas coisas que precisam ser atualizadas. Em vez de pedir ajuda para cada problema individual, basta solicitar que alguém atualize o plug-in por completo. [/ QUOTE]
    -----------------------------

    Eu ficaria muito feliz se alguém fizesse isso, porque eu não poderia, e o criador não tem tempo para dedicar a isso!
    this link plugin https://github.com/Muqsit/mcMMO
    ---

    I would be very happy if someone did it since I could not, and the creator has no time to devote to it!
    this link plugin
    https://github.com/Muqsit/mcMMO
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.