diff --git a/src/API/ChatAPI.php b/src/API/ChatAPI.php index 69fade6d..eb29459b 100644 --- a/src/API/ChatAPI.php +++ b/src/API/ChatAPI.php @@ -3,18 +3,21 @@ class ChatAPI{ private $server; - + public $lastTells = []; function __construct(){ $this->server = ServerAPI::request(); } public function init(){ $this->server->api->console->register("tell", " ", [$this, "commandHandler"]); + $this->server->api->console->register("reply", "", [$this, "commandHandler"]); $this->server->api->console->register("me", "", [$this, "commandHandler"]); $this->server->api->console->register("say", "", [$this, "commandHandler"]); $this->server->api->console->cmdWhitelist("tell"); + $this->server->api->console->cmdWhitelist("reply"); $this->server->api->console->cmdWhitelist("me"); $this->server->api->console->alias("msg", "tell"); + $this->server->api->console->alias("r", "reply"); } /** @@ -26,13 +29,11 @@ class ChatAPI{ * @return string */ public function commandHandler($cmd, $params, $issuer, $alias){ - $output = ""; switch($cmd){ case "say": $s = implode(" ", $params); if(trim($s) == ""){ - $output .= "Usage: /say \n"; - break; + return "Usage: /say "; } $sender = ($issuer instanceof Player) ? "Server" : ucfirst($issuer); if(Utils::hasEmoji($s)) return "Your message contains illegal characters!"; @@ -41,8 +42,7 @@ class ChatAPI{ case "me": $s = implode(" ", $params); if(trim($s) == ""){ - $output .= "Usage: /me \n"; - break; + return "Usage: /me "; } if(!($issuer instanceof Player)){ if($issuer === "rcon"){ @@ -58,42 +58,58 @@ class ChatAPI{ $this->broadcast("* $sender $msg"); break; case "tell": - if(!isset($params[0]) or !isset($params[1])){ - $output .= "Usage: /$cmd \n"; - break; - } - if(!($issuer instanceof Player)){ - $sender = ucfirst($issuer); - }else{ - $sender = $issuer->username; - } + if(!isset($params[0]) or !isset($params[1])) return "Usage: /$cmd \n"; + + if(!($issuer instanceof Player)) $sender = ucfirst($issuer); + else $sender = $issuer->username; + $n = array_shift($params); $target = $this->server->api->player->get($n); if($target instanceof Player){ $target = $target->username; }else{ $target = strtolower($n); - if($target === "server" or $target === "console" or $target === "rcon"){ + if($target === "server" || $target === "console" || $target === "rcon"){ $target = "Console"; }else{ - return "The player is offline."; + return "$target is offline."; } } - if(strtolower($target) === strtolower($issuer)){ - return "You can't send message to yourself."; + if(strtolower($target) === strtolower($sender)) return "You can't send message to yourself."; + + $mes = implode(" ", $params); + if(Utils::hasEmoji($mes)) return "Your message contains illegal characters!"; + + if($target !== "Console" && $target !== "Rcon") $this->sendTo(false, "$sender whispers to you: $mes", $target); + if($target === "Console" || $sender === "Console") console("[INFO] $sender whispers to $target: $mes"); + + + $this->lastTells[strtolower($target)] = strtolower($sender); + $this->lastTells[strtolower($sender)] = strtolower($target); + + return "You're whispering to $target: $mes"; + case "reply": + if(!($issuer instanceof Player)) $sender = ucfirst($issuer); + else $sender = $issuer->username; + + if(!isset($this->lastTells[strtolower($sender)])) return "You have no one to reply to."; + $target = $this->lastTells[strtolower($sender)]; + if($target !== "server" && $target !== "console" && $target !== "rcon"){ + if(!($this->server->api->player->get($target) instanceof Player)){ + return "$target is offline."; + } } $mes = implode(" ", $params); if(Utils::hasEmoji($mes)) return "Your message contains illegal characters!"; - $output .= "You're whispering to " . $target . ": " . $mes . "\n"; - if($target !== "Console" and $target !== "Rcon"){ - $this->sendTo(false, $sender . " whispers to you: " . $mes, $target); - } - if($target === "Console" or $sender === "Console"){ - console("[INFO] " . $sender . " whispers to " . $target . ": " . $mes); - } - break; + + if($target !== "Console" && $target !== "Rcon") $this->sendTo(false, "$sender whispers to you: $mes", $target); + if($target === "Console" || $sender === "Console") console("[INFO] $sender whispers to $target: $mes"); + + $this->lastTells[strtolower($target)] = strtolower($sender); + $this->lastTells[strtolower($sender)] = strtolower($target); + + return "You're whispering to $target: $mes"; } - return $output; } /** diff --git a/src/Player.php b/src/Player.php index 9279f6c0..5a942b95 100755 --- a/src/Player.php +++ b/src/Player.php @@ -1467,6 +1467,7 @@ class Player{ $this->chunkCount = []; $this->craftingItems = []; $this->received = []; + unset($this->server->api->chat->lastTells[$this->iusername]); //$this->entity->close(); } } diff --git a/src/material/block/plant/DandelionBlock.php b/src/material/block/plant/DandelionBlock.php index 57f5ef64..236fa778 100644 --- a/src/material/block/plant/DandelionBlock.php +++ b/src/material/block/plant/DandelionBlock.php @@ -22,7 +22,7 @@ class DandelionBlock extends FlowableBlock{ public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){ $downId = $level->level->getBlockID($x, $y - 1, $z); if(StaticBlock::getIsTransparent($downId) and $downId !== FARMLAND){ //Replace with common break method - ServerAPI::request()->api->entity->drop(new Position($x+0.5, $y, $z+0.5, $level), BlockAPI::getItem(CYAN_FLOWER)); + ServerAPI::request()->api->entity->drop(new Position($x+0.5, $y, $z+0.5, $level), BlockAPI::getItem(DANDELION)); $level->fastSetBlockUpdate($x, $y, $z, 0, 0); } }