Merge branch 'master'

# Conflicts:
#	src/API/AchievementAPI.php
#	src/API/BanAPI.php
#	src/API/BlockAPI.php
#	src/API/EntityAPI.php
#	src/API/PlayerAPI.php
#	src/Player.php
#	src/PocketMinecraftServer.php
#	src/config.php
#	src/entity/Animal.php
#	src/entity/Breedable.php
#	src/entity/Creature.php
#	src/entity/Entity.php
#	src/entity/animal/Sheep.php
#	src/entity/monster/Creeper.php
#	src/entity/monster/Zombie.php
#	src/entity/object/Arrow.php
#	src/entity/object/FallingSand.php
#	src/entity/object/ItemEntity.php
#	src/entity/object/Minecart.php
#	src/entity/object/Painting.php
#	src/entity/object/PrimedTNT.php
#	src/material/Block.php
#	src/material/Item.php
#	src/material/Material.php
#	src/material/StaticBlock.php
#	src/material/block/DoorBlock.php
#	src/material/block/GenericBlock.php
#	src/material/block/attachable/WallSignBlock.php
#	src/material/block/liquid/LiquidBlockDynamic.php
#	src/material/block/misc/AirBlock.php
#	src/material/block/misc/BedBlock.php
#	src/material/block/misc/TNTBlock.php
#	src/material/block/nonfull/CarpetBlock.php
#	src/material/block/nonfull/FenceBlock.php
#	src/material/block/nonfull/PoweredRailBlock.php
#	src/material/block/nonfull/RailBlock.php
#	src/material/block/nonfull/SnowLayerBlock.php
#	src/material/block/nonfull/WoodSlabBlock.php
#	src/material/block/plant/BrownMushroomBlock.php
#	src/material/block/plant/DandelionBlock.php
#	src/material/block/plant/MelonStemBlock.php
#	src/material/block/plant/PumpkinStemBlock.php
#	src/material/block/plant/RedMushroomBlock.php
#	src/material/block/plant/SugarcaneBlock.php
#	src/material/block/solid/GrassBlock.php
#	src/material/block/solid/IceBlock.php
#	src/material/block/solid/LeavesBlock.php
#	src/material/block/solid/ObsidianBlock.php
#	src/material/block/solid/PumpkinBlock.php
#	src/material/block/solid/WoolBlock.php
#	src/material/item/base/ItemHoe.php
#	src/material/item/base/ItemTool.php
#	src/material/item/generic/DyeItem.php
#	src/material/item/generic/SpawnEggItem.php
#	src/material/item/tool/FlintSteelItem.php
#	src/material/item/tool/ShearsItem.php
#	src/math/AxisAlignedBB.php
#	src/network/MinecraftInterface.php
#	src/network/UDPSocket.php
#	src/network/protocol/packet/AddItemEntityPacket.php
#	src/network/protocol/packet/ContainerSetContentPacket.php
#	src/network/raknet/RakNetDataPacket.php
#	src/network/raknet/RakNetParser.php
#	src/pmf/PMFLevel.php
#	src/utils/Utils.php
#	src/world/Explosion.php
#	src/world/Level.php
#	src/world/MobSpawner.php
This commit is contained in:
yefengeeeeeeeeeee 2026-04-04 14:52:08 +08:00
commit 3fbab46e60
245 changed files with 6118 additions and 3408 deletions

View file

@ -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", "<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("say", "<message ...>", [$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,23 +29,20 @@ 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 <message>\n";
break;
return "Usage: /say <message>";
}
$sender = ($issuer instanceof Player) ? "Server" : ucfirst($issuer);
if(Utils::hasEmoji($s)) return "Your message contains illegal characters!";
if(Player::$disableEmojisInChat && Utils::hasEmoji($s)) return "Your message contains illegal characters!";
$this->server->api->chat->broadcast("[$sender] " . $s);
break;
case "me":
$s = implode(" ", $params);
if(trim($s) == ""){
$output .= "Usage: /me <message>\n";
break;
return "Usage: /me <message>";
}
if(!($issuer instanceof Player)){
if($issuer === "rcon"){
@ -54,46 +54,62 @@ class ChatAPI{
$sender = $issuer->username;
}
$msg = implode(" ", $params);
if(Utils::hasEmoji($msg)) return "Your message contains illegal characters!";
if(Player::$disableEmojisInChat && Utils::hasEmoji($msg)) return "Your message contains illegal characters!";
$this->broadcast("* $sender $msg");
break;
case "tell":
if(!isset($params[0]) or !isset($params[1])){
$output .= "Usage: /$cmd <player> <message>\n";
break;
}
if(!($issuer instanceof Player)){
$sender = ucfirst($issuer);
}else{
$sender = $issuer->username;
}
if(!isset($params[0]) or !isset($params[1])) return "Usage: /$cmd <player> <message>\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;
}
/**