Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions plugin.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
name: PureChat
main: _64FF00\PureChat\PureChat
version: 2.0.2
api: [4.0.0]
version: 2.1.2
api: [5.0.0]
load: POSTWORLD
author: [Vecnavium , 64FF00]
authors:
- "DemonicDev (bump to API5)"
depend: [PurePerms]
softdepend: [FactionsPro, XeviousPE-Factions]
commands:
Expand Down
28 changes: 28 additions & 0 deletions src/_64FF00/PureChat/ChatFormat.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace _64FF00\PureChat;
use pocketmine\player\chat\ChatFormatter;
use pocketmine\lang\Translatable;
use _64FF00\PureChat\PureChat;
use pocketmine\player\Player;
use pocketmine\utils\TextFormat;
use pocketmine\world\World;
class ChatFormat implements ChatFormatter
{

public PureChat $PureChat;
public $player;
public $WorldName;
public function __construct($player, $message, $WorldName, $PureChat)
{
$this->PureChat = $PureChat;
$this->player = $player;
$this->WorldName = $WorldName;
$this->format("", $message);
}

public function format($username, $message): Translatable|string{
$msg = $this->PureChat->getChatFormat($this->player, $message, $this->WorldName);
return $msg;
}
}
7 changes: 4 additions & 3 deletions src/_64FF00/PureChat/PCListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use pocketmine\event\player\PlayerJoinEvent;
use pocketmine\player\IPlayer;
use pocketmine\player\Player;

