Skip to content
This repository has been archived by the owner on Jul 11, 2018. It is now read-only.

Commit

Permalink
Fixing code
Browse files Browse the repository at this point in the history
  • Loading branch information
alejandroliu committed Aug 20, 2015
1 parent 4768929 commit a4bf157
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 103 deletions.
54 changes: 19 additions & 35 deletions KillRate/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# KillRate

* Summary: Keep track of the number of kills
* PocketMine-MP version: 1.4 (API:1.10.0)
* PocketMine-MP version: 1.5 (API:1.12.0)
* DependencyPlugins: -
* OptionalPlugins: PocketMoney,MassiveEconomy,EconomyAPI,GoldStd
* Categories: Informational
Expand All @@ -24,13 +24,13 @@ that. You are more likely to get a response and help that way.

_NOTE:_

This documentation was last updated for version **2.0.0**.
This documentation was last updated for version **2.0.0dev1**.

Please go to
[github](https://github.com/alejandroliu/pocketmine-plugins/tree/master/KillRate)
for the most up-to-date documentation.

You can also download this plugin from this [page](https://github.com/alejandroliu/pocketmine-plugins/releases/tag/KillRate-2.0.0).
You can also download this plugin from this [page](https://github.com/alejandroliu/pocketmine-plugins/releases/tag/KillRate-2.0.0dev1).

<!-- template-end -->

Expand All @@ -47,8 +47,6 @@ Basic Usage:

You can also place signs to show game statistics.

Thanks to @Daniel123 and @CaptainKenji17 for suggestions and feedback.

## Documentation

This plugin supports PocketMoney and GoldStd and has experimental
Expand Down Expand Up @@ -147,50 +145,36 @@ The contents of these "ini" files are key-value pairs:

"Base text"="Translated Text"

## API

The following functions are available to get information from this
plugin:

* getRankings($limit=10,$online=false,$stat = "points")
* $limit - the number of rows to return
* $online - false, all players, true, only on-line players are
returned
* $stat - the statistic you want to display
* updateDb($player,$stat,$incr = 1)
* $player - the player you want to score
* $stat - type of statistic to update
* $incr - how many units to increase
* getScore($player,$stat = "points")
* $player - player to look-up
* $stat - statistic to return

To use the api:

```php
[PHP]
$server->getPluginManager()->getPlugin("KillRate")->function()
[/PHP]
```

## FAQ

* Q: Can you score when you push people to lava (or other indirect kills)?
* A: Only direct kills are scored. All indirect kills (pushing people
to lava, causing explosions, etc) can not be scored.

# TODO

* getSysVars : should cache values.
- death-dealer should expire cache.
- getSysVars when called will check cache and return.
- if cache is expire, we calculate.
- Alternatively, getRankings should do the caching....

# Changes

* 1.2.4: Bug Fix
* 2.0.0: Partial rewrite
* Fixed bug prevents scoring on creative
* Fixed bug related to libcommon MoneyAPI (crash when no Economy loaded)
* Dropping support for PocketMine v1.4 and lower
* API has been revamped!
* Included example extension
* 1.2.3:
* MySqlMgr: Fixed typo
* Fixed bug with setting rewards/points to false (Reported by @reidq7)
* 1.2.2
* small tweaks on the comments of the config file...
* Added achievements
* 1.2.1:
* CptKenji's features:
* Requested by @CaptainKenji17:
* Double money and Best streak tracking.
* Fixed MySql support. It should work now.
* 1.2.0: Bumped the version number to reflect config changes.
Expand All @@ -202,8 +186,8 @@ $server->getPluginManager()->getPlugin("KillRate")->function()
* Signs are more configurable
* **PLEASE DELETE OLD CONFIG.YML FILE**
* 1.1.0: General improvements
* Added experimental MySQL support
* Messages file and translations: spanish
* Added experimental MySQL support (@predawnia)
* Messages file and translations: spanish (@Daniel123)
* Dynamic signs
* Pop-up scores
* Kill Streak
Expand Down
4 changes: 2 additions & 2 deletions KillRate/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: KillRate
version: 2.0.0
version: 2.0.0dev1
main: aliuly\killrate\Main
api: 1.10.0
api: 1.12.0
load: POSTWORLD
# You have to have at least one of these...
softdepend: [PocketMoney,MassiveEconomy,EconomyAPI,GoldStd]
Expand Down
2 changes: 1 addition & 1 deletion KillRate/resources/messages/messages.ini
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
"Spectator"=""
"Stats: %1%"=""
"Survival"=""
"This plugin has not been tested to run on %1%"=""
"Top Names"=""
"Top Online"=""
"Top Players"=""
Expand Down Expand Up @@ -65,3 +64,4 @@
"#{count}"=""
"#{n}.{player}"=""
"#{sname} {count}"=""
"#This plugin has not been tested to run on %1%"=""
2 changes: 1 addition & 1 deletion KillRate/resources/messages/spa.ini
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
"Spectator"="Espectador"
"Stats: %1%"="Marcadores: %1%"
"Survival"="Supervivencia"
"This plugin has not been tested to run on %1%"="Este Plugin no esta probado en %1%"
"Top Names"="Mejores Nombres"
"Top Online"="Mejores en-línea"
"Top Players"="Mejores"
Expand Down Expand Up @@ -62,3 +61,4 @@
"#Using deprecated pop-up feature"="Usando módulo de pop-up obsoleto"
"#You can only use this command in-game"="Solo puedes usar esto dendro del juego"
"#You have a %1% kill streak."="Tienes una racha de %1% victorias"
"#This plugin has not been tested to run on %1%"="Este Plugin no esta probado en %1%"
68 changes: 45 additions & 23 deletions KillRate/src/aliuly/killrate/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use pocketmine\utils\TextFormat;

use pocketmine\Player;
use pocketmine\Server;
use pocketmine\event\Listener;
use pocketmine\utils\Config;

Expand Down Expand Up @@ -46,7 +47,7 @@ class Main extends PluginBase implements CommandExecutor,Listener {
protected $cfg;
protected $money;
protected $stats;
protected $api;
public $api;

//////////////////////////////////////////////////////////////////////
//
Expand Down Expand Up @@ -138,21 +139,13 @@ public function onEnable(){
&& $this->cfg["settings"]["dynamic-updates"] > 0) {
$this->getServer()->getScheduler()->scheduleRepeatingTask(new PluginCallbackTask($this,[$this,"updateTimer"],[]),$this->cfg["settings"]["dynamic-updates"]);
}
if (MPMU::apiVersion("1.12.0")) {
if (MPMU::apiVersion(">1.12.0")) {
$this->getLogger()->warning(TextFormat::YELLOW.
mc::_("This plugin has not been tested to run on %1%", MPMU::apiVersion()));
}
$this->api = 12;
} else {
$this->api = 10;
}

$this->stats = [];
if ($this->cfg["settings"]["achievements"]) {
Achievement::add("killer","First Blood!",[]);
Achievement::add("serialKiller","Killer Streak!",["killer"]);
}
$this->saveResource("KillRateEx.php");
}
public function onDisable() {
if ($this->dbm !== null) $this->dbm->close();
Expand Down Expand Up @@ -483,16 +476,7 @@ public function updateTimer() {
//echo __METHOD__.",".__LINE__."\n";//##DEBUG
}
private function updateSign($pl,$tile,$text) {
switch($this->api) {
case 10:
$pk = new EntityDataPacket();
break;
case 12:
$pk = new TileEntityDataPacket();
break;
default:
return;
}
$pk = new TileEntityDataPacket();
$data = $tile->getSpawnCompound();
$data->Text1 = new String("Text1",$text[0]);
$data->Text2 = new String("Text2",$text[1]);
Expand Down Expand Up @@ -617,12 +601,50 @@ public function updateDb($perp,$vic,$incr = 1) {
return $incr;

}
public function getScore($pl,$type = "points") {
$score = $this->dbm->getScore($pl->getName(),$type);
/**
* @deprecated
*/
public function getScore($pn,$type = "points") {
if ($pn instanceof Player) $pn = $pn->getName();
$score = $this->dbm->getScore($pn,$type);
if ($score) return $score["count"];
return 0;
}
public function delScore($pl, $ype = null) {
public function getScoreV2($pn,$type = "points") {
$score = $this->dbm->getScore($pn,$type);
if ($score) return $score["count"];
return 0;
}
public function delScore($pn, $type = null) {
$this->dbm->delScore($pl->getName(), $type);
}
public function getPlayerVars(Player $player, array &$vars) {
$vars["{score}"] = $this->getScore($player);
}
public function getSysVars(Server $srv, array &$vars) {
$ranks = $this->getRankings(10);
if ($ranks == null) {
$vars["{tops}"] = "N/A";
$vars["{top10}"] = "N/A";
$vars["{top10names}"] = "N/A";
$vars["{top10scores}"] = "N/A";
} else {
$vars["{tops}"] = "";
$vars["{top10}"] = "";
$vars["{top10names}"] = "";
$vars["{top10scores}"] = "";
$i = 1; $q = "";
foreach ($ranks as $r) {
if ($i <= 3) {
$vars["{tops}"] .= $q.$i.". ".substr($r["player"],0,8).
" ".$r["count"];
$q = " ";
}
$vars["{top10}"] .= $i.". ".$r["player"]." ".$r["count"]."\n";
$vars["{top10names}"] .= $r["player"]."\n";
$vars["{top10scores}"] .= $r["count"]."\n";
++$i;
}
}
}
}
27 changes: 14 additions & 13 deletions KillRate/src/aliuly/killrate/api/KillRate.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
namespace aliuly\killrate\api;

use aliuly\killrate\Main as KillRatePlugin;
use pocketmine\Player;
use pocketmine\IPlayer;

/**
* KillRate API
Expand Down Expand Up @@ -30,44 +30,45 @@ public function getRankings($limit=10,$online=false,$col = "points") {
}
/**
* Update Database values. Returns the new updated value.
* @param Player|str $player - Player that is scoring
* @param IPlayer|str $player - Player that is scoring
* @param str $col - Type of data to update
* @param int $incr - Amount to increment
* @return int
*/
public function updateScore($player,$col = "points",$incr = 1) {
if ($player instanceof Player) $player = $player->getName();
if ($player instanceof IPlayer) $player = $player->getName();
return $this->plugin->updateDb($player, $col, $incr);
}
/**
* Returns a player's specific score.
* @param Player|str $player - Player that is scoring
* @param IPlayer|str $player - Player that is scoring
* @param str $col - Type of data to update
* @return int
*/
public function getScore($player,$col = "points") {
if ($player instanceof Player) $player = $player->getName();
return $this->plugin->getScore($player);
if ($player instanceof IPlayer) $player = $player->getName();
return $this->plugin->getScoreV2($player);
}
/**
* Set the score value
* @param Player|str $player - Player that is scoring
* @param str $col - Type of data to update
* @param IPlayer|str $player - Player that is scoring
* @param int $score - new score
* @param str $col - Type of data to update
* @return int
*/
public function setScore($player,$col = "points",$score) {
if ($player instanceof Player) $player = $player->getName();
$old_score = $this->plugin->getScore($player,$col);
public function setScore($player,$score, $col = "points") {
if ($player instanceof IPlayer) $player = $player->getName();
$old_score = $this->plugin->getScoreV2($player,$col);
return $this->plugin->updateDb($player, $col, $score - $old_score);
}
/**
* Returns a player's specific score.
* @param Player|str $player - Player that is scoring
* @param IPlayer|str $player - Player that is scoring
* @param str $col - Type of data to update
* @return int
*/
public function delScore($pl, $type = null) {
$this->dbm->delScore($pl->getName(), $type);
if ($player instanceof IPlayer) $player = $player->getName();
$this->plugin->delScore($player, $type);
}
}
11 changes: 8 additions & 3 deletions libcommon/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Contains quite a few utility functions. Available modules:
- BasicHelp - Implements help functionality for sub-commands
- BasicPlugin - My extensions to PluginBase
- Cmd - execute PocketMine commands from a PHP module.
- ExpandVars - utility for variable expansions
- FileUtils - Generic file system functions
- FreezeSession - Session implementing frozen players
- GetMotd - Retrieve motd data from remote servers
Expand Down Expand Up @@ -84,9 +85,13 @@ Link.

- 1.2.0: Update 2<br/>
* MoneyAPI bug fix<br/>
* Added GetMotdAsyncTask<br/>
* Added Session management<br/>
* Added FileUtils<br/>
* New Features:<br/>
* GetMotdAsyncTask<br/>
* Session management<br/>
* FileUtils<br/>
* ArmorItems<br/>
* Variables<br/>
* ItemName can load user defined tables<br/>
- 1.1.0: Update 1<br/>
* Added ItemName class (with more item names)<br/>
* Removed MPMU::itemName<br/>
Expand Down
Loading

0 comments on commit a4bf157

Please sign in to comment.