Pocketmine Git client !
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Main.php 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. namespace Ad5001\Gitable;
  3. use pocketmine\command\CommandSender;
  4. use pocketmine\command\Command;
  5. use pocketmine\event\Listener;
  6. use pocketmine\plugin\PluginBase;
  7. use pocketmine\utils\TextFormat as C;
  8. use pocketmine\Server;
  9. use pocketmine\utils\Utils;
  10. use pocketmine\Player;
  11. class Main extends PluginBase implements Listener {
  12. protected $git;
  13. const PREFIX = C::BLACK .C::BOLD . C::ITALIC . "[" . C::RESET . C::BOLD .C::GRAY . "Git" . C::BLACK . C::ITALIC . "] " . C::RESET . C::GRAY;
  14. public function onEnable() {
  15. @mkdir($this->getDataFolder());
  16. @mkdir($this->getDataFolder() . "bin");
  17. $this->getServer()->getPluginManager()->registerEvents($this, $this);
  18. $zip = new ZipArchive();
  19. if(Utils::getOS() == "win") {
  20. if(!file_exists($this->getDataFolder() . "bin/git.exe") && $zip->open("../../resources/Windows.zip")) {
  21. $zip->extractTo($this->getDataFolder() . "bin");
  22. $zip->close();
  23. }
  24. $this->git = new Windows($this, $this->getDataFolder());
  25. } elseif(Utils::getOS() == "linux") {
  26. if(!file_exists($this->getDataFolder() . "bin/git.exe") && $zip->open("../../resources/Linux.zip")) {
  27. $zip->extractTo($this->getDataFolder() . "bin");
  28. $zip->close();
  29. }
  30. $this->git = new Linux($this, $this->getDataFolder());
  31. } elseif(Utils::getOS() == "mac") {
  32. if(!file_exists($this->getDataFolder() . "bin/git.exe") && $zip->open("../../resources/Mac.zip")) {
  33. $zip->extractTo($this->getDataFolder() . "bin");
  34. $zip->close();
  35. }
  36. $this->git = new Mac($this, $this->getDataFolder());
  37. } else {
  38. $this->getLogger()->critical("Unsuported device ! Please refer to the download page to see the list of available devices.");
  39. $this->setEnable(false);
  40. }
  41. }
  42. public function onCommand(CommandSender $sender, Command $cmd, $label, array $args){
  43. switch($cmd->getName()){
  44. case 'git':
  45. if(count($args) >= 2) {
  46. switch($args[0]) {
  47. case "cd":
  48. $this->git->cd($args[1]);
  49. $sender->sendMessage(self::PREFIX . "New path: " . $this->git->getDir());
  50. break;
  51. case "commit":
  52. unset($args[0]);
  53. $sender->sendMessage(self::PREFIX . $this->git->commit(implode(" ", $args)));
  54. $sender->sendMessage(self::PREFIX . "Commited !");
  55. break;
  56. case "checkout":
  57. $sender->sendMessage(self::PREFIX . $this->git->checkout($args[1]));
  58. break;
  59. case "dir":
  60. $sender->sendMessage(self::PREFIX . $this->git->getDir());
  61. break;
  62. case "clone":
  63. $sender->sendMessage(self::PREFIX . $this->git->clone($args[1]));
  64. break;
  65. }
  66. return true;
  67. }
  68. break;
  69. }
  70. return false;
  71. }
  72. public function getGitClient() {
  73. return $this->git;
  74. }
  75. public function setGitClient(GitClient $client) {
  76. $this->git = $client;
  77. return $this->git == $client;
  78. }
  79. }