Skip to content

Instantly share code, notes, and snippets.

@PJZ9n
Created July 27, 2019 17:13
Show Gist options
  • Save PJZ9n/16d1745631431f88e04ea98ad9e07d75 to your computer and use it in GitHub Desktop.
Save PJZ9n/16d1745631431f88e04ea98ad9e07d75 to your computer and use it in GitHub Desktop.
<?php
namespace StopMessagePlugin;
//Events
use pocketmine\event\block\BlockBreakEvent;
use pocketmine\event\block\BlockPlaceEvent;
use pocketmine\event\entity\EntityInventoryChangeEvent;
use pocketmine\event\player\PlayerAchievementAwardedEvent;
use pocketmine\event\player\PlayerChatEvent;
use pocketmine\event\player\PlayerCommandPreprocessEvent;
use pocketmine\event\player\PlayerDeathEvent;
use pocketmine\event\player\PlayerGameModeChangeEvent;
use pocketmine\event\player\PlayerInteractEvent;
use pocketmine\event\player\PlayerJoinEvent;
use pocketmine\event\player\PlayerKickEvent;
use pocketmine\event\player\PlayerLoginEvent;
use pocketmine\event\player\PlayerMoveEvent;
use pocketmine\event\player\PlayerQuitEvent;
use pocketmine\event\server\DataPacketReceiveEvent;
//Packet
//use pocketmine\item\Sign;
use pocketmine\event\server\ServerCommandEvent;
use pocketmine\level\Position;
use pocketmine\math\Vector3;
use pocketmine\nbt\NBT;
use pocketmine\network\mcpe\protocol\ModalFormResponsePacket;
//Base
use pocketmine\network\mcpe\protocol\TransferPacket;
use pocketmine\plugin\PluginBase;
//EventUse
use pocketmine\event\Listener;
use pocketmine\event\Cancellable;
//Task
use pocketmine\scheduler\PluginTask;
use pocketmine\scheduler\Task;
use pocketmine\scheduler;
use StopMessagePlugin\CallbackTask;
//Server
use pocketmine\Player;
use pocketmine\Server;
//Utils
use pocketmine\tile\Tile;
use pocketmine\tile\Sign;
use pocketmine\utils\Config;
//Command
use pocketmine\command\command;
use pocketmine\command\CommandSender;
use pocketmine\command\CommandExecutor;
use pocketmine\command\ConsoleCommandSender;
//API
use RuinPray\ui\elements\Label;
use RuinPray\ui\UI;
use RuinPray\ui\elements\Input;
class main extends PluginBase implements Listener{
public function onEnable(){
$this->pluginname = "StopMessagePlugin";
$this->message_tag = "§l§d[ SYSTEM ]§r ";
$this->getLogger()->notice($this->pluginname."が有効化されました。");
$this->getServer()->getPluginManager()->registerEvents($this, $this);
$this->api = $this->getServer()->getPluginManager()->getPlugin("NoJoinApi");
if($this->api === NULL){
$this->getLogger()->info("NoJoinApiを読み込めませんでした。");
$this->getLogger()->info("サーバーを停止します。");
$this->getServer()->shutdown();
}else{
$this->getLogger()->info("NoJoinApiを読み込みました");
}
}
/*debug!!*/
public function onServerCommand(ServerCommandEvent $event){
$cmd = $event->getCommand();
if($cmd == "stop"){
$event->setCancelled();
foreach($this->getServer()->getOnlinePlayers() as $player){
//$player->kick($this->message_tag."サーバーは管理者(CONSOLE)によって再起動されました。", false);
$packet = new TransferPacket();
$packet->address = "v1.asvd.net";
$packet->port = 19132;
$player->sendDataPacket($packet);
$this->getServer()->getScheduler()->scheduleDelayedTask(new CallbackTask([$this, "kick"], [$player]), 12.5 * 2);
}
$this->getServer()->getScheduler()->scheduleDelayedTask(new CallbackTask([$this, "shutdownTask"], []), 12.5 * 4);
}else if($cmd == "stop server"){
$event->setCancelled();
foreach($this->getServer()->getOnlinePlayers() as $player){
$player->kick($this->message_tag."サーバーは管理者(CONSOLE)によってメンテナンスが開始されました。", false);
}
$this->api->setReason("メンテナンス中のため");
$this->api->setMode(true);
$this->getServer()->getScheduler()->scheduleDelayedTask(new CallbackTask([$this, "shutdownTask"], []), 12.5 * 4);
}
}
public function onPlayerCommand(PlayerCommandPreprocessEvent $event){
$player = $event->getPlayer();
$name = $player->getName();
$cmd = $event->getMessage();
if($player->isOp()){
if($cmd == "/stop"){
$event->setCancelled();
foreach($this->getServer()->getOnlinePlayers() as $player){
//$player->kick($this->message_tag."サーバーは管理者(".$name.")によって再起動されました。", false);
$packet = new TransferPacket();
$packet->address = "v1.asvd.net";
$packet->port = 19132;
$player->sendDataPacket($packet);
$this->getServer()->getScheduler()->scheduleDelayedTask(new CallbackTask([$this, "kick"], [$player]), 12.5 * 2);
}
$this->getServer()->getScheduler()->scheduleDelayedTask(new CallbackTask([$this, "shutdownTask"], []), 12.5 * 4);
}else{
if($cmd == "/stop server"){
$event->setCancelled();
foreach($this->getServer()->getOnlinePlayers() as $player){
$player->kick($this->message_tag."サーバーは管理者(".$name.")によってメンテナンスが開始されました。", false);
}
$this->api->setReason("メンテナンス中のため");
$this->api->setMode(true);
$this->getServer()->getScheduler()->scheduleDelayedTask(new CallbackTask([$this, "shutdownTask"], []), 12.5 * 4);
}
}
}
}
public function shutdownTask(){
$this->getServer()->shutdown();
}
public function kick(Player $player){
$player->kick("", false);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment