Skip to content

Commit

Permalink
Added support for KDR. Closes #2
Browse files Browse the repository at this point in the history
  • Loading branch information
JackMD committed Nov 1, 2018
1 parent 3ad2695 commit 7c22224
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- PurePerms
- RankUp
- FactionsPro
- KDR
- If you want a feature to be added then be sure to make an issue regarding it.
### How to setup?
- Head over to `config.yml` for details.
- Head over to `config.yml` for details.
7 changes: 5 additions & 2 deletions resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ server-names:
# {online} - The number of online players.
# {max_online} - Max number of players allowed on the server.
# {rank} - Players current in-game rank/group. (Requires PurePerms).
# {prison-rank} - Get players Prison rank. (Requires RankUp)
# {prison_rank} - Get players Prison rank. (Requires RankUp)
# {item_name} - Name of the item in players hand.
# {item_id} - ID of the item in players hand.
# {item_meta} - Meta/Damage of the item in players hand.
Expand All @@ -60,6 +60,9 @@ server-names:
# {level_folder_name} - Folder name of the players current level/world.
# {ip} - IP of the player.
# {ping} - Ping of the player.
# {kills} - Get kill count of a player. (Requires KDR)
# {deaths} - Get death count of a player. (Requires KDR)
# {kdr} - Get kill to death ratio of a player. (Requires KDR)

# Add the lines that would be shown on the Scoreboard.
# Follow the same pattern as below.
Expand All @@ -81,4 +84,4 @@ score-lines:
- " §cPing: §d{ping}"
- " §3Vote:"
- " §cwww.server.com"
...
...
42 changes: 41 additions & 1 deletion src/JackMD/ScoreHud/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

use _64FF00\PurePerms\PurePerms;
use FactionsPro\FactionMain;
use JackMD\KDR\KDR;
use JackMD\ScoreFactory\ScoreFactory;
use JackMD\ScoreHud\task\ScoreUpdateTask;
use onebone\economyapi\EconomyAPI;
Expand Down Expand Up @@ -140,6 +141,42 @@ public function getPlayerFaction(Player $player): string{
return "Plugin not found";
}

/**
* @param Player $player
* @return int|string
*/
public function getPlayerKills(Player $player){
if(KDR::getInstance() !== null){
return KDR::getInstance()->getProvider()->getPlayerKillPoints($player);
}else{
return "Plugin Not Found";
}
}

/**
* @param Player $player
* @return int|string
*/
public function getPlayerDeaths(Player $player){
if(KDR::getInstance() !== null){
return KDR::getInstance()->getProvider()->getPlayerDeathPoints($player);
}else{
return "Plugin Not Found";
}
}

/**
* @param Player $player
* @return string
*/
public function getPlayerKillToDeathRatio(Player $player): string{
if(KDR::getInstance() !== null){
return KDR::getInstance()->getProvider()->getKillToDeathRatio($player);
}else{
return "Plugin Not Found";
}
}

/**
* @param Player $player
* @param string $string
Expand All @@ -151,7 +188,7 @@ public function process(Player $player, string $string): string{
$string = str_replace("{online}", count($this->getServer()->getOnlinePlayers()), $string);
$string = str_replace("{max_online}", $this->getServer()->getMaxPlayers(), $string);
$string = str_replace("{rank}", $this->getPlayerRank($player), $string);
$string = str_replace("{prison-rank}", $this->getPlayerPrisonRank($player), $string);
$string = str_replace("{prison_rank}", $this->getPlayerPrisonRank($player), $string);
$string = str_replace("{item_name}", $player->getInventory()->getItemInHand()->getName(), $string);
$string = str_replace("{item_id}", $player->getInventory()->getItemInHand()->getId(), $string);
$string = str_replace("{item_meta}", $player->getInventory()->getItemInHand()->getDamage(), $string);
Expand All @@ -166,6 +203,9 @@ public function process(Player $player, string $string): string{
$string = str_replace("{level_folder_name}", $player->getLevel()->getFolderName(), $string);
$string = str_replace("{ip}", $player->getAddress(), $string);
$string = str_replace("{ping}", $player->getPing(), $string);
$string = str_replace("{kills}", $this->getPlayerKills($player), $string);
$string = str_replace("{deaths}", $this->getPlayerDeaths($player), $string);
$string = str_replace("{kdr}", $this->getPlayerKillToDeathRatio($player), $string);
return $string;
}
}

6 comments on commit 7c22224

@SOF3
Copy link

@SOF3 SOF3 commented on 7c22224 Nov 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this works if KDR wasn't loaded. Have you tested that?

@Ifera
Copy link
Owner

@Ifera Ifera commented on 7c22224 Nov 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I tested it and it works

@Ifera
Copy link
Owner

@Ifera Ifera commented on 7c22224 Nov 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SOF3 the plugin load order doesn't matter in this case since by the time a player joins the server everything is fully loaded. The scoreboard is sent to the player via a task.

@SOF3
Copy link

@SOF3 SOF3 commented on 7c22224 Nov 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But you are calling KDR::getInstance(), which doesn't even exist if the plugin isn't loaded. The plugin will crash. It won't just return null.

@Ifera
Copy link
Owner

@Ifera Ifera commented on 7c22224 Nov 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But its the same case for EconomyAPI::gretInstance() also besides the function will only be called if the player sets {kills} or {deaths} or {kdr} in the config. Which in that case it depends upon the user.

@SOF3
Copy link

@SOF3 SOF3 commented on 7c22224 Nov 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better if you detect it beforehand

Please sign in to comment.