Skip to content

Commit

Permalink
Plugin Terminer
Browse files Browse the repository at this point in the history
  • Loading branch information
HyrPiikk committed Jan 13, 2024
1 parent 3e004e9 commit 6883064
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 30 deletions.
4 changes: 3 additions & 1 deletion .idea/spider.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions ressources/config.yml → resources/config.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#Explication du plugin:
#Ceci est un plugin qui sert à grimper sur les murs pendant 5 seconde grace à la commande /spider
#Ceci est un plugin qui sert à grimper sur les murs pendant 5 seconde grace à la commande /spider (ne peut pas modifier)
#la commande à un cooldown de 15 seconde parametre part default.
# Vous pouvez modifier en dessous:

message-power: "§aPouvoir activer"
message-nopower: "§cPouvoir désactiver"

time-utilisation: 15
time-sort: 5
time-utilisation: 15 #Ceci est en seconde !
48 changes: 22 additions & 26 deletions src/core/Command/spider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use pocketmine\command\Command;
use pocketmine\command\CommandSender;
use pocketmine\player\Player;
use pocketmine\scheduler\ClosureTask;

class spider extends Command
{
Expand All @@ -19,43 +20,38 @@ public function __construct(Main $plugin)

private $timer = [];

public function execute(CommandSender $sender, $commandLabel, array $args)
public function execute(CommandSender $sender, string $commandLabel, array $args)
{
if(!$sender instanceof Player){
if (!$sender instanceof Player) {
$sender->sendMessage("Please run the command in-game.");
return true;
}

if($sender->hasPermission("spider.command")){
$name = $sender->getName();

if(!isset($this->timer[$sender->getName()])) {
// the timer for this player is not set, so this is the first time the command is run
$this->timer[$sender->getName()]["end"] = time() + Main::getInstance()->getConfig()->get("time-utilisation");
$this->timer[$sender->getName()]["cooldown"] = time() + Main::getInstance()->getConfig()->get("time-sort") + Main::getInstance()->getConfig()->get("time-utilisation");

$sender->setCanClimbWalls(true);
$sender->sendMessage(Main::getInstance()->getConfig()->get("message-power"));
return true;
// Vérifier si le timer est activé pour le joueur
if(isset($this->timer[$name])) {
$expiry = $this->timer[$name];
if(time() < $expiry) {
$remaining = $expiry - time();
$sender->sendMessage("§7§l>> §r§7Veuillez attendre §c{$remaining} secondes §7avant d'utiliser à nouveau cette commande !");
return false;
}
}

if(time() > $this->timer[$sender->getName()]["cooldown"]){
// the cooldown is over, so the player can run the command again
$this->timer[$sender->getName()]["end"] = time() + Main::getInstance()->getConfig()->get("time-utilisation");
$this->timer[$sender->getName()]["cooldown"] = time() + Main::getInstance()->getConfig()->get("time-sort") + Main::getInstance()->getConfig()->get("time-utilisation");
// Activer l'effet
$this->timer[$name] = time() + Main::getInstance()->getConfig()->get("time-utilisation"); // 15 secondes d'attente avant de pouvoir réutiliser la commande
$sender->setCanClimbWalls(true);
$sender->sendMessage(Main::getInstance()->getConfig()->get("message-power"));

$sender->setCanClimbWalls(true);
$sender->sendMessage(Main::getInstance()->getConfig()->get("message-power"));
} else if(time() > $this->timer[$sender->getName()]["end"]){
// the utility time is over but the cooldown is not, so the player can not run the command
// Désactiver l'effet après 5 secondes
Main::getInstance()->getScheduler()->scheduleDelayedTask(new ClosureTask(function() use($sender): void {
if($sender->isOnline()) { // Check if the player is still online
$sender->setCanClimbWalls(false);
$sender->sendMessage("§l§e»§r§f Time's up!");
} else {
// the utility time is not over and the cooldown is not either, so the player can not run the command
$time = $this->timer[$sender->getName()]["cooldown"] - time();
$sender->sendMessage("§l§e»§r§f Please wait §e{$time} seconds §fbefore using this command again!");
$sender->sendMessage(Main::getInstance()->getConfig()->get("message-nopower"));
}
}
}), 20 * 5); // 5 seconds

return true;
}

}
1 change: 1 addition & 0 deletions src/core/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public function onEnable(): void
self::$instance = $this;
$this->getLogger()->notice("Le plugin à bien démarrer !");
$this->getLogger()->notice("By HyrPikk ");
$this->saveDefaultConfig();

$this->getServer()->getCommandMap()->register("spider", $this->commands[] = new spider($this));
}
Expand Down

0 comments on commit 6883064

Please sign in to comment.