use _64FF00\PureChat\ChatFormat;
class PCListener implements Listener
{
/*
Expand Down Expand Up @@ -69,7 +69,8 @@ public function onPlayerChat(PlayerChatEvent $event)
$player = $event->getPlayer();
$message = $event->getMessage();
$WorldName = $this->plugin->getConfig()->get("enable-multiworld-chat") ? $player->getWorld()->getDisplayName() : null;
$chatFormat = $this->plugin->getChatFormat($player, $message, $WorldName);
$event->setFormat($chatFormat);
$ChatFormat = new ChatFormat($player, $message, $WorldName, $this->plugin);
$event->setFormatter($ChatFormat);
}

}
140 changes: 76 additions & 64 deletions src/_64FF00/PureChat/PureChat.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ class PureChat extends PluginBase
private Config $config;

private PurePerms $purePerms;
public function getPurePerms(){
return $this->purePerms;
}
public function getthisConfig(){
return $this->config;
}


public function onLoad(): void
{
Expand Down Expand Up @@ -234,42 +241,8 @@ private function fixOldData(string $string): string
888 888 d88P 888 888 8888888
*/

public function applyColors(string $string): string
{
return TextFormat::colorize($string);
}

public function applyPCTags(string $string, Player $player, ?string $message, ?string $WorldName): string
{
// TODO
$string = str_replace("{display_name}", $player->getDisplayName(), $string);
if($message === null)
$message = "";
if($player->hasPermission("pchat.coloredMessages"))
{
$string = str_replace("{msg}", $this->applyColors($message), $string);
}
else
{
$string = str_replace("{msg}", $this->stripColors($message), $string);
}
{
$string = str_replace("{fac_name}", '', $string);
$string = str_replace("{fac_rank}", '', $string);
}
$string = str_replace("{world}", ($WorldName === null ? "" : $WorldName), $string);
$string = str_replace("{prefix}", $this->getPrefix($player, $WorldName), $string);
$string = str_replace("{suffix}", $this->getSuffix($player, $WorldName), $string);
return $string;
}

public function getChatFormat(Player $player, ?string $message, ?string $WorldName = null): string
{
$originalChatFormat = $this->getOriginalChatFormat($player, $WorldName);
$chatFormat = $this->applyColors($originalChatFormat);
$chatFormat = $this->applyPCTags($chatFormat, $player, $message, $WorldName);
return $chatFormat;
}

public function getNametag(Player $player, ?string $WorldName = null): string
{
Expand All @@ -279,37 +252,7 @@ public function getNametag(Player $player, ?string $WorldName = null): string
return $nameTag;
}

public function getOriginalChatFormat(Player $player, ?string $WorldName = null): string
{
/** @var \_64FF00\PurePerms\PPGroup $group */
$group = $this->purePerms->getUserDataMgr()->getGroup($player, $WorldName);
if($WorldName === null)
{
$originalChatFormat = $this->config->getNested("groups." . $group->getName() . ".chat");
if(!is_string($originalChatFormat))
{
$this->getLogger()->critical("Invalid chat format found in config.yml (Group: " . $group->getName() . ") / Setting it to default value.");
$this->config->setNested("groups." . $group->getName() . ".chat", $originalChatFormat = "&8&l[" . $group->getName() . "]&f&r {display_name} &7> {msg}");
$this->config->save();
$this->config->reload();
}

return $originalChatFormat;
}
else
{
$originalChatFormat = $this->config->getNested("groups." . $group->getName() . "worlds.$WorldName.chat");
if(!is_string($originalChatFormat))
{
$this->getLogger()->critical("Invalid chat format found in config.yml (Group: " . $group->getName() . ", WorldName = $WorldName) / Setting it to default value.");
$this->config->setNested("groups." . $group->getName() . "worlds.$WorldName.chat", $originalChatFormat = "&8&l[" . $group->getName() . "]&f&r {display_name} &7> {msg}");
$this->config->save();
$this->config->reload();
}

return $originalChatFormat;
}
}

public function getOriginalNametag(Player $player, ?string $WorldName = null): string
{
Expand Down Expand Up @@ -440,4 +383,73 @@ public function stripColors(string $string): string
{
return TextFormat::clean($string);
}

public function applyColors(string $string): string
{
return TextFormat::colorize($string);
}

public function applyPCTags(string $string, Player $player, ?string $message, ?string $WorldName): string
{
// TODO
$string = str_replace("{display_name}", $player->getDisplayName(), $string);
if($message === null)
$message = "";
if($player->hasPermission("pchat.coloredMessages"))
{
$string = str_replace("{msg}", $this->applyColors($message), $string);
}
else
{
$string = str_replace("{msg}", $this->stripColors($message), $string);
}
{
$string = str_replace("{fac_name}", '', $string);
$string = str_replace("{fac_rank}", '', $string);
}
$string = str_replace("{world}", ($WorldName === null ? "" : $WorldName), $string);
$string = str_replace("{prefix}", $this->getPrefix($player, $WorldName), $string);
$string = str_replace("{suffix}", $this->getSuffix($player, $WorldName), $string);
return $string;
}
public function getChatFormat(Player $player, ?string $message, ?string $WorldName = null): string
{
$originalChatFormat = $this->getOriginalChatFormat($player, $WorldName);
$chatFormat = $this->applyColors($originalChatFormat);
$chatFormat = $this->applyPCTags($chatFormat, $player, $message, $WorldName);
return $chatFormat;
}
public function getOriginalChatFormat(Player $player, ?string $WorldName = null): string
{
/** @var \_64FF00\PurePerms\PPGroup $group */
$group = $this->purePerms->getUserDataMgr()->getGroup($player, $WorldName);
if($WorldName === null)
{
$originalChatFormat = $this->config->getNested("groups." . $group->getName() . ".chat");
if(!is_string($originalChatFormat))
{
$this->getLogger()->critical("Invalid chat format found in config.yml (Group: " . $group->getName() . ") / Setting it to default value.");
$this->config->setNested("groups." . $group->getName() . ".chat", $originalChatFormat = "&8&l[" . $group->getName() . "]&f&r {display_name} &7> {msg}");
$this->config->save();
$this->config->reload();
}

return $originalChatFormat;
}
else
{
$originalChatFormat = $this->config->getNested("groups." . $group->getName() . "worlds.$WorldName.chat");
if(!is_string($originalChatFormat))
{
$this->getLogger()->critical("Invalid chat format found in config.yml (Group: " . $group->getName() . ", WorldName = $WorldName) / Setting it to default value.");
$this->config->setNested("groups." . $group->getName() . "worlds.$WorldName.chat", $originalChatFormat = "&8&l[" . $group->getName() . "]&f&r {display_name} &7> {msg}");
$this->config->save();
$this->config->reload();
}

return $originalChatFormat;
}
}


}