Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add {ITEM} #47

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 10 additions & 16 deletions CustomAlerts/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,22 @@
name: CustomAlerts
main: CustomAlerts\CustomAlerts
version: 2.1
api: [3.0.0]
api: [4.0.0]
load: STARTUP
author: EvolSoft
description: Customize or hide alerts (join/leave messages, whitelist messages, outdated server/client messages, etc...) plugin
website: https://www.evolsoft.tk

commands:
customalerts:
aliases: [calerts]
description: CustomAlerts commands.
permission: customalerts
permissions:
customalerts:
default: op
description: CustomAlerts permission tree.
children:
customalerts.help:
default: op
description: let player read CustomAlerts commands help.
customalerts.info:
default: op
description: Let player read info about CustomAlerts.
customalerts.reload:
default: op
description: Let player reload CustomAlerts configuration.
customalerts.help:
default: op
description: let player read CustomAlerts commands help.
customalerts.info:
default: op
description: Let player read info about CustomAlerts.
customalerts.reload:
default: op
description: Let player reload CustomAlerts configuration.
20 changes: 13 additions & 7 deletions CustomAlerts/src/CustomAlerts/Commands/Commands.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,26 @@
namespace CustomAlerts\Commands;

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

use CustomAlerts\CustomAlerts;

class Commands extends PluginCommand implements CommandExecutor {
class Commands extends Command implements PluginOwned {

use PluginOwnedTrait;

private CustomAlerts $plugin;

public function __construct(CustomAlerts $plugin){
$this->plugin = $plugin;
parent::__construct("customalerts");
$this->plugin = $plugin;
$this->setPermission("customalerts.help");
}

public function onCommand(CommandSender $sender, Command $cmd, $label, array $args) : bool {
public function execute(CommandSender $sender, string $commandLabel, array $args){
if(isset($args[0])){
$args[0] = strtolower($args[0]);
switch($args[0]){
Expand Down Expand Up @@ -55,7 +61,7 @@ public function onCommand(CommandSender $sender, Command $cmd, $label, array $ar
$sender->sendMessage(TextFormat::colorize("&cYou don't have permissions to use this command"));
break;
}
return true;
return;
}
help:
if($sender->hasPermission("customalerts.help")){
Expand All @@ -66,6 +72,6 @@ public function onCommand(CommandSender $sender, Command $cmd, $label, array $ar
}else{
$sender->sendMessage(TextFormat::colorize("&cYou don't have permissions to use this command"));
}
return true;
return;
}
}
54 changes: 26 additions & 28 deletions CustomAlerts/src/CustomAlerts/CustomAlerts.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
*/

namespace CustomAlerts;

use pocketmine\Player;
use pocketmine\entity\Living;
use pocketmine\event\entity\EntityDamageByBlockEvent;
use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\level\Level;

use pocketmine\player\Player;
use pocketmine\entity\Living;
use pocketmine\event\entity\EntityDamageByBlockEvent;
use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\player\PlayerInfo;
use pocketmine\world\World;
use pocketmine\plugin\PluginBase;
use pocketmine\utils\TextFormat;

Expand All @@ -27,24 +28,24 @@ class CustomAlerts extends PluginBase {
const PREFIX = "&b[&aCustom&cAlerts&b] ";

/** @var string */
const API_VERSION = "2.0";
private $cfg;
const API_VERSION = "4.0";

public $cfg;

/** @var CustomAlerts $instance */
private static $instance = null;
/** @var null|CustomAlerts $instance */
private static ?CustomAlerts $instance = null;

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

public function onEnable(){
public function onEnable(): void{
@mkdir($this->getDataFolder());
$this->saveDefaultConfig();
$this->cfg = $this->getConfig()->getAll();
$this->getCommand("customalerts")->setExecutor(new Commands($this));
$this->getServer()->getCommandMap()->register("customalerts", new Commands($this));
$this->getServer()->getPluginManager()->registerEvents(new EventListener($this), $this);
$this->getScheduler()->scheduleRepeatingTask(new MotdTask($this), 20);
}
Expand Down Expand Up @@ -115,13 +116,13 @@ public function getMotdMessage(){
}

public function updateMotd(){
$cevent = new CustomAlertsMotdUpdateEvent();
$cevent = new CustomAlertsMotdUpdateEvent($this);
if($this->isMotdCustom()){
$cevent->setMessage($this->getMotdMessage());
}else{
$cevent->setMessage($this->getServer()->getMotd());
}
$this->getServer()->getPluginManager()->callEvent($cevent);
$cevent->call();
$this->getServer()->getNetwork()->setName($cevent->getMessage());
}

Expand Down Expand Up @@ -189,9 +190,9 @@ public function isWhitelistMessageCustom() : bool {
*
* @return string
*/
public function getWhitelistMessage(Player $player){
public function getWhitelistMessage(PlayerInfo $player){
return TextFormat::colorize($this->replaceVars($this->cfg["WhitelistedServer"]["message"], array(
"PLAYER" => $player->getName(),
"PLAYER" => $player->getUsername(),
"MAXPLAYERS" => $this->getServer()->getMaxPlayers(),
"TOTALPLAYERS" => count($this->getServer()->getOnlinePlayers()),
"TIME" => date($this->cfg["datetime-format"]))));
Expand All @@ -214,9 +215,9 @@ public function isFullServerMessageCustom() : bool {
*
* @return string
*/
public function getFullServerMessage(Player $player){
public function getFullServerMessage(PlayerInfo $player){
return TextFormat::colorize($this->replaceVars($this->cfg["FullServer"]["message"], array(
"PLAYER" => $player->getName(),
"PLAYER" => $player->getUsername(),
"MAXPLAYERS" => $this->getServer()->getMaxPlayers(),
"TOTALPLAYERS" => count($this->getServer()->getOnlinePlayers()),
"TIME" => date($this->cfg["datetime-format"]))));
Expand Down Expand Up @@ -325,15 +326,15 @@ public function isWorldChangeMessageEnabled(){
* Get world change message
*
* @param Player $player
* @param Level $origin
* @param Level $target
* @param World $origin
* @param World $target
*
* @return string
*/
public function getWorldChangeMessage(Player $player, Level $origin, Level $target){
public function getWorldChangeMessage(Player $player, World $origin, World $target){
return TextFormat::colorize($this->replaceVars($this->cfg["WorldChange"]["message"], array(
"ORIGIN" => $origin->getName(),
"TARGET" => $target->getName(),
"ORIGIN" => $origin->getDisplayName(),
"TARGET" => $target->getDisplayName(),
"PLAYER" => $player->getName(),
"MAXPLAYERS" => $this->getServer()->getMaxPlayers(),
"TOTALPLAYERS" => count($this->getServer()->getOnlinePlayers()),
Expand All @@ -342,9 +343,6 @@ public function getWorldChangeMessage(Player $player, Level $origin, Level $targ

/**
* Check if death messages are custom
*
* @param EntityDeathEvent $cause
*
* @return bool
*/
public function isDeathMessageCustom(EntityDamageEvent $cause = null){
Expand Down
Loading