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

Running code from another plugin

Discussion in 'Plugin Help' started by WEATHERCRAFTYT1, Nov 2, 2020.

  1. WEATHERCRAFTYT1

    WEATHERCRAFTYT1 Baby Zombie

    Messages:
    121
    Hello this is my TheBridge plugin and to join a match it does this.
    Code:
    $this->getGameParty($player);
    Is there any chance how you can do this is an another plugin like TNTTag and run this command and takes me to TheBridge match instead of TNTTag game?

    is it possible
     
  2. HeyDeniis_

    HeyDeniis_ Baby Zombie

    Messages:
    137
    I don't understand it very well but if you want to run this function with another plugin make sure that it is public and use
    PHP:
    $plugin $this->getServer()->getPluginManager()->getPlugin("TheBridge"); //or name do plugin
    if($plugin instanceof PluginBase){
         
    $party $plugin->getGameParty($player);
    }
     
    Primus likes this.
  3. WEATHERCRAFTYT1

    WEATHERCRAFTYT1 Baby Zombie

    Messages:
    121
    Yea exactly but does $party runs the function or it defines it?
     
  4. HeyDeniis_

    HeyDeniis_ Baby Zombie

    Messages:
    137
    $party is the result of the execution of the function
     
    Primus likes this.
  5. WEATHERCRAFTYT1

    WEATHERCRAFTYT1 Baby Zombie

    Messages:
    121
    PHP:
          $level $player->getLevel()->getFolderName();
          
    $cause $event->getCause();
          
    $config = new Config($this->plugin->getDataFolder()."/config.yml"Config::YAML);
          
    $rule $config->get($level."Game");
         if(
    $cause===EntityDamageEvent::CAUSE_ENTITY_ATTACK) {
            if(
    $event instanceof EntityDamageByEntityEvent) {
                 
    $damager $event->getDamager();
                 
    $entity $event->getEntity();
                 if(
    $damager instanceof Player and $entity instanceof NPCSpeed) {
                    
    $plugin $this->getServer()->getPluginManager()->getPlugin("TheBridge"); //error here
                    
    if($plugin instanceof PluginBase){
                        
    $party $plugin->openMyForm($player);
                    }
                     
    $event->setCancelled(true);
                     }
                 if(
    $damager instanceof Player and $entity instanceof Player) {
                     
    $players2 $this->plugin->manager->hasPlayers($level)== is_null(null) ? $this->plugin->manager->hasPlayers($level) : null;
                        if(isset(
    $players2[$player->getName()])) {
                     
    $event->setCancelled(true);
                           }
                     }
                 }
              } else if(
    $cause===EntityDamageEvent::CAUSE_FALL) {
                  
    $players2 $this->plugin->manager->hasPlayers($level)== is_null(null) ? $this->plugin->manager->hasPlayers($level) : null;
                        if(isset(
    $players2[$player->getName()])) {
                     
    $event->setCancelled(true);
                           }
                  }
           }
     
  6. HeyDeniis_

    HeyDeniis_ Baby Zombie

    Messages:
    137
    What is the error
     
    Primus likes this.
  7. WEATHERCRAFTYT1

    WEATHERCRAFTYT1 Baby Zombie

    Messages:
    121
    PHP:
    $plugin $this->getServer()->getPluginManager()->getPlugin("TheBridge");
    It says call to a undefined method on getServer
     
  8. HeyDeniis_

    HeyDeniis_ Baby Zombie

    Messages:
    137
    use $damager->getServer() not $this->getServer()
     
  9. WEATHERCRAFTYT1

    WEATHERCRAFTYT1 Baby Zombie

    Messages:
    121
    Um when I tested it, it didnt do anything? Why?
     
  10. HeyDeniis_

    HeyDeniis_ Baby Zombie

    Messages:
    137
    maybe the plugin name is incorrect, put an echo "this\n"; in the code to see if the function was executed
     
    Primus likes this.
  11. WEATHERCRAFTYT1

    WEATHERCRAFTYT1 Baby Zombie

    Messages:
    121
  12. WEATHERCRAFTYT1

    WEATHERCRAFTYT1 Baby Zombie

    Messages:
    121
    Maybe instead of getting plugin and run function I can use a command and that command runs a function. Just don’t know how
     
  13. WEATHERCRAFTYT1

    WEATHERCRAFTYT1 Baby Zombie

    Messages:
    121
    I really don’t get what ur trying to point out
     
  14. Primus

    Primus Zombie Pigman

    Messages:
    749
    You clearly lack the knowledge in OOP.
     
    minijaham likes this.
  15. WEATHERCRAFTYT1

    WEATHERCRAFTYT1 Baby Zombie

    Messages:
    121
  16. DragKills

    DragKills Creeper

    Messages:
    2
    GitHub:
    HixX
    make foreach not if
     
  17. minijaham

    minijaham Skeleton

    Messages:
    801
    GitHub:
    minijaham
    He told you to add a debugging message to see if the code is being executed because you said the code wasn’t doing anything :facepalm:
     
  18. minijaham

    minijaham Skeleton

    Messages:
    801
    GitHub:
    minijaham
    To make his point even more clearer for you, message after echo will send through console if the code is executed. If not, echo won’t be executed along with the code.

    This helps you to see what part of the code isn’t executed or has an error on.

    Example:
    PHP:
    // OMG idk where this code no execute! Pales Help!
    if ($player->isBruh()){
    $player->sendMessage(“BRUH”);
    }

    // Now let’s see what da heck is wrong with a debugging message!
    if ($player->isBruh()){
    echo 
    ‘vruh!!!!;
    }

    // Console: nothing L

    // vruh!!! What!!!??? Why no execute???
    // oh!!! Player wasn’t bruh!(isBruh())

    // New code
    if (!$player->isBruh()){
    $player->sendMessage(“vruh”);
    }

    // Yes code work now!!
     
    Last edited: Feb 8, 2021
  19. Primus

    Primus Zombie Pigman

    Messages:
    749
    or simply have the output of the Player::isBruh function
    PHP:
    var_dump($player->isBruh()) # output: boolean(true)
     
    minijaham likes this.
  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.