From ae459fe9700a5bce1e0e2a9609f89a0e0261752c Mon Sep 17 00:00:00 2001 From: Wertzui123 <46199283+Wertzui123@users.noreply.github.com> Date: Fri, 31 Jul 2020 13:30:43 +0200 Subject: [PATCH] BedrockClans 3.0 BedrockClans 3.0 is out and added some nice new features, e.g.: - /clan chat on - Clan bank accounts - More clan ranks This update is not backwards compatible! All clans will be invalid! I plan to release a backwards compatible version soon. --- README.md | 14 +- plugin.yml | 15 +- resources/config.yml | 68 +-- resources/strings.yml | 110 +++++ src/Wertzui123/BedrockClans/BCPlayer.php | 165 +++++++- src/Wertzui123/BedrockClans/Clan.php | 289 ++++++++++--- src/Wertzui123/BedrockClans/Main.php | 388 ++++++++++++------ .../BedrockClans/commands/clancmd.php | 30 +- .../commands/subcommands/about.php | 2 +- .../commands/subcommands/accept.php | 20 +- .../commands/subcommands/chat.php | 24 +- .../commands/subcommands/create.php | 53 ++- .../commands/subcommands/delete.php | 10 +- .../commands/subcommands/demote.php | 61 +++ .../commands/subcommands/deposit.php | 50 +++ .../commands/subcommands/help.php | 2 +- .../commands/subcommands/info.php | 36 +- .../commands/subcommands/invite.php | 34 +- .../commands/subcommands/join.php | 22 +- .../commands/subcommands/kick.php | 42 +- .../commands/subcommands/leader.php | 23 +- .../commands/subcommands/leave.php | 31 +- .../commands/subcommands/promote.php | 61 +++ .../commands/subcommands/withdraw.php | 58 +++ .../events/clan/ClanCreateEvent.php | 46 +++ .../events/clan/ClanDeleteEvent.php | 31 ++ .../BedrockClans/events/clan/ClanEvent.php | 31 ++ .../events/player/ClanJoinEvent.php | 37 ++ .../events/player/ClanLeaveEvent.php | 37 ++ .../events/player/PlayerChatEvent.php | 45 ++ .../events/player/PlayerEvent.php | 31 ++ .../BedrockClans/listener/CustomListener.php | 3 + .../BedrockClans/listener/EventListener.php | 17 +- .../BedrockClans/tasks/invitetask.php | 11 +- 34 files changed, 1479 insertions(+), 418 deletions(-) create mode 100644 resources/strings.yml create mode 100644 src/Wertzui123/BedrockClans/commands/subcommands/demote.php create mode 100644 src/Wertzui123/BedrockClans/commands/subcommands/deposit.php create mode 100644 src/Wertzui123/BedrockClans/commands/subcommands/promote.php create mode 100644 src/Wertzui123/BedrockClans/commands/subcommands/withdraw.php create mode 100644 src/Wertzui123/BedrockClans/events/clan/ClanCreateEvent.php create mode 100644 src/Wertzui123/BedrockClans/events/clan/ClanDeleteEvent.php create mode 100644 src/Wertzui123/BedrockClans/events/clan/ClanEvent.php create mode 100644 src/Wertzui123/BedrockClans/events/player/ClanJoinEvent.php create mode 100644 src/Wertzui123/BedrockClans/events/player/ClanLeaveEvent.php create mode 100644 src/Wertzui123/BedrockClans/events/player/PlayerChatEvent.php create mode 100644 src/Wertzui123/BedrockClans/events/player/PlayerEvent.php diff --git a/README.md b/README.md index fe6ffd4..a353a95 100644 --- a/README.md +++ b/README.md @@ -11,12 +11,9 @@ Try their cool IDEs out! # Commands /clan - Manage clans # Permissions -bedrockclans: Lets you use all features of this plugin +bedrockclans: Allows you to use all features of this plugin
Default: op -bedrockclans.cmd: Allows you to use /clan -
Default: true - bedrockclans.cmd.join: Allows you to use /clan join
Default: op @@ -29,10 +26,13 @@ bedrockclans.cmd.create.costs.bypass: Allows you to bypass the clan creation cos This are some cool features of BedrockClans:

- Easy to understand config -
- Custom messages (messages.yml) +
- Custom messages (messages.yml), colors and more
- /clan chat
- Blacklisted clan names -
- Clan creation costs +
- Clan creation costs (using EconomyAPI) +
- Multiple clan ranks +
- Clan bank (using EconomyAPI) + # Can I use BedrockClans with PureChat? You can use my PureChat Fork to show the players clanname and clanrank in the chat/nametag. How to setup PureChat with BedrockClans? @@ -55,4 +55,4 @@ BedrockClans was written by Wertzui123.

