Skip to content

Commit

Permalink
Add restrictions on clan names using regular expressions (close #16)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wertzui123 committed Jul 26, 2023
1 parent f56645b commit e358827
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ JetBrains supports me in the development of BedrockClans.
* Clan creation costs (using EconomyAPI)
* Clan chat
* Clan homes
* Blacklisted clan names
* Clan name restrictions
* ...

# Commands
Expand Down
2 changes: 1 addition & 1 deletion plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: BedrockClans
main: Wertzui123\BedrockClans\Main
version: "3.8.1"
version: "3.9"
api: 5.0.0
load: POSTWORLD
author: Wertzui123
Expand Down
4 changes: 3 additions & 1 deletion resources/config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
---
# BedrockClans | Copyright 2019 - 2023 Wertzui123
# Don't edit this if you don't know what you're doing
config-version: "3.8.1"
config-version: "3.9"
# Regex for valid clan names; see https://regexr.com/ for help
clan_name_regex: "/^[a-zA-Z0-9_]{3,16}$/"
# Banned clan names
banned_clan_names:
- Hacker
Expand Down
4 changes: 2 additions & 2 deletions resources/strings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ command:
off: "§aYou are no longer in the clan chat mode."
create:
alreadyInClan: "§cYou are already in a clan!"
passClan: "§cPlease pass a clan!"
passName: "§cPlease pass a name for your new clan!"
clanExists: "§cThere already is a clan by that name!"
bannedName: "§cThis name is banned!"
invalidName: "§cThis name is invalid/not allowed on this server!"
notEnoughMoney: "§cYou don't have enough money (§6{price}§c) to create a clan!"
success: "§aYou successfully created the clan {clan}§a."
delete:
Expand Down
2 changes: 1 addition & 1 deletion src/Wertzui123/BedrockClans/Clan.php
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ public static function rankToNumber(string $rank)
*/
public static function isValidName(string $name): bool
{
return !in_array($name, Main::getInstance()->getConfig()->get('banned_clan_names'));
return preg_match(Main::getInstance()->getConfig()->get('clan_name_regex'), $name) && !in_array($name, Main::getInstance()->getConfig()->get('banned_clan_names'));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Wertzui123/BedrockClans/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Main extends PluginBase
private $withdrawCooldownsFile;
private $players = [];

const CONFIG_VERSION = '3.8.1';
const CONFIG_VERSION = '3.9';

public function onEnable(): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function execute(CommandSender $sender, array $args)
return;
}
if (!isset($args[0])) {
$sender->sendMessage($this->plugin->getMessage('command.create.passClan'));
$sender->sendMessage($this->plugin->getMessage('command.create.passName'));
return;
}
$name = implode(' ', $args);
Expand All @@ -31,7 +31,7 @@ public function execute(CommandSender $sender, array $args)
return;
}
if (!Clan::isValidName($name)) {
$sender->sendMessage($this->plugin->getMessage('command.create.bannedName'));
$sender->sendMessage($this->plugin->getMessage('command.create.invalidName'));
return;
}
if ($this->plugin->getConfig()->get('create_costs') && !is_null($this->plugin->getServer()->getPluginManager()->getPlugin('EconomyAPI'))) {
Expand Down

0 comments on commit e358827

Please sign in to comment.