КОД
public function onPlayerChat(PlayerChatEvent $event) {
$player = $event->getPlayer();
$message = $event->getMessage();
$group = $this->purePerms->getUserDataMgr()->getGroup($player);
if (is_object($group)) {
$group = (string) $group;
}
if (!isset($this->groups[$group])) {
$this->groups[$group] = [
'chat' => "%group% %name%: %message%",
'abovehead' => "%group% %player%",
'tab' => "%group% %player%"
];
file_put_contents($this->getDataFolder() . 'groups.yml', yaml_emit($this->groups, YAML_UTF8_ENCODING));
}
if (isset($this->groups[$group])) {
$groupData = $this->groups[$group];
$chatFormat = isset($groupData['chat']) ? $groupData['chat'] : "%name%: %message%";
$formattedMessage = $this->applyPlaceholders($chatFormat, $player, $message, $group);
$event->setFormat($formattedMessage);
}
}
public function onGroupChanged(Player $player) {
$group = $this->purePerms->getUserDataMgr()->getGroup($player);
if (is_object($group)) {
$group = (string) $group;
}
if (!isset($this->groups[$group])) {
$this->groups[$group] = [
'chat' => "%group% %name%: %message%",
'abovehead' => "%group% %player%",
'tab' => "%group% %player%"
];
file_put_contents($this->getDataFolder() . 'groups.yml', yaml_emit($this->groups, YAML_UTF8_ENCODING));
}
if (isset($this->groups[$group])) {
$groupData = $this->groups[$group];
$abovehead = isset($groupData['abovehead']) ? $this->applyPlaceholders($groupData['abovehead'], $player, '', $group) : "%group% %player%";
$player->setNameTag($abovehead);
$tabName = isset($groupData['tab']) ? $this->applyPlaceholders($groupData['tab'], $player, '', $group) : "%group% %player%";
$player->setDisplayName($tabName);
}
}
public function onPlayerJoin(PlayerJoinEvent $event) {
$player = $event->getPlayer();
$group = $this->purePerms->getUserDataMgr()->getGroup($player);
if (is_object($group)) {
$group = (string) $group;
}
if (!isset($this->groups[$group])) {
$this->groups[$group] = [
'chat' => "%group% %name%: %message%",
'abovehead' => "%group% %player%",
'tab' => "%group% %player%"
];
file_put_contents($this->getDataFolder() . 'groups.yml', yaml_emit($this->groups, YAML_UTF8_ENCODING));
}
if (isset($this->groups[$group])) {
$groupData = $this->groups[$group];
$abovehead = isset($groupData['abovehead']) ? $this->applyPlaceholders($groupData['abovehead'], $player, '', $group) : "%group% %player%";
$player->setNameTag($abovehead);
$tabName = isset($groupData['tab']) ? $this->applyPlaceholders($groupData['tab'], $player, '', $group) : "%group% %player%";
$player->setDisplayName($tabName);
}
}
private function applyPlaceholders($string, Player $player, $message = "", $group = "") {
$string = str_replace(
["%name%", "%player%", "%message%", "%group%"],
[$player->getName(), $player->getName(), $message, $group],
$string
);
return $string;
}
groups.yml
default:
chat: "§7§lᴘʟᴀʏᴇʀ§r §f%player% §8→ §7%message%"
abovehead: "§7§lᴘʟᴀʏᴇʀ§r §7%player%"
tab: "§7● §lᴘʟᴀʏᴇʀ§r §7%player%"
chat - это чат
abovehead - над головой
tab - в табе(displayname)
Почему-то над головой отображается в displayname. А что в displayname должно другое немного