Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: Vaivez66/NoAdvertisingPE
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: poggit-orphanage/NoAdvertisingPE
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Able to merge. These branches can be automatically merged.
  • 3 commits
  • 5 files changed
  • 1 contributor

Commits on Jul 22, 2018

  1. Fix indenting

    robske110 committed Jul 22, 2018

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    ed5a215 View commit details
  2. Improve english messages

    robske110 committed Jul 22, 2018
    Copy the full SHA
    822cb01 View commit details
  3. Update to API 3.0.0

    robske110 committed Jul 22, 2018
    Copy the full SHA
    fdff400 View commit details
12 changes: 6 additions & 6 deletions plugin.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
name: NoAdvertisingPE
main: Vaivez66\NoAdvertisingPE\NoAdvertising
version: 1.0.1
api: [1.12.0, 2.0.0]
version: 1.0.2
api: [3.0.0]
load: POSTWORLD
authors: [Vaivez66]
description: "Stop those advertiser!"
authors: [Vaivez66, robske_110]
description: "Stop those advertisers!"
commands:
na:
description: "Main command"
description: "Manage the domain list."
usage: "/na <add|remove|list> [domain]"
permissions:
no.advertising.pe:
description: "Permission to perform command"
description: "Permission to execute na"
default: op
no.advertising.pe.bypass:
description: "Permission to bypass from blocking"
12 changes: 6 additions & 6 deletions resources/config.yml
Original file line number Diff line number Diff line change
@@ -4,27 +4,27 @@
# - block
# - kick
type: block
# The message that will send
# The message that will be sent
# You can use {player} to mention their name
message: '{RED}Do not try to advertising!'
# Blocked domain names
message: '{RED}Do not try to advertise!'
# Blocked domain extensions
domain:
- ".me"
- ".com"
- ".net"
# The domains that allowed to use
# Whitelisted domains
allowed.domain:
- "yourserver.com"
- "pocketmine.net"
# If true, it will detect a sign
# If true, content on signs will also be filtered
detect.sign: true
# Lines that will change if player advertise on sign
lines:
- '============='
- 'No Advertising!'
- '============='
- ''
# The command that will protected from advertising
# Commands that will also be filtered
blocked.cmd:
- "/me"
- "/tell"
271 changes: 135 additions & 136 deletions src/Vaivez66/NoAdvertisingPE/NoAdvertising.php
Original file line number Diff line number Diff line change
@@ -9,147 +9,146 @@

