Skip to content

Commit

Permalink
Now using ktpmpl-cfs and code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
KygekDev committed Feb 2, 2022
1 parent ba4acc6 commit f0b38e3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
3 changes: 3 additions & 0 deletions .poggit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ branches:
projects:
KygekEasyGamemode:
path: ""
libs:
- src: KygekTeam/ktpmpl-cfs/ktpmpl-cfs
version: ^4.0.0
...
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ A PocketMine-MP plugin to quickly change between gamemodes. This plugin will sav
| `/gmda [player]` | Change gamemode to Adventure | `kygekeasygmd.gmda` |
| `/gmdsp [player]` | Change gamemode to Spectator | `kygekeasygmd.gmdsp` |

# Planned Features

- Handle `Player->setGamemode()` returning `false`

You can request for a feature to be added in a future update [here](https://github.com/KygekTeam/KygekEasyGamemode/issues)!

# Additional Notes

KygekEasyGamemode plugin is made by KygekTeam and licensed under **GPL-3.0**.
Expand Down
30 changes: 11 additions & 19 deletions src/Kygekraqmak/KygekEasyGamemode/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

namespace Kygekraqmak\KygekEasyGamemode;

use KygekTeam\KtpmplCfs\KtpmplCfs;
use pocketmine\player\GameMode;
use pocketmine\player\Player;
use pocketmine\plugin\PluginBase;
Expand All @@ -35,23 +36,17 @@ class Main extends PluginBase {
protected function onEnable() : void {
/** @phpstan-ignore-next-line */
if (self::IS_DEV) {
$this->getLogger()->warning("This plugin is running on a development version. There might be some major bugs. If you found one, please submit an issue in https://github.com/KygekTeam/KygekEasyGamemode/issues.");
(new KtpmplCfs($this))->warnDevelopmentVersion();
}
}

public function onCommand(CommandSender $sender, Command $command, string $label, array $args) : bool {
switch (strtolower($command->getName())) {
switch ($cmd = strtolower($command->getName())) {
case "gmds":
$this->changeGamemode($sender, "gmds", $args);
break;
case "gmdc":
$this->changeGamemode($sender, "gmdc", $args);
break;
case "gmda":
$this->changeGamemode($sender, "gmda", $args);
break;
case "gmdsp":
$this->changeGamemode($sender, "gmdsp", $args);
$this->changeGamemode($sender, $cmd, $args);
}
return true;
}
Expand Down Expand Up @@ -86,26 +81,23 @@ private function changeGamemode(CommandSender $sender, string $cmd, array $args)
private function setGamemode(Player $player, string $cmd) : string {
switch ($cmd) {
case "gmds":
$player->setGamemode(GameMode::SURVIVAL());
$gamemode = "Survival";
$gamemode = GameMode::SURVIVAL();
break;
case "gmdc":
$player->setGamemode(GameMode::CREATIVE());
$gamemode = "Creative";
$gamemode = GameMode::CREATIVE();
break;
case "gmda":
$player->setGamemode(GameMode::ADVENTURE());
$gamemode = "Adventure";
$gamemode = GameMode::ADVENTURE();
break;
case "gmdsp":
$player->setGamemode(GameMode::SPECTATOR());
$gamemode = "Spectator";
$gamemode = GameMode::SPECTATOR();
break;
default:
$gamemode = "";
return "";
}

return $gamemode;
$player->setGamemode($gamemode);
return $gamemode->getEnglishName();
}

}

0 comments on commit f0b38e3

Please sign in to comment.