Added new dynamic StringToEnchantmentParser

this should be used instead of VanillaEnchantments::fromString(), because it allows registering custom aliases.
This commit is contained in:
Dylan K. Taylor
2021-11-08 18:44:15 +00:00
parent 18f5fb66bb
commit 08420c2556
2 changed files with 69 additions and 4 deletions

View File

@ -26,7 +26,7 @@ namespace pocketmine\command\defaults;
use pocketmine\command\CommandSender;
use pocketmine\command\utils\InvalidCommandSyntaxException;
use pocketmine\item\enchantment\EnchantmentInstance;
use pocketmine\item\enchantment\VanillaEnchantments;
use pocketmine\item\enchantment\StringToEnchantmentParser;
use pocketmine\lang\KnownTranslationFactory;
use pocketmine\permission\DefaultPermissionNames;
use pocketmine\utils\TextFormat;
@ -66,9 +66,8 @@ class EnchantCommand extends VanillaCommand{
return true;
}
try{
$enchantment = VanillaEnchantments::fromString($args[1]);
}catch(\InvalidArgumentException $e){
$enchantment = StringToEnchantmentParser::getInstance()->parse($args[1]);
if($enchantment === null){
$sender->sendMessage(KnownTranslationFactory::commands_enchant_notFound($args[1]));
return true;
}