Skip to content

Commit

Permalink
Fix #1 and other bug
Browse files Browse the repository at this point in the history
- Fix #1
- Fix error that happened when a rank was eliminated and a player with that rank joined the server.
  • Loading branch information
IvanCraft623 committed Sep 8, 2021
1 parent e54d8fd commit 3507b5c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
10 changes: 9 additions & 1 deletion src/IvanCraft623/RankSystem/command/RanksCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function execute(CommandSender $sender, string $label, array $args) {
$sender->sendMessage("§cUse: /ranks delete <rank>");
return true;
}
if ($this->plugin->getRankManager()->exists($args[1])) {
if (!$this->plugin->getRankManager()->exists($args[1])) {
$sender->sendMessage("§c".$args[1]." rank does not exist!");
return true;
}
Expand All @@ -81,13 +81,21 @@ public function execute(CommandSender $sender, string $label, array $args) {
return true;
}
$this->plugin->getRankManager()->delete($args[1]);
$sender->sendMessage("§bYou have successfully §cdeleted§b the rank §e".$args[1]);
break;

case 'edit':
if (!$sender->hasPermission("ranksystem.commands")) {
$sender->sendMessage("§cYou do not have permission to use this command!");
return true;
}
if (!$sender instanceof Player) {
$sender->sendMessage(
"§cYou can only use this command in game!"."\n".
"§eTo edit a rank you must go to §bplugin_data/Ranks/ranks.yml §eand edit it manually."
);
return true;
}
if (!isset($args[1])) {
$sender->sendMessage("§cUse: /ranks edit <rank>");
return true;
Expand Down
4 changes: 3 additions & 1 deletion src/IvanCraft623/RankSystem/provider/SQLite3.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ public function getRanks(string $user) : array {
if (is_numeric($expTime)) {
$expTime = (int)$expTime;
}
$ranks[$data[0]] = $expTime;
if (Ranks::getInstance()->getRankManager()->exists($data[0])) {
$ranks[$data[0]] = $expTime;
}
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/IvanCraft623/RankSystem/provider/YAML.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ public function getRanks(string $user) : array {
if ($this->isInDb($user)) {
$all = $this->db->getAll();
$ranks = $all[$user]["ranks"];
foreach ($ranks as $rank => $expTime) {
if (!Ranks::getInstance()->getRankManager()->exists($rank)) {
unset($ranks[$rank]);
}
}
}
return $ranks;
}
Expand Down
9 changes: 6 additions & 3 deletions src/IvanCraft623/RankSystem/session/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private function loadRanks() : void {
$ranks[] = $rank;
}
if ($ranks === []) {
$ranks = [$this->plugin->getRankManager()->getDefault()];
$ranks[0] = $this->plugin->getRankManager()->getDefault();
}
$this->ranks = $manager->getHierarchical($ranks);
}
Expand Down Expand Up @@ -277,15 +277,18 @@ public function removePermission(string $perm) : bool {

public function updateRanks() {
$this->ranks = $this->plugin->getRankManager()->getHierarchical($this->ranks);
$player = Ranks::getInstance()->getServer()->getPlayerByPrefix($this->name);
if ($this->ranks === []) {
$this->ranks = [$this->plugin->getRankManager()->getDefault()];
}
$player = Ranks::getInstance()->getServer()->getPlayerExact($this->name);
if ($player !== null) {
$this->updatePermissions();
$player->setNameTag($this->getNameTagFormat());
}
}

public function updatePermissions() {
$player = Ranks::getInstance()->getServer()->getPlayerByPrefix($this->name);
$player = Ranks::getInstance()->getServer()->getPlayerExact($this->name);
if ($player !== null) {
foreach ($this->attachments as $attachment) {
$player->removeAttachment($attachment);
Expand Down

0 comments on commit 3507b5c

Please sign in to comment.