From ccdea98d280de5acb2098a6f3dd6c5304c82d2aa Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Sun, 25 May 2025 20:24:35 +0300 Subject: [PATCH] added ability to disable emojis on signs --- src/API/ChatAPI.php | 4 ++-- src/Player.php | 4 +++- src/PocketMinecraftServer.php | 4 ++++ src/utils/Utils.php | 4 ++++ src/world/Level.php | 1 + src/world/Tile.php | 7 +++++++ 6 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/API/ChatAPI.php b/src/API/ChatAPI.php index eb29459b..ff6aaf2a 100644 --- a/src/API/ChatAPI.php +++ b/src/API/ChatAPI.php @@ -36,7 +36,7 @@ class ChatAPI{ return "Usage: /say "; } $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": @@ -54,7 +54,7 @@ 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": diff --git a/src/Player.php b/src/Player.php index 166640cf..4435c930 100755 --- a/src/Player.php +++ b/src/Player.php @@ -6,6 +6,7 @@ class Player{ public static $experimentalHotbar = false; public static $allowDroppingSingleItems = true; + public static $disableEmojisInChat = true; /** @var Config */ public $data; /** @var Entity */ @@ -2502,7 +2503,7 @@ class Player{ $this->server->api->console->run(substr($message, 1), $this); }else{ $data = ["player" => $this, "message" => $message]; - if(Utils::hasEmoji($data["message"])){ + if(Player::$disableEmojisInChat && Utils::hasEmoji($data["message"])){ $this->sendChat("Your message contains illegal characters"); break; } @@ -2712,6 +2713,7 @@ class Player{ if($d["id"] !== TILE_SIGN){ $t->spawn($this); }else{ + $t->setText($d["Text1"], $d["Text2"], $d["Text3"], $d["Text4"]); } } diff --git a/src/PocketMinecraftServer.php b/src/PocketMinecraftServer.php index b8590262..ac306df3 100644 --- a/src/PocketMinecraftServer.php +++ b/src/PocketMinecraftServer.php @@ -94,8 +94,12 @@ class PocketMinecraftServer{ "keep-chunks-loaded" => self::$KEEP_CHUNKS_LOADED, "use-experimental-hotbar" => Player::$experimentalHotbar, "keep-items-on-death" => Entity::$keepInventory, + "disable-emojis-in-chat" => Player::$disableEmojisInChat, + "disable-emojis-on-signs" => Level::$disableEmojisOnSigns, //"allow-dropping-single-items" => Player::$allowDroppingSingleItems ]); + Player::$disableEmojisInChat = $this->extraprops->get("disable-emojis-in-chat"); + Level::$disableEmojisOnSigns = $this->extraprops->get("disable-emojis-on-signs"); Entity::$keepInventory = $this->extraprops->get("keep-items-on-death"); Player::$experimentalHotbar = $this->extraprops->get("use-experimental-hotbar"); //Player::$allowDroppingSingleItems = $this->extraprops->get("allow-dropping-single-items"); diff --git a/src/utils/Utils.php b/src/utils/Utils.php index a6f8a08c..2f146cba 100644 --- a/src/utils/Utils.php +++ b/src/utils/Utils.php @@ -77,6 +77,10 @@ class Utils{ return preg_match(Utils::emojiRegex, $s); } + public static function replaceEmoji($s){ + return preg_replace(Utils::emojiRegex, " ", $s); + } + public static function getCallableIdentifier(callable $variable){ if(is_array($variable)){ return sha1(strtolower(get_class($variable[0])) . "::" . strtolower($variable[1])); diff --git a/src/world/Level.php b/src/world/Level.php index 9f743577..a3a907a2 100644 --- a/src/world/Level.php +++ b/src/world/Level.php @@ -1,6 +1,7 @@ class !== TILE_SIGN){ return false; } + if(Level::$disableEmojisOnSigns){ + $line1 = Utils::replaceEmoji($line1); + $line2 = Utils::replaceEmoji($line2); + $line3 = Utils::replaceEmoji($line3); + $line4 = Utils::replaceEmoji($line4); + + } $this->data["Text1"] = $line1; $this->data["Text2"] = $line2; $this->data["Text3"] = $line3;