On my interact event, the potion line isnt where, where i get haste if the name that name, no errors or anything PHP: <?phpnamespace CustomPotions;use pocketmine\plugin\PluginBase;use pocketmine\event\Listener;use pocketmine\event\player\PlayerInteractEvent;use CustomPotions\EventHandler;use pocketmine\utils\TextFormat as TF;use pocketmine\Player;use pocketmine\level\Level;use pocketmine\level\sound;use pocketmine\Server;use pocketmine\item\Item;use pocketmine\utils\Config;use pocketmine\scheduler\PluginTask;use pocketmine\command\CommandSender;use pocketmine\command\Command;use pocketmine\command\ConsoleCommandSender;use pocketmine\nbt\NBT;use pocketmine\nbt\tag\ByteTag;use pocketmine\nbt\tag\CompoundTag;use pocketmine\nbt\tag\DoubleTag;use pocketmine\nbt\tag\FloatTag;use pocketmine\nbt\tag\IntTag;use pocketmine\entity\Effect;use pocketmine\nbt\tag\ListTag;use pocketmine\nbt\tag\ShortTag;use pocketmine\nbt\tag\StringTag;use pocketmine\nbt\tag\IntArrayTag;class Main extends PluginBase implements Listener { public function onEnable() { $this->getServer()->getPluginManager()->registerEvents($this, $this); $this->getServer()->getPluginManager()->registerEvents(new EventHandler($this), $this); } public function onDisable() { } //I REALISE THESE ARE FROM ESSENTIALSPE! public function validateName(string $string, $allowColorCodes = false): bool{ if(trim($string) === ""){ return false; } $format = []; if($allowColorCodes){ $format[] = "/(\&|\ยง)[0-9a-fk-or]/"; } $format[] = "/[a-zA-Z0-9_]/"; // Due to color codes can be allowed, then check for them first, so after, make a normal lookup $s = preg_replace($format, "", $string); if(strlen($s) !== 0){ return false; } return true; } public function givePotion($player, $potion) { switch($potion) { case "haste1": $potion = Item::get(373, 1234, 1); $potion->setDamage(500); $tag = new CompoundTag('', []); $tag->haste1 = new IntTag('haste1', 1); $tag->display = new CompoundTag("display", [ "Name" => new StringTag("Name", TF::YELLOW."Potion Of Haste I\n".TF::WHITE."1 Minute"."\n".TF::AQUA."To mine a little faster...") ]); $inventory = $player->getInventory(); $potion->setCompoundTag($tag); $inventory->addItem($potion); return; } } public function onInteract(PlayerInteractEvent $event) { $item = $event->getItem(); $held = $event->getPlayer()->getInventory()->getItemInHand(); $player = $event->getPlayer(); $block = $event->getBlock(); $slot = $player->getInventory()->getHeldItemSlot(); $potion = Item::get(373, 1234, 1); if($potion->getName() === TF::YELLOW."Potion Of Haste I\n".TF::WHITE."1 Minute"."\n".TF::AQUA."To mine a little faster...") { $haste = Effect::getEffect(3)->setVisible(false)->setAmplifier(0); $haste->setDuration(1020); $player->addEffect($haste); } $player->sendMessage("asah dood"); } public function getPlayer($player){ if(!$this->validateName($player, false)){ return false; } $player = strtolower($player); $found = false; foreach($this->getServer()->getOnlinePlayers() as $p){ if(strtolower(TF::clean($p->getDisplayName(), true)) === $player || strtolower($p->getName()) === $player){ $found = $p; break; } } // If cannot get the exact player name/nick, try with portions of it if(!$found){ $found = ($f = $this->getServer()->getPlayer($player)) === null ? false : $f; // PocketMine function to get from portions of name } /* * Copy from PocketMine's function (use above xD) but modified to work with Nicknames :P * * ALL THE RIGHTS FROM THE FOLLOWING CODE BELONGS TO POCKETMINE-MP */ if(!$found){ $delta = \PHP_INT_MAX; foreach($this->getServer()->getOnlinePlayers() as $p){ // Clean the Display Name due to colored nicks :S if(\stripos(($n = TF::clean($p->getDisplayName(), true)), $player) === 0){ $curDelta = \strlen($n) - \strlen($player); if($curDelta < $delta){ $found = $p; $delta = $curDelta; } if($curDelta === 0){ break; } } } } return $found; } public function onCommand(CommandSender $sender, Command $command, $label, array $args) { if ($sender instanceof Player) { $player = $sender->getPlayer()->getName(); if (empty($args[0]) or empty($args[1]) or empty($args[2])) { $sender->sendMessage("Please read the ReadME!"); return true; } if(isset($args[2]) && !($player = $this->getPlayer($args[2]))){ $sender->sendMessage(TF::RED . "Player Not Online!"); return false; } if ($command->getName('cp')) { if($args[0] == "give") { if($args[1] == "haste1" or $args[1] == "drunk1") {//THIS IS JUST TO CHECK THE ARGS[1] AND MAKE SURE NOTHINGS WRONG if(isset($args[2]) && !($player = $this->getPlayer($args[2]))){ $sender->sendMessage(TF::RED . "Player Not Online!"); return false; } } switch($args[1]) { case "haste1": $player = $this->getServer()->getPlayer($args[2]); $this->givePotion($player, "haste1"); return; } } } } } public function translateColors($symbol, $message) { $message = str_replace($symbol."0", TF::BLACK, $message); $message = str_replace($symbol."1", TF::DARK_BLUE, $message); $message = str_replace($symbol."2", TF::DARK_GREEN, $message); $message = str_replace($symbol."3", TF::DARK_AQUA, $message); $message = str_replace($symbol."4", TF::DARK_RED, $message); $message = str_replace($symbol."5", TF::DARK_PURPLE, $message); $message = str_replace($symbol."6", TF::GOLD, $message); $message = str_replace($symbol."7", TF::GRAY, $message); $message = str_replace($symbol."8", TF::DARK_GRAY, $message); $message = str_replace($symbol."9", TF::BLUE, $message); $message = str_replace($symbol."a", TF::GREEN, $message); $message = str_replace($symbol."b", TF::AQUA, $message); $message = str_replace($symbol."c", TF::RED, $message); $message = str_replace($symbol."d", TF::LIGHT_PURPLE, $message); $message = str_replace($symbol."e", TF::YELLOW, $message); $message = str_replace($symbol."f", TF::WHITE, $message); $message = str_replace($symbol."k", TF::OBFUSCATED, $message); $message = str_replace($symbol."l", TF::BOLD, $message); $message = str_replace($symbol."m", TF::STRIKETHROUGH, $message); $message = str_replace($symbol."n", TF::UNDERLINE, $message); $message = str_replace($symbol."o", TF::ITALIC, $message); $message = str_replace($symbol."r", TF::RESET, $message); return $message; } }
Have you added a default case to check if the switch statement is being called? Because if I understand correctly, you're saying it isn't called? Correct?
its not the switch arguement its the on interact, the line where it checks the name isnt workng yet the name is right
Maybe because the item you are getting the name of is an item you created without any extra data, therefore it will never have the specified custom name.
Did anyone notice that the amplifier is set to 0? the effect wont be recognised anyway unless the amplifier is 1 or more