mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-07 02:21:46 +00:00
Added new dynamic StringToEffectParser
This commit is contained in:
parent
1fb60b5b3a
commit
f93b5be789
@ -26,7 +26,7 @@ namespace pocketmine\command\defaults;
|
|||||||
use pocketmine\command\CommandSender;
|
use pocketmine\command\CommandSender;
|
||||||
use pocketmine\command\utils\InvalidCommandSyntaxException;
|
use pocketmine\command\utils\InvalidCommandSyntaxException;
|
||||||
use pocketmine\entity\effect\EffectInstance;
|
use pocketmine\entity\effect\EffectInstance;
|
||||||
use pocketmine\entity\effect\VanillaEffects;
|
use pocketmine\entity\effect\StringToEffectParser;
|
||||||
use pocketmine\lang\KnownTranslationFactory;
|
use pocketmine\lang\KnownTranslationFactory;
|
||||||
use pocketmine\permission\DefaultPermissionNames;
|
use pocketmine\permission\DefaultPermissionNames;
|
||||||
use pocketmine\utils\Limits;
|
use pocketmine\utils\Limits;
|
||||||
@ -69,9 +69,8 @@ class EffectCommand extends VanillaCommand{
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
try{
|
$effect = StringToEffectParser::getInstance()->parse($args[1]);
|
||||||
$effect = VanillaEffects::fromString($args[1]);
|
if($effect === null){
|
||||||
}catch(\InvalidArgumentException $e){
|
|
||||||
$sender->sendMessage(KnownTranslationFactory::commands_effect_notFound($args[1])->prefix(TextFormat::RED));
|
$sender->sendMessage(KnownTranslationFactory::commands_effect_notFound($args[1])->prefix(TextFormat::RED));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
73
src/entity/effect/StringToEffectParser.php
Normal file
73
src/entity/effect/StringToEffectParser.php
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace pocketmine\entity\effect;
|
||||||
|
|
||||||
|
use pocketmine\utils\SingletonTrait;
|
||||||
|
use pocketmine\utils\StringToTParser;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles parsing effect types from strings. This is used to interpret names in the /effect command.
|
||||||
|
*
|
||||||
|
* @phpstan-extends StringToTParser<Effect>
|
||||||
|
*/
|
||||||
|
final class StringToEffectParser extends StringToTParser{
|
||||||
|
use SingletonTrait;
|
||||||
|
|
||||||
|
private static function make() : self{
|
||||||
|
$result = new self;
|
||||||
|
|
||||||
|
$result->register("absorption", fn() => VanillaEffects::ABSORPTION());
|
||||||
|
$result->register("blindness", fn() => VanillaEffects::BLINDNESS());
|
||||||
|
$result->register("conduit_power", fn() => VanillaEffects::CONDUIT_POWER());
|
||||||
|
$result->register("fatal_poison", fn() => VanillaEffects::FATAL_POISON());
|
||||||
|
$result->register("fire_resistance", fn() => VanillaEffects::FIRE_RESISTANCE());
|
||||||
|
$result->register("haste", fn() => VanillaEffects::HASTE());
|
||||||
|
$result->register("health_boost", fn() => VanillaEffects::HEALTH_BOOST());
|
||||||
|
$result->register("hunger", fn() => VanillaEffects::HUNGER());
|
||||||
|
$result->register("instant_damage", fn() => VanillaEffects::INSTANT_DAMAGE());
|
||||||
|
$result->register("instant_health", fn() => VanillaEffects::INSTANT_HEALTH());
|
||||||
|
$result->register("invisibility", fn() => VanillaEffects::INVISIBILITY());
|
||||||
|
$result->register("jump_boost", fn() => VanillaEffects::JUMP_BOOST());
|
||||||
|
$result->register("levitation", fn() => VanillaEffects::LEVITATION());
|
||||||
|
$result->register("mining_fatigue", fn() => VanillaEffects::MINING_FATIGUE());
|
||||||
|
$result->register("nausea", fn() => VanillaEffects::NAUSEA());
|
||||||
|
$result->register("night_vision", fn() => VanillaEffects::NIGHT_VISION());
|
||||||
|
$result->register("poison", fn() => VanillaEffects::POISON());
|
||||||
|
$result->register("regeneration", fn() => VanillaEffects::REGENERATION());
|
||||||
|
$result->register("resistance", fn() => VanillaEffects::RESISTANCE());
|
||||||
|
$result->register("saturation", fn() => VanillaEffects::SATURATION());
|
||||||
|
$result->register("slowness", fn() => VanillaEffects::SLOWNESS());
|
||||||
|
$result->register("speed", fn() => VanillaEffects::SPEED());
|
||||||
|
$result->register("strength", fn() => VanillaEffects::STRENGTH());
|
||||||
|
$result->register("water_breathing", fn() => VanillaEffects::WATER_BREATHING());
|
||||||
|
$result->register("weakness", fn() => VanillaEffects::WEAKNESS());
|
||||||
|
$result->register("wither", fn() => VanillaEffects::WITHER());
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function parse(string $input) : ?Effect{
|
||||||
|
return parent::parse($input);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user