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

Solved Plugin doesnt work (EconomyAPI)

Discussion in 'Plugin Help' started by ExZe, Mar 7, 2020.

  1. ExZe

    ExZe Silverfish

    Messages:
    21
    GitHub:
    mzztin
    This is the code:
    PHP:
    public function KillMoney(PlayerDeathEvent $event)
        {
            
    $damager $event->getPlayer()->getLastDamageCause()->getEntity();
            
    $player $event->getPlayer()->getName();
            
    $pl $event->getPlayer();

            
    // SOME LOGGING STUFF FOR MONEY
            
    $a $this->getCfg()->get("a");
            
    $b $this->getCfg()->get("b");
            
    $c $this->getCfg()->get("c");
            
    $d $this->getCfg()->get("d");

            if (
    $pl->getLastDamageCause() instanceof EntityDamageEvent)
            {
                if (
    $damager instanceof Player)
            {
                if (
    $damager->hasPermission("killmoney.a")){
                    
    $this->ecoAPI->setMoney($damager$a);
                    
    $damager->sendMessage(TF::GREEN "You just got " $a "$ for killing " $player);
                } elseif (
    $damager->hasPermission("killmoney.b")){
                    
    $this->ecoAPI->setMoney($damager$b);
                    
    $damager->sendMessage(TF::GREEN "You just got " $b "$ for killing " $player);
                } elseif (
    $damager->hasPermission("killmoney.c")){
                    
    $this->ecoAPI->setMoney($damager$c);
                    
    $damager->sendMessage(TF::GREEN "You just got " $c "$ for killing " $player);
                } elseif (
    $damager->hasPermission("killmoney.d")){
                    
    $this->ecoAPI->setMoney($damager$d);
                    
    $damager->sendMessage(TF::GREEN "You just got " $d "$ for killing " $player);
                } else {
                    
    // WHEN PLAYER HAS NONE OF THESE PERMISSIONS AN ERROR MESSAGE WILL COME
                    
    $damager->sendMessage($this->getCfg()->get("error"));
                }

            }

            }
        }
    I get no message or anything
     
  2. ExZe

    ExZe Silverfish

    Messages:
    21
    GitHub:
    mzztin
    Here is the full code:
    PHP:
    <?php

    declare(strict_types=1);
    <?
    php

    declare(strict_types=1);

    namespace 
    mzztin\KillMoney;

    use 
    onebone\economyapi\EconomyAPI;
    use 
    pocketmine\event\entity\EntityDamageEvent;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\event\player\PlayerDeathEvent;
    use 
    pocketmine\Player;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\utils\Config;
    use 
    pocketmine\utils\TextFormat as TF;

    class 
    Main extends PluginBase implements Listener
    {

        private 
    $ecoAPI;

        public function 
    onLoad()
        {
            
    $this->ecoAPI $this->getServer()->getPluginManager()->getPlugin("EconomyAPI");

            @
    mkdir($this->getDataFolder());

            
    $this->saveResource("config.yml");

        }

        public function 
    getCfg() : Config
        
    {
            
    $cfg = new Config($this->getDataFolder() . "config.yml"Config::YAML);
            return 
    $cfg;
        }

        public function 
    KillMoney(PlayerDeathEvent $event)
    {
        
    $damager $event->getPlayer()->getLastDamageCause()->getEntity();
        
    $player $event->getPlayer()->getName();
        
    $pl $event->getPlayer();

        
    // SOME LOGGING STUFF FOR MONEY
        
    $a $this->getCfg()->get("a");
        
    $b $this->getCfg()->get("b");
        
    $c $this->getCfg()->get("c");
        
    $d $this->getCfg()->get("d");

        if (
    $pl->getLastDamageCause() instanceof EntityDamageEvent)
        {
            if (
    $damager instanceof Player)
            {
                if (
    $damager->hasPermission("killmoney.a")){
                    
    $this->ecoAPI->setMoney($damager$a);
                    
    $damager->sendMessage(TF::GREEN "You just got " $a "$ for killing " $player);
                } elseif (
    $damager->hasPermission("killmoney.b")){
                    
    $this->ecoAPI->setMoney($damager$b);
                    
    $damager->sendMessage(TF::GREEN "You just got " $b "$ for killing " $player);
                } elseif (
    $damager->hasPermission("killmoney.c")){
                    
    $this->ecoAPI->setMoney($damager$c);
                    
    $damager->sendMessage(TF::GREEN "You just got " $c "$ for killing " $player);
                } elseif (
    $damager->hasPermission("killmoney.d")){
                    
    $this->ecoAPI->setMoney($damager$d);
                    
    $damager->sendMessage(TF::GREEN "You just got " $d "$ for killing " $player);
                } else {
                    
    // WHEN PLAYER HAS NONE OF THESE PERMISSIONS AN ERROR MESSAGE WILL COME
                    
    $damager->sendMessage($this->getCfg()->get("error"));
                }

            }

        }
    }

    }
     
  3. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    Looks like you forgot to register your event listener
     
  4. ExZe

    ExZe Silverfish

    Messages:
    21
    GitHub:
    mzztin
    Ty, I'm really stupid
     
    HimbeersaftLP likes this.
  5. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    No problem, it happens to all of us :p
     
  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.