From 45250a4882e2eea4844cfac8b74a1c830cb4035d Mon Sep 17 00:00:00 2001 From: Falkirks Date: Fri, 5 May 2017 16:24:55 -0700 Subject: [PATCH] Prevent non-100 mine sets --- src/falkirks/minereset/command/SetCommand.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/falkirks/minereset/command/SetCommand.php b/src/falkirks/minereset/command/SetCommand.php index 210f661..a59bae8 100644 --- a/src/falkirks/minereset/command/SetCommand.php +++ b/src/falkirks/minereset/command/SetCommand.php @@ -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; } @@ -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);