fixed dandelions dropping cyan flowers on neighbor change, add /reply(/r) command

This commit is contained in:
GameHerobrine 2025-05-10 16:16:31 +03:00
parent 5538e197bf
commit a8bf2f9ce9
3 changed files with 46 additions and 29 deletions

View file

@ -3,18 +3,21 @@
class ChatAPI{ class ChatAPI{
private $server; private $server;
public $lastTells = [];
function __construct(){ function __construct(){
$this->server = ServerAPI::request(); $this->server = ServerAPI::request();
} }
public function init(){ public function init(){
$this->server->api->console->register("tell", "<player> <private message ...>", [$this, "commandHandler"]); $this->server->api->console->register("tell", "<player> <private message ...>", [$this, "commandHandler"]);
$this->server->api->console->register("reply", "<private message ...>", [$this, "commandHandler"]);
$this->server->api->console->register("me", "<action ...>", [$this, "commandHandler"]); $this->server->api->console->register("me", "<action ...>", [$this, "commandHandler"]);
$this->server->api->console->register("say", "<message ...>", [$this, "commandHandler"]); $this->server->api->console->register("say", "<message ...>", [$this, "commandHandler"]);
$this->server->api->console->cmdWhitelist("tell"); $this->server->api->console->cmdWhitelist("tell");
$this->server->api->console->cmdWhitelist("reply");
$this->server->api->console->cmdWhitelist("me"); $this->server->api->console->cmdWhitelist("me");
$this->server->api->console->alias("msg", "tell"); $this->server->api->console->alias("msg", "tell");
$this->server->api->console->alias("r", "reply");
} }
/** /**
@ -26,13 +29,11 @@ class ChatAPI{
* @return string * @return string
*/ */
public function commandHandler($cmd, $params, $issuer, $alias){ public function commandHandler($cmd, $params, $issuer, $alias){
$output = "";
switch($cmd){ switch($cmd){
case "say": case "say":
$s = implode(" ", $params); $s = implode(" ", $params);
if(trim($s) == ""){ if(trim($s) == ""){
$output .= "Usage: /say <message>\n"; return "Usage: /say <message>";
break;
} }
$sender = ($issuer instanceof Player) ? "Server" : ucfirst($issuer); $sender = ($issuer instanceof Player) ? "Server" : ucfirst($issuer);
if(Utils::hasEmoji($s)) return "Your message contains illegal characters!"; if(Utils::hasEmoji($s)) return "Your message contains illegal characters!";
@ -41,8 +42,7 @@ class ChatAPI{
case "me": case "me":
$s = implode(" ", $params); $s = implode(" ", $params);
if(trim($s) == ""){ if(trim($s) == ""){
$output .= "Usage: /me <message>\n"; return "Usage: /me <message>";
break;
} }
if(!($issuer instanceof Player)){ if(!($issuer instanceof Player)){
if($issuer === "rcon"){ if($issuer === "rcon"){
@ -58,42 +58,58 @@ class ChatAPI{
$this->broadcast("* $sender $msg"); $this->broadcast("* $sender $msg");
break; break;
case "tell": case "tell":
if(!isset($params[0]) or !isset($params[1])){ if(!isset($params[0]) or !isset($params[1])) return "Usage: /$cmd <player> <message>\n";
$output .= "Usage: /$cmd <player> <message>\n";
break; if(!($issuer instanceof Player)) $sender = ucfirst($issuer);
} else $sender = $issuer->username;
if(!($issuer instanceof Player)){
$sender = ucfirst($issuer);
}else{
$sender = $issuer->username;
}
$n = array_shift($params); $n = array_shift($params);
$target = $this->server->api->player->get($n); $target = $this->server->api->player->get($n);
if($target instanceof Player){ if($target instanceof Player){
$target = $target->username; $target = $target->username;
}else{ }else{
$target = strtolower($n); $target = strtolower($n);
if($target === "server" or $target === "console" or $target === "rcon"){ if($target === "server" || $target === "console" || $target === "rcon"){
$target = "Console"; $target = "Console";
}else{ }else{
return "The player is offline."; return "$target is offline.";
} }
} }
if(strtolower($target) === strtolower($issuer)){ if(strtolower($target) === strtolower($sender)) return "You can't send message to yourself.";
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); $mes = implode(" ", $params);
if(Utils::hasEmoji($mes)) return "Your message contains illegal characters!"; if(Utils::hasEmoji($mes)) return "Your message contains illegal characters!";
$output .= "You're whispering to " . $target . ": " . $mes . "\n";
if($target !== "Console" and $target !== "Rcon"){ if($target !== "Console" && $target !== "Rcon") $this->sendTo(false, "$sender whispers to you: $mes", $target);
$this->sendTo(false, $sender . " whispers to you: " . $mes, $target); if($target === "Console" || $sender === "Console") console("[INFO] $sender whispers to $target: $mes");
}
if($target === "Console" or $sender === "Console"){ $this->lastTells[strtolower($target)] = strtolower($sender);
console("[INFO] " . $sender . " whispers to " . $target . ": " . $mes); $this->lastTells[strtolower($sender)] = strtolower($target);
}
break; return "You're whispering to $target: $mes";
} }
return $output;
} }
/** /**

View file

@ -1467,6 +1467,7 @@ class Player{
$this->chunkCount = []; $this->chunkCount = [];
$this->craftingItems = []; $this->craftingItems = [];
$this->received = []; $this->received = [];
unset($this->server->api->chat->lastTells[$this->iusername]);
//$this->entity->close(); //$this->entity->close();
} }
} }

View file

@ -22,7 +22,7 @@ class DandelionBlock extends FlowableBlock{
public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){ public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){
$downId = $level->level->getBlockID($x, $y - 1, $z); $downId = $level->level->getBlockID($x, $y - 1, $z);
if(StaticBlock::getIsTransparent($downId) and $downId !== FARMLAND){ //Replace with common break method 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); $level->fastSetBlockUpdate($x, $y, $z, 0, 0);
} }
} }