Skip to content
This repository has been archived by the owner on Nov 20, 2022. It is now read-only.

Commit

Permalink
1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Nyrok authored Jan 5, 2022
1 parent 83c9a09 commit 4b8aa2d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
6 changes: 4 additions & 2 deletions plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ main: Nyrok\LottoPlugin\Main
api: [ 3.0.0 ]
commands:
lotto:
description: Voir le temps restant du lotto. Powered by @Nyrok10 on Twitter.
description: See timeleft before next lotto. Powered by @Nyrok10 on Twitter.
aliases:
- loto
ticket:
description: Acheter des tickets pour jouer au lotto. Powered by @Nyrok10 on Twitter.
description: Buy tickets to play at lotto. Powered by @Nyrok10 on Twitter.
depend:
- EconomyAPI
...
6 changes: 3 additions & 3 deletions src/Nyrok/LottoPlugin/LottoTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function onRun(int $currentTick)
$repeating = $this->config->get("repeating-time") ?? 15;
$repeating = $repeating >= 60 || $repeating <= 1 ? 15 : $repeating;
if(gettype($minutes / $repeating) === "integer" && $seconds == 0){
$restant = 60 - (int)$minutes;
$restant = 60 - (int)$minutes === 60 ? 0 : 60 - (int)$minutes;
$addicts = gettype($this->config->get("lotto")) === "array" ? $this->config->get("lotto") : array() ;
$cashprize = 0;
foreach ($addicts as $amount){
Expand All @@ -42,6 +42,7 @@ public function onRun(int $currentTick)
$this->main->getServer()->broadcastMessage($message);
}
if($minutes == 0 && $seconds == 0){
$this->config->save();
$is_someone = gettype($this->config->get("lotto")) === "array" ? $this->config->get("lotto") : null;
$is_someone = $is_someone === [] && gettype($is_someone) === "array" ? array_push($is_someone, array("Nobody")) : $is_someone;
$addicts = $is_someone !== null ? $this->config->get("lotto") : array();
Expand All @@ -54,8 +55,7 @@ public function onRun(int $currentTick)
$message = str_replace("{winner}", (string)$winner, $message);
$message = str_replace("{participants}", (string)count($addicts), $message);
$message = str_replace("{cashprize}", (string)$cashprize, $message);
$win = $winner !== "Personne" ? $message : $this->config->getNested("messages.success.no-winner");
$this->config->save();
$win = $winner !== "Nobody" ? $message : $this->config->getNested("messages.success.no-winner");
$this->config->remove("lotto");
$this->config->save();
EconomyAPI::getInstance()->addMoney($winner, $cashprize);
Expand Down
8 changes: 4 additions & 4 deletions src/Nyrok/LottoPlugin/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function onCommand(CommandSender $sender, Command $command, string $label
$minutes = $date->format("i");
$restant = 60 - (int)$minutes;
$this->config->save();
$addicts = gettype($this->config->get("loto")) === "array" ? $this->config->get("loto") : array();
$addicts = gettype($this->config->get("lotto")) === "array" ? $this->config->get("lotto") : array();
$cashprize = 0;
foreach ($addicts as $amount){
$cashprize = $cashprize + $amount;
Expand All @@ -104,7 +104,7 @@ public function onCommand(CommandSender $sender, Command $command, string $label
if(EconomyAPI::getInstance()->myMoney($sender->getName()) >= $amount && $amount > 0){
EconomyAPI::getInstance()->reduceMoney($sender->getName(), $amount);
$this->config->save();
$this->config->setNested("loto.".$sender->getName(), ($this->config->getNested("loto.".$sender->getName()) ?? 0) + $amount);
$this->config->setNested("lotto.".$sender->getName(), ($this->config->getNested("lotto.".$sender->getName()) ?? 0) + $amount);
$this->config->save();
$message = $this->config->getNested("messages.success.ticket-buy");
$message = str_replace("{amount}", "$amount", $message);
Expand All @@ -129,11 +129,11 @@ public function onCommand(CommandSender $sender, Command $command, string $label
}
else if($args[0] === "info") {
$this->config->save();
$amount = $this->config->getNested("loto.".$sender->getName());
$amount = $this->config->getNested("lotto.".$sender->getName());
$message = $this->config->getNested("messages.success.ticket-info-buyed");
$message = str_replace("{tickets}", (string)($amount / $amplifier), $message);
$message = str_replace("{amount}", (string)$amount, $message);
$info = $this->config->getNested("loto.".$sender->getName()) ? $message : $this->config->getNested("messages.success.ticket-info-not-buyed");
$info = $this->config->getNested("lotto.".$sender->getName()) ? $message : $this->config->getNested("messages.success.ticket-info-not-buyed");
$sender->sendMessage($info);

}
Expand Down

0 comments on commit 4b8aa2d

Please sign in to comment.