So, I fixed my code, but no matter what I try to set it, it only goes up 30. No error or anything, just goes up by 30 PHP: <?phpnamespace MCMMOPE\Skills;use pocketmine\Player;use pocketmine\plugin\PluginBase;use pocketmine\utils\TextFormat as c;use pocketmine\Server;use pocketmine\event\Cancellable;use pocketmine\event\Listener;use pocketmine\event\block\BlockBreakEvent;use pocketmine\utils\Config;use pocketmine\command\CommandExecutor;use pocketmine\command\CommandSender;use pocketmine\command\Command;use MCMMOPE\Loader;use pocketmine\entity\Effect;class Mining extends PluginBase implements Listener{ public function dataPath() { return $this->getDataFolder(); } public $mining; public function __construct(Loader $plugin){ $this->loader = $plugin; } public function getPlugin() { return $this->plugin; } public function onBreak(BlockBreakEvent $event){ $player = $event->getPlayer(); $name = $player->getName(); $this->miningexp = new Config($this->loader->getDataFolder()."Mining/"."miningexp.yml", Config::YAML,array()); $this->mininglevel = new Config($this->loader->getDataFolder()."Mining/"."mininglevel.yml", Config::YAML,array()); $miningcooldown = $this->loader->getDataFolder()."Mining/". strtolower($player->getName()); if($event->getBlock()->GetId() == 1 or 89 or 48 or 87 or 24){ if(!$event->isCancelled()) { $this->miningexp->set($name,$this->miningexp->get($name) + 30); $this->miningexp->save(); return true; } } if($event->getBlock()->GetId() == 174 or 159){ if(!$event->isCancelled()) { $this->miningexp->set($name,$this->miningexp->get($name) + 50); $this->miningexp->save(); return true; } } if($event->getBlock()->GetId() == 16 or 179 or 153 ){ if(!$event->isCancelled()) { $this->miningexp->set($name,$this->miningexp->get($name) + 100); $this->miningexp->save(); return true; } } if($event->getBlock()->GetId() == 49){ if(!$event->isCancelled()) { $this->miningexp->set($name,$this->miningexp->get($name) + 150); $this->miningexp->save(); return true; } } if($event->getBlock()->GetId() == 15){ $this->miningexp->set($name,$this->miningexp->get($name) + 250); $this->miningexp->save(); return true; } if($event->getBlock()->GetId() == 14){ if(!$event->isCancelled()) { $this->miningexp->set($name,$this->miningexp->get($name) + 1); $this->miningexp->save(); return true; } } if($event->getBlock()->GetId() == 21){ if(!$event->isCancelled()) { $this->miningexp->set($name,$this->miningexp->get($name) + 400); $this->miningexp->save(); return true; } } if($event->getBlock()->GetId() == 56){ if(!$event->isCancelled()) { $this->miningexp->set($name,$this->miningexp->get($name) + 750); $this->miningexp->save(); return true; } } if($event->getBlock()->GetId() == 129){ if(!$event->isCancelled()) { $this->miningexp->set($name,$this->miningexp->get($name) + 1000); $this->miningexp->save(); return true; } } if($this->miningexp->get($name) == 15000){ $level = $this->mininglevel->get($name); $this->mininglevel->set($name,$this->mininglevel->get($name) + 1); $this->mininglevel->save(); $player->sendMessage(c::GREEN . "Your Mining Skill Is Now Level" . $level); return true; } if($this->miningexp->get($name) == 30000){ $level = $this->mininglevel->get($name); $this->mininglevel->set($name,$this->mininglevel->get($name) + 1); $this->mininglevel->save(); $player->sendMessage(c::GREEN . "Your Mining Skill Is Now Level" . $level); return true; } if($this->miningexp->get($name) == 45000){ $level = $this->mininglevel->get($name); $this->mininglevel->set($name,$this->mininglevel->get($name) + 1); $this->mininglevel->save(); $player->sendMessage(c::GREEN . "Your Mining Skill Is Now Level" . $level); return true; } if($this->miningexp->get($name) == 60000){ $level = $this->mininglevel->get($name); $this->mininglevel->set($name,$this->mininglevel->get($name) + 1); $this->mininglevel->save(); $player->sendMessage(c::GREEN . "Your Mining Skill Is Now Level" . $level); return true; } if($event->getBlock()->GetId() == 1 or 89 or 48 or 87 or 24 or 174 or 159 or 16 or 179 or 153 or 49 or 15 or 14 or 21 or 56 or 129){ if(is_file($miningcooldown)) { $data = yaml_parse_file($miningcooldown); $lastTime = $data["last-execute-miningskill"]; } else { $lastTime = 0; } if(time() - $lastTime < 5) { return true; }else if(time() - $lastTime > 5) { $player->SendMessage("Skill Activated"); $player->addEffect(Effect::getEffect(3)->setDuration(100)->setAmplifier(10)); $this->miningexp->set($name,$this->miningexp->get($name) + 50); $this->miningexp->save(); } $data["last-execute-miningskill"] = time(); yaml_emit_file($miningcooldown, $data); return true; } } }
a switch would probably be better in this case And also the redundant if(!$event->isCancelled()) { should be replaced by just one big one around all the code on the event. (And you don't really need that check anyway)
Learn PHP. It's tiring to explain this every time, but well... PHP is not English. You should look at what `or` means before using it. `$a or $b` resolves to true if $a is true or $b is true. Not mentioning the problem in operator precedence here (`getId() == 1` is resolved before the `or` operator), assuming all your integers are resolved into one value, please look at what `==` means. `$a == $b` resolves to true if `$a` and `$b` represent the same value. Your `$a` here is the block ID, and what is your `$b`? Fine, let's forget what `or` actually means. You expect the `==` to work like "if block ID is in one of the integers behind...". in one of. This is not what the == operator means. Now looking at the `or` operator again, the result always resolves into a boolean. And even if you add parentheses around `1 or 89 or 48 or 87 or 24`, you will just end up comparing an integer to a boolean, which is also wrong. Correct code: PHP: $id = $event->getBlock()->getId();if($id == 1 or $id == 89 or $id == 48 or $id == 87 or $id ==27) {...} Or if you don't want to write `$id ==` so many times, or if you have a variable number of integers in an array to compare, you can use in_array: PHP: if(in_array($id, [1, 89, 48, 87, 27])) {...} Hint: one more closely related problem: `1 <= $x <= 3` also doesn't do what you expect it to do! You will be comparing `1 <= $x` (a boolean) against the integer 3!
There's no point in making a switch statement if you want the outcome to be the same for every value that returns true...