Skip to content

Commit

Permalink
Merge pull request #49 from ReinfyTeam/php-cs-fixer
Browse files Browse the repository at this point in the history
Fix Code Syntax (Auto-Generated)
  • Loading branch information
xqwtxon authored Sep 3, 2022
2 parents 5338bab + 30c9cda commit 466f64b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 28 deletions.
22 changes: 11 additions & 11 deletions src/EventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@
use ReinfyTeam\ProfanityFilter\Utils\PluginUtils;

class EventListener implements Listener {
private Loader $plugin;
private Loader $plugin;

private string $type;
private ?array $duration;

private ?array $duration;

public function __construct(string $type) {
$this->plugin = Loader::getInstance();
Expand All @@ -58,7 +58,7 @@ public function onChat(PlayerChatEvent $event) : void {
case "block":
$event->cancel();
$player->sendMessage(PluginUtils::colorize($this->plugin->getConfig()->get("block-message")));
$this->plugin->getLogger()->warning(PluginUtils::format(PluginUtils::colorize($this->plugin->getConfig()->get("block-warning-message")), ["{player_name}"], [$player->getName()]));
$this->plugin->getLogger()->warning(PluginUtils::format(PluginUtils::colorize($this->plugin->getConfig()->get("block-warning-message")), ["{player_name}"], [$player->getName()]));
break;
case "hide":
/**
Expand All @@ -70,7 +70,7 @@ public function onChat(PlayerChatEvent $event) : void {
} else {
$event->setMessage(PluginAPI::removeProfanity($message, $words));
}
$this->plugin->getLogger()->warning(PluginUtils::format(PluginUtils::colorize($this->plugin->getConfig()->get("hide-warning-message")), ["{player_name}"], [$player->getName()]));
$this->plugin->getLogger()->warning(PluginUtils::format(PluginUtils::colorize($this->plugin->getConfig()->get("hide-warning-message")), ["{player_name}"], [$player->getName()]));
break;
default:
throw new Exception("Cannot Identify the type of profanity in config.yml");
Expand All @@ -81,12 +81,12 @@ public function onChat(PlayerChatEvent $event) : void {
$this->plugin->punishment[$player->getName()] = isset($this->plugin->punishment[$player->getName()]);
$player->getServer()->getNameBans()->addBan($player->getName(), "Profanity", $this->duration[0], $player->getServer()->getName());
$player->kick(PluginUtils::colorize($this->plugin->formatMessage($this->plugin->getConfig()->get("kick-message"))));
$this->plugin->getLogger()->warning(PluginUtils::format(PluginUtils::colorize($this->plugin->getConfig()->get("ban-warning-message")), ["{player_name}"], [$player->getName()]));
$this->plugin->getLogger()->warning(PluginUtils::format(PluginUtils::colorize($this->plugin->getConfig()->get("ban-warning-message")), ["{player_name}"], [$player->getName()]));
break;
case "kick":
$this->plugin->punishment[$player->getName()] = isset($this->plugin->punishment[$player->getName()]);
$player->kick(PluginUtils::colorize($this->plugin->formatMessage($this->plugin->getConfig()->get("kick-message"))));
$this->plugin->getLogger()->warning(PluginUtils::format(PluginUtils::colorize($this->plugin->getConfig()->get("kick-warning-message")), ["{player_name}"], [$player->getName()]));
$this->plugin->getLogger()->warning(PluginUtils::format(PluginUtils::colorize($this->plugin->getConfig()->get("kick-warning-message")), ["{player_name}"], [$player->getName()]));
break;
default:
throw new Exception("Cannot Identify the type of punishment in config.yml");
Expand All @@ -112,7 +112,7 @@ public function onCommand(PlayerCommandPreprocessEvent $event) : void {
case "block":
$event->cancel();
$player->sendMessage(PluginUtils::colorize($this->plugin->getConfig()->get("block-message")));
$this->plugin->getLogger()->warning(PluginUtils::format(PluginUtils::colorize($this->plugin->getConfig()->get("block-warning-message")), ["{player_name}"], [$player->getName()]));
$this->plugin->getLogger()->warning(PluginUtils::format(PluginUtils::colorize($this->plugin->getConfig()->get("block-warning-message")), ["{player_name}"], [$player->getName()]));
break;
case "hide":
/**
Expand All @@ -124,7 +124,7 @@ public function onCommand(PlayerCommandPreprocessEvent $event) : void {
} else {
$event->setMessage(PluginAPI::removeProfanity($message, $words));
}
$this->plugin->getLogger()->warning(PluginUtils::format(PluginUtils::colorize($this->plugin->getConfig()->get("hide-warning-message")), ["{player_name}"], [$player->getName()]));
$this->plugin->getLogger()->warning(PluginUtils::format(PluginUtils::colorize($this->plugin->getConfig()->get("hide-warning-message")), ["{player_name}"], [$player->getName()]));
break;
default:
throw new Exception("Cannot Identify the type of profanity in config.yml");
Expand All @@ -135,12 +135,12 @@ public function onCommand(PlayerCommandPreprocessEvent $event) : void {
$this->plugin->punishment[$player->getName()] = isset($this->plugin->punishment[$player->getName()]);
$player->getServer()->getNameBans()->addBan($player->getName(), "Profanity", $this->duration[0], $player->getServer()->getName());
$player->kick(PluginUtils::colorize($this->plugin->formatMessage($this->plugin->getConfig()->get("kick-message"))));
$this->plugin->getLogger()->warning(PluginUtils::format(PluginUtils::colorize($this->plugin->getConfig()->get("ban-warning-message")), ["{player_name}"], [$player->getName()]));
$this->plugin->getLogger()->warning(PluginUtils::format(PluginUtils::colorize($this->plugin->getConfig()->get("ban-warning-message")), ["{player_name}"], [$player->getName()]));
break;
case "kick":
$this->plugin->punishment[$player->getName()] = isset($this->plugin->punishment[$player->getName()]);
$player->kick(PluginUtils::colorize($this->plugin->formatMessage($this->plugin->getConfig()->get("kick-message"))));
$this->plugin->getLogger()->warning(PluginUtils::format(PluginUtils::colorize($this->plugin->getConfig()->get("kick-warning-message")), ["{player_name}"], [$player->getName()]));
$this->plugin->getLogger()->warning(PluginUtils::format(PluginUtils::colorize($this->plugin->getConfig()->get("kick-warning-message")), ["{player_name}"], [$player->getName()]));
break;
default:
throw new Exception("Cannot Identify the type of punishment in config.yml");
Expand Down
14 changes: 6 additions & 8 deletions src/PluginAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
use function strlen;

final class PluginAPI {

/**
* Whether to detect message on provided words.
*/
Expand Down Expand Up @@ -69,7 +68,6 @@ public static function removeProfanity(string $message, array $words, string $re
* TODO: Improve this blocking in future...
*/
public static function removeUnicode(string $text, bool $include_unicode = false) : string {

// Single Characters
$text = preg_replace("/[∂άαáàâãªä]/u", "a", $text);
$text = preg_replace("/[∆лДΛдАÁÀÂÃÄ]/u", "A", $text);
Expand Down Expand Up @@ -152,12 +150,12 @@ public static function removeUnicode(string $text, bool $include_unicode = false
$text = preg_replace("/[‰]/u", "%", $text);
$text = preg_replace("/[↨↕↓↑│]/u", "|", $text);
$text = preg_replace("/[∞∩∫⌂⌠⌡]/u", "", $text);
if($include_unicode){
// Remove Unicode Characters
$text = preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $text);
}

if ($include_unicode) {
// Remove Unicode Characters
$text = preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $text);
}

return $text;
}

Expand Down
17 changes: 8 additions & 9 deletions src/Utils/PluginUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
use function str_replace;

final class PluginUtils {

/**
* Colorise Messages turns & to § and etc.
*/
Expand Down Expand Up @@ -75,12 +74,12 @@ public static function formatMessage(?Player $player = null, string $message) :
}
}

public static function format(string $message, array $options, array $value) : string{
foreach($value as $v){
foreach($options as $o){
$message = str_replace($o, $v, $message);
}
}
return $message;
}
public static function format(string $message, array $options, array $value) : string {
foreach ($value as $v) {
foreach ($options as $o) {
$message = str_replace($o, $v, $message);
}
}
return $message;
}
}

0 comments on commit 466f64b

Please sign in to comment.