class NoAdvertising extends PluginBase{

public $cfg;
private $format;

public function onEnable(){
$this->saveDefaultConfig();
$this->format = new NoAdvertisingFormat($this);
$this->cfg = new Config($this->getDataFolder() . "config.yml", Config::YAML, array());
$this->getServer()->getLogger()->info(TF::GREEN . "NoAdvertisingPE is ready!");
$this->getServer()->getPluginManager()->registerEvents(new NoAdvertisingListener($this), $this);
$this->getCommand("na")->setExecutor(new NoAdvertisingCommand($this));
}

/**
* @return array
*/

public function getDomain(){
$domain = (array) $this->cfg->get("domain");
return $domain;
}

/**
* @return array
*/

public function getAllowedDomain(){
$allowed = (array) $this->cfg->get("allowed.domain");
return $allowed;
}

/**
* @return mixed
*/

public function getType(){
return $this->cfg->get("type");
}

/**
* @return mixed
*/

public function getMsg(){
return $this->cfg->get("message");
}

/**
* @return bool
*/

public function detectSign(){
return $this->cfg->get('detect.sign') === true;
}

/**
* @return array
*/

public function getSignLines(){
return (array) $this->cfg->get('lines');
}

/**
* @return array
*/

public function getBlockedCmd(){
return (array) $this->cfg->get('blocked.cmd');
}

/**
* @param $p
* @param $name
* @return bool
*/

public function addDomain($p, $name){
$domain = $this->getDomain();
if(in_array($name, $domain)){
$p->sendMessage(TF::RED . "That domain already exist!");
return false;
public $cfg;
private $format;

public function onEnable(){
$this->saveDefaultConfig();
$this->format = new NoAdvertisingFormat($this);
$this->cfg = new Config($this->getDataFolder() . "config.yml", Config::YAML, array());
$this->getServer()->getPluginManager()->registerEvents(new NoAdvertisingListener($this), $this);
$this->getCommand("na")->setExecutor(new NoAdvertisingCommand($this));
}

/**
* @return array
*/

public function getDomain(){
$domain = (array) $this->cfg->get("domain");
return $domain;
}

/**
* @return array
*/

public function getAllowedDomain(){
$allowed = (array) $this->cfg->get("allowed.domain");
return $allowed;
}

/**
* @return mixed
*/

public function getType(){
return $this->cfg->get("type");
}

/**
* @return mixed
*/

public function getMsg(){
return $this->cfg->get("message");
}

/**
* @return bool
*/

public function detectSign(){
return $this->cfg->get('detect.sign') === true;
}

/**
* @return array
*/

public function getSignLines(){
return (array) $this->cfg->get('lines');
}

/**
* @return array
*/

public function getBlockedCmd(){
return (array) $this->cfg->get('blocked.cmd');
}

/**
* @param $p
* @param $name
* @return bool
*/

public function addDomain($p, $name){
$domain = $this->getDomain();
if(in_array($name, $domain)){
$p->sendMessage(TF::RED . "That domain already exist!");
return false;
}
$domain[] = $name;
$this->cfg->set("domain", $domain);
$this->cfg->save();
$p->sendMessage(TF::GREEN . "Successfully added " . $name . " into config");
return true;
}
$domain[] = $name;
$this->cfg->set("domain", $domain);
$this->cfg->save();
$p->sendMessage(TF::GREEN . "Successfully added " . $name . " into config");
return true;
}

/**
* @param $p
* @param $name
* @return bool
*/

public function removeDomain($p, $name){
$domain = $this->getDomain();
$key = array_search($name, $domain);
if($key === false){
$p->sendMessage(TF::RED . "That domain does not exist!");
return false;
}
unset($domain[$key]);
$this->cfg->set("domain", array_values($domain));
$this->cfg->save();
$p->sendMessage(TF::GREEN . "Successfully removed " . $name . " from config");
return true;
}

/**
* @param $p
* @return bool
*/

public function listDomain($p){
$domain = implode("\n" . TF::YELLOW . "- ", $this->getDomain());
$p->sendMessage(TF::YELLOW . "Available domain:");
$p->sendMessage(TF::YELLOW . "- " . $domain);
return true;
}

/**
* @param $m
*/

public function broadcastMsg($m){
foreach($this->getServer()->getOnlinePlayers() as $p){
$p->sendMessage($m);
/**
* @param $p
* @param $name
* @return bool
*/

public function removeDomain($p, $name){
$domain = $this->getDomain();
$key = array_search($name, $domain);
if($key === false){
$p->sendMessage(TF::RED . "That domain does not exist!");
return false;
}
unset($domain[$key]);
$this->cfg->set("domain", array_values($domain));
$this->cfg->save();
$p->sendMessage(TF::GREEN . "Successfully removed " . $name . " from config");
return true;
}
}

/**
* @return mixed
*/
/**
* @param $p
* @return bool
*/

public function getFormat(){
return $this->format;
}
public function listDomain($p){
$domain = implode("\n" . TF::YELLOW . "- ", $this->getDomain());
$p->sendMessage(TF::YELLOW . "Available domain:");
$p->sendMessage(TF::YELLOW . "- " . $domain);
return true;
}

/**
* @param $m
*/

public function broadcastMsg($m){
foreach($this->getServer()->getOnlinePlayers() as $p){
$p->sendMessage($m);
}
}

/**
* @return mixed
*/

public function getFormat(){
return $this->format;
}

public function onDisable(){
$this->getServer()->getLogger()->info(TF::RED . "NoAdvertisingPE was disabled!");
}
public function onDisable(){
$this->getServer()->getLogger()->info(TF::RED . "NoAdvertisingPE was disabled!");
}

}
18 changes: 7 additions & 11 deletions src/Vaivez66/NoAdvertisingPE/NoAdvertisingCommand.php
Original file line number Diff line number Diff line change
@@ -3,20 +3,20 @@
namespace Vaivez66\NoAdvertisingPE;

use pocketmine\Server;
use pocketmine\plugin\PluginBase;
use pocketmine\Player;
use pocketmine\command\Command;
use pocketmine\command\PluginCommand;
use pocketmine\command\CommandSender;
use pocketmine\command\CommandExecutor;
use pocketmine\utils\TextFormat as TF;

class NoAdvertisingCommand extends PluginBase implements CommandExecutor{
class NoAdvertisingCommand extends PluginCommand implements CommandExecutor{

public function __construct(NoAdvertising $plugin){
$this->plugin = $plugin;
}

public function onCommand(CommandSender $sender, Command $cmd, $label, array $args){
public function onCommand(CommandSender $sender, Command $cmd, string $label, array $args): bool{
switch(strtolower($cmd->getName())){
case "na":
if($sender->hasPermission("no.advertising.pe")) {
@@ -25,29 +25,25 @@ public function onCommand(CommandSender $sender, Command $cmd, $label, array $ar
case "add":
if(isset($args[1])){
return $this->plugin->addDomain($sender, $args[1]);
}
else{
}else{
return false;
}
break;
case "remove":
if(isset($args[1])){
return $this->plugin->removeDomain($sender, $args[1]);
}
else{
}else{
return false;
}
break;
case "list":
return $this->plugin->listDomain($sender);
break;
}
}
else{
}else{
return false;
}
}
else{
}else{
$sender->sendMessage(TF::RED . "You do not have permission");
return true;
}
4 changes: 2 additions & 2 deletions src/Vaivez66/NoAdvertisingPE/NoAdvertisingListener.php
Original file line number Diff line number Diff line change
@@ -69,7 +69,7 @@ public function onSign(SignChangeEvent $event){
for ($i = 0; $i <= 3; $i++) {
$event->setLine($i, $sign[$i]);
}
$p->sendMessage(TF::RED . 'Do not try to advertising, ' . $p->getName());
$p->sendMessage(TF::RED . 'Please do not advertise, ' . $p->getName());
}
}
}
@@ -93,7 +93,7 @@ public function onCmd(PlayerCommandPreprocessEvent $event){
foreach ($this->plugin->getDomain() as $d) {
if (stripos($m, $d) !== false) {
$event->setCancelled(true);
$p->sendMessage(TF::RED . 'Do not try to advertising with ' . $cmd . ', ' . $p->getName());
$p->sendMessage(TF::RED . 'Please do not advertise using ' . $cmd . ', ' . $p->getName());
}
}
}