Added /me and /say, fixed a bunch of things, chat working

This commit is contained in:
Shoghi Cervantes 2014-03-31 06:51:34 +02:00
parent 22b5255421
commit f9a7385b47
6 changed files with 145 additions and 8 deletions

View File

@ -275,7 +275,6 @@ class Player extends RealHuman implements CommandSender{
$this->buffer->data = array();
$this->tasks[] = $this->server->getScheduler()->scheduleRepeatingTask(new CallbackTask(array($this, "handlePacketQueues")), 1);
$this->tasks[] = $this->server->getScheduler()->scheduleRepeatingTask(new CallbackTask(array($this, "clearQueue")), 20 * 60);
console("[DEBUG] New Session started with " . $ip . ":" . $port . ". MTU " . $this->MTU . ", Client ID " . $this->clientID, true, true, 2);
}
@ -1030,6 +1029,7 @@ class Player extends RealHuman implements CommandSender{
break;
}
$this->username = $packet->username;
$this->displayName = $this->username;
$this->iusername = strtolower($this->username);
$this->loginData = array("clientId" => $packet->clientId, "loginData" => $packet->loginData);
@ -1075,6 +1075,8 @@ class Player extends RealHuman implements CommandSender{
return;
}
$this->server->getPluginManager()->subscribeToPermission(Player::BROADCAST_CHANNEL_ADMINISTRATIVE, $this);
$this->server->getPluginManager()->subscribeToPermission(Player::BROADCAST_CHANNEL_USERS, $this);
$this->loggedIn = true;
$u = Player::get($this->iusername, false, true);
@ -2072,6 +2074,8 @@ class Player extends RealHuman implements CommandSender{
if(isset($ev) and $this->username != "" and $this->spawned !== false and $ev->getQuitMessage() != ""){
Player::broadcastMessage($ev->getQuitMessage());
}
$this->server->getPluginManager()->unsubscribeFromPermission(Player::BROADCAST_CHANNEL_ADMINISTRATIVE, $this);
$this->server->getPluginManager()->unsubscribeFromPermission(Player::BROADCAST_CHANNEL_USERS, $this);
$this->spawned = false;
console("[INFO] " . TextFormat::AQUA . $this->username . TextFormat::RESET . "[/" . $this->ip . ":" . $this->port . "] logged out due to " . $reason);
$this->windows = array();
@ -2145,7 +2149,7 @@ class Player extends RealHuman implements CommandSender{
* @param string $message
*/
public static function broadcastMessage($message){
self::groupChat($message, self::getAll());
self::groupChat($message, Server::getInstance()->getPluginManager()->getPermissionSubscriptions(Player::BROADCAST_CHANNEL_USERS));
}
/**
@ -2319,7 +2323,9 @@ class Player extends RealHuman implements CommandSender{
*/
public static function groupChat($message, array $players){
foreach($players as $p){
$p->sendMessage($message);
if($p instanceof CommandSender){
$p->sendMessage($message);
}
}
}

View File

@ -26,9 +26,11 @@ use PocketMine\Command\Defaults\BanIpCommand;
use PocketMine\Command\Defaults\BanListCommand;
use PocketMine\Command\Defaults\DefaultGamemodeCommand;
use PocketMine\Command\Defaults\HelpCommand;
use PocketMine\Command\Defaults\MeCommand;
use PocketMine\Command\Defaults\PardonCommand;
use PocketMine\Command\Defaults\PardonIpCommand;
use PocketMine\Command\Defaults\PluginsCommand;
use PocketMine\Command\Defaults\SayCommand;
use PocketMine\Command\Defaults\SeedCommand;
use PocketMine\Command\Defaults\StopCommand;
use PocketMine\Command\Defaults\TellCommand;
@ -52,7 +54,6 @@ class SimpleCommandMap implements CommandMap{
}
private function setDefaultCommands(){
//TODO
$this->register("pocketmine", new VersionCommand("version"));
$this->register("pocketmine", new PluginsCommand("plugins"));
$this->register("pocketmine", new SeedCommand("seed"));
@ -65,6 +66,8 @@ class SimpleCommandMap implements CommandMap{
$this->register("pocketmine", new BanListCommand("banlist"));
$this->register("pocketmine", new PardonCommand("pardon"));
$this->register("pocketmine", new PardonIpCommand("pardon-ip"));
$this->register("pocketmine", new SayCommand("say"));
$this->register("pocketmine", new MeCommand("me"));
}

View File

@ -0,0 +1,61 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
namespace PocketMine\Command\Defaults;
use PocketMine\Command\CommandSender;
use PocketMine\Player;
use PocketMine\Utils\TextFormat;
class MeCommand extends VanillaCommand{
public function __construct($name){
parent::__construct(
$name,
"Performs the specified action in chat",
"/me <action...>"
);
$this->setPermission("pocketmine.command.me");
}
public function execute(CommandSender $sender, $currentAlias, array $args){
if(!$this->testPermission($sender)){
return true;
}
if(count($args) === 0){
$sender->sendMessage(TextFormat::RED . "Usage: " . $this->usageMessage);
return false;
}
$message = "* ";
if($sender instanceof Player){
$message .= $sender->getDisplayName();
}else{
$message .= $sender->getName();
}
Player::broadcastMessage($message . " " . implode(" ", $args));
return true;
}
}

View File

@ -0,0 +1,64 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
namespace PocketMine\Command\Defaults;
use PocketMine\Command\CommandSender;
use PocketMine\Command\ConsoleCommandSender;
use PocketMine\Player;
use PocketMine\Utils\TextFormat;
class SayCommand extends VanillaCommand{
public function __construct($name){
parent::__construct(
$name,
"Broadcasts the given message as the sender",
"/say <message...>"
);
$this->setPermission("pocketmine.command.seed");
}
public function execute(CommandSender $sender, $currentAlias, array $args){
if(!$this->testPermission($sender)){
return true;
}
if(count($args) === 0){
$sender->sendMessage(TextFormat::RED . "Usage: " . $this->usageMessage);
return false;
}
$message = TextFormat::LIGHT_PURPLE . "[";
if($sender instanceof ConsoleCommandSender){
$message .= "Server";
}elseif($sender instanceof Player){
$message .= $sender->getDisplayName();
}else{
$message .= $sender->getName();
}
$message .= TextFormat::LIGHT_PURPLE . "] " . implode(" ", $args);
Player::broadcastMessage($message);
return true;
}
}

View File

@ -23,6 +23,7 @@ namespace PocketMine\Event\Player;
use PocketMine\Event\Cancellable;
use PocketMine\Player;
use PocketMine\Server;
/**
* Called when a player chats something
@ -46,7 +47,7 @@ class PlayerChatEvent extends PlayerEvent implements Cancellable{
$this->message = $message;
$this->format = $format;
if($recipients === null){
$this->recipients = Player::getAll();
$this->recipients = Server::getInstance()->getPluginManager()->getPermissionSubscriptions(Player::BROADCAST_CHANNEL_USERS);
}else{
$this->recipients = $recipients;
}

View File

@ -77,6 +77,8 @@ class Level{
/** @var Level */
public static $default = null;
public static $saveEnabled = true;
/**
* @var Player[]
*/
@ -533,7 +535,7 @@ class Level{
unset($this->usedChunks[$i]);
LevelFormat::getXZ($i, $X, $Z);
if(!$this->isSpawnChunk($X, $Z)){
$this->level->unloadChunk($X, $Z, $this->server->saveEnabled);
$this->level->unloadChunk($X, $Z, self::$saveEnabled);
}
}
}
@ -570,7 +572,7 @@ class Level{
return false;
}
//TODO: save enabled/disabled
/*if($this->server->saveEnabled === false and $force === false){
/*if(self::$saveEnabled === false and $force === false){
return;
}*/
@ -1070,7 +1072,7 @@ class Level{
unset($this->chunkTiles[$index]);
Cache::remove("world:{$this->name}:$X:$Z");
return $this->level->unloadChunk($X, $Z, $this->server->saveEnabled);
return $this->level->unloadChunk($X, $Z, self::$saveEnabled);
}
/**