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

Getting another plugin to show kills on a scoreboard

Discussion in 'Plugin Help' started by WEATHERCRAFTYT1, Mar 19, 2021.

  1. WEATHERCRAFTYT1

    WEATHERCRAFTYT1 Baby Zombie

    Messages:
    121
    Hello I have a core plugin and here a repeating scoreboard. My goal is to call in the BedWars plugin I have (not a phar using devtools) and get the kills config to show in a scoreboard.
    PHP:
    $plugin $pl->getServer()->getPluginManager()->getPlugin("Bedwars");

    $api Core::getInstance()->score;

    $rank Core::getInstance()->getRank($pl);
    $name $pl->getName();

    $only count(Core::getInstance()->getServer()->getOnlinePlayers());

    $api->new($pl$pl->getName(), " §l§eBEDWARS ");
    $api->setLine($pl1"§7".date("d/m/Y"));
    $api->setLine($pl2"§f Name:§a ".$name);
    $api->setLine($pl3"§f Ping:§r ".$this->getPingInt($pl));
    $api->setLine($pl4"§l§f STATS");
    $api->setLine($pl5"§f Online:§a ".$only);
    $api->setLine($pl6"§f BedWars Kills: §a");
    $api->setLine($pl7"§f BedWars Wins:§a ");
    $api->setLine($pl8"§f Beds Destroyed:§a ");
    $api->setLine($pl9"");
    $api->setLine($pl10" §ejoinwcserver.ddns.net");

    $api->getObjectiveName($pl);

                }
    So, I can’t seem to get the amount of kills, beds or win the player has by calling in a another plugin. Need help getting the kills, beds, and wins the player has an show into the scoreboard. here is the BedWars plugin when I create a config for kills.
    PHP:
    public function addKill(string $name) {
                
    $tops = new Config($this->plugin->getDataFolder() . "/Kills.yml"Config::YAML);
                
    $tops->set($name,$tops->get($name) + 1);
                
    $tops->save();
        }
    This works!
     
  2. minijaham

    minijaham Skeleton

    Messages:
    801
    GitHub:
    minijaham
    Use events!

    For kills, use
    PHP:
    public function onKill(PlayerDeathEvent $event){
            
    $ent $event->getEntity();
            
    $cause $ent->getLastDamageCause();
            if(
    $cause instanceof EntityDamageByEntityEvent) {
                
    $killer $cause->getDamager();
                if(
    $killer instanceof Player) {
                     
    $this->addKill($killed->getName());
                }
            }
    }
    For beds, you can use
    PHP:
    public function onBreak(BlockBreakEvent $event){
            
    $block $event->getBlock();
            if(
    $block->getId() === 26){ // if the broken block is bed
               // Code for adding whatever function you have for adding bed broken
            
    }
    }
    Solved?
     
    Primus likes this.
  3. minijaham

    minijaham Skeleton

    Messages:
    801
    GitHub:
    minijaham
    And for getting these, you can make a function like this

    PHP:
    public function getKill(Player $player) {
                
    $tops = new Config($this->plugin->getDataFolder() . "/Kills.yml"Config::YAML);
                
    $tops->get($player->getName());
        }
    And same for bed, just with different file.
     
    Primus likes this.
  4. WEATHERCRAFTYT1

    WEATHERCRAFTYT1 Baby Zombie

    Messages:
    121
    The function solves me problem. Imma test it because I need to call in my BedWars plugin and then call function you applied.
     
    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.