Skip to content

Commit

Permalink
Prevent non-100 mine sets
Browse files Browse the repository at this point in the history
  • Loading branch information
falkirks committed May 5, 2017
1 parent 2ce10be commit 45250a4
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/falkirks/minereset/command/SetCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ public function execute(CommandSender $sender, $commandLabel, array $args){
$sets = array_slice($args, 1);
$save = [];
if (count($sets) % 2 === 0) {
$total = 0;
foreach ($sets as $key => $item) {
if (strpos($item, "%")) {
$sender->sendMessage(TextFormat::RED . "Your format string looks incorrect." . TextFormat::RESET);
return;
}
if ($key & 1) {
$total += $item;
if (isset($save[$sets[$key - 1]])) {
$save[$sets[$key - 1]] += $item;
}
Expand All @@ -29,8 +31,13 @@ public function execute(CommandSender $sender, $commandLabel, array $args){
}
}
}
$this->getApi()->getMineManager()[$args[0]]->setData($save);
$sender->sendMessage(TextFormat::GREEN . "Mine has been setted. Use /mine reset {$args[0]} to see your changes.");
if($total === 100) {
$this->getApi()->getMineManager()[$args[0]]->setData($save);
$sender->sendMessage(TextFormat::GREEN . "Mine has been setted. Use /mine reset {$args[0]} to see your changes.");
}
else{
$sender->sendMessage(TextFormat::RED . "The percents on your mine must add to 100, but they add to {$total}." . TextFormat::RESET);
}
}
else {
$sender->sendMessage(TextFormat::RED . "Your format string looks incorrect." . TextFormat::RESET);
Expand Down

0 comments on commit 45250a4

Please sign in to comment.