Thanks to Wertzui12345 for always testing features and everyone else who has contributed to BedrockClans.
-
You can help me too by reporting bugs and making suggestions! +
You can help me too by reporting bugs and making suggestions! \ No newline at end of file diff --git a/plugin.yml b/plugin.yml index 46c9284..8432a73 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,25 +1,22 @@ name: BedrockClans main: Wertzui123\BedrockClans\Main -version: 2.0 +version: 3.0 api: 3.0.0 load: POSTWORLD author: Wertzui123 -description: A feature rich, easy to use and advanced clan plugin +description: A PocketMine-MP clan plugin with many cool features website: https://github.com/Wertzui123/BedrockClans permissions: bedrockclans: default: op description: Lets you use a BedrockClans features children: - bedrockclans.cmd: - default: true - description: Allows you to use /clan - bedrockclans.cmd.join: + bedrockclans.command.join: default: op description: Allows you to use /clan join - bedrockclans.cmd.create: + bedrockclans.command.create: default: op description: Allows you to create clans - bedrockclans.cmd.create.costs.bypass: + bedrockclans.create.cost.bypass: default: false - description: Allows you to bypass the clan creation cost + description: Allows you to bypass the clan creation cost \ No newline at end of file diff --git a/resources/config.yml b/resources/config.yml index 444e4d4..8475afd 100644 --- a/resources/config.yml +++ b/resources/config.yml @@ -1,8 +1,7 @@ --- -# BedrockClans - (C) 2019 - 2020 Wertzui123 - -version: 2.0 - +# BedrockClans - Copyright 2019 - 2020 Wertzui123 +# Don't edit this if you don't know what you're doing +config-version: 3.0 # Banned clan names banned_clan_names: - Hacker @@ -12,27 +11,50 @@ banned_clan_names: - Supporter - Nazi - Team + - Staff - Server - Clan - -# Clan chat format -clan_chat_format: "§bClan §c> §a{name} §c: §r{message}" - +# Commands +command: + clan: + command: clan + description: Create, delete and manage clans + usage: "/clan " + aliases: ['clans'] # Should /clan create cost money? (EconomyAPI) create_costs: false - -# How much money it should cost to create a clan when create_costs is enabled. +# How much money it should cost to create a clan when create_costs is enabled clan_create_costs: 100 - -# How many seconds an invite is valid -expire_time: 30 - -# Whether /clan chat should be disabled or not -chat_disabled: false - -# Command -command: clan -description: Create, delete and manage clans -usage: "§cUsage: /clan " -aliases: ['clans'] -... +# Whether /clan chat should be enabled or disabled +chat: + enabled: true + on: "on" + off: "off" +# How many seconds an invitation is valid +invitation_expire_time: 3000 +# The display-names and colors for the clan ranks +ranks: + member: + name: "Member" + color: "§7" + vim: + name: "VIM" + color: "§e" + coleader: + name: "Co-Leader" + color: "§a" + leader: + name: "Leader" + color: "§5" +bank: + enabled: true + withdraw: + # All members (except the clan leader) have to wait this long (in hours) between withdrawing from the clan's bank + cooldown: 24 + maximum: + # How much percent of the money on the clan bank can be withdrawn from members with the following ranks + member: 5 + vim: 10 + coleader: 30 + leader: 100 +... \ No newline at end of file diff --git a/resources/strings.yml b/resources/strings.yml new file mode 100644 index 0000000..933d658 --- /dev/null +++ b/resources/strings.yml @@ -0,0 +1,110 @@ +--- +command: + clan: + usage: "§cUsage: /clan " + cannotUseSubcommand: "§cYou cannot use this subcommand!" + accept: + alreadyInClan: "§cYou are already in a clan!" + passClan: "§cPlease pass a clan!" + invalidClan: "§cThere is no clan by that name!" + notInvited: "§cYou have not been invited to this clan!" + success: "§aYou joined §b{clan}§a." + chat: + disabled: "§cThis feature is disabled!" + noClan: "§cYou need to be in a clan to use this feature!" + passMessage: "§cPlease pass a message!" + on: "§aYou are now in the clan chat mode." + off: "§aYou are no longer in the clan chat mode." + create: + alreadyInClan: "§cYou are already in a clan!" + passClan: "§cPlease pass a clan!" + clanExists: "§cThere already is a clan by that name!" + bannedName: "§cThis name is banned!" + notEnoughMoney: "§cYou don't have enough money (§6{price}§c) to create a clan!" + success: "§aYou successfully created the clan §b{clan}§a." + delete: + noClan: "§cYou need to be in a clan to use this feature!" + notLeader: "§cYou must be the leader of your clan to delete it!" + cancelled: "§cDeleting the clan has been cancelled!" + demote: + noClan: "§cYou need to be in a clan to use this feature!" + notLeader: "§cYou must be the leader of your clan to promote someone!" + passPlayer: "§cPlease pass a player!" + notInClan: "§b{player} §cis not in your clan!" + alreadyLowest: "§cThis player cannot be demoted anymore!" + success: "§aYou successfully demoted §b{player} §ato {rank}§a." + deposit: + disabled: "§cThis feature is disabled!" + noClan: "§cYou need to be in a clan to use this feature!" + passNumber: "§cPlease pass a valid number!" + tooMuch: "§cYou cannot deposit this much!" + success: "§aYou have successfully deposited §6{amount} §amoney to your clan's bank account." + help: + success: "§bClan §cHelp:\n§e/clan help §d- §6Displays this list of available commands\n§e/clan create §d- §6Creates a clan\n§e/clan demote §d- §6Demotes a player\n§e/clan deposit §d- §6Deposits money to the clan bank\n§e/clan info [clanname] §d- §6Gives you information about your/a clan\n§e/clan invite §d- §6Invites a player to your clan\n§e/clan accept §d- §6Accepts a clan invitation\n§e/clan join §d- §6Joins a clan (only for staff)\n§e/clan leave §d- §6Leaves a clan\n§e/clan leader §d- §6Promotes a player to the clan leader\n§e/clan chat §d- §6Sends a message to your clan\n§e/clan kick §d- §6Kicks the given player from the clan\n§e/clan delete §d- §6Deletes your clan\n§e/clan promote §d- §6Promotes a player\n§e/clan withdraw §d- §6Withdraws money from the clan bank\n§e/clan about §d- §6Shows credits and the version of BedrockClans" + info: + noClan: "§cYou need to be in a clan or pass a clanname!" + invalidClan: "§cThere is no clan by that name!" + success: "§eInfo about {name}:\n§bLeader: §c{leader}\n§bMembers: §c{members}\n§bBank: §c{bank}$" + invite: + noClan: "§cYou need to be in a clan to use this feature!" + passPlayer: "§cPlease pass a player!" + notFound: "§cThere is no player by that name online on this server!" + alreadyInClan: "§cThis player is already in a clan!" + alreadyInvited: "§cThis player has already been invited to your clan!" + sender: "§aYou successfully invited §b{player} §ato your clan." + target: "§aYou have been invited to the clan §b{clan} §aby §b{player}§a." + join: + alreadyInClan: "§cYou are already in a clan!" + passClan: "§cPlease pass a clan!" + invalidClan: "§cThere is no clan by that name!" + success: "§aYou joined §b{clan}§a." + kick: + noClan: "§cYou need to be in a clan to use this feature!" + notLeader: "§cYou must be the leader of your clan to kick a player out of it!" + passPlayer: "§cPlease pass a player!" + notInClan: "§b{player} §cis not in your clan!" + cannotKickLeader: "§cYou cannot kick the leader of your clan!" + success: "§aYou successfully kicked §b{player} §aout of your clan." + leader: + noClan: "§cYou need to be in a clan to use this feature!" + notLeader: "§cYou must be the leader of your clan to promote someone to the leader!" + passPlayer: "§cPlease pass a player!" + notInClan: "§b{player} §cis not in your clan!" + alreadyLeader: "§cThis player is already the leader!" + success: "§aYou successfully promoted §b{player} §ato the leader of your clan." + leave: + noClan: "§cYou need to be in a clan to use this feature!" + leader: "§cYou cannot leave your clan because you are the clan leader!" + success: "§aYou successfully left your clan." + promote: + noClan: "§cYou need to be in a clan to use this feature!" + notLeader: "§cYou must be the leader of your clan to promote someone!" + passPlayer: "§cPlease pass a player!" + notInClan: "§b{player} §cis not in your clan!" + alreadyHighest: "§cThis player is already a co-leader or higher!" + success: "§aYou successfully promoted §b{player} §ato {rank}§a." + withdraw: + disabled: "§cThis feature is disabled!" + noClan: "§cYou need to be in a clan to use this feature!" + cooldown: "§cYou cannot withdraw money from clan bank for the next §e{hours} hours, {minutes} minutes and {seconds} seconds§c!" + passNumber: "§cPlease pass a valid number!" + tooMuch: "§cYou cannot withdraw this much!" + success: "§aYou have successfully withdrawn §6{amount} §amoney from your clan's bank account." +clan: + join: + members: "§a{player} §6joined your clan." + chat: + members: "§bClan §c> {player} §c: §r{message}" + delete: + members: "§cYour clan has been deleted!" + kick: + kicked: "§cYou were kicked out of your clan by §b{player}§c." + leader: + newleader: "§aYou are now the leader of your clan." + leave: + members: "§a{player} §cleft your clan." + promote: + promoted: "§aYou have been promoted to {rank}§a." + demote: + demoted: "§cYou have been demoted to {rank}§c." +... \ No newline at end of file diff --git a/src/Wertzui123/BedrockClans/BCPlayer.php b/src/Wertzui123/BedrockClans/BCPlayer.php index 730166c..b05b258 100644 --- a/src/Wertzui123/BedrockClans/BCPlayer.php +++ b/src/Wertzui123/BedrockClans/BCPlayer.php @@ -5,44 +5,195 @@ namespace Wertzui123\BedrockClans; use pocketmine\Player; +use pocketmine\Server; +use Wertzui123\BedrockClans\events\player\ClanJoinEvent; class BCPlayer { private $plugin; private $player; private $clan; + private $withdrawCooldown = 0; + private $chatting = false; - public function __construct(Main $plugin, Player $player, $clan = null) + /** + * BCPlayer constructor. + * @param Main $plugin + * @param Player $player + * @param Clan|null $clan + * @param int $withdrawCooldown + */ + public function __construct(Main $plugin, Player $player, $clan = null, $withdrawCooldown = null) { $this->plugin = $plugin; $this->player = $player; - $this->clan = $clan ?? $plugin->getPlayersFile()->get(strtolower($player->getName())) !== false ? $this->plugin->getClan($plugin->getPlayersFile()->get(strtolower($player->getName()))) : null; + $this->clan= $clan ?? $plugin->getPlayersFile()->get(strtolower($player->getName())) !== false ? $this->plugin->getClan($plugin->getPlayersFile()->get(strtolower($player->getName()))) : null; + $this->withdrawCooldown = $clan ?? $plugin->getWithdrawCooldownsFile()->get(strtolower($player->getName()), 0); } + /** + * Returns the player instance of this player + * @return Player + */ public function getPlayer() : Player{ return $this->player; } + /** + * Returns whether the player is in a clan + * @return bool + */ + public function isInClan() : bool{ + return $this->clan !== null; + } + + /** + * Returns the players clan + * @return Clan|null + */ public function getClan() : ?Clan{ return $this->clan; } + /** + * Updates the players clan + * @param Clan|null $clan + */ public function setClan(?Clan $clan){ $this->clan = $clan; } - public function isInClan() : bool{ - return $this->clan !== null; + /** + * Returns whether this player is currently in clan chat mode + * @return bool + */ + public function isChatting() + { + return $this->chatting; } + /** + * Defines whether the given player is currently in chat mode + * @param bool $value + */ + public function setChatting($value = true){ + $this->chatting = $value; + } + + /** + * Returns whether the player is the leader of their clan or false if the player is not in a clan + * @return bool + */ public function isLeader() : bool{ return $this->isInClan() ? $this->getClan()->getLeader() === strtolower($this->getPlayer()->getName()) : false; } + /** + * Adds a withdraw cooldown of the given seconds + * @param int $seconds + */ + public function addWithdrawCooldown($seconds){ + $this->withdrawCooldown = time() + $seconds; + } + + /** + * @api + * Returns the number of seconds until the player can withdraw from the clan bank again + * @return int + */ + public function getWithdrawCooldown(){ + return $this->withdrawCooldown - time(); + } + + /** + * @api + * Returns the whether the player cannot withdraw from the clan bank + * @return int + */ + public function hasWithdrawCooldown(){ + return $this->getWithdrawCooldown() > 0; + } + + /** + * @internal + * Returns how much money is on the player's economy api account + * @return int + */ + public function getMoney(){ + if(!is_null(Server::getInstance()->getPluginManager()->getPlugin('EconomyAPI'))){ + return Server::getInstance()->getPluginManager()->getPlugin('EconomyAPI')->myMoney($this->getPlayer()); + } + return 0; + } + + /** + * @internal + * Adds money to the given player's economy api account + * @param int $amount + */ + public function addMoney($amount){ + if(!is_null(Server::getInstance()->getPluginManager()->getPlugin('EconomyAPI'))){ + Server::getInstance()->getPluginManager()->getPlugin('EconomyAPI')->addMoney($this->getPlayer(), $amount); + } + } + + /** + * @internal + * Removes money from the given player's economy api account + * @param int $amount + */ + public function removeMoney($amount){ + if(!is_null(Server::getInstance()->getPluginManager()->getPlugin('EconomyAPI'))){ + Server::getInstance()->getPluginManager()->getPlugin('EconomyAPI')->reduceMoney($this->getPlayer(), $amount); + } + } + + /** + * Makes this player join the given clan + * @param Clan $clan + * @return bool + */ + public function joinClan(Clan $clan) + { + $event = new ClanJoinEvent($this->getPlayer(), $clan); + $event->call(); + if($event->isCancelled()) return false; + foreach ($clan->getMembers() as $member) { + if (!is_null($m = Server::getInstance()->getPlayerExact(Main::getInstance()->getPlayerName($member)))) { + $m->sendMessage(Main::getInstance()->getMessage('clan.join.members', ['{player}' => $this->getPlayer()->getName()])); + } + } + $clan->addMember($this); + $this->setClan($clan); + return true; + } + + /** + * Makes the player send a message to the clan chat + * @param string $message + * @return bool + */ + public function chat($message){ + if(!$this->isInClan()) return false; + foreach ($this->getClan()->getMembersWithRealName() as $member){ + if(($m = $this->plugin->getServer()->getPlayerExact($member)) instanceof Player){ + $m->sendMessage($this->plugin->getMessage('clan.chat.members', ['{player}' => Clan::getRankColor($this->getClan()->getRank($this)) . $this->getPlayer()->getName(), '{message}' => $message])); + } + } + return true; + } + + /** + * Saves the player to the file system + */ public function save(){ - $cfg = $this->plugin->getPlayersFile(); - $cfg->set(strtolower($this->getPlayer()->getName()), $this->getClan() === null ? $this->getClan() : $this->getClan()->getName()); - $cfg->save(); + $file = $this->plugin->getPlayersFile(); + $file->set(strtolower($this->getPlayer()->getName()), $this->getClan() === null ? null : $this->getClan()->getName()); + $file->save(); + + $file = $this->plugin->getWithdrawCooldownsFile(); + $file->set(strtolower($this->getPlayer()->getName()), $this->getWithdrawCooldown()); + $file->save(); } } \ No newline at end of file diff --git a/src/Wertzui123/BedrockClans/Clan.php b/src/Wertzui123/BedrockClans/Clan.php index a907f74..5ad61f5 100644 --- a/src/Wertzui123/BedrockClans/Clan.php +++ b/src/Wertzui123/BedrockClans/Clan.php @@ -6,131 +6,314 @@ use pocketmine\Player; use pocketmine\utils\Config; +use Wertzui123\BedrockClans\tasks\invitetask; class Clan { private $plugin; private $name; - private $config; + private $file; private $members; private $leader; - public $invites = []; + private $invites = []; + private $bank = 0; - public function __construct(Main $plugin, $name, $cfg = null, $leader = null, $members = null) + /** + * Clan constructor. + * @param Main $plugin + * @param string $name + * @param Config|null $file + * @param string|null $leader + * @param string[]|null $members + * @param int $bank + */ + public function __construct(Main $plugin, $name, $file = null, $leader = null, $members = null, $bank = null) { $this->plugin = $plugin; $this->name = $name; - $this->config = $cfg ?? new Config($this->plugin->getDataFolder() . "clans/" . $this->name . ".yml", Config::YAML); - $this->leader = $leader ?? $this->getConfig()->get('leader'); - $this->members = $members ?? $this->getConfig()->get('members'); + $this->file = $file ?? new Config($this->plugin->getDataFolder() . 'clans/' . $this->name . '.json', Config::JSON); + if(file_exists($this->plugin->getDataFolder() . 'clans/' . $this->name . '.yml')){ + $this->file->setAll((new Config($this->plugin->getDataFolder() . "clans/" . $this->name . ".yml", Config::YAML))->getAll()); + } + $this->leader = $leader ?? $this->getFile()->get('leader', ''); + $this->members = $members ?? $this->getFile()->get('members', []); + $this->bank = $bank ?? $this->getFile()->get('bank', 0); } - - public function getConfig(): Config + /** + * Returns the clan file + * @return Config + */ + public function getFile(): Config { - return $this->config; + return $this->file; } + /** + * Returns the clans name + * @return string + */ public function getName() { return $this->name; } /** + * Returns a list of all members of the clan + * The returned array contains the save-names of the players * @return string[] */ public function getMembers(): array { - return $this->members; + return array_keys($this->members); } /** + * Returns a list of all members of the clan + * The returned array contains the real names of the players + * @param bool $color [optional] * @return string[] */ - public function getMembersWithRealName(): array + public function getMembersWithRealName($color = false): array { - $members = []; - foreach ($this->members as $index => $member) { - $members[$index] = $this->plugin->getPlayerName($member); - } - return $members; + return array_map(function ($member) use ($color) { + return ($color ? self::getRankColor($this->getRank($member)) : '') . $this->plugin->getPlayerName($member); + }, array_keys($this->members)); } - public function addMember($player) + /** + * Adds a player to the clans members + * @param BCPlayer|Player|string $player + * @param string $rank + * @return bool + */ + public function addMember($player, $rank = 'member') { - if($player instanceof BCPlayer) $player = $player->getPlayer()->getName(); else if($player instanceof Player) $player = $player->getName(); - $player = strtolower($player); + $player = strtolower($player instanceof BCPlayer ? $player->getPlayer()->getName() : ($player instanceof Player ? $player->getName() : $player)); if (!in_array($player, $this->members)) { - array_push($this->members, $player); + $this->members[$player] = strtolower($rank); + return true; } + return false; } + /** + * Adds a player to the clans members + * @param BCPlayer|Player|string $player + * @return bool + */ public function removeMember($player) { - if($player instanceof BCPlayer) $player = $player->getPlayer()->getName(); else if($player instanceof Player) $player = $player->getName(); - $player = strtolower($player); - if (in_array($player, $this->members)) { - unset($this->members[array_search($player, $this->members)]); + $player = strtolower($player instanceof BCPlayer ? $player->getPlayer()->getName() : ($player instanceof Player ? $player->getName() : $player)); + if (isset($this->members[$player])) { + unset($this->members[$player]); + return true; } + return false; } - public function setMembers(array $members){ + /** + * Updates the list of members of the clan + * @param string[] $members + */ + public function setMembers(array $members) + { $this->members = $members; } - public function getLeaderWithRealName(){ - return $this->plugin->getPlayerName($this->leader); + /** + * Returns the clan rank of the given player + * @param BCPlayer|Player|string $player + * @return string|null + */ + public function getRank($player){ + $player = strtolower($player instanceof BCPlayer ? $player->getPlayer()->getName() : ($player instanceof Player ? $player->getName() : $player)); + return $this->members[$player] ?? null; + } + + /** + * Updates the clan rank of the given player + * @param BCPlayer|Player|string $player + * @param string $rank + */ + public function setRank($player, $rank){ + $player = strtolower($player instanceof BCPlayer ? $player->getPlayer()->getName() : ($player instanceof Player ? $player->getName() : $player)); + $this->members[$player] = $rank; } - public function getLeader(){ + /** + * Returns the save-name of the clan leader + * @return string + */ + public function getLeader() + { return $this->leader; } - public function setLeader($player){ - if($player instanceof BCPlayer){ - $player = strtolower($player->getPlayer()->getName()); - }elseif($player instanceof Player){ - $player = strtolower($player->getName()); - }else { - $player = strtolower($player); - } - $this->leader = $player; + /** + * Returns the real name of the clan leader + * @return string + */ + public function getLeaderWithRealName() + { + return $this->plugin->getPlayerName($this->leader); } + /** + * Updates the clan leader + * @param BCPlayer|Player|string $player + */ + public function setLeader($player) + { + $this->leader = strtolower($player instanceof BCPlayer ? $player->getPlayer()->getName() : ($player instanceof Player ? $player->getName() : $player)); + } /** + * Returns whether a given player is invited to this clan + * @param BCPlayer $player + * @return bool + */ + public function isInvited(BCPlayer $player) + { + return in_array($player, $this->invites, true); + } + + /** + * Returns a list of all players currently invited to this clan * @return BCPlayer[] */ - public function getInvites() : array { + public function getInvites(): array + { return $this->invites; } - public function setInvites(array $invites){ + /** + * Updates the list of all players invited to this clan + * @param BCPlayer[] $invites + */ + public function setInvites(array $invites) + { $this->invites = $invites; } - public function invite(BCPlayer $player){ - if(!in_array($player, $this->invites, true)) $this->invites[] = $player; + /** + * Invites a player to the clan + * @param BCPlayer $player + */ + public function addInvite(BCPlayer $player) + { + if (!in_array($player, $this->invites, true)) $this->invites[] = $player; } - public function removeInvite(BCPlayer $player){ + /** + * Removes a player from being invited to the clan + * @param BCPlayer $player + */ + public function removeInvite(BCPlayer $player) + { unset($this->invites[array_search($player, $this->invites, true)]); } - public function isInvited(BCPlayer $player){ - return in_array($player, $this->invites, true); + /** + * Returns how much money is stored on the clan bank + * @return int + */ + public function getBank() + { + return $this->bank; + } + + /** + * Updates how much money is stored on the clan bank + * @param int $bank + */ + public function setBank($bank) + { + $this->bank = $bank; + } + + /** + * Invites a player to this clan + * @param BCPlayer $sender + * @param BCPlayer $target + */ + public function invite(BCPlayer $sender, BCPlayer $target) + { + $target->getPlayer()->sendMessage(Main::getInstance()->getMessage('command.invite.target', ['{clan}' => $this->getName(), '{player}' => $sender->getPlayer()->getName()])); + $this->addInvite($target); + $task = new invitetask(Main::getInstance(), $sender, $target, Main::getInstance()->getConfig()->get('invitation_expire_time') * 20); + $handle = Main::getInstance()->getScheduler()->scheduleRepeatingTask($task, 1); + $task->setHandler($handle); + } + + /** + * Saves the clan to memory + */ + public function save() + { + $file = $this->getFile(); + $file->set('name', $this->getName()); + $file->set('members', $this->members); // not getMembers() because it doesn't return the ranks + $file->set('leader', $this->getLeader()); + $file->set('bank', $this->getBank()); + $file->save(); + unset($file); + } + + /** + * Returns the save (or display) name fpr all clan-ranks + * @param bool $displayName [optional} + * @return string[] + */ + public static function getRanks($displayName = false){ + if($displayName) { + return ['member' => self::getRankName('member'), 'vim' => self::getRankName('vim'), 'coleader' => self::getRankName('coleader'), 'leader' => self::getRankName('leader')]; + }else{ + return ['member', 'vim', 'coleader', 'leader']; + } } - public function save(){ - $cfg = $this->getConfig(); - $cfg->set("name", $this->getName()); - $cfg->set("members", $this->getMembers()); - $cfg->set("leader", $this->getLeader()); - $cfg->save(); - unset($cfg); - //Save's the clan members, the clan name and the clan leader. + /** + * Returns the display name of the given rank + * @param string $rank + * @param bool $color [optional] + * @return string|false + */ + public static function getRankName($rank, $color = false){ + if($color){ + return self::getRankColor($rank) . Main::getInstance()->getConfig()->getNested('ranks.' . strtolower($rank) . '.name'); + } + return Main::getInstance()->getConfig()->getNested('ranks.' . strtolower($rank) . '.name'); } -} + + /** + * Returns the color of the given rank + * @param string $rank + * @return string|false + */ + public static function getRankColor($rank){ + return Main::getInstance()->getConfig()->getNested('ranks.' . strtolower($rank) . '.color'); + } + + /** + * Returns whether the given name is a valid clan name + * @param string $name + * @return bool + */ + public static function isValidName($name){ + return !in_array($name, Main::getInstance()->getConfig()->get('banned_clan_names')); + } + + /** + * Returns the maximum amount of money which can be withdrawn from the clan bank with the given rank + * @param string $rank + * @return int + */ + public static function getMaxWithdrawAmount($rank){ + return Main::getInstance()->getConfig()->getNested('bank.withdraw.maximum.' . $rank, 0); + } + +} \ No newline at end of file diff --git a/src/Wertzui123/BedrockClans/Main.php b/src/Wertzui123/BedrockClans/Main.php index 6b1f7e5..2bfcac2 100644 --- a/src/Wertzui123/BedrockClans/Main.php +++ b/src/Wertzui123/BedrockClans/Main.php @@ -4,92 +4,213 @@ namespace Wertzui123\BedrockClans; -use pocketmine\IPlayer; +use pocketmine\OfflinePlayer; use pocketmine\Player; use pocketmine\plugin\PluginBase; use pocketmine\utils\Config; use Wertzui123\BedrockClans\commands\clancmd; +use Wertzui123\BedrockClans\events\clan\ClanCreateEvent; +use Wertzui123\BedrockClans\events\clan\ClanDeleteEvent; use Wertzui123\BedrockClans\listener\CustomListener; use Wertzui123\BedrockClans\listener\EventListener; -use Wertzui123\BedrockClans\tasks\invitetask; class Main extends PluginBase { + // TODO: UIs + + private static $instance; + private $prefix; private $clans = []; - private $playernames; - private $msgs; - private $playersfile; + private $playerNames; + private $stringsFile; + private $playersFile; + private $withdrawCooldownsFile; private $players = []; - const CFG_VERSION = 2.0; + const CONFIG_VERSION = 3.0; public function onEnable(): void { - $this->ConfigUpdater(self::CFG_VERSION); - if (!is_dir($this->getDataFolder() . 'clans')) @mkdir($this->getDataFolder() . "clans"); - $data = ['command' => $this->getConfig()->get('command'), 'description' => $this->getConfig()->get('description'), 'aliases' => $this->getConfig()->get('aliases')]; - $this->getServer()->getCommandMap()->register("clancmd", new clancmd($this, $data)); + self::$instance = $this; + $this->ConfigUpdater(); + if (!is_dir($this->getDataFolder() . 'clans')) @mkdir($this->getDataFolder() . 'clans'); + $this->playerNames = new Config($this->getDataFolder() . "names.json", Config::YAML); + $this->stringsFile = new Config($this->getDataFolder() . 'strings.yml', Config::YAML); + $this->playersFile = new Config($this->getDataFolder() . 'players.json', Config::JSON); + $this->withdrawCooldownsFile = new Config($this->getDataFolder() . 'withdrawCooldowns.json', Config::JSON); + $this->loadClans(true); + $this->prefix = (string)$this->getConfig()->get('prefix'); $this->getServer()->getPluginManager()->registerEvents(new CustomListener($this), $this); $this->getServer()->getPluginManager()->registerEvents(new EventListener($this), $this); - $this->playernames = new Config($this->getDataFolder() . "names.yml", Config::YAML); - $this->msgs = new Config($this->getDataFolder() . 'messages.yml', Config::YAML); - $this->playersfile = new Config($this->getDataFolder() . 'players.yml'); - $this->loadClans(); + $data = ['command' => $this->getConfig()->getNested('command.clan.command'), 'description' => $this->getConfig()->getNested('command.clan.description'), 'usage' => $this->getConfig()->getNested('command.clan.usage'), 'aliases' => $this->getConfig()->getNested('command.clan.aliases')]; + $this->getServer()->getCommandMap()->register("BedrockClans", new clancmd($this, $data)); } - public function getPath(){ - return $this->getDataFolder(); + /** + * Returns the current (and only) instance of this class + * @return Main + */ + public static function getInstance(){ + return self::$instance; } - private function ConfigUpdater($version){ - $cfgpath = $this->getDataFolder() . "config.yml"; - $msgpath = $this->getDataFolder() . "messages.yml"; - if (file_exists($cfgpath)) { - $cfgversion = $this->getConfig()->get("version"); - if ($cfgversion !== $version) { - $this->getLogger()->info("Your config has been renamed to config-" . $cfgversion . ".yml and your messages file has been renamed to messages-" . $cfgversion . ".yml. That's because your config version wasn't the latest avable. So we created a new config and a new messages file for you!"); - rename($cfgpath, $this->getDataFolder() . "config-" . $cfgversion . ".yml"); - rename($msgpath, $this->getDataFolder() . "messages-" . $cfgversion . ".yml"); - $this->saveResource("config.yml"); - $this->saveResource("messages.yml"); - } - } else { - $this->saveResource("config.yml"); - $this->saveResource("messages.yml"); - } + /** + * @deprecated + * @return array + */ + public function getMessagesArray(): array + { + return $this->getStringsFile()->getAll(); } - private function loadClans() + /** + * @internal + * @return Config + */ + public function getStringsFile(): Config + { + return $this->stringsFile; + } + + /** + * @internal + * @return Config + */ + public function getPlayersFile(): Config { - foreach ($this->allClans() as $clan) { - $name = substr($clan, 0, -4); - $name = substr($name, strlen($this->getDataFolder()."clans/")); + return $this->playersFile; + } + + /** + * @internal + * @return Config + */ + public function getWithdrawCooldownsFile(): Config + { + return $this->withdrawCooldownsFile; + } + + /** + * @internal + * @return Config + */ + public function getPlayerNames(): Config + { + return $this->playerNames; + } + + /** + * @param string $key + * @param array $replace [optional] + * @param mixed $default [optional] + * @return string|mixed + * @internal + * Returns a string from the strings file + */ + public function getString($key, $replace = [], $default = "") + { + return str_replace(array_keys($replace), $replace, $this->getStringsFile()->getNested($key, $default)); + } + + /** + * @param string $key + * @param array $replace [optional] + * @param mixed $default [optional] + * @return string|mixed + * @internal + * Returns a message from the strings file + */ + public function getMessage($key, $replace = [], $default = "") + { + return $this->prefix . $this->getString($key, $replace, $default); + } + + /** + * Returns all clans found in the database + * @return array|false + * @param bool $loadYAML [optional] + */ + public function allClans($loadYAML = false) + { + return array_merge(glob($this->getDataFolder() . 'clans/*.json'), $loadYAML ? glob($this->getDataFolder() . 'clans/*.yml') : []); + } + + /** + * Loads all clans from the database + * @param bool $loadYAML [optional] + */ + private function loadClans($loadYAML = false) + { + foreach ($this->allClans($loadYAML) as $clan) { + $name = basename($clan, '.json'); + if($loadYAML){ + $name = basename($name, '.yml'); + } $this->addClan($name); } } + /** + * @return BCPlayer[] + */ + public function getPlayers(): array + { + return $this->players; + } + + /** + * Returns whether a clan by the given name exists + * @param string $name + * @return bool + */ + public function clanExists($name){ + return !is_null($this->getClan($name)); + } + + /** + * @return Clan[] + */ + public function getClans(): array + { + return $this->players; + } + + /** + * @internal + * @param Player $player + */ public function addPlayer(Player $player) { $this->players[$player->getName()] = new BCPlayer($this, $player); } + /** + * @internal + * @param BCPlayer $player + */ public function removePlayer(BCPlayer $player) { $player->save(); unset($this->players[$player->getPlayer()->getName()]); } + /** + * @api + * Returns a BCPLayer instance for the given player + * @param Player|string $player + * @return BCPlayer + */ public function getPlayer($player): BCPlayer { return $this->players[$player instanceof Player ? $player->getName() : $player]; } - public function getPlayerNames(): Config - { - return $this->playernames; - } - + /** + * Returns the full name of the given player + * @param BCPlayer|Player|string $player + * @return bool|mixed + */ public function getPlayerName($player) { if ($player instanceof BCPlayer) { @@ -101,6 +222,13 @@ public function getPlayerName($player) return $this->getPlayerNames()->get(strtolower($player)); } + /** + * @internal + * @see Main::createClan() + * Registers a clan to the plugin + * @param Clan|string $clan + * @return Clan + */ public function addClan($clan) { if ($clan instanceof Clan) { @@ -113,89 +241,78 @@ public function addClan($clan) } } - public function createClan($name, BCPlayer $leader) - { - $cfg = new Config($this->getDataFolder() . 'clans/' . $name . '.yml', Config::YAML); - $cfg->set('name', $name); - $cfg->set('leader', strtolower($leader->getPlayer()->getName())); - $cfg->set('members', [strtolower($leader->getPlayer()->getName())]); - $cfg->save(); - $clan = new Clan($this, $name, $cfg, strtolower($leader->getPlayer()->getName()), [strtolower($leader->getPlayer()->getName())]); - return $this->addClan($clan); - } - - public function joinClan(BCPlayer $player, Clan $clan) - { - foreach ($clan->getMembers() as $member) { - if (($mp = $this->getServer()->getPlayerExact($this->getPlayerName($member)))) { - $mp->sendMessage(str_replace("{playername}", $player->getPlayer()->getName(), $this->getMessagesArray()["join_player_joined_clan"])); - } - } - $clan->addMember($player); - $player->setClan($clan); - } - - public function getMessagesArray(): array + /** + * @api + * Returns a clan by its name or null if no clan by the given name exists + * @param string $name + * @return Clan|null + */ + public function getClan($name): ?Clan { - return $this->getMessages()->getAll(); + return $this->clans[$name] ?? null; } - public function getMessages(): Config + /** + * @api + * Returns a clan by the given player + * @param BCPlayer|Player|string $player + * @return Clan|null + */ + public function getClanByPlayer($player) { - return $this->msgs; + $player = strtolower($player instanceof BCPlayer ? $player->getPlayer()->getName() : ($player instanceof Player ? $player->getName() : $player)); + return $this->getClan($this->getPlayersFile()->get($player, null)); } - public function getClan($cname): ?Clan + /** + * @api + * Creates a new clan + * @param string $name + * @param BCPlayer $leader + * @return Clan|null + */ + public function createClan($name, BCPlayer $leader) { - return isset($this->clans[$cname]) ? $this->clans[$cname] : null; - } - - public function getClanByPlayer($player){ - return $this->getClan($this->getPlayersFile()->get(strtolower($player instanceof BCPlayer ? $player->getPlayer()->getName() : $player))); + $file = new Config($this->getDataFolder() . 'clans/' . $name . '.json', Config::JSON); + $file->set('name', $name); + $file->set('leader', strtolower($leader->getPlayer()->getName())); + $file->set('members', [strtolower($leader->getPlayer()->getName()) => 'leader']); + $file->save(); + $clan = new Clan($this, $name, $file, strtolower($leader->getPlayer()->getName()), [strtolower($leader->getPlayer()->getName()) => 'leader']); + $clan->setRank($leader, 'leader'); + $event = new ClanCreateEvent($clan, $leader->getPlayer()); + $event->call(); + if($event->isCancelled()) return null; + return $this->addClan($clan); } + /** + * @api + * Deletes the given clan + * @param Clan|string $clan + * @return bool + */ public function deleteClan($clan) { - if (!$clan instanceof Clan) { - $clan = $this->getClan($clan); - } + if (!$clan instanceof Clan) $clan = $this->getClan($clan); + $event = new ClanDeleteEvent($clan); + $event->call(); + if($event->isCancelled()) return false; $members = $clan->getMembers(); - $msgs = $this->getMessagesArray(); foreach ($members as $member) { - if (($member = $this->getServer()->getPlayerExact($member))) { - $member->sendMessage($msgs["delete_clan_deleted_members"]); - $member = $this->getPlayer($member->getName()); - $member->setClan(null); + if ($player = $this->getServer()->getPlayerExact($member)) { + $player->sendMessage($this->getMessage('clan.delete.members')); + $this->getPlayer($player)->setClan(null); } else { - $member = $this->getServer()->getOfflinePlayer($member); $this->setClan($member, null); } } unset($this->clans[$clan->getName()]); - $file = $this->getPath().'clans/'.$clan->getName().'.yml'; + $file = $this->getDataFolder() . 'clans/' . $clan->getName() . '.json'; unset($clan); unlink($file); unset($file); - } - - public function clanExist($clanname) - { - return isset($this->clans[$clanname]); - } - - public function invite(BCPlayer $sender, BCPlayer $target) - { - $messages = $this->getMessagesArray(); - $sclan = $sender->getClan(); - $sname = $this->getPlayerName($sender); - $message = str_replace("{clan}", $sclan->getName(), $messages["invite_were_invited"]); - $message = str_replace("{player}", $sname, $message); - $target->getPlayer()->sendMessage($message); - $sclan->invite($target); - - $task = new invitetask($this, $sender, $target, $this->ConfigArray()["expire_time"] * 20); - $handler = $this->getScheduler()->scheduleRepeatingTask($task, 1); - $task->setHandler($handler); + return true; } public function expire(BCPlayer $sender, BCPlayer $target) @@ -212,47 +329,50 @@ public function expire(BCPlayer $sender, BCPlayer $target) $sclan->removeInvite($target); } - public function getPlayersFile(): Config - { - return $this->playersfile; - } - + /** + * @internal + * @see BCPlayer::joinClan() + * @param OfflinePlayer|string $player + * @param Clan|null $clan + */ public function setClan($player, ?Clan $clan) { $clan = $clan === null ? $clan : $clan->getName(); - $this->getPlayersFile()->set($player instanceof IPlayer ? strtolower($player->getName()) : $player, $clan); + $this->getPlayersFile()->set($player instanceof OfflinePlayer ? strtolower($player->getName()) : $player, $clan); $this->getPlayersFile()->save(); } - public function ConfigArray() - { - return $this->getConfig()->getAll(); - } - - public function allClans() - { - $clans = glob($this->getDataFolder() . "clans/*.yml"); - return $clans; - } - /** - * @return BCPlayer[] + * Checks whether the config version is the latest and updates it if it isn't */ - public function getPlayers(): array + private function ConfigUpdater() { - return $this->players; + if (!file_exists($this->getDataFolder() . "config.yml")) { + $this->saveResource('config.yml'); + $this->saveResource('strings.yml'); + return; + } + if ($this->getConfig()->get('config-version') !== self::CONFIG_VERSION) { + $config_version = $this->getConfig()->get('config-version'); + $this->getLogger()->info("§eYour Config isn't the latest. BedrockClans renamed your old config to §bconfig-" . $config_version . ".yml §6and created a new config. Have fun!"); + rename($this->getDataFolder() . "config.yml", $this->getDataFolder() . "config-" . $config_version . ".yml"); + rename($this->getDataFolder() . "strings.yml", $this->getDataFolder() . "strings-" . $config_version . ".yml"); + $this->saveResource("config.yml"); + $this->saveResource("strings.yml"); + } } /** - * @return Clan[] + * Converts seconds to hours, minutes and seconds + * @param int $seconds + * @param string $message + * @return string */ - public function getClans(): array - { - return $this->players; - } - - public function getMessage($key){ - return $this->getMessagesArray()[$key]; + public function ConvertSeconds($seconds, $message){ + $hours = floor($seconds / 3600); + $minutes = floor(($seconds / 60) % 60); + $seconds = $seconds % 60; + return str_replace(["{hours}", "{minutes}", "{seconds}"], [$hours, $minutes, $seconds], $message); } public function onDisable(): void @@ -260,8 +380,10 @@ public function onDisable(): void foreach ($this->getPlayers() as $player) { $player->save(); } - foreach ($this->clans as $clan){ + foreach ($this->clans as $clan) { $clan->save(); } + $this->withdrawCooldownsFile->save(); } -} + +} \ No newline at end of file diff --git a/src/Wertzui123/BedrockClans/commands/clancmd.php b/src/Wertzui123/BedrockClans/commands/clancmd.php index 9284ea7..2d5c3de 100644 --- a/src/Wertzui123/BedrockClans/commands/clancmd.php +++ b/src/Wertzui123/BedrockClans/commands/clancmd.php @@ -9,8 +9,10 @@ use Wertzui123\BedrockClans\commands\subcommands\about; use Wertzui123\BedrockClans\commands\subcommands\accept; use Wertzui123\BedrockClans\commands\subcommands\chat; +use Wertzui123\BedrockClans\commands\subcommands\demote; use Wertzui123\BedrockClans\commands\subcommands\create; use Wertzui123\BedrockClans\commands\subcommands\delete; +use Wertzui123\BedrockClans\commands\subcommands\deposit; use Wertzui123\BedrockClans\commands\subcommands\help; use Wertzui123\BedrockClans\commands\subcommands\info; use Wertzui123\BedrockClans\commands\subcommands\invite; @@ -18,7 +20,9 @@ use Wertzui123\BedrockClans\commands\subcommands\kick; use Wertzui123\BedrockClans\commands\subcommands\leader; use Wertzui123\BedrockClans\commands\subcommands\leave; +use Wertzui123\BedrockClans\commands\subcommands\promote; use Wertzui123\BedrockClans\commands\subcommands\Subcommand; +use Wertzui123\BedrockClans\commands\subcommands\withdraw; use Wertzui123\BedrockClans\Main; class clancmd extends Command @@ -28,29 +32,27 @@ class clancmd extends Command public function __construct(Main $plugin, $data) { - parent::__construct($data['command'], $data['description'], null, $data['aliases']); - $this->setPermission("bedrockclans.cmd"); + parent::__construct($data['command'], $data['description'], $data['usage'], $data['aliases']); $this->plugin = $plugin; } public function execute(CommandSender $sender, string $commandLabel, array $args) { if(!isset($args[0])){ - $sender->sendMessage($this->plugin->getConfig()->get("usage")); + $sender->sendMessage($this->plugin->getMessage('command.clan.usage')); return; } $subcommand = $this->getSubCommand($args[0]); - if($subcommand === null){ - $sender->sendMessage($this->plugin->getConfig()->get("usage")); + if(is_null($subcommand)){ + $sender->sendMessage($this->plugin->getMessage('command.clan.usage')); return; } - if(!$subcommand->canUse($sender)){ - $sender->sendMessage($this->plugin->getMessage('cannot_use_subcommand')); + if(!$subcommand->canUse($sender)) { + $sender->sendMessage($this->plugin->getMessage('command.clan.cannotUseSubcommand')); return; } - $arguments = $args; - array_shift($arguments); - $subcommand->execute($sender, $arguments); + array_shift($args); + $subcommand->execute($sender, $args); } public function getSubCommand($name) : ?Subcommand{ @@ -65,6 +67,10 @@ public function getSubCommand($name) : ?Subcommand{ return new create($this->plugin); case "delete": return new delete($this->plugin); + case "demote": + return new demote($this->plugin); + case "deposit": + return new deposit($this->plugin); case "help": return new help($this->plugin); case "info": @@ -79,6 +85,10 @@ public function getSubCommand($name) : ?Subcommand{ return new leader($this->plugin); case "leave": return new leave($this->plugin); + case "promote": + return new promote($this->plugin); + case "withdraw": + return new withdraw($this->plugin); } return null; } diff --git a/src/Wertzui123/BedrockClans/commands/subcommands/about.php b/src/Wertzui123/BedrockClans/commands/subcommands/about.php index 94dd376..965cb6e 100644 --- a/src/Wertzui123/BedrockClans/commands/subcommands/about.php +++ b/src/Wertzui123/BedrockClans/commands/subcommands/about.php @@ -14,7 +14,7 @@ public function canUse(CommandSender $sender) : bool public function execute(CommandSender $sender, array $args) { - $sender->sendMessage("§cBedrock§bClans §awas written by Wertzui123. Your using version §72.0§a. Thanks for downloading (:"); + $sender->sendMessage("§cBedrock§bClans §awas written by Wertzui123. You are using version §73.0§a. Thanks for downloading (:"); } } \ No newline at end of file diff --git a/src/Wertzui123/BedrockClans/commands/subcommands/accept.php b/src/Wertzui123/BedrockClans/commands/subcommands/accept.php index dcd693f..371881b 100644 --- a/src/Wertzui123/BedrockClans/commands/subcommands/accept.php +++ b/src/Wertzui123/BedrockClans/commands/subcommands/accept.php @@ -25,31 +25,25 @@ public function execute(CommandSender $sender, array $args) { $player = $this->plugin->getPlayer($sender); if ($player->isInClan()) { - $sender->sendMessage($this->plugin->getMessage("accept_already_in_clan")); + $sender->sendMessage($this->plugin->getMessage('command.accept.alreadyInClan')); return; } - if (!isset($args[0])) { - $sender->sendMessage($this->plugin->getMessage("accept_provide_clan")); + $sender->sendMessage($this->plugin->getMessage('command.accept.passClan')); return; } - - if (!$this->plugin->clanExist($args[0])) { - $sender->sendMessage($this->plugin->getMessage("accept_clan_does_not_exist")); + if (!$this->plugin->clanExists($args[0])) { + $sender->sendMessage($this->plugin->getMessage('command.accept.invalidClan')); return; } - $clan = $this->plugin->getClan($args[0]); - if (!$clan->isInvited($player)) { - $sender->sendMessage($this->plugin->getMessage("accept_not_invited")); + $sender->sendMessage($this->plugin->getMessage('command.accept.notInvited')); return; } - $clan->removeInvite($player); - $message = str_replace("{clan}", $clan->getName(), $this->plugin->getMessage("accept_accepted_invite")); - $sender->sendMessage($message); - $this->plugin->joinClan($player, $clan); + $player->joinClan($clan); + $sender->sendMessage($this->plugin->getMessage('command.accept.success', ['{clan}' => $clan->getName()])); } } \ No newline at end of file diff --git a/src/Wertzui123/BedrockClans/commands/subcommands/chat.php b/src/Wertzui123/BedrockClans/commands/subcommands/chat.php index 3541120..b507aa4 100644 --- a/src/Wertzui123/BedrockClans/commands/subcommands/chat.php +++ b/src/Wertzui123/BedrockClans/commands/subcommands/chat.php @@ -23,26 +23,32 @@ public function canUse(CommandSender $sender) : bool public function execute(CommandSender $sender, array $args) { - if($this->plugin->ConfigArray()['chat_disabled'] === true){ - $sender->sendMessage($this->plugin->getMessage('chat_disabled')); + if($this->plugin->getConfig()->getNested('chat.enabled') !== true){ + $sender->sendMessage($this->plugin->getMessage('command.chat.disabled')); return; } $player = $this->plugin->getPlayer($sender); $clan = $player->getClan(); if($clan === null){ - $sender->sendMessage($this->plugin->getMessage('chat_not_in_clan')); + $sender->sendMessage($this->plugin->getMessage('command.chat.noClan')); return; } if(!isset($args[0])){ - $sender->sendMessage($this->plugin->getMessage('chat_provide_message')); + $sender->sendMessage($this->plugin->getMessage('command.chat.passMessage')); return; } - - foreach ($clan->getMembersWithRealName() as $member){ - if(($member = $this->plugin->getServer()->getPlayerExact($member)) instanceof Player){ - $member->sendMessage(str_replace(['{name}', '{message}'], [$sender->getName(), implode(' ', $args)], $this->plugin->getConfig()->get('clan_chat_format'))); - } + $message = implode(' ', $args); + if($message === $this->plugin->getConfig()->getNested('chat.on')){ + $player->setChatting(); + $sender->sendMessage($this->plugin->getMessage('command.chat.on')); + return; + } + if($message === $this->plugin->getConfig()->getNested('chat.off')){ + $player->setChatting(false); + $sender->sendMessage($this->plugin->getMessage('command.chat.off')); + return; } + $player->chat($message); } } \ No newline at end of file diff --git a/src/Wertzui123/BedrockClans/commands/subcommands/create.php b/src/Wertzui123/BedrockClans/commands/subcommands/create.php index eab2eb4..88de2db 100644 --- a/src/Wertzui123/BedrockClans/commands/subcommands/create.php +++ b/src/Wertzui123/BedrockClans/commands/subcommands/create.php @@ -4,6 +4,7 @@ use pocketmine\command\CommandSender; use pocketmine\Player; +use Wertzui123\BedrockClans\Clan; use Wertzui123\BedrockClans\Main; class create extends Subcommand @@ -18,47 +19,43 @@ public function __construct(Main $plugin) public function canUse(CommandSender $sender): bool { - return $sender instanceof Player && $sender->hasPermission("bedrockclans.cmd.create"); + return $sender instanceof Player && $sender->hasPermission("bedrockclans.command.create"); } public function execute(CommandSender $sender, array $args) { $player = $this->plugin->getPlayer($sender); - $money = $this->plugin->getServer()->getPluginManager()->getPlugin("EconomyAPI"); if ($player->isInClan()) { - $sender->sendMessage($this->plugin->getMessage("create_already_in_clan")); + $sender->sendMessage($this->plugin->getMessage("command.create.alreadyInClan")); return; } - if (!isset($args[0])) { - $sender->sendMessage($this->plugin->getMessage("create_provide_name")); - } else { - if (!$this->plugin->ClanExist($args[0])) { - if (in_array($args[0], $this->plugin->getConfig()->get("banned_clan_names"))) { - $sender->sendMessage($this->plugin->getMessage("create_name_is_banned")); + $sender->sendMessage($this->plugin->getMessage("command.create.passClan")); + return; + } + $name = implode(' ', $args); + if ($this->plugin->clanExists($name)) { + $sender->sendMessage($this->plugin->getMessage("command.create.clanExists")); + return; + } + if (!Clan::isValidName($name)) { + $sender->sendMessage($this->plugin->getMessage("command.create.bannedName")); + return; + } + if ($this->plugin->getConfig()->get("create_costs") && !is_null($money = $this->plugin->getServer()->getPluginManager()->getPlugin("EconomyAPI"))) { + if (!$sender->hasPermission("bedrockclans.create.cost.bypass")) { + $price = (int)$this->plugin->getConfig()->get("clan_create_cost"); + if ($money->myMoney($sender) >= $price) { + $money->reduceMoney($sender, $price); + } else { + $sender->sendMessage($this->plugin->getMessage("command.create.notEnoughMoney", ['{price}' => $price])); return; } - if ($this->plugin->getConfig()->get("create_costs")) { - if ($money === null) { - $sender->sendMessage($this->plugin->getMessage("economy_plugin_was_not_found")); - return; - } - if (!$sender->hasPermission("bedrockclans.cmd.create.costs.bypass")) { - if ($money->myMoney($sender) >= (int)$this->plugin->getMessage("clan_create_cost")) { - $money->reduceMoney($sender, (int)$this->plugin->getMessage("clan_create_costs")); - } else { - $sender->sendMessage($this->plugin->getMessage("create_not_enought_money")); - return; - } - } - } - $sender->sendMessage($this->plugin->getMessage("create_create_succes")); - $clan = $this->plugin->createClan($args[0], $player); - $player->setClan($clan); - } else { - $sender->sendMessage($this->plugin->getMessage("create_already_exist")); } } + $sender->sendMessage($this->plugin->getMessage("command.create.success", ['{clan}' => $name])); + $clan = $this->plugin->createClan($name, $player); + $player->setClan($clan); } } \ No newline at end of file diff --git a/src/Wertzui123/BedrockClans/commands/subcommands/delete.php b/src/Wertzui123/BedrockClans/commands/subcommands/delete.php index cce20df..4032549 100644 --- a/src/Wertzui123/BedrockClans/commands/subcommands/delete.php +++ b/src/Wertzui123/BedrockClans/commands/subcommands/delete.php @@ -25,16 +25,16 @@ public function execute(CommandSender $sender, array $args) { $player = $this->plugin->getPlayer($sender); if (!$player->isInClan()) { - $sender->sendMessage($this->plugin->getMessage("delete_not_in_clan")); + $sender->sendMessage($this->plugin->getMessage('command.delete.noClan')); return; } - if (!$player->isLeader()) { - $sender->sendMessage($this->plugin->getMessage("delete_not_leader")); + $sender->sendMessage($this->plugin->getMessage('command.delete.notLeader')); return; } - - $this->plugin->deleteClan($player->getClan()); + if(!$this->plugin->deleteClan($player->getClan())){ + $sender->sendMessage($this->plugin->getMessage('command.delete.cancelled')); + } } } \ No newline at end of file diff --git a/src/Wertzui123/BedrockClans/commands/subcommands/demote.php b/src/Wertzui123/BedrockClans/commands/subcommands/demote.php new file mode 100644 index 0000000..14a7875 --- /dev/null +++ b/src/Wertzui123/BedrockClans/commands/subcommands/demote.php @@ -0,0 +1,61 @@ +plugin = $plugin; + } + + public function canUse(CommandSender $sender): bool + { + return $sender instanceof Player; + } + + public function execute(CommandSender $sender, array $args) + { + $player = $this->plugin->getPlayer($sender); + if (!$player->isInClan()) { + $sender->sendMessage($this->plugin->getMessage('command.demote.noClan')); + return; + } + $clan = $player->getClan(); + if (strtolower($sender->getName()) !== $clan->getLeader()) { + $sender->sendMessage($this->plugin->getMessage('command.demote.notLeader')); + return; + } + if (!isset($args[0])) { + $sender->sendMessage($this->plugin->getMessage('command.demote.passPlayer')); + return; + } + if (!in_array(strtolower(implode(' ', $args)), $clan->getMembers())) { + $sender->sendMessage($this->plugin->getMessage('command.demote.notInClan', ['{player}' => implode(' ', $args)])); + return; + } + if($clan->getRank(implode(' ', $args)) === 'leader' || $clan->getRank(implode(' ', $args)) === 'member'){ + $sender->sendMessage($this->plugin->getMessage('command.demote.alreadyLowest')); + return; + } + if($clan->getRank(implode(' ', $args)) === "vim"){ + $rank = "member"; + }else{ + $rank = "vim"; + } + $clan->setRank(implode(' ', $args), $rank); + $sender->sendMessage($this->plugin->getMessage('command.demote.success', ['{player}' => implode(' ', $args), '{rank}' => Clan::getRankName($rank, true)])); + if (!is_null($p = $this->plugin->getServer()->getPlayerExact($this->plugin->getPlayerName(strtolower(implode(' ', $args)))))) { + $p->sendMessage($this->plugin->getMessage('clan.demote.demoted', ['{rank}' => Clan::getRankName($rank, true)])); + } + } + +} \ No newline at end of file diff --git a/src/Wertzui123/BedrockClans/commands/subcommands/deposit.php b/src/Wertzui123/BedrockClans/commands/subcommands/deposit.php new file mode 100644 index 0000000..9c97dd7 --- /dev/null +++ b/src/Wertzui123/BedrockClans/commands/subcommands/deposit.php @@ -0,0 +1,50 @@ +plugin = $plugin; + } + + public function canUse(CommandSender $sender): bool + { + return $sender instanceof Player; + } + + public function execute(CommandSender $sender, array $args) + { + if($this->plugin->getConfig()->getNested('bank.enabled') !== true){ + $sender->sendMessage($this->plugin->getMessage('command.deposit.disabled')); + return; + } + $player = $this->plugin->getPlayer($sender); + if (!$player->isInClan()) { + $sender->sendMessage($this->plugin->getMessage('command.deposit.noClan')); + return; + } + $clan = $player->getClan(); + if (!isset($args[0]) || !is_numeric($args[0]) || (int)$args[0] <= 0) { + $sender->sendMessage($this->plugin->getMessage('command.deposit.passNumber')); + return; + } + $amount = (int)$args[0]; + if($player->getMoney() < $amount){ + $sender->sendMessage($this->plugin->getMessage('command.deposit.tooMuch')); + return; + } + $clan->setBank($clan->getBank() + $amount); + $player->removeMoney($amount); + $sender->sendMessage($this->plugin->getMessage('command.deposit.success', ['{amount}' => $amount])); + } + +} \ No newline at end of file diff --git a/src/Wertzui123/BedrockClans/commands/subcommands/help.php b/src/Wertzui123/BedrockClans/commands/subcommands/help.php index 2202867..67e1083 100644 --- a/src/Wertzui123/BedrockClans/commands/subcommands/help.php +++ b/src/Wertzui123/BedrockClans/commands/subcommands/help.php @@ -22,7 +22,7 @@ public function canUse(CommandSender $sender): bool public function execute(CommandSender $sender, array $args) { - $sender->sendMessage($this->plugin->getMessage("help_help_list")); + $sender->sendMessage($this->plugin->getMessage("command.help.success")); } } \ No newline at end of file diff --git a/src/Wertzui123/BedrockClans/commands/subcommands/info.php b/src/Wertzui123/BedrockClans/commands/subcommands/info.php index 4410fad..2b0032c 100644 --- a/src/Wertzui123/BedrockClans/commands/subcommands/info.php +++ b/src/Wertzui123/BedrockClans/commands/subcommands/info.php @@ -24,40 +24,20 @@ public function canUse(CommandSender $sender): bool public function execute(CommandSender $sender, array $args) { $player = $this->plugin->getPlayer($sender); - if (!isset($args[0])) { - if (!$player->isInClan()) { - $sender->sendMessage($this->plugin->getMessage("info_not_in_clan")); + if (isset($args[0])) { + if (!$this->plugin->clanExists(implode(' ', $args))) { + $sender->sendMessage($this->plugin->getMessage('command.info.invalidClan')); return; } - - $clan = $player->getClan(); - $members = $clan->getMembersWithRealName(); - $leader = $clan->getLeaderWithRealName(); - $cname = $clan->getName(); - $memberss = implode(", ", $members); - $m = str_replace("{clanname}", $cname, $this->plugin->getMessage("info_info_about_your_clan")); - $m = str_replace("{leader}", $leader, $m); - $m = str_replace("{members}", $memberss, $m); - $sender->sendMessage($m); + $clan = $this->plugin->getClan(implode(' ', $args)); } else { - - $cname = implode(' ', $args); - - if (!$this->plugin->clanExist($cname)) { - $sender->sendMessage($this->plugin->getMessage("info_clan_does_not_exist")); + if (!$player->isInClan()) { + $sender->sendMessage($this->plugin->getMessage('command.info.noClan')); return; } - - $clan = $this->plugin->getClan($cname); - $members = $clan->getMembersWithRealName(); - $leader = $clan->getLeaderWithRealName(); - $cname = $clan->getName(); - $memberss = implode(", ", $members); - $m = str_replace("{clanname}", $cname, $this->plugin->getMessage("info_info_about_an_other_clan")); - $m = str_replace("{leader}", $leader, $m); - $m = str_replace("{members}", $memberss, $m); - $sender->sendMessage($m); + $clan = $player->getClan(); } + $sender->sendMessage($this->plugin->getMessage('command.info.success', ['{name}' => $clan->getName(), '{leader}' => $clan->getLeaderWithRealName(), '{members}' => implode(', ', $clan->getMembersWithRealName(true)), '{bank}' => $clan->getBank()])); } } \ No newline at end of file diff --git a/src/Wertzui123/BedrockClans/commands/subcommands/invite.php b/src/Wertzui123/BedrockClans/commands/subcommands/invite.php index 713ad08..d1b6438 100644 --- a/src/Wertzui123/BedrockClans/commands/subcommands/invite.php +++ b/src/Wertzui123/BedrockClans/commands/subcommands/invite.php @@ -25,38 +25,28 @@ public function execute(CommandSender $sender, array $args) { $player = $this->plugin->getPlayer($sender); if (!$player->isInClan()) { - $sender->sendMessage($this->plugin->getMessage("invite_not_in_clan")); + $sender->sendMessage($this->plugin->getMessage('command.invite.noClan')); return; } - - if (!isset($args[0])) { - $sender->sendMessage($this->plugin->getMessage("invite_provide_player")); - return; - } - - if (in_array(strtolower($args[0]), $player->getClan()->getMembers())) { - $sender->sendMessage($this->plugin->getMessage("invite_in_same_clan")); + $name = implode(' ', $args); + if (!isset($name)) { + $sender->sendMessage($this->plugin->getMessage('command.invite.passPlayer')); return; } - - if (!$this->plugin->getServer()->getPlayerExact($args[0])) { - $sender->sendMessage($this->plugin->getMessage("invite_player_does_not_exist")); + if (!$this->plugin->getServer()->getPlayerExact($name)) { + $sender->sendMessage($this->plugin->getMessage('command.invite.notFound')); return; } - - if ($this->plugin->getPlayer($this->plugin->getServer()->getPlayerExact($args[0]))->getClan() === $player->getClan()) { - $sender->sendMessage($this->plugin->getMessage("invite_already_in_clan")); + if ($this->plugin->getPlayer($this->plugin->getServer()->getPlayerExact($name))->getClan() === $player->getClan()) { + $sender->sendMessage($this->plugin->getMessage('command.invite.alreadyInClan')); return; } - - if($player->getClan()->isInvited($this->plugin->getPlayer($this->plugin->getServer()->getPlayerExact($args[0])))){ - $sender->sendMessage($this->plugin->getMessage('invite_already_invited')); + if($player->getClan()->isInvited($this->plugin->getPlayer($this->plugin->getServer()->getPlayerExact($name)))){ + $sender->sendMessage($this->plugin->getMessage('command.invite.alreadyInvited')); return; } - - $this->plugin->invite($player, $this->plugin->getPlayer($this->plugin->getServer()->getPlayerExact($args[0]))); - $msg = str_replace("{player}", $this->plugin->getServer()->getPlayerExact($args[0])->getName(), $this->plugin->getMessage("invite_invited")); - $sender->sendMessage($msg); + $player->getClan()->invite($player, $this->plugin->getPlayer($this->plugin->getServer()->getPlayerExact($args[0]))); + $sender->sendMessage($this->plugin->getMessage('command.invite.sender', ['{player}' => $this->plugin->getServer()->getPlayerExact($name)->getName()])); } } \ No newline at end of file diff --git a/src/Wertzui123/BedrockClans/commands/subcommands/join.php b/src/Wertzui123/BedrockClans/commands/subcommands/join.php index d8f5e61..a5eadd9 100644 --- a/src/Wertzui123/BedrockClans/commands/subcommands/join.php +++ b/src/Wertzui123/BedrockClans/commands/subcommands/join.php @@ -18,28 +18,28 @@ public function __construct(Main $plugin) public function canUse(CommandSender $sender): bool { - return $sender instanceof Player && $sender->hasPermission("bedrockclans.cmd.join"); + return $sender instanceof Player && $sender->hasPermission("bedrockclans.command.join"); } public function execute(CommandSender $sender, array $args) { $player = $this->plugin->getPlayer($sender); - if (!isset($args[0])) { - $sender->sendMessage($this->plugin->getMessage("join_provide_clan")); + if ($player->isInClan()) { + $sender->sendMessage($this->plugin->getMessage('command.join.alreadyInClan')); return; } - if (!$this->plugin->clanExist($args[0])) { - $sender->sendMessage($this->plugin->getMessage("join_clan_does_not_exist")); + if (!isset($args[0])) { + $sender->sendMessage($this->plugin->getMessage('command.join.passClan')); return; } - if ($player->isInClan()) { - $sender->sendMessage($this->plugin->getMessage("join_already_in_clan")); + $name = implode(' ', $args); + if (!$this->plugin->clanExists($name)) { + $sender->sendMessage($this->plugin->getMessage('command.join.invalidClan')); return; } - $clan = $this->plugin->getClan($args[0]); - $this->plugin->joinClan($player, $clan); - $jc = str_replace("{clan}", $args[0], $this->plugin->getMessage("join_joined_clan")); - $sender->sendMessage($jc); + $clan = $this->plugin->getClan($name); + $player->joinClan($clan); + $sender->sendMessage($this->plugin->getMessage('command.join.success', ['{clan}' => $clan->getName()])); } } \ No newline at end of file diff --git a/src/Wertzui123/BedrockClans/commands/subcommands/kick.php b/src/Wertzui123/BedrockClans/commands/subcommands/kick.php index 72f97f0..64556c2 100644 --- a/src/Wertzui123/BedrockClans/commands/subcommands/kick.php +++ b/src/Wertzui123/BedrockClans/commands/subcommands/kick.php @@ -24,48 +24,40 @@ public function canUse(CommandSender $sender): bool public function execute(CommandSender $sender, array $args) { $player = $this->plugin->getPlayer($sender); - if (!isset($args[0])) { - $sender->sendMessage($this->plugin->getMessage("kick_provide_player")); - return; - } if (!$player->isInClan()) { - $sender->sendMessage($this->plugin->getMessage("kick_not_in_clan")); + $sender->sendMessage($this->plugin->getMessage('command.kick.noClan')); return; } - - $clan = $player->getClan(); - $kicked = strtolower($args[0]); if (!$player->isLeader()) { $sender->sendMessage($this->plugin->getMessage("kick_not_leader")); return; } - - if ($clan->getLeader() === $kicked) { - $sender->sendMessage($this->plugin->getMessage("kick_cannot_kick_leader")); + if (!isset($args[0])) { + $sender->sendMessage($this->plugin->getMessage('command.kick.passPlayer')); return; } - + $clan = $player->getClan(); + $kicked = strtolower(implode(' ', $args)); if (!in_array($kicked, $clan->getMembers())) { - $sender->sendMessage($this->plugin->getMessage("kick_player_not_exists")); + $sender->sendMessage($this->plugin->getMessage('command.kick.passPlayer')); return; } - - if (($k = $this->plugin->getServer()->getPlayerExact($kicked))) { + if ($clan->getLeader() === $kicked) { + $sender->sendMessage($this->plugin->getMessage('command.kick.cannotKickLeader')); + return; + } + if (!is_null($k = $this->plugin->getServer()->getPlayerExact($kicked))) { $k = $this->plugin->getPlayer($k); $clan = $k->getClan(); $k->setClan(null); $clan->removeMember($k); - $message = str_replace("{player}", $sender->getName(), $this->plugin->getMessage("kick_kicked")); - $k->getPlayer()->sendMessage($message); - $msg = str_replace("{player}", $k->getPlayer()->getName(), $this->plugin->getMessage("kick_kicked_sender")); - $sender->sendMessage($msg); + $sender->sendMessage($this->plugin->getMessage('command.kick.success', ['{player}' => $k->getPlayer()->getName()])); + $k->getPlayer()->sendMessage($this->plugin->getMessage('clan.kick.kicked', ['{player}' => $sender->getName()])); } else { - $k = $kicked; - $clan = $this->plugin->getClanByPlayer($k); - $this->plugin->setClan($k, null); - $clan->removeMember($k); - $msg = str_replace("{player}", $kicked, $this->plugin->getMessage("kick_kicked_sender")); - $sender->sendMessage($msg); + $clan = $this->plugin->getClanByPlayer($kicked); + $this->plugin->setClan($kicked, null); + $clan->removeMember($kicked); + $sender->sendMessage($this->plugin->getMessage('command.kick.success', ['{player}' => $kicked])); } } diff --git a/src/Wertzui123/BedrockClans/commands/subcommands/leader.php b/src/Wertzui123/BedrockClans/commands/subcommands/leader.php index 4c9a042..f585f41 100644 --- a/src/Wertzui123/BedrockClans/commands/subcommands/leader.php +++ b/src/Wertzui123/BedrockClans/commands/subcommands/leader.php @@ -25,29 +25,32 @@ public function execute(CommandSender $sender, array $args) { $player = $this->plugin->getPlayer($sender); if (!$player->isInClan()) { - $sender->sendMessage($this->plugin->getMessage("leader_not_in_clan")); + $sender->sendMessage($this->plugin->getMessage('command.leader.noClan')); return; } $clan = $player->getClan(); if (strtolower($sender->getName()) !== $clan->getLeader()) { - $sender->sendMessage($this->plugin->getMessage("leader_not_leader")); + $sender->sendMessage($this->plugin->getMessage('command.leader.notLeader')); return; } if (!isset($args[0])) { - $sender->sendMessage($this->plugin->getMessage("leader_provide_player")); + $sender->sendMessage($this->plugin->getMessage('command.leader.passPlayer')); return; } if (!in_array(strtolower(implode(' ', $args)), $clan->getMembers())) { - $message = str_replace("{player}", implode(' ', $args), $this->plugin->getMessage("leader_not_in_your_clan")); - $sender->sendMessage($message); + $sender->sendMessage($this->plugin->getMessage('command.leader.notInClan', ['{player}' => implode(' ', $args)])); return; } + if($clan->getLeader() === strtolower(implode(' ', $args))){ + $sender->sendMessage($this->plugin->getMessage('command.leader.alreadyLeader')); + return; + } + $clan->setRank($player, 'member'); $clan->setLeader(implode(' ', $args)); - $ps = str_replace("{player}", implode(' ', $args), $this->plugin->getMessage("leader_promoted_to_leader")); - $sender->sendMessage($ps); - if (($p = $this->plugin->getServer()->getPlayerExact($this->plugin->getPlayerName(strtolower(implode(' ', $args)))))) { - $target = $this->plugin->getServer()->getPlayerExact(implode(' ', $args)); - $target->sendMessage($this->plugin->getMessage("leader_now_leader")); + $clan->setRank(implode(' ', $args), 'leader'); + $sender->sendMessage($this->plugin->getMessage('command.leader.success', ['{player}' => implode(' ', $args)])); + if (!is_null($p = $this->plugin->getServer()->getPlayerExact($this->plugin->getPlayerName(strtolower(implode(' ', $args)))))) { + $p->sendMessage($this->plugin->getMessage('clan.leader.newLeader')); } } diff --git a/src/Wertzui123/BedrockClans/commands/subcommands/leave.php b/src/Wertzui123/BedrockClans/commands/subcommands/leave.php index f7868b5..cef8ae5 100644 --- a/src/Wertzui123/BedrockClans/commands/subcommands/leave.php +++ b/src/Wertzui123/BedrockClans/commands/subcommands/leave.php @@ -4,6 +4,7 @@ use pocketmine\command\CommandSender; use pocketmine\Player; +use Wertzui123\BedrockClans\events\player\ClanLeaveEvent; use Wertzui123\BedrockClans\Main; class leave extends Subcommand @@ -24,23 +25,25 @@ public function canUse(CommandSender $sender): bool public function execute(CommandSender $sender, array $args) { $player = $this->plugin->getPlayer($sender); - if ($player->isInClan()) { - if (strtolower($sender->getName()) !== $player->getClan()->getLeader()) { - $clan = $player->getClan(); - $player->setClan(null); - $clan->removeMember($player); - $sender->sendMessage($this->plugin->getMessage("leave_leaved_clan")); - foreach ($clan->getMembers() as $member) { - if (($p = $this->plugin->getServer()->getPlayerExact($this->plugin->getPlayerName($member)))) { - $msg = str_replace("{player}", $sender->getName(), $this->plugin->getMessage("leave_player_leaved_clan")); - $p->sendMessage($msg); - } + if (!$player->isInClan()) { + $sender->sendMessage($this->plugin->getMessage('command.leave.noClan')); + return; + } + if (strtolower($sender->getName()) !== $player->getClan()->getLeader()) { + $clan = $player->getClan(); + $event = new ClanLeaveEvent($player->getPlayer(), $clan); + $event->call(); + if($event->isCancelled()) return; // TODO: Message + $player->setClan(null); + $clan->removeMember($player); + $sender->sendMessage($this->plugin->getMessage('command.leave.success')); + foreach ($clan->getMembers() as $member) { + if (($p = $this->plugin->getServer()->getPlayerExact($this->plugin->getPlayerName($member)))) { + $p->sendMessage($this->plugin->getMessage('clan.leave.members', ['{player}' => $sender->getName()])); } - } else { - $sender->sendMessage($this->plugin->getMessage("leave_cannot_leave")); } } else { - $sender->sendMessage($this->plugin->getMessage("leave_not_in_clan")); + $sender->sendMessage($this->plugin->getMessage('command.leave.leader')); } } diff --git a/src/Wertzui123/BedrockClans/commands/subcommands/promote.php b/src/Wertzui123/BedrockClans/commands/subcommands/promote.php new file mode 100644 index 0000000..e97da47 --- /dev/null +++ b/src/Wertzui123/BedrockClans/commands/subcommands/promote.php @@ -0,0 +1,61 @@ +plugin = $plugin; + } + + public function canUse(CommandSender $sender): bool + { + return $sender instanceof Player; + } + + public function execute(CommandSender $sender, array $args) + { + $player = $this->plugin->getPlayer($sender); + if (!$player->isInClan()) { + $sender->sendMessage($this->plugin->getMessage('command.promote.noClan')); + return; + } + $clan = $player->getClan(); + if (strtolower($sender->getName()) !== $clan->getLeader()) { + $sender->sendMessage($this->plugin->getMessage('command.promote.notLeader')); + return; + } + if (!isset($args[0])) { + $sender->sendMessage($this->plugin->getMessage('command.promote.passPlayer')); + return; + } + if (!in_array(strtolower(implode(' ', $args)), $clan->getMembers())) { + $sender->sendMessage($this->plugin->getMessage('command.promote.notInClan', ['{player}' => implode(' ', $args)])); + return; + } + if($clan->getRank(implode(' ', $args)) === 'leader' || $clan->getRank(implode(' ', $args)) === 'coleader'){ + $sender->sendMessage($this->plugin->getMessage('command.promote.alreadyHighest')); + return; + } + if($clan->getRank(implode(' ', $args)) === "vim"){ + $rank = "coleader"; + }else{ + $rank = "vim"; + } + $clan->setRank(implode(' ', $args), $rank); + $sender->sendMessage($this->plugin->getMessage('command.promote.success', ['{player}' => implode(' ', $args), '{rank}' => Clan::getRankName($rank, true)])); + if (!is_null($p = $this->plugin->getServer()->getPlayerExact($this->plugin->getPlayerName(strtolower(implode(' ', $args)))))) { + $p->sendMessage($this->plugin->getMessage('clan.promote.promoted', ['{rank}' => Clan::getRankName($rank, true)])); + } + } + +} \ No newline at end of file diff --git a/src/Wertzui123/BedrockClans/commands/subcommands/withdraw.php b/src/Wertzui123/BedrockClans/commands/subcommands/withdraw.php new file mode 100644 index 0000000..1f27861 --- /dev/null +++ b/src/Wertzui123/BedrockClans/commands/subcommands/withdraw.php @@ -0,0 +1,58 @@ +plugin = $plugin; + } + + public function canUse(CommandSender $sender): bool + { + return $sender instanceof Player; + } + + public function execute(CommandSender $sender, array $args) + { + if($this->plugin->getConfig()->getNested('bank.enabled') !== true){ + $sender->sendMessage($this->plugin->getMessage('command.withdraw.disabled')); + return; + } + $player = $this->plugin->getPlayer($sender); + if (!$player->isInClan()) { + $sender->sendMessage($this->plugin->getMessage('command.withdraw.noClan')); + return; + } + if($player->hasWithdrawCooldown()){ + $sender->sendMessage($this->plugin->ConvertSeconds($player->getWithdrawCooldown(), $this->plugin->getMessage('command.withdraw.cooldown'))); + return; + } + if(!isset($args[0]) || !is_numeric($args[0]) || (int)$args[0] <= 0){ + $sender->sendMessage($this->plugin->getMessage('command.withdraw.passNumber')); + return; + } + $clan = $player->getClan(); + $amount = (int)$args[0]; + if($amount > ($clan->getBank() * (0.01 * Clan::getMaxWithdrawAmount($player->getClan()->getRank($player)))) || $amount > $clan->getBank()){ + $sender->sendMessage($this->plugin->getMessage('command.withdraw.tooMuch')); + return; + } + $clan->setBank($clan->getBank() - $amount); + $player->addMoney($amount); + if(!$player->isLeader()){ + $player->addWithdrawCooldown(Main::getInstance()->getConfig()->getNested('bank.withdraw.cooldown', 24) * 60 * 60); + } + $sender->sendMessage($this->plugin->getMessage('command.withdraw.success', ['{amount}' => $amount])); + } + +} \ No newline at end of file diff --git a/src/Wertzui123/BedrockClans/events/clan/ClanCreateEvent.php b/src/Wertzui123/BedrockClans/events/clan/ClanCreateEvent.php new file mode 100644 index 0000000..c95b852 --- /dev/null +++ b/src/Wertzui123/BedrockClans/events/clan/ClanCreateEvent.php @@ -0,0 +1,46 @@ +player = $player; + } + + /** + * Returns the player who is creating the clan + * @return Player + */ + public function getPlayer() + { + return $this->player; + } + + /** + * Returns the new clan + * @return Clan + */ + public function getClan(): Clan + { + return $this->clan; + } + +} \ No newline at end of file diff --git a/src/Wertzui123/BedrockClans/events/clan/ClanDeleteEvent.php b/src/Wertzui123/BedrockClans/events/clan/ClanDeleteEvent.php new file mode 100644 index 0000000..cb90b33 --- /dev/null +++ b/src/Wertzui123/BedrockClans/events/clan/ClanDeleteEvent.php @@ -0,0 +1,31 @@ +clan; + } + +} \ No newline at end of file diff --git a/src/Wertzui123/BedrockClans/events/clan/ClanEvent.php b/src/Wertzui123/BedrockClans/events/clan/ClanEvent.php new file mode 100644 index 0000000..df9266e --- /dev/null +++ b/src/Wertzui123/BedrockClans/events/clan/ClanEvent.php @@ -0,0 +1,31 @@ +clan = $clan; + } + + /** + * @return Clan + */ + public function getClan() + { + return $this->clan; + } + +} \ No newline at end of file diff --git a/src/Wertzui123/BedrockClans/events/player/ClanJoinEvent.php b/src/Wertzui123/BedrockClans/events/player/ClanJoinEvent.php new file mode 100644 index 0000000..de674c6 --- /dev/null +++ b/src/Wertzui123/BedrockClans/events/player/ClanJoinEvent.php @@ -0,0 +1,37 @@ +clan = $clan; + } + + /** + * Returns the new clan + * @return Clan + */ + public function getClan(): Clan + { + return $this->clan; + } + +} \ No newline at end of file diff --git a/src/Wertzui123/BedrockClans/events/player/ClanLeaveEvent.php b/src/Wertzui123/BedrockClans/events/player/ClanLeaveEvent.php new file mode 100644 index 0000000..094fdac --- /dev/null +++ b/src/Wertzui123/BedrockClans/events/player/ClanLeaveEvent.php @@ -0,0 +1,37 @@ +clan = $clan; + } + + /** + * Returns the new clan + * @return Clan + */ + public function getClan(): Clan + { + return $this->clan; + } + +} \ No newline at end of file diff --git a/src/Wertzui123/BedrockClans/events/player/PlayerChatEvent.php b/src/Wertzui123/BedrockClans/events/player/PlayerChatEvent.php new file mode 100644 index 0000000..73c0367 --- /dev/null +++ b/src/Wertzui123/BedrockClans/events/player/PlayerChatEvent.php @@ -0,0 +1,45 @@ +message = $message; + } + + /** + * Returns the clan chat message + * @return string + */ + public function getMessage() + { + return $this->message; + } + + /** + * Updates the clan chat message + * @param string $message + */ + public function setMessage($message) + { + $this->message = $message; + } + +} \ No newline at end of file diff --git a/src/Wertzui123/BedrockClans/events/player/PlayerEvent.php b/src/Wertzui123/BedrockClans/events/player/PlayerEvent.php new file mode 100644 index 0000000..cf94d24 --- /dev/null +++ b/src/Wertzui123/BedrockClans/events/player/PlayerEvent.php @@ -0,0 +1,31 @@ +player = $player; + } + + /** + * @return Player + */ + public function getPlayer() + { + return $this->player; + } + +} \ No newline at end of file diff --git a/src/Wertzui123/BedrockClans/listener/CustomListener.php b/src/Wertzui123/BedrockClans/listener/CustomListener.php index b68bea5..19bc7dc 100644 --- a/src/Wertzui123/BedrockClans/listener/CustomListener.php +++ b/src/Wertzui123/BedrockClans/listener/CustomListener.php @@ -6,12 +6,15 @@ use Wertzui123\BedrockClans\Main; use pocketmine\event\Listener; + class CustomListener implements Listener { + private $plugin; public function __construct(Main $plugin) { $this->plugin = $plugin; } + } \ No newline at end of file diff --git a/src/Wertzui123/BedrockClans/listener/EventListener.php b/src/Wertzui123/BedrockClans/listener/EventListener.php index 5e2f621..7ca9cd2 100644 --- a/src/Wertzui123/BedrockClans/listener/EventListener.php +++ b/src/Wertzui123/BedrockClans/listener/EventListener.php @@ -4,6 +4,7 @@ namespace Wertzui123\BedrockClans\listener; +use pocketmine\event\player\PlayerChatEvent; use pocketmine\event\player\PlayerLoginEvent; use pocketmine\event\player\PlayerQuitEvent; use Wertzui123\BedrockClans\Main; @@ -11,6 +12,7 @@ class EventListener implements Listener { + private $plugin; public function __construct(Main $plugin) @@ -30,7 +32,20 @@ public function onLogin(PlayerLoginEvent $event) $this->plugin->addPlayer($player); } - public function onQuit(PlayerQuitEvent $event){ + /** + * @priority LOW + * @param PlayerChatEvent $event + */ + public function onChat(PlayerChatEvent $event){ + if($this->plugin->getPlayer($event->getPlayer())->isChatting()){ + $event->setCancelled(); + $this->plugin->getPlayer($event->getPlayer())->chat($event->getMessage()); + } + } + + public function onQuit(PlayerQuitEvent $event) + { $this->plugin->removePlayer($this->plugin->getPlayer($event->getPlayer())); } + } \ No newline at end of file diff --git a/src/Wertzui123/BedrockClans/tasks/invitetask.php b/src/Wertzui123/BedrockClans/tasks/invitetask.php index 849bf54..b85fb06 100644 --- a/src/Wertzui123/BedrockClans/tasks/invitetask.php +++ b/src/Wertzui123/BedrockClans/tasks/invitetask.php @@ -2,7 +2,6 @@ namespace Wertzui123\BedrockClans\tasks; -use pocketmine\Player; use pocketmine\scheduler\Task; use Wertzui123\BedrockClans\BCPlayer; use Wertzui123\BedrockClans\Main; @@ -15,21 +14,17 @@ class invitetask extends Task public $sender; public $target; - public function __construct(Main $plugin, BCPlayer $sender, BCPlayer $target, $time) + public function __construct(Main $plugin, BCPlayer $sender, BCPlayer $target, $ticks) { $this->plugin = $plugin; - $this->ticks = $time; + $this->ticks = $ticks; $this->sender = $sender; $this->target = $target; } - public function getPlugin() - { - return $this->plugin; - } - public function onRun(int $currentTick) { + if ($this->ticks > 0) { $this->ticks--; }else{