From e9de39bf45d087445a817f426dd81abb19a3e986 Mon Sep 17 00:00:00 2001 From: KanekiLeChomeur <52374013+KanekiLeChomeur@users.noreply.github.com> Date: Fri, 13 Oct 2023 00:38:10 +0200 Subject: [PATCH 1/8] PM5 Update and bump version from 2.4 to 3.1 --- CustomAlerts/plugin.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CustomAlerts/plugin.yml b/CustomAlerts/plugin.yml index d86469b..4b2463c 100755 --- a/CustomAlerts/plugin.yml +++ b/CustomAlerts/plugin.yml @@ -1,7 +1,7 @@ name: CustomAlerts main: CustomAlerts\CustomAlerts -version: 2.4 -api: [4.0.0] +version: 3.1 +api: [5.0.0] load: STARTUP author: [EvolSoft, KanekiLeChomeur] description: Customize or hide alerts (join/leave messages, whitelist messages, outdated server/client messages, etc...) plugin From 159d9b00a1cc14a0c9d5bc5331ac49bf7e9622be Mon Sep 17 00:00:00 2001 From: KanekiLeChomeur <52374013+KanekiLeChomeur@users.noreply.github.com> Date: Fri, 13 Oct 2023 00:53:50 +0200 Subject: [PATCH 2/8] Patched Config Reload Patched the Config Reload, now it can be reloaded using the function `CustomAlerts->reloadCfg()` --- CustomAlerts/src/CustomAlerts/Commands/Commands.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CustomAlerts/src/CustomAlerts/Commands/Commands.php b/CustomAlerts/src/CustomAlerts/Commands/Commands.php index b0649c7..cb11281 100755 --- a/CustomAlerts/src/CustomAlerts/Commands/Commands.php +++ b/CustomAlerts/src/CustomAlerts/Commands/Commands.php @@ -43,7 +43,7 @@ public function execute(CommandSender $sender, string $commandLabel, array $args case "reload": if($sender->hasPermission("customalerts.reload")){ $this->plugin->reloadConfig(); - $this->plugin->cfg = $this->plugin->getConfig()->getAll(); + $this->plugin->reloadCfg(); $sender->sendMessage(TextFormat::colorize(CustomAlerts::PREFIX . "&aConfiguration Reloaded.")); }else{ $sender->sendMessage(TextFormat::colorize("&cYou don't have permissions to use this command")); From 96692b7e2e83973e9bbb490ab5945f41561d49cc Mon Sep 17 00:00:00 2001 From: KanekiLeChomeur <52374013+KanekiLeChomeur@users.noreply.github.com> Date: Fri, 13 Oct 2023 00:55:31 +0200 Subject: [PATCH 3/8] Added `reloadCfg() ` Added `reloadCfg() ` to patch Reload config command --- .../src/CustomAlerts/CustomAlerts.php | 559 ++---------------- 1 file changed, 56 insertions(+), 503 deletions(-) diff --git a/CustomAlerts/src/CustomAlerts/CustomAlerts.php b/CustomAlerts/src/CustomAlerts/CustomAlerts.php index d230881..6d59656 100755 --- a/CustomAlerts/src/CustomAlerts/CustomAlerts.php +++ b/CustomAlerts/src/CustomAlerts/CustomAlerts.php @@ -1,516 +1,69 @@ getDataFolder()); - $this->saveDefaultConfig(); - $this->cfg = $this->getConfig()->getAll(); - $this->getServer()->getCommandMap()->register("customalerts", new Commands($this)); - $this->getServer()->getPluginManager()->registerEvents(new EventListener($this), $this); - $this->getScheduler()->scheduleRepeatingTask(new MotdTask($this), 20); - } - - /** - * Replace variables inside a string - * - * @param string $str - * @param array $vars - * - * @return string - */ - public function replaceVars($str, array $vars){ - foreach($vars as $key => $value){ - $str = str_replace("{" . $key . "}", $value, $str); - } - return $str; - } - - //API Functions - - /** - * Get CustomAlerts API - * - * @return CustomAlerts - */ - public static function getAPI(){ - return self::$instance; - } - - /** - * Get CustomAlerts version - * - * @return string - */ - public function getVersion(){ - return $this->getVersion(); - } - - /** - * Get CustomAlerts API version - * - * @return string - */ - public function getAPIVersion(){ - return self::API_VERSION; - } - - /** - * Check if motd is custom - * - * @return bool - */ - public function isMotdCustom() : bool { - return $this->cfg["Motd"]["custom"]; - } - - /** - * Get motd message - * - * @return string - */ - public function getMotdMessage(){ - return TextFormat::colorize($this->replaceVars($this->cfg["Motd"]["message"], array( - "MAXPLAYERS" => $this->getServer()->getMaxPlayers(), - "TOTALPLAYERS" => count($this->getServer()->getOnlinePlayers()), - "TIME" => date($this->cfg["datetime-format"])))); - } - - public function updateMotd(){ - $cevent = new CustomAlertsMotdUpdateEvent(); - if($this->isMotdCustom()){ - $cevent->setMessage($this->getMotdMessage()); - }else{ - $cevent->setMessage($this->getServer()->getMotd()); - } - $cevent->call(); - $this->getServer()->getNetwork()->setName($cevent->getMessage()); - } - - /** - * Check if outdated client message is custom - * - * @return bool - */ - public function isOutdatedClientMessageCustom() : bool { - return $this->cfg["OutdatedClient"]["custom"]; - } - - /** - * Get outdated client message - * - * @return string - */ - public function getOutdatedClientMessage(){ - return TextFormat::colorize($this->replaceVars($this->cfg["OutdatedClient"]["message"], array( - "MAXPLAYERS" => $this->getServer()->getMaxPlayers(), - "TOTALPLAYERS" => count($this->getServer()->getOnlinePlayers()), - "TIME" => date($this->cfg["datetime-format"])))); - } - - /** - * Check if outdated server message is custom - * - * @return bool - */ - public function isOutdatedServerMessageCustom() : bool { - return $this->cfg["OutdatedServer"]["custom"]; - } - - /** - * Get outdated server message - * - * - * @return string - */ - public function getOutdatedServerMessage(){ - return TextFormat::colorize($this->replaceVars($this->cfg["OutdatedServer"]["message"], array( - "MAXPLAYERS" => $this->getServer()->getMaxPlayers(), - "TOTALPLAYERS" => count($this->getServer()->getOnlinePlayers()), - "TIME" => date($this->cfg["datetime-format"])))); - } - - /** - * Check if whitelist message is custom - * - * @return bool - */ - public function isWhitelistMessageCustom() : bool { - return $this->cfg["WhitelistedServer"]["custom"]; - } - - /** - * Get whitelist message - * - * @return string - */ - public function getWhitelistMessage(){ - return TextFormat::colorize($this->replaceVars($this->cfg["WhitelistedServer"]["message"], array( - "MAXPLAYERS" => $this->getServer()->getMaxPlayers(), - "TOTALPLAYERS" => count($this->getServer()->getOnlinePlayers()), - "TIME" => date($this->cfg["datetime-format"])))); - } - - /** - * Check if full server message is custom - * - * @return bool - */ - public function isFullServerMessageCustom() : bool { - $cfg = $this->getConfig()->getAll(); - return $cfg["FullServer"]["custom"]; - } - - /** - * Get full server message - * - * - * @return string - */ - public function getFullServerMessage(){ - return TextFormat::colorize($this->replaceVars($this->cfg["FullServer"]["message"], array( - "MAXPLAYERS" => $this->getServer()->getMaxPlayers(), - "TOTALPLAYERS" => count($this->getServer()->getOnlinePlayers()), - "TIME" => date($this->cfg["datetime-format"])))); - } - - /** - * Check if first join message is enabled - * - * @return bool - */ - public function isFirstJoinMessageEnabled() : bool { - return $this->cfg["FirstJoin"]["enable"]; - } + private $plugin; + + public function __construct(CustomAlerts $plugin) + { + parent::__construct("customalerts", "CustomAlerts commands.", null, ["calerts"]); + $this->plugin = $plugin; - /** - * Get first join message - * - * @param Player $player - * - * @return string - */ - public function getFirstJoinMessage(Player $player){ - return TextFormat::colorize($this->replaceVars($this->cfg["FirstJoin"]["message"], array( - "PLAYER" => $player->getName(), - "MAXPLAYERS" => $this->getServer()->getMaxPlayers(), - "TOTALPLAYERS" => count($this->getServer()->getOnlinePlayers()), - "TIME" => date($this->cfg["datetime-format"])))); - } - - /** - * Check if join message is custom - * - * @return bool - */ - public function isJoinMessageCustom() : bool { - return $this->cfg["Join"]["custom"]; - } - - /** - * Check if join message is hidden - * - * @return bool - */ - public function isJoinMessageHidden() : bool { - return $this->cfg["Join"]["hide"]; - } - - /** - * Get join message - * - * @param Player $player - * - * @return string - */ - public function getJoinMessage(Player $player){ - return TextFormat::colorize($this->replaceVars($this->cfg["Join"]["message"], array( - "PLAYER" => $player->getName(), - "MAXPLAYERS" => $this->getServer()->getMaxPlayers(), - "TOTALPLAYERS" => count($this->getServer()->getOnlinePlayers()), - "TIME" => date($this->cfg["datetime-format"])))); - } - - /** - * Check if quit message is custom - * - * @return bool - */ - public function isQuitMessageCustom(){ - return $this->cfg["Quit"]["custom"]; - } - - /** - * Check if quit message is hidden - * - * @return bool - */ - public function isQuitMessageHidden(){ - return $this->cfg["Quit"]["hide"]; - } - - /** - * Get default quit message - * - * @param Player $player - * - * @return string - */ - public function getQuitMessage(Player $player){ - return TextFormat::colorize($this->replaceVars($this->cfg["Quit"]["message"], array( - "PLAYER" => $player->getName(), - "MAXPLAYERS" => $this->getServer()->getMaxPlayers(), - "TOTALPLAYERS" => count($this->getServer()->getOnlinePlayers()), - "TIME" => date($this->cfg["datetime-format"])))); - } - - /** - * Check if world change message is enabled - * - * @return bool - */ - public function isWorldChangeMessageEnabled(){ - return $this->cfg["WorldChange"]["enable"]; - } - - /** - * Get world change message - * - * @param Player $player - * @param World $origin - * @param World $target - * - * @return string - */ - public function getWorldChangeMessage(Player $player, World $origin, World $target){ - return TextFormat::colorize($this->replaceVars($this->cfg["WorldChange"]["message"], array( - "ORIGIN" => $origin->getDisplayName(), - "TARGET" => $target->getDisplayName(), - "PLAYER" => $player->getName(), - "MAXPLAYERS" => $this->getServer()->getMaxPlayers(), - "TOTALPLAYERS" => count($this->getServer()->getOnlinePlayers()), - "TIME" => date($this->cfg["datetime-format"])))); - } - - /** - * Check if death messages are custom - * - * - * @return bool - */ - public function isDeathMessageCustom(?EntityDamageEvent $cause = null){ - if(!$cause){ - return $this->cfg["Death"]["custom"]; - } - switch($cause->getCause()){ - case EntityDamageEvent::CAUSE_CONTACT: - return $this->cfg["Death"]["death-contact-message"]["custom"]; - case EntityDamageEvent::CAUSE_ENTITY_ATTACK: - return $this->cfg["Death"]["kill-message"]["custom"]; - case EntityDamageEvent::CAUSE_PROJECTILE: - return $this->cfg["Death"]["death-projectile-message"]["custom"]; - case EntityDamageEvent::CAUSE_SUFFOCATION: - return $this->cfg["Death"]["death-suffocation-message"]["custom"]; - case EntityDamageEvent::CAUSE_FALL: - return $this->cfg["Death"]["death-fall-message"]["custom"]; - case EntityDamageEvent::CAUSE_FIRE: - return $this->cfg["Death"]["death-fire-message"]["custom"]; - case EntityDamageEvent::CAUSE_FIRE_TICK: - return $this->cfg["Death"]["death-on-fire-message"]["custom"]; - case EntityDamageEvent::CAUSE_LAVA: - return $this->cfg["Death"]["death-lava-message"]["custom"]; - case EntityDamageEvent::CAUSE_DROWNING: - return $this->cfg["Death"]["death-drowning-message"]["custom"]; - case EntityDamageEvent::CAUSE_ENTITY_EXPLOSION: - case EntityDamageEvent::CAUSE_BLOCK_EXPLOSION: - return $this->cfg["Death"]["death-explosion-message"]["custom"]; - case EntityDamageEvent::CAUSE_VOID: - return $this->cfg["Death"]["death-void-message"]["custom"]; - case EntityDamageEvent::CAUSE_SUICIDE: - return $this->cfg["Death"]["death-suicide-message"]["custom"]; - case EntityDamageEvent::CAUSE_MAGIC: - return $this->cfg["Death"]["death-magic-message"]["custom"]; - default: - return $this->cfg["Death"]["custom"]; - } - } - - /** - * Check if death messages are hidden - * - * @param EntityDamageEvent $cause - * - * @return bool - */ - public function isDeathMessageHidden(EntityDamageEvent $cause = null){ - if(!$cause){ - return $this->cfg["Death"]["hide"]; - } - switch($cause->getCause()){ - case EntityDamageEvent::CAUSE_CONTACT: - return $this->cfg["Death"]["death-contact-message"]["hide"]; - case EntityDamageEvent::CAUSE_ENTITY_ATTACK: - return $this->cfg["Death"]["kill-message"]["hide"]; - case EntityDamageEvent::CAUSE_PROJECTILE: - return $this->cfg["Death"]["death-projectile-message"]["hide"]; - case EntityDamageEvent::CAUSE_SUFFOCATION: - return $this->cfg["Death"]["death-suffocation-message"]["hide"]; - case EntityDamageEvent::CAUSE_FALL: - return $this->cfg["Death"]["death-fall-message"]["hide"]; - case EntityDamageEvent::CAUSE_FIRE: - return $this->cfg["Death"]["death-fire-message"]["hide"]; - case EntityDamageEvent::CAUSE_FIRE_TICK: - return $this->cfg["Death"]["death-on-fire-message"]["hide"]; - case EntityDamageEvent::CAUSE_LAVA: - return $this->cfg["Death"]["death-lava-message"]["hide"]; - case EntityDamageEvent::CAUSE_DROWNING: - return $this->cfg["Death"]["death-drowning-message"]["hide"]; - case EntityDamageEvent::CAUSE_ENTITY_EXPLOSION: - case EntityDamageEvent::CAUSE_BLOCK_EXPLOSION: - return $this->cfg["Death"]["death-explosion-message"]["hide"]; - case EntityDamageEvent::CAUSE_VOID: - return $this->cfg["Death"]["death-void-message"]["hide"]; - case EntityDamageEvent::CAUSE_SUICIDE: - return $this->cfg["Death"]["death-suicide-message"]["hide"]; - case EntityDamageEvent::CAUSE_MAGIC: - return $this->cfg["Death"]["death-magic-message"]["hide"]; - default: - return $this->cfg["Death"]["hide"]; - } } - - /** - * Get death message related to the specified cause - * - * @param Player $player - * @param EntityDamageEvent $cause - * - * @return string - */ - public function getDeathMessage(Player $player, EntityDamageEvent $cause = null){ - $array = array( - "PLAYER" => $player->getName(), - "MAXPLAYERS" => $this->getServer()->getMaxPlayers(), - "TOTALPLAYERS" => count($this->getServer()->getOnlinePlayers()), - "TIME" => date($this->cfg["datetime-format"])); - if(!$cause){ - $message = $this->cfg["Death"]["message"]; - }else{ - switch($cause->getCause()){ - case EntityDamageEvent::CAUSE_CONTACT: - $message = $this->cfg["Death"]["death-contact-message"]["message"]; - if($cause instanceof EntityDamageByBlockEvent){ - $array["BLOCK"] = $cause->getDamager()->getName(); - break; - } - $array["BLOCK"] = "Unknown"; - break; - case EntityDamageEvent::CAUSE_ENTITY_ATTACK: - $message = $this->cfg["Death"]["kill-message"]["message"]; - if($cause instanceof EntityDamageByEntityEvent){ - $killer = $cause->getDamager(); - if($killer instanceof Living){ - $array["KILLER"] = $killer->getName(); - break; - } - } - $array["KILLER"] = "Unknown"; - break; - case EntityDamageEvent::CAUSE_PROJECTILE: - $message = $this->cfg["Death"]["death-projectile-message"]["message"]; - if($cause instanceof ProjectileHitEntityEvent){ - $projectile = $cause->getEntity(); - if($projectile instanceof Projectile){ - $killer = $projectile->getOwningEntity(); - if($killer instanceof Living){ - $array["KILLER"] = $killer->getName(); - break; - } - } - } - $array["KILLER"] = "Unknown"; - break; - case EntityDamageEvent::CAUSE_SUFFOCATION: - $message = $this->cfg["Death"]["death-suffocation-message"]["message"]; - break; - case EntityDamageEvent::CAUSE_FALL: - $message = $this->cfg["Death"]["death-fall-message"]["message"]; - break; - case EntityDamageEvent::CAUSE_FIRE: - $message = $this->cfg["Death"]["death-fire-message"]["message"]; - break; - case EntityDamageEvent::CAUSE_FIRE_TICK: - $message = $this->cfg["Death"]["death-on-fire-message"]["message"]; - break; - case EntityDamageEvent::CAUSE_LAVA: - $message = $this->cfg["Death"]["death-lava-message"]["message"]; - break; - case EntityDamageEvent::CAUSE_DROWNING: - $message = $this->cfg["Death"]["death-drowning-message"]["message"]; - break; - case EntityDamageEvent::CAUSE_ENTITY_EXPLOSION: - case EntityDamageEvent::CAUSE_BLOCK_EXPLOSION: - $message = $this->cfg["Death"]["death-explosion-message"]["message"]; - break; - case EntityDamageEvent::CAUSE_VOID: - $message = $this->cfg["Death"]["death-void-message"]["message"]; - break; - case EntityDamageEvent::CAUSE_SUICIDE: - $message = $this->cfg["Death"]["death-suicide-message"]["message"]; - break; - case EntityDamageEvent::CAUSE_MAGIC: - $message = $this->cfg["Death"]["death-magic-message"]["message"]; - break; + + public function execute(CommandSender $sender, string $commandLabel, array $args) + { + if(isset($args[0])){ + switch(strtolower($args[0])){ + case "help": + if($sender->hasPermission("customalerts.help")){ + $sender->sendMessage(TextFormat::colorize("&b-- &aAvailable Commands &b--")); + $sender->sendMessage(TextFormat::colorize("&d/calerts help &b-&a Show help about this plugin")); + $sender->sendMessage(TextFormat::colorize("&d/calerts info &b-&a Show info about this plugin")); + $sender->sendMessage(TextFormat::colorize("&d/calerts reload &b-&a Reload the config")); + }else{ + $sender->sendMessage(TextFormat::colorize("&cYou don't have permissions to use this command")); + } + break; + case "info": + if($sender->hasPermission("customalerts.info")){ + $sender->sendMessage(TextFormat::colorize(CustomAlerts::PREFIX . "&aCustomAlerts &dv" . $this->plugin->getDescription()->getVersion() . "&a developed by &dEvolSoft §r§aand updated by §dKanekiLeChomeur ")); + $sender->sendMessage(TextFormat::colorize(CustomAlerts::PREFIX . "&aWebsite &d" . $this->plugin->getDescription()->getWebsite())); + }else{ + $sender->sendMessage(TextFormat::colorize("&cYou don't have permissions to use this command")); + } + break; + case "reload": + if($sender->hasPermission("customalerts.reload")){ + $this->plugin->reloadConfig(); + $this->plugin->reloadCfg(); + $sender->sendMessage(TextFormat::colorize(CustomAlerts::PREFIX . "&aConfiguration Reloaded.")); + }else{ + $sender->sendMessage(TextFormat::colorize("&cYou don't have permissions to use this command")); + } + break; default: - $message = $this->cfg["Death"]["message"]; - break; + if($sender->hasPermission("customalerts")){ + $sender->sendMessage(TextFormat::colorize(CustomAlerts::PREFIX . "&cSubcommand &a" . $args[0] . " &cnot found. Use &a/calerts help &cto show available commands")); + }else{ + $sender->sendMessage(TextFormat::colorize("&cYou don't have permissions to use this command")); + } + break; + } + }else{ + if($sender->hasPermission("customalerts")){ + $sender->sendMessage(TextFormat::colorize(CustomAlerts::PREFIX . "&cUse &a/calerts help &cto show available commands")); + }else{ + $sender->sendMessage(TextFormat::colorize("&cYou don't have permissions to use this command")); } } - return TextFormat::colorize($this->replaceVars($message, $array)); } + } From 9255f9a86d68940bc170fca0b35cf670b08c7c0d Mon Sep 17 00:00:00 2001 From: KanekiLeChomeur <52374013+KanekiLeChomeur@users.noreply.github.com> Date: Fri, 13 Oct 2023 00:57:07 +0200 Subject: [PATCH 4/8] Sorry, put wrong patch into the file --- .../src/CustomAlerts/CustomAlerts.php | 562 ++++++++++++++++-- 1 file changed, 507 insertions(+), 55 deletions(-) diff --git a/CustomAlerts/src/CustomAlerts/CustomAlerts.php b/CustomAlerts/src/CustomAlerts/CustomAlerts.php index 6d59656..502076e 100755 --- a/CustomAlerts/src/CustomAlerts/CustomAlerts.php +++ b/CustomAlerts/src/CustomAlerts/CustomAlerts.php @@ -1,69 +1,521 @@ plugin = $plugin; +class CustomAlerts extends PluginBase { + + /** @var string */ + const PREFIX = "&b[&aCustom&cAlerts&b] "; + + /** @var string */ + const API_VERSION = "2.0"; + + protected Config $cfg; + + /** @var CustomAlerts $instance */ + private static $instance = null; + + public function onLoad():void{ + if(!self::$instance instanceof CustomAlerts){ + self::$instance = $this; + } + } + + public function onEnable():void{ + @mkdir($this->getDataFolder()); + $this->saveDefaultConfig(); + $this->cfg = $this->getConfig()->getAll(); + $this->getServer()->getCommandMap()->register("customalerts", new Commands($this)); + $this->getServer()->getPluginManager()->registerEvents(new EventListener($this), $this); + $this->getScheduler()->scheduleRepeatingTask(new MotdTask($this), 20); + } + + /** + * Replace variables inside a string + * + * @param string $str + * @param array $vars + * + * @return string + */ + public function replaceVars($str, array $vars){ + foreach($vars as $key => $value){ + $str = str_replace("{" . $key . "}", $value, $str); + } + return $str; + } + + //API Functions + + /** + * Get CustomAlerts API + * + * @return CustomAlerts + */ + public static function getAPI(){ + return self::$instance; + } + + /** + * Get CustomAlerts version + * + * @return string + */ + public function getVersion(){ + return $this->getVersion(); + } + + /** + * Get CustomAlerts API version + * + * @return string + */ + public function getAPIVersion(){ + return self::API_VERSION; + } + + /** + * Check if motd is custom + * + * @return bool + */ + public function isMotdCustom() : bool { + return $this->cfg["Motd"]["custom"]; + } + + /** + * Get motd message + * + * @return string + */ + public function getMotdMessage(){ + return TextFormat::colorize($this->replaceVars($this->cfg["Motd"]["message"], array( + "MAXPLAYERS" => $this->getServer()->getMaxPlayers(), + "TOTALPLAYERS" => count($this->getServer()->getOnlinePlayers()), + "TIME" => date($this->cfg["datetime-format"])))); + } + + public function updateMotd(){ + $cevent = new CustomAlertsMotdUpdateEvent(); + if($this->isMotdCustom()){ + $cevent->setMessage($this->getMotdMessage()); + }else{ + $cevent->setMessage($this->getServer()->getMotd()); + } + $cevent->call(); + $this->getServer()->getNetwork()->setName($cevent->getMessage()); + } + + /** + * Check if outdated client message is custom + * + * @return bool + */ + public function isOutdatedClientMessageCustom() : bool { + return $this->cfg["OutdatedClient"]["custom"]; + } + + /** + * Get outdated client message + * + * @return string + */ + public function getOutdatedClientMessage(){ + return TextFormat::colorize($this->replaceVars($this->cfg["OutdatedClient"]["message"], array( + "MAXPLAYERS" => $this->getServer()->getMaxPlayers(), + "TOTALPLAYERS" => count($this->getServer()->getOnlinePlayers()), + "TIME" => date($this->cfg["datetime-format"])))); + } + + /** + * Check if outdated server message is custom + * + * @return bool + */ + public function isOutdatedServerMessageCustom() : bool { + return $this->cfg["OutdatedServer"]["custom"]; + } + + /** + * Get outdated server message + * + * + * @return string + */ + public function getOutdatedServerMessage(){ + return TextFormat::colorize($this->replaceVars($this->cfg["OutdatedServer"]["message"], array( + "MAXPLAYERS" => $this->getServer()->getMaxPlayers(), + "TOTALPLAYERS" => count($this->getServer()->getOnlinePlayers()), + "TIME" => date($this->cfg["datetime-format"])))); + } + + /** + * Check if whitelist message is custom + * + * @return bool + */ + public function isWhitelistMessageCustom() : bool { + return $this->cfg["WhitelistedServer"]["custom"]; + } + + /** + * Get whitelist message + * + * @return string + */ + public function getWhitelistMessage(){ + return TextFormat::colorize($this->replaceVars($this->cfg["WhitelistedServer"]["message"], array( + "MAXPLAYERS" => $this->getServer()->getMaxPlayers(), + "TOTALPLAYERS" => count($this->getServer()->getOnlinePlayers()), + "TIME" => date($this->cfg["datetime-format"])))); + } + + /** + * Check if full server message is custom + * + * @return bool + */ + public function isFullServerMessageCustom() : bool { + $cfg = $this->getConfig()->getAll(); + return $cfg["FullServer"]["custom"]; + } + + /** + * Get full server message + * + * + * @return string + */ + public function getFullServerMessage(){ + return TextFormat::colorize($this->replaceVars($this->cfg["FullServer"]["message"], array( + "MAXPLAYERS" => $this->getServer()->getMaxPlayers(), + "TOTALPLAYERS" => count($this->getServer()->getOnlinePlayers()), + "TIME" => date($this->cfg["datetime-format"])))); + } + + /** + * Check if first join message is enabled + * + * @return bool + */ + public function isFirstJoinMessageEnabled() : bool { + return $this->cfg["FirstJoin"]["enable"]; + } + public function reloadCfg(){ + $this->cfg = $this->getConfig()->getAll(); } - public function execute(CommandSender $sender, string $commandLabel, array $args) - { - if(isset($args[0])){ - switch(strtolower($args[0])){ - case "help": - if($sender->hasPermission("customalerts.help")){ - $sender->sendMessage(TextFormat::colorize("&b-- &aAvailable Commands &b--")); - $sender->sendMessage(TextFormat::colorize("&d/calerts help &b-&a Show help about this plugin")); - $sender->sendMessage(TextFormat::colorize("&d/calerts info &b-&a Show info about this plugin")); - $sender->sendMessage(TextFormat::colorize("&d/calerts reload &b-&a Reload the config")); - }else{ - $sender->sendMessage(TextFormat::colorize("&cYou don't have permissions to use this command")); - } - break; - case "info": - if($sender->hasPermission("customalerts.info")){ - $sender->sendMessage(TextFormat::colorize(CustomAlerts::PREFIX . "&aCustomAlerts &dv" . $this->plugin->getDescription()->getVersion() . "&a developed by &dEvolSoft §r§aand updated by §dKanekiLeChomeur ")); - $sender->sendMessage(TextFormat::colorize(CustomAlerts::PREFIX . "&aWebsite &d" . $this->plugin->getDescription()->getWebsite())); - }else{ - $sender->sendMessage(TextFormat::colorize("&cYou don't have permissions to use this command")); - } - break; - case "reload": - if($sender->hasPermission("customalerts.reload")){ - $this->plugin->reloadConfig(); - $this->plugin->reloadCfg(); - $sender->sendMessage(TextFormat::colorize(CustomAlerts::PREFIX . "&aConfiguration Reloaded.")); - }else{ - $sender->sendMessage(TextFormat::colorize("&cYou don't have permissions to use this command")); - } - break; - default: - if($sender->hasPermission("customalerts")){ - $sender->sendMessage(TextFormat::colorize(CustomAlerts::PREFIX . "&cSubcommand &a" . $args[0] . " &cnot found. Use &a/calerts help &cto show available commands")); - }else{ - $sender->sendMessage(TextFormat::colorize("&cYou don't have permissions to use this command")); - } - break; - } + /** + * Get first join message + * + * @param Player $player + * + * @return string + */ + public function getFirstJoinMessage(Player $player){ + return TextFormat::colorize($this->replaceVars($this->cfg["FirstJoin"]["message"], array( + "PLAYER" => $player->getName(), + "MAXPLAYERS" => $this->getServer()->getMaxPlayers(), + "TOTALPLAYERS" => count($this->getServer()->getOnlinePlayers()), + "TIME" => date($this->cfg["datetime-format"])))); + } + + /** + * Check if join message is custom + * + * @return bool + */ + public function isJoinMessageCustom() : bool { + return $this->cfg["Join"]["custom"]; + } + + /** + * Check if join message is hidden + * + * @return bool + */ + public function isJoinMessageHidden() : bool { + return $this->cfg["Join"]["hide"]; + } + + /** + * Get join message + * + * @param Player $player + * + * @return string + */ + public function getJoinMessage(Player $player){ + return TextFormat::colorize($this->replaceVars($this->cfg["Join"]["message"], array( + "PLAYER" => $player->getName(), + "MAXPLAYERS" => $this->getServer()->getMaxPlayers(), + "TOTALPLAYERS" => count($this->getServer()->getOnlinePlayers()), + "TIME" => date($this->cfg["datetime-format"])))); + } + + /** + * Check if quit message is custom + * + * @return bool + */ + public function isQuitMessageCustom(){ + return $this->cfg["Quit"]["custom"]; + } + + /** + * Check if quit message is hidden + * + * @return bool + */ + public function isQuitMessageHidden(){ + return $this->cfg["Quit"]["hide"]; + } + + /** + * Get default quit message + * + * @param Player $player + * + * @return string + */ + public function getQuitMessage(Player $player){ + return TextFormat::colorize($this->replaceVars($this->cfg["Quit"]["message"], array( + "PLAYER" => $player->getName(), + "MAXPLAYERS" => $this->getServer()->getMaxPlayers(), + "TOTALPLAYERS" => count($this->getServer()->getOnlinePlayers()), + "TIME" => date($this->cfg["datetime-format"])))); + } + + /** + * Check if world change message is enabled + * + * @return bool + */ + public function isWorldChangeMessageEnabled(){ + return $this->cfg["WorldChange"]["enable"]; + } + + /** + * Get world change message + * + * @param Player $player + * @param World $origin + * @param World $target + * + * @return string + */ + public function getWorldChangeMessage(Player $player, World $origin, World $target){ + return TextFormat::colorize($this->replaceVars($this->cfg["WorldChange"]["message"], array( + "ORIGIN" => $origin->getDisplayName(), + "TARGET" => $target->getDisplayName(), + "PLAYER" => $player->getName(), + "MAXPLAYERS" => $this->getServer()->getMaxPlayers(), + "TOTALPLAYERS" => count($this->getServer()->getOnlinePlayers()), + "TIME" => date($this->cfg["datetime-format"])))); + } + + /** + * Check if death messages are custom + * + * + * @return bool + */ + public function isDeathMessageCustom(?EntityDamageEvent $cause = null){ + if(!$cause){ + return $this->cfg["Death"]["custom"]; + } + switch($cause->getCause()){ + case EntityDamageEvent::CAUSE_CONTACT: + return $this->cfg["Death"]["death-contact-message"]["custom"]; + case EntityDamageEvent::CAUSE_ENTITY_ATTACK: + return $this->cfg["Death"]["kill-message"]["custom"]; + case EntityDamageEvent::CAUSE_PROJECTILE: + return $this->cfg["Death"]["death-projectile-message"]["custom"]; + case EntityDamageEvent::CAUSE_SUFFOCATION: + return $this->cfg["Death"]["death-suffocation-message"]["custom"]; + case EntityDamageEvent::CAUSE_FALL: + return $this->cfg["Death"]["death-fall-message"]["custom"]; + case EntityDamageEvent::CAUSE_FIRE: + return $this->cfg["Death"]["death-fire-message"]["custom"]; + case EntityDamageEvent::CAUSE_FIRE_TICK: + return $this->cfg["Death"]["death-on-fire-message"]["custom"]; + case EntityDamageEvent::CAUSE_LAVA: + return $this->cfg["Death"]["death-lava-message"]["custom"]; + case EntityDamageEvent::CAUSE_DROWNING: + return $this->cfg["Death"]["death-drowning-message"]["custom"]; + case EntityDamageEvent::CAUSE_ENTITY_EXPLOSION: + case EntityDamageEvent::CAUSE_BLOCK_EXPLOSION: + return $this->cfg["Death"]["death-explosion-message"]["custom"]; + case EntityDamageEvent::CAUSE_VOID: + return $this->cfg["Death"]["death-void-message"]["custom"]; + case EntityDamageEvent::CAUSE_SUICIDE: + return $this->cfg["Death"]["death-suicide-message"]["custom"]; + case EntityDamageEvent::CAUSE_MAGIC: + return $this->cfg["Death"]["death-magic-message"]["custom"]; + default: + return $this->cfg["Death"]["custom"]; + } + } + + /** + * Check if death messages are hidden + * + * @param EntityDamageEvent $cause + * + * @return bool + */ + public function isDeathMessageHidden(EntityDamageEvent $cause = null){ + if(!$cause){ + return $this->cfg["Death"]["hide"]; + } + switch($cause->getCause()){ + case EntityDamageEvent::CAUSE_CONTACT: + return $this->cfg["Death"]["death-contact-message"]["hide"]; + case EntityDamageEvent::CAUSE_ENTITY_ATTACK: + return $this->cfg["Death"]["kill-message"]["hide"]; + case EntityDamageEvent::CAUSE_PROJECTILE: + return $this->cfg["Death"]["death-projectile-message"]["hide"]; + case EntityDamageEvent::CAUSE_SUFFOCATION: + return $this->cfg["Death"]["death-suffocation-message"]["hide"]; + case EntityDamageEvent::CAUSE_FALL: + return $this->cfg["Death"]["death-fall-message"]["hide"]; + case EntityDamageEvent::CAUSE_FIRE: + return $this->cfg["Death"]["death-fire-message"]["hide"]; + case EntityDamageEvent::CAUSE_FIRE_TICK: + return $this->cfg["Death"]["death-on-fire-message"]["hide"]; + case EntityDamageEvent::CAUSE_LAVA: + return $this->cfg["Death"]["death-lava-message"]["hide"]; + case EntityDamageEvent::CAUSE_DROWNING: + return $this->cfg["Death"]["death-drowning-message"]["hide"]; + case EntityDamageEvent::CAUSE_ENTITY_EXPLOSION: + case EntityDamageEvent::CAUSE_BLOCK_EXPLOSION: + return $this->cfg["Death"]["death-explosion-message"]["hide"]; + case EntityDamageEvent::CAUSE_VOID: + return $this->cfg["Death"]["death-void-message"]["hide"]; + case EntityDamageEvent::CAUSE_SUICIDE: + return $this->cfg["Death"]["death-suicide-message"]["hide"]; + case EntityDamageEvent::CAUSE_MAGIC: + return $this->cfg["Death"]["death-magic-message"]["hide"]; + default: + return $this->cfg["Death"]["hide"]; + } + } + + /** + * Get death message related to the specified cause + * + * @param Player $player + * @param EntityDamageEvent $cause + * + * @return string + */ + public function getDeathMessage(Player $player, EntityDamageEvent $cause = null){ + $array = array( + "PLAYER" => $player->getName(), + "MAXPLAYERS" => $this->getServer()->getMaxPlayers(), + "TOTALPLAYERS" => count($this->getServer()->getOnlinePlayers()), + "TIME" => date($this->cfg["datetime-format"])); + if(!$cause){ + $message = $this->cfg["Death"]["message"]; }else{ - if($sender->hasPermission("customalerts")){ - $sender->sendMessage(TextFormat::colorize(CustomAlerts::PREFIX . "&cUse &a/calerts help &cto show available commands")); - }else{ - $sender->sendMessage(TextFormat::colorize("&cYou don't have permissions to use this command")); + switch($cause->getCause()){ + case EntityDamageEvent::CAUSE_CONTACT: + $message = $this->cfg["Death"]["death-contact-message"]["message"]; + if($cause instanceof EntityDamageByBlockEvent){ + $array["BLOCK"] = $cause->getDamager()->getName(); + break; + } + $array["BLOCK"] = "Unknown"; + break; + case EntityDamageEvent::CAUSE_ENTITY_ATTACK: + $message = $this->cfg["Death"]["kill-message"]["message"]; + if($cause instanceof EntityDamageByEntityEvent){ + $killer = $cause->getDamager(); + if($killer instanceof Living){ + $array["KILLER"] = $killer->getName(); + break; + } + } + $array["KILLER"] = "Unknown"; + break; + case EntityDamageEvent::CAUSE_PROJECTILE: + $message = $this->cfg["Death"]["death-projectile-message"]["message"]; + if($cause instanceof ProjectileHitEntityEvent){ + $projectile = $cause->getEntity(); + if($projectile instanceof Projectile){ + $killer = $projectile->getOwningEntity(); + if($killer instanceof Living){ + $array["KILLER"] = $killer->getName(); + break; + } + } + } + $array["KILLER"] = "Unknown"; + break; + case EntityDamageEvent::CAUSE_SUFFOCATION: + $message = $this->cfg["Death"]["death-suffocation-message"]["message"]; + break; + case EntityDamageEvent::CAUSE_FALL: + $message = $this->cfg["Death"]["death-fall-message"]["message"]; + break; + case EntityDamageEvent::CAUSE_FIRE: + $message = $this->cfg["Death"]["death-fire-message"]["message"]; + break; + case EntityDamageEvent::CAUSE_FIRE_TICK: + $message = $this->cfg["Death"]["death-on-fire-message"]["message"]; + break; + case EntityDamageEvent::CAUSE_LAVA: + $message = $this->cfg["Death"]["death-lava-message"]["message"]; + break; + case EntityDamageEvent::CAUSE_DROWNING: + $message = $this->cfg["Death"]["death-drowning-message"]["message"]; + break; + case EntityDamageEvent::CAUSE_ENTITY_EXPLOSION: + case EntityDamageEvent::CAUSE_BLOCK_EXPLOSION: + $message = $this->cfg["Death"]["death-explosion-message"]["message"]; + break; + case EntityDamageEvent::CAUSE_VOID: + $message = $this->cfg["Death"]["death-void-message"]["message"]; + break; + case EntityDamageEvent::CAUSE_SUICIDE: + $message = $this->cfg["Death"]["death-suicide-message"]["message"]; + break; + case EntityDamageEvent::CAUSE_MAGIC: + $message = $this->cfg["Death"]["death-magic-message"]["message"]; + break; + default: + $message = $this->cfg["Death"]["message"]; + break; } } + return TextFormat::colorize($this->replaceVars($message, $array)); } - } From 2ddcdf216d322b67b3b7b5b32665a12786fda70f Mon Sep 17 00:00:00 2001 From: KanekiLeChomeur <52374013+KanekiLeChomeur@users.noreply.github.com> Date: Fri, 13 Oct 2023 00:58:02 +0200 Subject: [PATCH 5/8] Applied PM5 modifcations --- CustomAlerts/src/CustomAlerts/EventListener.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CustomAlerts/src/CustomAlerts/EventListener.php b/CustomAlerts/src/CustomAlerts/EventListener.php index bcd3672..a0dfe62 100755 --- a/CustomAlerts/src/CustomAlerts/EventListener.php +++ b/CustomAlerts/src/CustomAlerts/EventListener.php @@ -106,7 +106,7 @@ public function onPlayerPreLogin(PlayerPreLoginEvent $event){ } $cevent->call(); if($cevent->getMessage() != ""){ - $event->setKickReason(PlayerPreLoginEvent::KICK_REASON_SERVER_WHITELISTED, $cevent->getMessage()); + $event->setKickFlag(PlayerPreLoginEvent::KICK_FLAG_SERVER_WHITELISTED, $cevent->getMessage()); return; } } From da83a614709789c6c9a525b12873c5654adc5bf3 Mon Sep 17 00:00:00 2001 From: KanekiLeChomeur <52374013+KanekiLeChomeur@users.noreply.github.com> Date: Fri, 13 Oct 2023 00:58:24 +0200 Subject: [PATCH 6/8] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7ca2862..d65bb45 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ PocketMine-MP plugins ## Requirements -PocketMine-MP API 4.0.0 +PocketMine-MP API 5.0.0 ## Overview From c5384814bcd0cd78550783c464633c706f713bb0 Mon Sep 17 00:00:00 2001 From: KanekiLeChomeur <52374013+KanekiLeChomeur@users.noreply.github.com> Date: Fri, 13 Oct 2023 01:00:48 +0200 Subject: [PATCH 7/8] Update README.md --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index d65bb45..41dba2b 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,12 @@ PocketMine-MP API 5.0.0 With CustomAlerts you can customize or hide whitelist kick messages, outdated server/client messages, join/leave messages, first join messages, death messages, world change messages... (read documentation) +**Changelogs** + +- Applied PocketMine-MP API 5.0.0 changes +- Bumped version from 2.4 to 3.1 +- Patched Config Reload Command + **Features** - Customize or hide join, quit and death messages From c650753f69e557bcfd522563ac81ae6fa455c4fb Mon Sep 17 00:00:00 2001 From: KanekiLeChomeur <52374013+KanekiLeChomeur@users.noreply.github.com> Date: Fri, 13 Oct 2023 01:01:50 +0200 Subject: [PATCH 8/8] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 41dba2b..d39a22d 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ PocketMine-MP API 5.0.0 With CustomAlerts you can customize or hide whitelist kick messages, outdated server/client messages, join/leave messages, first join messages, death messages, world change messages... (read documentation) -**Changelogs** +**Changelogs** 13/10/2023 - Applied PocketMine-MP API 5.0.0 changes - Bumped version from 2.4 to 3.1