Skip to content

Commit

Permalink
Updated to PocketMine-MP API 3.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Flavius12 committed Jul 6, 2018
1 parent bffa482 commit 9db0018
Show file tree
Hide file tree
Showing 10 changed files with 179 additions and 198 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ PocketMine-MP plugins

## Requirements

PocketMine-MP 1.7dev API 3.0.0-ALPHA7 -> 3.0.0-ALPHA12
PocketMine-MP API 3.0.0

## Overview

Expand Down
4 changes: 2 additions & 2 deletions plugin.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: ChatCensor
main: ChatCensor\ChatCensor
version: 2.2
api: [3.0.0-ALPHA7, 3.0.0-ALPHA8, 3.0.0-ALPHA9, 3.0.0-ALPHA10, 3.0.0-ALPHA11, 3.0.0-ALPHA12]
version: 2.3
api: [3.0.0]
load: STARTUP
author: EvolSoft
description: A powerful chat censoring plugin
Expand Down
132 changes: 50 additions & 82 deletions src/ChatCensor/ChatCensor.php
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
<?php

/*
* ChatCensor (v2.2) by EvolSoft
* Developer: EvolSoft (Flavius12)
* ChatCensor v2.3 by EvolSoft
* Developer: Flavius12
* Website: https://www.evolsoft.tk
* Date: 08/01/2018 04:05 PM (UTC)
* Copyright & License: (C) 2014-2018 EvolSoft
* Copyright (C) 2014-2018 EvolSoft
* Licensed under MIT (https://github.com/EvolSoft/ChatCensor/blob/master/LICENSE)
*/

namespace ChatCensor;

use pocketmine\plugin\PluginBase;
use pocketmine\utils\Config;
use pocketmine\utils\TextFormat;
use const pocketmine\API_VERSION;

