Fixed effect amplifier overflow crash, close #147 (#191)

This commit is contained in:
Dylan K. Taylor 2016-12-27 21:30:54 +00:00 committed by GitHub
parent 942b35ee4c
commit 10c8632417
3 changed files with 12 additions and 3 deletions

View File

@ -90,6 +90,13 @@ class EffectCommand extends VanillaCommand{
if(count($args) >= 4){ if(count($args) >= 4){
$amplification = (int) $args[3]; $amplification = (int) $args[3];
if($amplification > 255){
$sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.generic.num.tooBig", [(string) $args[3], "255"]));
return true;
}elseif($amplification < 0){
$sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.generic.num.tooSmall", [(string) $args[3], "0"]));
return true;
}
} }
if(count($args) >= 5){ if(count($args) >= 5){

View File

@ -169,8 +169,8 @@ class Effect{
* *
* @return $this * @return $this
*/ */
public function setAmplifier($amplifier){ public function setAmplifier(int $amplifier){
$this->amplifier = (int) $amplifier; $this->amplifier = $amplifier & 0xff;
return $this; return $this;
} }

View File

@ -599,12 +599,14 @@ abstract class Entity extends Location implements Metadatable{
if(isset($this->namedtag->ActiveEffects)){ if(isset($this->namedtag->ActiveEffects)){
foreach($this->namedtag->ActiveEffects->getValue() as $e){ foreach($this->namedtag->ActiveEffects->getValue() as $e){
$amplifier = $e["Amplifier"] & 0xff; //0-255 only
$effect = Effect::getEffect($e["Id"]); $effect = Effect::getEffect($e["Id"]);
if($effect === null){ if($effect === null){
continue; continue;
} }
$effect->setAmplifier($e["Amplifier"])->setDuration($e["Duration"])->setVisible($e["ShowParticles"] > 0); $effect->setAmplifier($amplifier)->setDuration($e["Duration"])->setVisible($e["ShowParticles"] > 0);
$this->addEffect($effect); $this->addEffect($effect);
} }