Overview

Namespaces

  • aliuly
    • common
      • selectors
    • grabbag
      • api
    • killrate
      • api
  • xPaw

Classes

  • aliuly\common\ArmorItems
  • aliuly\common\BasicCli
  • aliuly\common\BasicHelp
  • aliuly\common\BasicPlugin
  • aliuly\common\ChatSession
  • aliuly\common\Cmd
  • aliuly\common\CmdSelector
  • aliuly\common\ExpandVars
  • aliuly\common\FileUtils
  • aliuly\common\FreezeSession
  • aliuly\common\GetMotd
  • aliuly\common\GetMotdAsyncTask
  • aliuly\common\InvisibleSession
  • aliuly\common\InvUtils
  • aliuly\common\ItemName
  • aliuly\common\mc
  • aliuly\common\mc2
  • aliuly\common\MoneyAPI
  • aliuly\common\MPMU
  • aliuly\common\Npc
  • aliuly\common\PermUtils
  • aliuly\common\PluginAsyncTask
  • aliuly\common\PluginCallbackTask
  • aliuly\common\PMScript
  • aliuly\common\QueryAsyncTask
  • aliuly\common\Rcon
  • aliuly\common\RconTask
  • aliuly\common\selectors\All
  • aliuly\common\selectors\AllEntity
  • aliuly\common\selectors\BaseSelector
  • aliuly\common\selectors\Random
  • aliuly\common\Session
  • aliuly\common\ShieldSession
  • aliuly\common\ShoppingCart
  • aliuly\common\SignUtils
  • aliuly\common\SkinUtils
  • aliuly\common\SpySession
  • aliuly\common\SubCommandMap
  • aliuly\common\TPUtils
  • aliuly\grabbag\api\GbAddServerEvent
  • aliuly\grabbag\api\GbRemoveServerEvent
  • aliuly\grabbag\api\GbRmQueryEvent
  • aliuly\grabbag\api\GbUpdateQueryEvent
  • aliuly\grabbag\api\GrabBag
  • aliuly\grabbag\api\GrabBagEvent
  • aliuly\killrate\api\KillRate
  • aliuly\killrate\api\KillRateBonusScoreEvent
  • aliuly\killrate\api\KillRateEndStreakEvent
  • aliuly\killrate\api\KillRateEvent
  • aliuly\killrate\api\KillRateNewStreakEvent
  • aliuly\killrate\api\KillRateResetEvent
  • aliuly\killrate\api\KillRateScoreEvent
  • xPaw\MinecraftQuery

Exceptions

  • xPaw\MinecraftQueryException
  • Overview
  • Namespace
  • Class
  1: <?php
  2: namespace aliuly\killrate\api;
  3: 
  4: use aliuly\killrate\Main as KillRatePlugin;
  5: use pocketmine\IPlayer;
  6: 
  7: /**
  8:  * KillRate API
  9:  */
 10: class KillRate {
 11:   protected $plugin;
 12:   /**
 13:    * @param KillRatePlugin $owner - plugin that owns this session
 14:    */
 15:   public function __construct(KillRatePlugin $owner) {
 16:     $this->plugin = $owner;
 17:   }
 18:   /**
 19:    * Show rankings
 20:    *
 21:    * Returns an array with each element having a ["player"] and ["count"].
 22:    *
 23:    * @param int $limit - Max number of players to rank
 24:    * @param bool $online - if true limit rankings to on-line players
 25:    * @param str $col - Type of data to return
 26:    * @return array
 27:    */
 28:   public function getRankings($limit=10,$online=false,$col = "points") {
 29:     return $this->plugin->getRankings($limit,$online,$col);
 30:   }
 31:   /**
 32:    * Return ranked scores
 33:    *
 34:    * Returns an array with each element having a ["player_name"] and
 35:    * all the values from `getScores`.
 36:    *
 37:    * @param int $limit - Max number of players to rank
 38:    * @param bool $online - if true limit rankings to on-line players
 39:    * @param str $col - Type of data to sort
 40:    * @return array
 41:    */
 42:   public function getRankedScores($limit=10,$online=false,$col = "points") {
 43:     $tab =  $this->plugin->getRankings($limit,$online,$col);
 44:     $res = [];
 45:     foreach ($tab as $n) {
 46:       $pn = $n["player"];
 47:       $scores = $this->plugin->getScores($pn);
 48:       if ($scores == null) continue;
 49:       $row = [ "player_name" => $pn ];
 50:       foreach ($scores as $dt) {
 51:         $row[$dt["type"]] = $dt["count"];
 52:       }
 53:       if (isset($row["deaths"]) && isset($row["player"]) && $row["deaths"] != 0) {
 54:         $row["kdratio"] = round((float)$row["player"]/$row["deaths"],2);
 55:       }
 56:       $res[] = $row;
 57:     }
 58:     return $res;
 59:   }
 60:   /**
 61:    * Update Database values.  Returns the new updated value.
 62:    * @param IPlayer|str $player - Player that is scoring
 63:    * @param str $col - Type of data to update
 64:    * @param int $incr - Amount to increment
 65:    * @return int
 66:    */
 67:     public function updateScore($player,$col = "points",$incr = 1) {
 68:     if ($player instanceof IPlayer) $player = $player->getName();
 69:     return $this->plugin->updateDb($player, $col, $incr);
 70:   }
 71:   /**
 72:    * Update Database values.
 73:    * @param IPlayer|str $player - Player that is scoring
 74:    * @param int $val - Value to set to
 75:    * @param str $col - Type of data to update
 76:    */
 77:     public function setScore($player,$val, $col = "points") {
 78:     if ($player instanceof IPlayer) $player = $player->getName();
 79:     return $this->plugin->setScore($player, $val, $col);
 80:   }
 81:   /**
 82:    * Returns a player's specific score.
 83:    * @param IPlayer|str $player - Player that is scoring
 84:    * @param str $col - Type of data to update
 85:    * @return int|float
 86:    */
 87:     public function getScore($player,$col = "points") {
 88:     if ($col == "kdratio") return $this->getKDRatio($player);
 89:     if ($player instanceof IPlayer) $player = $player->getName();
 90:     return $this->plugin->getScoreV2($player);
 91:     }
 92:   /**
 93:    * Get KillDeath Ratio
 94:    * @param IPlayer|str $player - Player that is scoring
 95:    * @return int|null
 96:    */
 97:   public function getKDRatio($player) {
 98:     if ($player instanceof IPlayer) $player = $player->getName();
 99:     $d = $this->plugin->getScoreV2($player,"deaths");
100:     $k = (float)$this->plugin->getScoreV2($player,"player");
101:     if ($d == 0) return null;
102:     return round($k/$d,2);
103:   }
104:   /**
105:    * Returns a player's specific score.
106:    * @param IPlayer|str $player - Player that is scoring
107:    * @param str $col - Type of data to update
108:    * @return int
109:    */
110:     public function delScore($pl, $type = null) {
111:     if ($player instanceof IPlayer) $player = $player->getName();
112:         $this->plugin->delScore($player, $type);
113:     }
114: }
115: 
API documentation generated by ApiGen