class ChatCensor extends PluginBase {

/** @var string */
const PREFIX = "&c[-&aChatCensor&c-] ";
const PREFIX = "&c[-&aChatCensor&c-]";

/** @var Config */
/** @var string */
const API_VERSION = "2.0";

/** @var array */
public $cfg;

/** @var Config */
Expand All @@ -33,59 +33,12 @@ class ChatCensor extends PluginBase {
/** @var Config */
private $messages;

/** @var float */
const API_VERSION = 1.0;

/** @var ChatCensor $object */
private static $object = null;

/**
* Get ChatCensor API
*
* @return ChatCensor
*/
public static function getAPI() : ChatCensor {
return self::$object;
}

/**
* Translate Minecraft colors
*
* @param string $symbol
* @param string $message
*
* @return string
*/
public function translateColors($symbol, $message){
$message = str_replace($symbol . "0", TextFormat::BLACK, $message);
$message = str_replace($symbol . "1", TextFormat::DARK_BLUE, $message);
$message = str_replace($symbol . "2", TextFormat::DARK_GREEN, $message);
$message = str_replace($symbol . "3", TextFormat::DARK_AQUA, $message);
$message = str_replace($symbol . "4", TextFormat::DARK_RED, $message);
$message = str_replace($symbol . "5", TextFormat::DARK_PURPLE, $message);
$message = str_replace($symbol . "6", TextFormat::GOLD, $message);
$message = str_replace($symbol . "7", TextFormat::GRAY, $message);
$message = str_replace($symbol . "8", TextFormat::DARK_GRAY, $message);
$message = str_replace($symbol . "9", TextFormat::BLUE, $message);
$message = str_replace($symbol . "a", TextFormat::GREEN, $message);
$message = str_replace($symbol . "b", TextFormat::AQUA, $message);
$message = str_replace($symbol . "c", TextFormat::RED, $message);
$message = str_replace($symbol . "d", TextFormat::LIGHT_PURPLE, $message);
$message = str_replace($symbol . "e", TextFormat::YELLOW, $message);
$message = str_replace($symbol . "f", TextFormat::WHITE, $message);

$message = str_replace($symbol . "k", TextFormat::OBFUSCATED, $message);
$message = str_replace($symbol . "l", TextFormat::BOLD, $message);
$message = str_replace($symbol . "m", TextFormat::STRIKETHROUGH, $message);
$message = str_replace($symbol . "n", TextFormat::UNDERLINE, $message);
$message = str_replace($symbol . "o", TextFormat::ITALIC, $message);
$message = str_replace($symbol . "r", TextFormat::RESET, $message);
return $message;
}
/** @var ChatCensor */
private static $instance = null;

public function onLoad(){
if(!(self::$object instanceof ChatCensor)){
self::$object = $this;
if(!(self::$instance instanceof ChatCensor)){
self::$instance = $this;
}
}

Expand All @@ -96,7 +49,7 @@ public function onEnable(){
$this->words = new Config($this->getDataFolder() . "words.yml", Config::YAML);
$this->muted = new Config($this->getDataFolder() . "muted.yml", Config::YAML);
$this->messages = new Config($this->getDataFolder() . "messages.yml", Config::YAML);
$this->cfg = $this->getConfig();
$this->cfg = $this->getConfig()->getAll();
$this->getCommand("chatcensor")->setExecutor(new Commands\Commands($this));
$this->getCommand("addword")->setExecutor(new Commands\AddWord($this));
$this->getCommand("removeword")->setExecutor(new Commands\RemoveWord($this));
Expand All @@ -106,6 +59,24 @@ public function onEnable(){
$this->getServer()->getPluginManager()->registerEvents(new EventListener($this), $this);
}

/**
* Get ChatCensor API
*
* @return ChatCensor
*/
public static function getAPI(){
return self::$instance;
}

/**
* Get ChatCensor version
*
* @return string
*/
public function getVersion(){
return $this->getVersion();
}

/**
* Get ChatCensor API version
*
Expand All @@ -115,13 +86,24 @@ public function getAPIVersion(){
return self::API_VERSION;
}

/**
* Reload ChatCensor configuration
*/
public function reload(){
$this->reloadConfig();
$this->cfg = $this->getConfig()->getAll();
$this->muted->reload();
$this->words->reload();
$this->messages->reload();
}

/**
* Get the list of allowed characters
*
* @return string
*/
public function getAllowedChars(){
return $this->getConfig()->getAll()["char-check"]["allowed-chars"];
return $this->cfg["char-check"]["allowed-chars"];
}

/**
Expand All @@ -130,7 +112,7 @@ public function getAllowedChars(){
* @return string
*/
public function getUnallowedChars(){
return $this->getConfig()->getAll()["char-check"]["unallowed-chars"];
return $this->cfg["char-check"]["unallowed-chars"];
}

/**
Expand All @@ -141,14 +123,14 @@ public function getUnallowedChars(){
* @return array|bool
*/
public function getWord($word){
if($this->cfg->getAll()["censor"]["advanced-mode"]){
if($this->cfg["censor"]["advanced-mode"]){
if($this->wordExists($word, $k)){
return $this->words->getAll()[$k];
return $this->words->get($k);
}
return false;
}
if($this->wordExists($word)){
return $this->words->getAll()[$word];
return $this->words->get($word);
}
return false;
}
Expand All @@ -162,7 +144,7 @@ public function getWord($word){
* @return bool
*/
public function wordExists($word, &$k = null) : bool {
if($this->cfg->getAll()["censor"]["advanced-mode"]){
if($this->cfg["censor"]["advanced-mode"]){
foreach($this->words->getAll() as $key => $value){
if(strpos($word, $key) !== false){
$k = $key;
Expand All @@ -172,7 +154,7 @@ public function wordExists($word, &$k = null) : bool {
return false;
}
$k = $word;
return isset($this->words->getAll()[$word]);
return $this->words->exists($word);
}

/**
Expand Down Expand Up @@ -279,21 +261,7 @@ public function getMessage($id){
return $this->messages->get($id);
}
}

/**
* Reload ChatCensor messages
*/
public function reloadMessages(){
$this->messages->reload();
}

/**
* Reload words configuration
*/
public function reloadWords(){
$this->words->reload();
}


/**
* Replace variables inside a string
*
Expand Down
24 changes: 13 additions & 11 deletions src/ChatCensor/Commands/AddWord.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
<?php

/*
* ChatCensor (v2.2) by EvolSoft
* Developer: EvolSoft (Flavius12)
* ChatCensor v2.3 by EvolSoft
* Developer: Flavius12
* Website: https://www.evolsoft.tk
* Date: 08/01/2018 01:37 PM (UTC)
* Copyright & License: (C) 2014-2018 EvolSoft
* Copyright (C) 2014-2018 EvolSoft
* Licensed under MIT (https://github.com/EvolSoft/ChatCensor/blob/master/LICENSE)
*/

namespace ChatCensor\Commands;

use pocketmine\plugin\PluginBase;
use pocketmine\command\Command;
use pocketmine\command\CommandExecutor;
use pocketmine\command\CommandSender;
use pocketmine\command\PluginCommand;
use pocketmine\utils\TextFormat;

use ChatCensor\ChatCensor;

class AddWord extends PluginBase implements CommandExecutor {
class AddWord extends PluginCommand implements CommandExecutor {

/** @var ChatCensor */
private $plugin;

public function __construct(ChatCensor $plugin){
$this->plugin = $plugin;
Expand All @@ -28,18 +31,17 @@ public function onCommand(CommandSender $sender, Command $cmd, $label, array $ar
if($sender->hasPermission("chatcensor.commands.addword")){
if(isset($args[0])){
$args[0] = strtolower($args[0]);
//Check if word exists
if($this->plugin->wordExists($args[0])){
$sender->sendMessage($this->plugin->translateColors("&", ChatCensor::PREFIX . "&cWord already added."));
$sender->sendMessage(TextFormat::colorize(ChatCensor::PREFIX . " &cWord already added."));
}else{
$this->plugin->addWord($args[0]);
$sender->sendMessage($this->plugin->translateColors("&", ChatCensor::PREFIX . "&aWord added!"));
$sender->sendMessage(TextFormat::colorize(ChatCensor::PREFIX . " &aWord added!"));
}
}else{
$sender->sendMessage($this->plugin->translateColors("&", ChatCensor::PREFIX . "&cUsage: /addword <word>"));
$sender->sendMessage(TextFormat::colorize(ChatCensor::PREFIX . " &cUsage: /addword <word>"));
}
}else{
$sender->sendMessage($this->plugin->translateColors("&", "&cYou don't have permissions to use this command"));
$sender->sendMessage(TextFormat::colorize("&cYou don't have permissions to use this command"));
}
return true;
}
Expand Down
Loading

0 comments on commit 9db0018

Please sign in to comment.