Skip to content
This repository has been archived by the owner on Jul 11, 2022. It is now read-only.

Commit

Permalink
Prepaire for Poggit Release on July 1, 2022 for #10
Browse files Browse the repository at this point in the history
  • Loading branch information
xqwtxon committed Jun 30, 2022
1 parent 6691704 commit 2d9dfdf
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 63 deletions.
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,22 @@ It is lightweight, easy to use, and easy to configure.
- [x] Profanity Filter Types!<br>
- [x] Custom Languages!<br>
- [x] Easy to configure.<br>
- [x] PluginAPI ([Wiki](https://github.com/xqwtxon/HiveProfanityFilter/wiki))
- [x] PluginAPI ([Wiki](https://github.com/xqwtxon/ProfanityFilter/wiki))

</details>

<h1>Screenshots 📷</h1>
<p align=center>
<img src="assets/chat-filter.jpg" align="center"><br>
<img src="assets/punish-from-player.jpg" align="center">
</p>



<h1>TODO: 🎯</h1>
<h1>TODO 🎯</h1>
<p align=left>
<ul>
<li>Other Country Languages (You can make <a href="https://github.com/xqwtxon/ProfanityFilter/pulls">pull request</a>)</li>
<li>Other Country Profanity Languages (You can make <a href="https://github.com/xqwtxon/ProfanityFilter/pulls">pull request</a>, but english only for <a href="https://github.com/xqwtxon/HiveProfanityFilter/blob/main/resources/banned-words.yml">global</a>)</li>
<li>Other Country Profanity Languages (You can make <a href="https://github.com/xqwtxon/ProfanityFilter/pulls">pull request</a>, but english only for <a href="https://github.com/xqwtxon/ProfanityFilter/blob/main/resources/banned-words.yml">global</a>)</li>
</ul>
</p>
<br>
Expand Down
Binary file added assets/chat-filter.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/punish-from-player.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 18 additions & 26 deletions resources/languages/custom.yml
Original file line number Diff line number Diff line change
@@ -1,43 +1,35 @@
---
# Custom Configuration
# You can change this if you want.
# Dont forget modify lang option value to "custom" in config.yml
# Custom Translation
# You can customize your own messages here. This file includes console message and play message even interface of form. If you want to contribute us making translation within this plugin. You can make your own language and make your own pull request on github.
outdated-config: "Your configuration is outdated. The configuration is renamed as old-config.yml"
outdated-plugin: "You are using an old version of plugin. Considering updating it to poggit or github releases."
new-update-prefix: "[Update Checker]"
new-update-found: "Your version of ProfanityFilter is out of date. Version %s was released for api %s."
new-update-details: "PocketMine API: %s to %s"
new-update-download: "Download: %s"
no-updates-found: "No Updates found! Enjoy!"
update-error: "Unable to Check Update. Please Check your connection and try again. %s"
config-notfound: "Creating config.yml..."
unable-to-check-update: "Unable check update at the moment. Please check your connection and try again."
config-corrupted: "Your config is currupted. It may cause issue or problems while reading your config."
stopped-plugin: "Sucessfully stopped work of plugin."
plugin-dir-notfound: "Creating plugin data..."
help-title: "Hive Profanity Filter"
help-title: "Profanity Filter"
help-subtitle: "List of profanity commands!"
help-page:
- "/pf help -- ProfanityFilter Help Command"
- "/pf ui -- Manage ProfanityFilter by GUI"
- "/pf credits -- View Plugin Creators & Contrubutors"
- "/pf type <hide/block-with-message/block> -- Changes the profanityfilter block option. (Please restart server to take effect.)"
- "/pf banned-words/list -- View all list currently banned-words."
- "/pf help — ProfanityFilter Help Command"
- "/pf ui — Manage ProfanityFilter by GUI"
- "/pf credits — View Plugin Creators & Contrubutors"
- "/pf banned-words/list — View all list currently banned-words."
profanity-command-only-ingame: "You can only use this at in-game!"
profanity-command-usage: "/pf <help/subcommand> [args]"
profanity-command-usage-execute: "Usage: /pf <help/subcommand> [args]"
banned-words-description: "These are currently banned words in config. It may cause some string like **** at in-game. So if you want to view them all, Check manualy banned-words config or in console."
banned-words-description-2: "If you want to add more. Kindly add banned-words in profanity config."
profanity-command-type-success-tip: "Please restart the server to take effect."
profanity-command-type-success: "Sucessfully set type of profanity filter to"
profanity-command-type-usage: "Usage: /pf type <hide/block/block-with-message>"
profanity-command-add-usage: "Usage: /pf add <word>"
profanity-command-add-success: "Sucessfully added profanity banned-words the word"
credits-title: "Hive Profanity Filter"
credits-subtitle: "https://github.com/xqwtxon/HiveProfanityFilter"
credits-description: "These are currently public contrubutors in plugin."
ui-pf-manage-title: "HiveProfanityFilter"
credits-title: "Profanity Filter"
credits-subtitle: "https://github.com/xqwtxon/ProfanityFilter"
credits-description: "These are currently public contributors in plugin."
ui-pf-manage-title: "ProfanityFilter"
ui-pf-manage-description: "Here you can manage here."
ui-pf-manage-button-1: "View Banned Words"
ui-pf-manage-button-2: "Change Profanity Filter"
ui-pf-manage-button-3: "Exit"
ui-pf-manage-button-4: "Hide"
ui-pf-manage-button-5: "Block"
ui-pf-manage-button-6: "Block With Message"
ui-pf-manage-button-exit: "Exit"
ui-pf-manage-button-return: "Return"
ui-pf-manage-type-profanity-description: "Here you can change type of profanityfilter.\nPlease restart your server to take effect."
...
File renamed without changes.
6 changes: 4 additions & 2 deletions src/Command/DefaultCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
use pocketmine\command\Command;
use pocketmine\command\CommandSender;
use pocketmine\player\Player;
use pocketmine\utils\Config;
use ProfanityFilter\Utils\Language;
use ProfanityFilter\Utils\Forms\SimpleForm;
use ProfanityFilter\Loader;

class DefaultCommand extends Command {
Expand All @@ -38,7 +40,7 @@ class DefaultCommand extends Command {
public function __construct(){
$this->plugin = Loader::getInstance();
$this->language = new Language();
parent::__construct("profanityfilter", "ProfanityFilter Management", $this->lang->translateMessage("profanity-command-usage"), ["pf"]);
parent::__construct("profanityfilter", "ProfanityFilter Management", "/profanityfilter <help/subcommand>", ["pf"]);
}

/*
Expand All @@ -57,7 +59,7 @@ public function execute(CommandSender $sender, string $commandLabel, array $args
case "help":
$sender->sendMessage($this->language->translateMessage("help-title"));
$sender->sendMessage($this->language->translateMessage("help-subtitle"));
foreach($this->language->translateMessage("help-title") as $command){
foreach($this->language->translateMessage("help-page") as $command){
$sender->sendMessage("- " . $command);
}
break;
Expand Down
3 changes: 2 additions & 1 deletion src/EventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

use pocketmine\event\Listener;
use pocketmine\event\player\PlayerChatEvent;
use pocketmine\event\player\PlayerCommandPreprocessEvent;
use ProfanityFilter\Loader;
use ProfanityFilter\Utils\Language;

Expand All @@ -47,7 +48,7 @@ public function __construct(string $type){
public function onChat(PlayerChatEvent $ev): void {
$message = $ev->getMessage();
$player = $ev->getPlayer();
$words = $this->plugin->getProfanity->get("banned-words");
$words = $this->plugin->getProfanity()->get("banned-words");
if(PluginAPI::detectProfanity($message, $words)){
switch($this->type){
case "block":
Expand Down
41 changes: 26 additions & 15 deletions src/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
namespace ProfanityFilter;

use pocketmine\plugin\PluginBase;
use pocketmime\utils\Config;
use pocketmine\utils\Config;
use pocketmine\Server;
use ProfanityFilter\DefaultCommand;
use ProfanityFilter\Command\DefaultCommand;
use ProfanityFilter\EventListener;
use ProfanityFilter\Utils\Language;
use ProfanityFilter\Tasks\UpdateTask;
Expand All @@ -36,10 +36,10 @@
class Loader extends PluginBase {

/** @var Loader $instance **/
private Loader $instance;
private static Loader $instance;

/** @var int $punishment **/
private int $punishment = 0;
public int $punishment = 0;


public function onLoad() :void {
Expand Down Expand Up @@ -79,7 +79,7 @@ private function checkConfig() :void {
$this->saveResource("config.yml");
}

private function loadListener() : void {
private function loadListeners() : void {
switch($this->getConfig()->get("type")){
case "block":
$this->getServer()->getPluginManager()->registerEvents(new EventListener("block"), $this);
Expand All @@ -104,26 +104,37 @@ private function registerCommands() : void {
* @param string $message
* @return string
*/
protected function formatMessage(string $message) : string {
public function formatMessage(string $message) : string { // TODO: Move this in the event class
$message = str_replace("{type}", $this->getConfig()->get("type"), $message);
return $message;
}

private function checkUpdate() :void {
$this->getServer()->getAsyncPool()->submitTask(new UpdateTask());
}

private function saveResources() :void {
foreach($this->getResources() as $resource){
$this->saveResource($resource->getFilename());
}
$this->getServer()->getAsyncPool()->submitTask(new UpdateTask($this->getDescription()->getName(), $this->getDescription()->getVersion()));
}

/*
* Get Profanity List. Do not call it directly.
* @return Config
*/
protected function getProfanity() : Config {
return new Config($this->getDataFolder() . "banned-words.yml");
public function getProfanity() : Config {
return new Config($this->getDataFolder() . "profanity.yml", Config::YAML);
}

/*
* Initilize the resource in the context.
* @return void
*/
private function saveResources(): void {
if(!file_exists($this->getDataFolder() . "languages/")){
@mkdir($this->getDataFolder() . "languages/");
}
if(!file_exists($this->getDataFolder() . "banned-words.yml")){
$this->saveResource("banned-words.yml");
}

foreach($this->getResources() as $file){
$this->saveResource($file->getFileName());
}
}
}
8 changes: 3 additions & 5 deletions src/Tasks/UpdateTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@ public function onRun() : void{
public function onCompletion() : void{
$lang = new Language();
$plugin = Server::getInstance()->getPluginManager()->getPlugin($this->pluginName);
if($plugin === null){
return;
}
if($plugin === null) return;

[$highestVersion, $artifactUrl, $api, $err] = $this->getResult();
if($err !== null){
Expand All @@ -76,9 +74,9 @@ public function onCompletion() : void{
}

if($highestVersion !== $this->pluginVersion){
$plugin->getServer()->getLogger()->error($lang->translateMessage("new-update-prefix") . " " . vsprintf($lang->translateMessage("new-update-found"), [$highestVersion, $api]));
$plugin->getServer()->getLogger()->warning($lang->translateMessage("new-update-prefix") . " " . vsprintf($lang->translateMessage("new-update-found"), [$highestVersion, $api]));
} else {
$plugin->getServer()->getLogger()->error($lang->translateMessage("new-update-prefix") . " " . $lang->translateMessage("no-updates-found"));
$plugin->getServer()->getLogger()->notice($lang->translateMessage("new-update-prefix") . " " . $lang->translateMessage("no-updates-found"));
}
}
}
Expand Down
18 changes: 8 additions & 10 deletions src/Utils/Language.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function __construct(){
}

public function getLanguage() : Config {
return new Config($this->plugin->getDataFolder() . "language/" . $this->getSelectedLanguage() . ".yml");
return new Config($this->plugin->getDataFolder() . "languages/" . $this->getSelectedLanguage() . ".yml");
}

public function getSelectedLanguage() :string {
Expand All @@ -48,26 +48,24 @@ public function getSelectedLanguage() :string {
* Translate Message from Language Configuration
* Do not call it directly.
*
* @param string $message
* @return string
* @param mixed $option
* @return mixed
*/
public function translateMessage(string $option) :string {
public function translateMessage(mixed $option) :mixed {
$lang = $this->getLanguage();

/** Check if selected language is missing. **/
if(is_null($this->getLanguage())) throw new \Exception("Missing file in " . $this->plugin->getDataFolder() . "language/" . $this->getSelectedLanguage() . ".yml");
if(is_null($this->getLanguage())) throw new \Exception("Missing file in " . $this->plugin->getDataFolder() . "languages/" . $this->getSelectedLanguage() . ".yml");

/** Check if option is exist. **/
if($lang->get($option) !== null) throw new \Exception("Trying to access on null.");
if($lang->get($option) === null) throw new \Exception("Trying to access on null.");

return $lang->get($option);
}

protected function init() :void {
if(!file_exist($this->plugin->getDataFolder() . "language/" . $this->getSelectedLanguage() . ".yml")){
public function init() :void {
if(!file_exists($this->plugin->getDataFolder() . "language/" . $this->getSelectedLanguage() . ".yml")){
$this->plugin->saveResource("languages/" . $this->getSelectedLanguage() . ".yml");
} else {
$this->getLanguage()->save();
}
}
}

0 comments on commit 2d9dfdf

Please sign in to comment.