awardAchievement() public method

public awardAchievement ( string $achievementId ) : boolean
$achievementId string
return boolean
 public function awardKills(Player $player, $vic, $kills)
 {
     if (!$this->enabled || !$kills) {
         return;
     }
     $player->awardAchievement("killer");
     if ($vic == "Player") {
         if ($kills >= 10) {
             $player->awardAchievement("kill10");
         }
         if ($kills >= 100) {
             $player->awardAchievement("kill100");
         }
         if ($kills >= 1000) {
             $player->awardAchievement("kill1000");
         }
     }
     $res = $this->owner->getRankings(1);
     if ($res !== null && $res[0]["player"] == strtolower($player->getName())) {
         // Achieved #1 ranking!
         $player->awardAchievement("ranked1");
     }
 }
示例#2
0
 /**
  * @param Player $source
  * @return bool
  *
  * Handles transaction execution. Returns whether transaction was successful or not.
  */
 public function execute(Player $source) : bool
 {
     if ($this->getInventory()->processSlotChange($this)) {
         //This means that the transaction should be handled the normal way
         if (!$source->getServer()->getAllowInvCheats() and !$source->isCreative()) {
             $change = $this->getChange();
             if ($change === null) {
                 //No changes to make, ignore this transaction
                 return true;
             }
             /* Verify that we have the required items */
             if ($change["out"] instanceof Item) {
                 if (!$this->getInventory()->slotContains($this->getSlot(), $change["out"])) {
                     return false;
                 }
             }
             if ($change["in"] instanceof Item) {
                 if (!$source->getFloatingInventory()->contains($change["in"])) {
                     return false;
                 }
             }
             /* All checks passed, make changes to floating inventory
              * This will not be reached unless all requirements are met */
             if ($change["out"] instanceof Item) {
                 $source->getFloatingInventory()->addItem($change["out"]);
             }
             if ($change["in"] instanceof Item) {
                 $source->getFloatingInventory()->removeItem($change["in"]);
             }
         }
         $this->getInventory()->setItem($this->getSlot(), $this->getTargetItem(), false);
     }
     /* Process transaction achievements, like getting iron from a furnace */
     foreach ($this->achievements as $achievement) {
         $source->awardAchievement($achievement);
     }
     return true;
 }