public static fromString ( string $str, boolean $multiple = false ) : |
||
$str | string | |
$multiple | boolean | |
return |
public function onCommand(CommandSender $sender, Command $cmd, $label, array $args) { if (!isset($args[0])) { return false; } if ($cmd->getName() != "get") { return false; } if ($sender->isCreative()) { $sender->sendMessage(mc::_("You are in creative mode")); return true; } $item = Item::fromString($args[0]); if ($item->getId() == 0) { $sender->sendMessage(TextFormat::RED . mc::_("There is no item called %1%", $args[0])); return true; } if (isset($args[1])) { $item->setCount((int) $args[1]); } else { if (isset(self::$stacks[$item->getId()])) { $item->setCount(self::$stacks[$item->getId()]); } else { $item->setCount($item->getMaxStackSize()); } } $sender->getInventory()->addItem(clone $item); $this->owner->getServer()->broadcastMessage(mc::_("%1% got %2% of %3% (%4%:%5%)", $sender->getName(), $item->getCount(), MPMU::itemName($item), $item->getId(), $item->getDamage())); return true; }
public function onEnable() { if (!is_dir($this->getDataFolder())) { mkdir($this->getDataFolder()); } $this->getServer()->getPluginManager()->registerEvents($this, $this); $this->dbm = null; if (!is_dir($this->getDataFolder())) { mkdir($this->getDataFolder()); } mc::plugin_init($this, $this->getFile()); $defaults = ["version" => $this->getDescription()->getVersion(), "# settings" => "Configuration settings", "settings" => ["# global" => "If true all worlds share the same NetherChest", "global" => false, "# particles" => "Decorate NetherChests...", "particles" => true, "# p-ticks" => "Particle ticks", "p-ticks" => 20, "# base-block" => "Block to use for the base", "base-block" => "NETHERRACK"], "# backend" => "Use YamlMgr or MySqlMgr", "backend" => "YamlMgr", "# MySql" => "MySQL settings.", "MySql" => ["host" => "localhost", "user" => "nobody", "password" => "secret", "database" => "netherchestdb", "port" => 3306]]; $cf = (new Config($this->getDataFolder() . "config.yml", Config::YAML, $defaults))->getAll(); $backend = __NAMESPACE__ . "\\" . $cf["backend"]; $this->dbm = new $backend($this, $cf); $this->getLogger()->info(mc::_("Using %1% as backend", $cf["backend"])); $bl = Item::fromString($cf["settings"]["base-block"]); if ($bl->getBlock()->getId() == Item::AIR) { $this->getLogger()->warning(mc::_("Invalid base-block %1%", $cf["settings"]["base-block"])); $this->base_block = Block::NETHERRACK; } else { $this->base_block = $bl->getBlock()->getId(); } $this->chests = []; if ($cf["settings"]["particles"]) { $this->getServer()->getScheduler()->scheduleRepeatingTask(new ParticleTask($this), $cf["settings"]["p-ticks"]); } }
public function execute(CommandSender $sender, $label, array $args) { if (!$this->testPermission($sender)) { return true; } for ($a = 0; $a < 6; $a++) { if (isset($args[$a])) { if (is_integer($args[$a])) { if (Item::fromString($args[6]) instanceof ItemBlock) { for ($x = $args[0]; $x <= $args[3]; $x++) { for ($y = $args[1]; $y <= $args[4]; $y++) { for ($z = $args[2]; $z <= $args[5]; $z++) { $this->setBlock(new Vector3($x, $y, $z), $sender->getLevel(), Item::fromString($args[6]), isset($args[7]) ? $args[7] : 0); $sender->sendMessage(); return true; } } } } $sender->sendMessage(TextFormat::RED . new TranslationContainer("pocketmine.command.fill.invalidBlock", [])); return false; } $sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage])); return false; } $sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage])); return false; } }
public function execute(CommandSender $sender, $currentAlias, array $args) { if (!$this->testPermission($sender)) { return \true; } if (\count($args) < 2) { $sender->sendMessage(TextFormat::RED . "Usage: " . $this->usageMessage); return \false; } $player = $sender->getServer()->getPlayer($args[0]); $item = Item::fromString($args[1]); if (!isset($args[2])) { $item->setCount($item->getMaxStackSize()); } else { $item->setCount((int) $args[2]); } if ($player instanceof Player) { if (($player->getGamemode() & 0x1) === 0x1) { $sender->sendMessage(TextFormat::RED . "Player is in creative mode"); return \true; } if ($item->getId() == 0) { $sender->sendMessage(TextFormat::RED . "There is no item called " . $args[1] . "."); return \true; } //TODO: overflow $player->getInventory()->addItem(clone $item); } else { $sender->sendMessage(TextFormat::RED . "Can't find player " . $args[0]); return \true; } Command::broadcastCommandMessage($sender, "Gave " . $player->getName() . " " . $item->getCount() . " of " . $item->getName() . " (" . $item->getId() . ":" . $item->getDamage() . ")"); return \true; }
public function onCommand(CommandSender $sender, Command $cmd, $label, array $args) { if (!isset($args[0])) { return false; } if ($cmd->getName() == "gift") { if (($receiver = $this->owner->getServer()->getPlayer($args[0])) == null) { if (!MPMU::inGame($sender)) { return true; } $receiver = $sender; } else { array_shift($args); } } else { if (!MPMU::inGame($sender)) { return true; } $receiver = $sender; } if ($receiver->isCreative()) { if ($receiver === $sender) { $receiver->sendMessage(mc::_("You are in creative mode")); } else { $sender->sendMessage(mc::_("%1% is in creative mode", $receiver->getDisplayName())); } return true; } if (count($args) > 1 && is_numeric($args[count($args) - 1])) { $amt = (int) array_pop($args); } else { $amt = -1; } $args = strtolower(implode("_", $args)); if ($args == "more") { $item = clone $receiver->getInventory()->getItemInHand(); if ($item->getId() == 0) { $sender->sendMessage(TextFormat::RED . mc::_("Must be holding something")); return true; } } else { $item = Item::fromString($args); if ($item->getId() == 0) { $sender->sendMessage(TextFormat::RED . mc::_("There is no item called %1%", $args)); return true; } } if ($amt != -1) { $item->setCount($amt); } else { if (isset(self::$stacks[$item->getId()])) { $item->setCount(self::$stacks[$item->getId()]); } else { $item->setCount($item->getMaxStackSize()); } } $receiver->getInventory()->addItem(clone $item); $this->owner->getServer()->broadcastMessage(mc::_("%1% got %2% of %3% (%4%:%5%)", $receiver->getDisplayName(), $item->getCount(), ItemName::str($item), $item->getId(), $item->getDamage())); return true; }
public function onSignChange(SignChangeEvent $event) { $tag = $event->getLine(0); if (($val = $this->checkTag($tag)) !== false) { $player = $event->getPlayer(); if (!$player->hasPermission("economysell.sell.create")) { $player->sendMessage($this->getMessage("no-permission-create")); return; } if (!is_numeric($event->getLine(1)) or !is_numeric($event->getLine(3))) { $player->sendMessage($this->getMessage("wrong-format")); return; } $item = Item::fromString($event->getLine(2)); if ($item === false) { $player->sendMessage($this->getMessage("item-not-support", array($event->getLine(2), "", ""))); return; } $block = $event->getBlock(); $this->sell[$block->getX() . ":" . $block->getY() . ":" . $block->getZ() . ":" . $player->getLevel()->getName()] = array("x" => $block->getX(), "y" => $block->getY(), "z" => $block->getZ(), "level" => $player->getLevel()->getName(), "cost" => (int) $event->getLine(1), "item" => (int) $item->getID(), "itemName" => $item->getName(), "meta" => (int) $item->getDamage(), "amount" => (int) $event->getLine(3)); $player->sendMessage($this->getMessage("sell-created", [$item->getName(), (int) $event->getLine(3), ""])); $mu = EconomyAPI::getInstance()->getMonetaryUnit(); $event->setLine(0, $val[0]); $event->setLine(1, str_replace(["%MONETARY_UNIT%", "%1"], [$mu, $event->getLine(1)], $val[1])); $event->setLine(2, str_replace(["%MONETARY_UNIT%", "%2"], [$mu, $item->getName()], $val[2])); $event->setLine(3, str_replace(["%MONETARY_UNIT%", "%3"], [$mu, $event->getLine(3)], $val[3])); } }
public static function fromString($string, $acceptWeightModification = true) { $weight = 1.0; if ($acceptWeightModification) { $pos = strpos($string, "/"); if ($pos !== false) { $weight = (double) substr($string, 0, $pos); $string = substr($string, $pos + 1); } } $pos = strpos($string, ":"); $damage = 0; if ($pos !== false) { $damage = (int) substr($string, $pos + 1); $id = substr($string, 0, $pos); $damageSensitive = true; } else { $id = $string; $damageSensitive = false; } $block = Item::fromString($id); if (!$block instanceof ItemBlock) { throw new NonExistentBlockException($id); } $block = $block->getBlock(); $block->setDamage($damage); return new BlockEntry($block, $damageSensitive, $weight); }
public function execute(CommandSender $sender, $currentAlias, array $args) { if (!$this->testPermission($sender)) { return true; } if (count($args) < 2) { $sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage])); return true; } $player = $sender->getServer()->getPlayer($args[0]); $item = Item::fromString($args[1]); if (!isset($args[2])) { $item->setCount($item->getMaxStackSize()); } else { $item->setCount((int) $args[2]); } if ($player instanceof Player) { if ($item->getId() === 0) { $sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.give.item.notFound", [$args[1]])); return true; } //TODO: overflow $player->getInventory()->addItem(clone $item); } else { $sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.generic.player.notFound")); return true; } Command::broadcastCommandMessage($sender, new TranslationContainer("%commands.give.success", [$item->getName() . " (" . $item->getId() . ":" . $item->getDamage() . ")", (string) $item->getCount(), $player->getName()])); return true; }
public function onCommand(CommandSender $sender, Command $cmd, $label, array $sub) { if (!isset($sub[0])) { return false; } $g = $this->g; $rm = TextFormat::RED . "Usage: /Grenade "; $mm = "[Grenade]"; $ik = $this->isKorean(); switch (strtolower($sub[0])) { case "gun": case "g": case "수류탄": case "item": case "i": case "아이템": case "템": if (!isset($sub[1])) { $r = $rm . ($ik ? "수류탄 <아이템ID>" : "Grenade(G) <ItemID>"); } else { $i = Item::fromString($sub[1]); $id = $i->getID() . ":" . $i->getDamage(); $g["Grenade"] = $id; $r = $mm . ($ik ? "수류탄을 {$id} 로 설정했습니다." : "Grenade is set {$id}"); } break; case "cool": case "cooltime": case "ct": case "쿨타임": case "쿨": if (!isset($sub[1])) { $r = $rm . ($ik ? "쿨타임 <시간>" : "CoolTime(CT) <Num>"); } else { if ($sub[1] < 0 || !is_numeric($sub[1])) { $sub[1] = 0; } if (isset($sub[2]) && $sub[2] > $sub[1] && is_numeric($sub[2]) !== false) { $sub[1] = $sub[1] . "~" . $sub[2]; } $g["Cool"] = $sub[1]; $r = $mm . ($ik ? "낚시 쿨타임을 [{$sub['1']}] 로 설정했습니다." : "Grenade cooltime is set [{$sub['1']}]"); } break; default: return false; break; } if (isset($r)) { $sender->sendMessage($r); } if ($this != $g) { $this->g = $g; $this->saveYml(); } return true; }
public function onSCommand(CommandSender $c, Command $cc, $scmd, $world, array $args) { if ($scmd != "banitem" && $scmd != "unbanitem") { return false; } if (count($args) == 0) { $ids = $this->owner->getCfg($world, "banitem", []); if (count($ids) == 0) { $c->sendMessage(mc::_("[WP] No banned items in %1%", $world)); } else { $ln = mc::_("[WP] Items(%1%):", count($ids)); $q = ""; foreach ($ids as $id => $n) { $ln .= "{$q} {$n}({$id})"; $q = ","; } $c->sendMessage($ln); } return true; } $cc = 0; echo __METHOD__ . "," . __LINE__ . "\n"; //##DEBUG $ids = $this->owner->getCfg($world, "banitem", []); if ($scmd == "unbanitem") { foreach ($args as $i) { $item = Item::fromString($i); if (isset($ids[$item->getId()])) { unset($ids[$item->getId()]); ++$cc; } } } elseif ($scmd == "banitem") { foreach ($args as $i) { $item = Item::fromString($i); if (isset($ids[$item->getId()])) { continue; } $ids[$item->getId()] = ItemName::str($item); ++$cc; } } else { return false; } if (!$cc) { $c->sendMessage(mc::_("No items updated")); return true; } if (count($ids)) { $this->owner->setCfg($world, "banitem", $ids); } else { $this->owner->unsetCfg($world, "banitem"); } $c->sendMessage(mc::_("Items changed: %1%", $cc)); return true; }
protected function parsePreset($preset, $chunkX, $chunkZ) { $this->preset = $preset; $preset = explode(";", $preset); $version = (int) $preset[0]; $blocks = isset($preset[1]) ? $preset[1] : ""; $biome = isset($preset[2]) ? $preset[2] : 1; $options = isset($preset[3]) ? $preset[3] : ""; preg_match_all('#^(([0-9]*x|)([0-9]{1,3})(|:[0-9]{0,2}))$#m', str_replace(",", "\n", $blocks), $matches); $y = 0; $this->structure = []; $this->chunks = []; foreach ($matches[3] as $i => $b) { $b = Item::fromString($b . $matches[4][$i]); $cnt = $matches[2][$i] === "" ? 1 : intval($matches[2][$i]); for ($cY = $y, $y += $cnt; $cY < $y; ++$cY) { $this->structure[$cY] = [$b->getId(), $b->getDamage()]; } } $this->floorLevel = $y; for (; $y < 0xff; ++$y) { $this->structure[$y] = [0, 0]; } $this->chunk = clone $this->level->getChunk($chunkX, $chunkZ); $this->chunk->setGenerated(); $c = Biome::getBiome($biome)->getColor(); $R = $c >> 16; $G = $c >> 8 & 0xff; $B = $c & 0xff; for ($Z = 0; $Z < 16; ++$Z) { for ($X = 0; $X < 16; ++$X) { $this->chunk->setBiomeId($X, $Z, $biome); $this->chunk->setBiomeColor($X, $Z, $R, $G, $B); for ($y = 0; $y < 128; ++$y) { $this->chunk->setBlock($X, $y, $Z, ...$this->structure[$y]); } } } preg_match_all('#(([0-9a-z_]{1,})\\(?([0-9a-z_ =:]{0,})\\)?),?#', $options, $matches); foreach ($matches[2] as $i => $option) { $params = true; if ($matches[3][$i] !== "") { $params = []; $p = explode(" ", $matches[3][$i]); foreach ($p as $k) { $k = explode("=", $k); if (isset($k[1])) { $params[$k[0]] = $k[1]; } } } $this->options[$option] = $params; } }
public function onSCommand(CommandSender $c, Command $cc, $scmd, $world, array $args) { if ($scmd != "breakable" && $scmd != "unbreakable") { return false; } if (count($args) == 0) { $ids = $this->owner->getCfg($world, "unbreakable", []); if (count($ids) == 0) { $c->sendMessage(mc::_("[WP] No unbreakable blocks in %1%", $world)); } else { $ln = mc::_("[WP] Blocks(%1%):", count($ids)); $q = ""; foreach ($ids as $id => $n) { $ln .= "{$q} {$n}({$id})"; $q = ","; } $c->sendMessage($ln); } return true; } $cc = 0; $ids = $this->owner->getCfg($world, "unbreakable", []); if ($scmd == "breakable") { foreach ($args as $i) { $item = Item::fromString($i); if (isset($ids[$item->getId()])) { unset($ids[$item->getId()]); ++$cc; } } } elseif ($scmd == "unbreakable") { foreach ($args as $i) { $item = Item::fromString($i); if (isset($ids[$item->getId()])) { continue; } $ids[$item->getId()] = MPMU::itemName($item); ++$cc; } } else { return false; } if (!$cc) { $c->sendMessage(mc::_("No blocks updated")); return true; } if (count($ids)) { $this->owner->setCfg($world, "unbreakable", $ids); } else { $this->owner->unsetCfg($world, "unbreakable"); } $c->sendMessage(mc::_("Blocks changed: %1%", $cc)); return true; }
public function onEnable() { if (!is_dir($this->getDataFolder())) { mkdir($this->getDataFolder()); } mc::plugin_init($this, $this->getFile()); $defaults = ["version" => $this->getDescription()->getVersion(), "settings" => ["# currency" => "Item to use for currency", "currency" => "GOLD_INGOT", "# signs" => "set to true to enable shops|casino signs", "signs" => true], "# trade-goods" => "List of tradeable goods", "trade-goods" => [], "defaults" => TradingMgr::defaults(), "# signs" => "Text used to identify GoldStd signs", "signs" => SignMgr::defaults(), "shop-keepers" => ShopKeep::defaults()]; $this->saveResource("shops.yml"); $cf = (new Config($this->getDataFolder() . "config.yml", Config::YAML, $defaults))->getAll(); if ($cf["settings"]["currency"]) { $item = Item::fromString($cf["settings"]["currency"]); if ($item->getId() == Item::AIR) { $this->getLogger()->error(TextFormat::RED . mc::_("Invalid currency item")); $this->currency = Item::GOLD_INGOT; } else { $this->currency = $item->getId(); } $this->api = null; } else { // No currency defined, so we use an external API $pm = $this->getServer()->getPluginManager(); if (!($money = $pm->getPlugin("PocketMoney")) && !($money = $pm->getPlugin("EconomyAPI")) && !($money = $pm->getPlugin("MassiveEconomy"))) { $this->api = null; $this->getLogger()->warning(TextFormat::YELLOW . mc::_("Using GOLD_INGOT as currency")); $this->currency = Item::GOLD_INGOT; } else { $this->api = $money; $this->currency = false; $this->getLogger()->info(TextFormat::BLUE . mc::_("Using Money API of %1%", $money->getFullName())); } } if ($this->currency || $cf["trade-goods"]) { $this->trading = new TradingMgr($this, $cf["trade-goods"], $cf["defaults"]); } else { $this->trading = null; $this->getLogger()->warning(TextFormat::RED . mc::_("Goods trading disabled!")); } if ($cf["signs"]) { new SignMgr($this, $cf["signs"]); } else { $this->getLogger()->warning(TextFormat::RED . mc::_("SignShops disabled")); } if (ShopKeep::cfEnabled($cf["shop-keepers"])) { $this->saveResource("default.skin"); $this->keepers = new ShopKeep($this, $cf["shop-keepers"]); if (!$this->keepers->isEnabled()) { $this->keepers = null; } } else { $this->keepers = null; $this->getLogger()->warning(TextFormat::RED . mc::_("Shop-Keepers disabled")); } }
public function onCommand(CommandSender $sender, Command $cmd, $label, array $sub) { if (!isset($sub[0])) { return false; } $rm = "Usage: /Delivery "; $mm = "[Delivery] "; $ik = $this->isKorean(); if ($sender->getName() == "CONSOLE") { $r = $mm . ($ik ? "게임내에서만 사용가능합니다." : "Please run this command in-game"); } elseif (!isset($sub[0]) || !isset($sub[1]) || !isset($sub[2])) { $r = $rm . ($ik ? "<플레이어명> <아이템ID> <갯수>" : "<PlayerName> <ItemID> <Amount>"); } if (isset($r)) { $sender->sendMessage($r); return true; } $i = Item::fromString($sub[1]); if (!($player = $this->getServer()->getPlayer(strtolower($sub[0])))) { $r = $mm . ($ik ? "{$sub['0']} 는 잘못된 플레이어명입니다." : "{$sub['0']} is invalid player"); } elseif ($i->getID() == 0) { $r = $mm . ($ik ? "{$sub['1']} 는 잘못된 아이템ID입니다." : "{$sub['1']} is invalid itemID"); } elseif (!is_numeric($sub[2]) || $sub[2] < 1) { $r = $mm . ($ik ? "{$sub['2']} 는 잘못된 갯수입니다." : "{$sub['2']} is invalid amount"); } elseif ($player->isCreative()) { $r = $mm . ($ik ? $mm . $player->getName() . " 님은 크리에이티브입니다." : $mm . $player->getName() . " is Creative mode"); } elseif (!$this->hasItem($sender, $i, $sub[2])) { $r = $mm . ($ik ? "아이템을 가지고있지 않습니다." : "Don't have Item"); } if (isset($r)) { $sender->sendMessage($r); return true; } $i->setCount($sub[2]); $inv = $sender->getInventory(); foreach ($inv->getContents() as $k => $item) { if ($item->getID() == $i->getID() && $item->getDamage() == $i->getDamage()) { $sub[2] = $item->getCount() - $sub[2]; if ($sub[2] <= 0) { $inv->clear($k); $sub[2] = -$sub[2]; } else { $inv->setItem($k, Item::get($item->getID(), $item->getDamage(), $sub[2])); break; } } $player->getInventory()->addItem($i); $ii = "\n {$i} (" . $i->getCount() . ")"; $sender->sendMessage($mm . ($ik ? $player->getName() . "님에게 아이템을 전송했습니다. {$ii}" : "SendItem to " . $player->getName() . $ii)); $player->sendMessage($mm . ($ik ? $sender->getName() . "님이 당신에게 아이템을 전송했습니다. {$ii}" : $mm . $sender->getName() . "is SendItem to you {$ii}")); } return true; }
/** * @param CommandSender $sender * @param string $alias * @param array $args * @return bool */ public function execute(CommandSender $sender, $alias, array $args) { if (!$this->testPermission($sender)) { return false; } if (!$sender instanceof Player) { $this->sendUsage($sender, $alias); return false; } if ($sender->getGamemode() === Player::CREATIVE || $sender->getGamemode() === Player::SPECTATOR) { $sender->sendMessage(TextFormat::RED . "[Error] You're in " . $this->getAPI()->getServer()->getGamemodeString($sender->getGamemode()) . " mode"); return false; } if (strtolower($args[0]) === "hand") { $item = $sender->getInventory()->getItemInHand(); if ($item->getId() === 0) { $sender->sendMessage(TextFormat::RED . "[Error] You don't have anything in your hand"); return false; } } else { if (!is_int($args[0])) { $item = Item::fromString($args[0]); } else { $item = Item::get($args[0]); } if ($item->getId() === 0) { $sender->sendMessage(TextFormat::RED . "[Error] Unknown item"); return false; } } if (!$sender->getInventory()->contains($item)) { $sender->sendMessage(TextFormat::RED . "[Error] You don't have that item in your inventory"); return false; } if (isset($args[1]) && !is_numeric($args[1])) { $sender->sendMessage(TextFormat::RED . "[Error] Please specify a valid amount to sell"); return false; } $amount = $this->getAPI()->sellPlayerItem($sender, $item, isset($args[1]) ? $args[1] : null); if (!$amount) { $sender->sendMessage(TextFormat::RED . "[Error] Worth not available for this item"); return false; } elseif ($amount === -1) { $sender->sendMessage(TextFormat::RED . "[Error] You don't have that amount of items"); return false; } if (is_array($amount)) { $sender->sendMessage(TextFormat::RED . "Sold " . $amount[0] . " items! You got" . $this->getAPI()->getCurrencySymbol() . $amount[1] * $amount[0]); } else { $sender->sendMessage(TextFormat::GREEN . "Item sold! You got " . $this->getAPI()->getCurrencySymbol() . $amount); } return true; }
protected function parsePreset($preset) { $this->preset = $preset; $preset = explode(";", $preset); $version = (int) $preset[0]; $blocks = @$preset[1]; $biome = isset($preset[2]) ? $preset[2] : 1; $options = isset($preset[3]) ? $preset[3] : ""; preg_match_all('#(([0-9]{0,})x?([0-9]{1,3}:?[0-9]{0,2})),?#', $blocks, $matches); $y = 0; $this->structure = []; $this->chunks = []; foreach ($matches[3] as $i => $b) { $b = Item::fromString($b); $cnt = $matches[2][$i] === "" ? 1 : intval($matches[2][$i]); for ($cY = $y, $y += $cnt; $cY < $y; ++$cY) { $this->structure[$cY] = [$b->getID(), $b->getDamage()]; } } $this->floorLevel = $y; for (; $y < 0xff; ++$y) { $this->structure[$y] = [0, 0]; } $this->chunk = $this->level->getChunk(0, 0); $this->chunk->setGenerated(); for ($Z = 0; $Z < 16; ++$Z) { for ($X = 0; $X < 16; ++$X) { for ($y = 0; $y < 128; ++$y) { if ($this->structure[$y][0] !== 0) { $this->chunk->setBlockId($X, $y, $Z, $this->structure[$y][0]); } if ($this->structure[$y][0] !== 0) { $this->chunk->setBlockData($X, $y, $Z, $this->structure[$y][1]); } } } } preg_match_all('#(([0-9a-z_]{1,})\\(?([0-9a-z_ =:]{0,})\\)?),?#', $options, $matches); foreach ($matches[2] as $i => $option) { $params = true; if ($matches[3][$i] !== "") { $params = []; $p = explode(" ", $matches[3][$i]); foreach ($p as $k) { $k = explode("=", $k); if (isset($k[1])) { $params[$k[0]] = $k[1]; } } } $this->options[$option] = $params; } }
public function execute(CommandSender $sender, $label, array $args) { if (!$this->testPermission($sender)) { return true; } for ($a = 0; $a < 6; $a++) { if (isset($args[$a])) { if (is_numeric($args[$a]) and is_integer($args[$a] + 0)) { $item = Item::fromString($args[6]); if ($item instanceof ItemBlock) { $xmin = min($args[0] + 0, $args[3] + 0); $xmax = max($args[0] + 0, $args[3] + 0); $ymin = min($args[1] + 0, $args[4] + 0); $ymax = max($args[1] + 0, $args[4] + 0); $zmin = min($args[2] + 0, $args[5] + 0); $zmax = max($args[2] + 0, $args[5] + 0); $level = $sender instanceof Player ? $sender->getLevel() : $sender->getServer()->getDefaultLevel(); $n = 0; $nmax = ($xmax - $xmin + 1) * ($ymax - $ymin + 1) * ($zmax - $zmin + 1); for ($x = $xmin; $x <= $xmax; $x++) { for ($y = $ymin; $y <= $ymax; $y++) { for ($z = $zmin; $z <= $zmax; $z++) { if ($this->setBlock(new Vector3($x, $y, $z), $level, $item, isset($args[7]) ? $args[7] : 0)) { $n++; if (is_int($n / 10000)) { $sender->sendMessage(new TranslationContainer("{$n} out of {$nmax} blocks filled, now at {$x} {$y} {$z}", [])); } } else { $sender->sendMessage(TextFormat::RED . new TranslationContainer("Error after filling {$n} out of {$nmax} blocks.", [])); return false; } } } } $sender->sendMessage(new TranslationContainer("Total of {$n} blocks filled.", [])); return true; } $sender->sendMessage(TextFormat::RED . new TranslationContainer($args[6] . " is not a valid block.", [])); return false; } $sender->sendMessage(TextFormat::RED . new TranslationContainer($args[$a] . " is not a valid coordinate.", [])); $sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage])); return false; } $sender->sendMessage(TextFormat::RED . new TranslationContainer("pocketmine.command.fill.missingParameter", [])); $sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage])); return false; } }
public function onRegister(PlayerRegisterEvent $ev) { $pl = $ev->getPlayer(); if (!$pl->hasPermission("spawnmgr.receive.nestegg")) { return; } foreach ($this->nest_egg as $i) { $r = explode(",", $i); if (count($r) != 2) { continue; } $item = Item::fromString($r[0]); $item->setCount(intval($r[1])); $pl->getInventory()->addItem($item); } }
public function __construct(Plugin $plugin, $goods, $dfts) { $this->owner = $plugin; $this->owner->getServer()->getPluginManager()->registerEvents($this, $this->owner); $this->goods = []; foreach ($goods as $cf) { $item = Item::fromString($cf); if (($item = $item->getId()) == Item::AIR) { $plugin->getLogger()->error(mc::_("Invalid trade-good: %1%", $cf)); continue; } $this->goods[$item] = $item; } $this->defaults = $dfts; $this->state = []; }
public function execute(CommandSender $sender, $currentAlias, array $args) { if (!$this->testPermission($sender)) { return true; } if (count($args) < 2) { $sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage])); return true; } $player = $sender->getServer()->getPlayer($args[0]); $item = Item::fromString($args[1]); if (!isset($args[2])) { $item->setCount($item->getMaxStackSize()); } else { $item->setCount((int) $args[2]); } if (isset($args[3])) { $tags = $exception = null; $data = implode(" ", array_slice($args, 3)); try { $tags = NBT::parseJSON($data); } catch (\Throwable $ex) { $exception = $ex; } if (!$tags instanceof CompoundTag or $exception !== null) { $sender->sendMessage(new TranslationContainer("commands.give.tagError", [$exception !== null ? $exception->getMessage() : "Invalid tag conversion"])); return true; } $item->setNamedTag($tags); } if ($player instanceof Player) { if ($item->getId() === 0) { $sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.give.item.notFound", [$args[1]])); return true; } //TODO: overflow $player->getInventory()->addItem(clone $item); } else { $sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.generic.player.notFound")); return true; } Command::broadcastCommandMessage($sender, new TranslationContainer("%commands.give.success", [$item->getName() . " (" . $item->getId() . ":" . $item->getDamage() . ")", (string) $item->getCount(), $player->getName()])); return true; }
public function execute(CommandSender $sender, $currentAlias, array $args) { if (!$this->testPermission($sender)) { return true; } if (!$sender instanceof Player) { $sender->sendMessage("Please run this command in-game"); return false; } if (count($args) !== 4) { $sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage])); return false; } $block = Item::fromString($args[3]); if ($block instanceof ItemBlock and $block->getBlock() instanceof Block) { $block = $block->getBlock(); } else { $sender->sendMessage("Invalid Block ID"); return false; } for ($i = 0; $i <= 2; $i++) { if ($args[$i] === chr(126)) { //Tilde if ($i === 0) { $args[$i] = $sender->x; } elseif ($i === 1) { $args[$i] = $sender->y; } elseif ($i === 2) { $args[$i] = $sender->z; } } } if (!is_numeric($args[0]) or !is_numeric($args[1]) or !is_numeric($args[2])) { $sender->sendMessage("Please use numeric values for coordinates arguments"); return false; } if ($sender->level->setBlock(new Vector3((int) $args[0], (int) $args[1], (int) $args[2]), $block)) { $sender->sendMessage("Block " . $block->getName() . " placed at x=" . $args[0] . ", y=" . $args[1] . ", z=" . $args[2]); return true; } $sender->sendMessage("Failed placing block due to unknown error"); return false; }
/** * @param CommandSender $sender * @param string $alias * @param array $args * @return bool */ public function execute(CommandSender $sender, $alias, array $args) { if (!$this->testPermission($sender)) { return false; } if (count($args) !== 1) { $sender->sendMessage($sender instanceof Player ? $this->getUsage() : $this->getConsoleUsage()); return false; } switch (strtolower($args[0])) { case "hand": if (!$sender instanceof Player) { $sender->sendMessage($this->getConsoleUsage()); return false; } $id = $sender->getInventory()->getItemInHand()->getId(); $worth = $this->getPlugin()->getItemWorth($id); if (!$worth) { $sender->sendMessage(TextFormat::RED . "[Error] Worth not available for this item"); return false; } $sender->sendMessage(TextFormat::AQUA . "This item worth is " . $this->getPlugin()->getCurrencySymbol() . $worth); break; default: if (!is_int($args[0])) { $item = Item::fromString($args[0]); } else { $item = Item::get($args[0]); } if ($item->getId() === 0) { $sender->sendMessage(TextFormat::RED . "[Error] Unknown item \"" . $args[0] . "\""); } $worth = $this->getPlugin()->getItemWorth($item->getId()); if (!$worth) { $sender->sendMessage(TextFormat::RED . "[Error] Worth not available for this item"); return false; } $sender->sendMessage(TextFormat::AQUA . "This item worth is " . $this->getPlugin()->getCurrencySymbol() . $worth); break; } return true; }
public function onJoin(PlayerJoinEvent $event) { $player = $event->getPlayer(); if ($player->isCreative()) { return; } foreach ($this->getConfig()->get("data") as $slot => $g) { if (is_numeric($g["id"])) { $item = new Item($g["id"], $g["damage"]); } else { $item = Item::fromString($g["id"]); } if ($item->getId() != Block::AIR && $item->getMaxStackSize() <= $g["amount"]) { $item->setCount($g["count"]); if (!$player->getInventory()->contains($item) && $player->getInventory()->canAddItem($item)) { $player->getInventory()->addItem($item); } } } }
public function getItem($txt, $default) { $r = explode(":", $txt); if (count($r)) { if (!isset($r[1])) { $r[1] = 0; } $item = Item::fromString($r[0] . ":" . $r[1]); if (isset($r[2])) { $item->setCount(intval($r[2])); } if ($item->getId() != Item::AIR) { return $item; } } $this->getLogger()->info("{$msg}: Invalid item {$txt}, using default"); $item = Item::fromString($default . ":0"); $item->setCount(1); return $item; }
private function parseItemLine($txt) { $txt = preg_split('/\\s+/', $txt); if (count($txt) == 0) { return null; } $cnt = $txt[count($txt) - 1]; if (preg_match('/^x(\\d+)$/', $cnt, $mv)) { $cnt = $mv[1]; array_pop($txt); } else { $cnt = 1; } $item = Item::fromString(implode("_", $txt)); if ($item->getId() == 0) { return null; } $item->setCount($cnt); return $item; }
/** * Uses a item on a position and face, placing it or activating the block * * @param Vector3 $vector * @param Item $item * @param int $face * @param float $fx default 0.0 * @param float $fy default 0.0 * @param float $fz default 0.0 * @param Player $player default null * * @return boolean */ public function useItemOn(Vector3 $vector, Item &$item, $face, $fx = 0.0, $fy = 0.0, $fz = 0.0, Player $player = null) { $target = $this->getBlock($vector); $block = $target->getSide($face); if ($block->y > 127 or $block->y < 0) { return false; } if ($target->getId() === Item::AIR) { return false; } if ($player !== null) { $ev = new PlayerInteractEvent($player, $item, $target, $face, $target->getId() === 0 ? PlayerInteractEvent::RIGHT_CLICK_AIR : PlayerInteractEvent::RIGHT_CLICK_BLOCK); if (!$player->isOp() and ($distance = $this->server->getSpawnRadius()) > -1) { $t = new Vector2($target->x, $target->z); $s = new Vector2($this->getSpawnLocation()->x, $this->getSpawnLocation()->z); if (count($this->server->getOps()->getAll()) > 0 and $t->distance($s) <= $distance) { //set it to cancelled so plugins can bypass this $ev->setCancelled(); } } $this->server->getPluginManager()->callEvent($ev); if (!$ev->isCancelled()) { $target->onUpdate(self::BLOCK_UPDATE_TOUCH); if (!$player->isSneaking() and $target->canBeActivated() === true and $target->onActivate($item, $player) === true) { return true; } if (!$player->isSneaking() and $item->canBeActivated() and $item->onActivate($this, $player, $block, $target, $face, $fx, $fy, $fz)) { if ($item->getCount() <= 0) { $item = Item::get(Item::AIR, 0, 0); return true; } } } else { return false; } } elseif ($target->canBeActivated() === true and $target->onActivate($item, $player) === true) { return true; } if ($item->canBePlaced()) { $hand = $item->getBlock(); $hand->position($block); } elseif ($block->getId() === Item::FIRE) { $this->setBlock($block, new Air(), true); return false; } else { return false; } if (!($block->canBeReplaced() === true or $hand->getId() === Item::SLAB and $block->getId() === Item::SLAB)) { return false; } if ($target->canBeReplaced() === true) { $block = $target; $hand->position($block); //$face = -1; } if ($hand->isSolid() === true and $hand->getBoundingBox() !== null) { $entities = $this->getCollidingEntities($hand->getBoundingBox()); $realCount = 0; foreach ($entities as $e) { if ($e instanceof Arrow or $e instanceof DroppedItem) { continue; } ++$realCount; } if ($player !== null) { if ($diff = $player->getNextPosition()->subtract($player->getPosition()) and $diff->lengthSquared() > 1.0E-5) { $bb = $player->getBoundingBox()->getOffsetBoundingBox($diff->x, $diff->y, $diff->z); if ($hand->getBoundingBox()->intersectsWith($bb)) { ++$realCount; } } } if ($realCount > 0) { return false; //Entity in block } } $tag = $item->getNamedTagEntry("CanPlaceOn"); if ($tag instanceof Enum) { $canPlace = false; foreach ($tag as $v) { if ($v instanceof String) { $entry = Item::fromString($v->getValue()); if ($entry->getId() > 0 and $entry->getBlock() !== null and $entry->getBlock()->getId() === $target->getId()) { $canPlace = true; break; } } } if (!$canPlace) { return false; } } if ($player !== null) { $ev = new BlockPlaceEvent($player, $hand, $block, $target, $item); if (!$player->isOp() and ($distance = $this->server->getSpawnRadius()) > -1) { $t = new Vector2($target->x, $target->z); $s = new Vector2($this->getSpawnLocation()->x, $this->getSpawnLocation()->z); if (count($this->server->getOps()->getAll()) > 0 and $t->distance($s) <= $distance) { //set it to cancelled so plugins can bypass this $ev->setCancelled(); } } $this->server->getPluginManager()->callEvent($ev); if ($ev->isCancelled()) { return false; } } if ($hand->place($item, $block, $target, $face, $fx, $fy, $fz, $player) === false) { return false; } if ($hand->getId() === Item::SIGN_POST or $hand->getId() === Item::WALL_SIGN) { $nbt = new Compound("", ["id" => new String("id", Tile::SIGN), "x" => new Int("x", $block->x), "y" => new Int("y", $block->y), "z" => new Int("z", $block->z), "Text1" => new String("Text1", ""), "Text2" => new String("Text2", ""), "Text3" => new String("Text3", ""), "Text4" => new String("Text4", "")]); if ($player !== null) { $nbt->Creator = new String("Creator", $player->getRawUniqueId()); } if ($item->hasCustomBlockData()) { foreach ($item->getCustomBlockData() as $key => $v) { $nbt->{$key} = $v; } } Tile::createTile("Sign", $this->getChunk($block->x >> 4, $block->z >> 4), $nbt); } $item->setCount($item->getCount() - 1); if ($item->getCount() <= 0) { $item = Item::get(Item::AIR, 0, 0); } return true; }
public function __construct(Plugin $plugin, $xfg) { $this->owner = $plugin; $this->keepers = []; $cfg = (new Config($plugin->getDataFolder() . "shops.yml", Config::YAML))->getAll(); $this->state = []; foreach ($cfg as $i => $j) { $this->keepers[$i] = []; if (isset($j["messages"])) { $this->keepers[$i]["messages"] = $j["messages"]; } else { $this->keepers[$i]["messages"] = []; } $this->keepers[$i]["attack"] = isset($j["attack"]) ? $j["attack"] : 5; $this->keepers[$i]["slim"] = isset($j["slim"]) ? $j["slim"] : false; $this->keepers[$i]["displayName"] = isset($j["display"]) ? $j["display"] : "default"; // Load the skin in memory if (is_file($plugin->getDataFolder() . $j["skin"])) { $this->keepers[$i]["skin"] = zlib_decode(file_get_contents($plugin->getDataFolder() . $j["skin"])); } else { $this->keepers[$i]["skin"] = null; } if (isset($cfg[$i]["msgs"])) { $this->keepers[$i]["msgs"] = $cfg[$i]["msgs"]; } $items = isset($cfg[$i]["items"]) && $cfg[$i]["items"] ? $cfg[$i]["items"] : ["IRON_SWORD,2", "APPLE,10,1"]; $this->keepers[$i]["items"] = []; foreach ($items as $n) { $t = explode(",", $n); if (count($t) < 2 || count($t) > 3) { $plugin->getLogger()->error(mc::_("Item error: %1%", $n)); continue; } $item = Item::fromString(array_shift($t)); if ($item->getId() == Item::AIR) { $plugin->getLogger()->error(mc::_("Unknown Item error: %1%", $n)); continue; } $price = intval(array_pop($t)); if ($price <= 0) { $plugin->getLogger()->error(mc::_("Invalid price: %1%", $n)); continue; } if (count($t)) { $qty = intval($t[0]); if ($qty <= 0 || $qty >= $item->getMaxStackSize()) { $plugin->getLogger()->error(mc::_("Bad quantity: %1%", $n)); continue; } $item->setCount($qty); } echo "Item: " . $item->getId() . "," . $item->getCount() . "\n"; //##DEBUG $this->keepers[$i]["items"][implode(":", [$item->getId(), $item->getDamage()])] = [$item, $price]; } if (count($this->keepers[$i]["items"])) { continue; } $plugin->getLogger()->error(mc::_("ShopKeep %1% disabled!", $i)); unset($this->keepers[$i]); continue; } if (count($this->keepers) == 0) { $plugin->getLogger()->error(mc::_("No shopkeepers found!")); $this->keepers = null; return; } Entity::registerEntity(TraderNpc::class, true); $this->owner->getServer()->getPluginManager()->registerEvents($this, $this->owner); $this->owner->getServer()->getScheduler()->scheduleRepeatingTask(new PluginCallbackTask($this->owner, [$this, "spamPlayers"], [$xfg["range"], $xfg["freq"]]), $xfg["ticks"]); }
public function spawnCase($time = false) { if (!$this->time) { $this->time = microtime(true); } if ($time && time(true) - $this->time < 5) { return; } $this->time = time(true); $this->despawnCase(); foreach ($this->ic as $k => $list) { $count = 0; foreach ($list as $item => $v) { if ($this->eid > 2100000000) { $this->eid = 9999; } $i = Item::fromString($v[0]); if ($v[1] == 2) { $size = 5; } elseif ($v[1] == 3) { $size = 10; } elseif ($v[1] == 4) { $size = 30; } elseif ($v[1] == 5) { $size = 100; } else { $size = 1; } $i->setCount($size); $pk = new AddItemEntityPacket(); $pk->eid = $this->eid; $pk->item = $i; $pos = explode(":", $k); $pk->x = $pos[0] + 0.5; $pk->y = $pos[1]; $pk->z = $pos[2] + 0.5; $pk->yaw = 0; $pk->pitch = 0; $pk->roll = 0; $this->dataPacket($pk, $k); $pk = new MoveEntityPacket(); if ($count % 2 == 1) { $dis = $count * 0.15; } else { $dis = $count * -0.15; } $count++; $pk->entities = [[$this->eid, $pos[0] + 0.5 + $dis, $pos[1] + 0.25, $pos[2] + 0.5 + $dis, 0, 0]]; $this->dataPacket($pk, $k); $this->item[] = $this->eid; $this->eid++; $this->dataPacket($pk, $k); } } }
public function onBlockTouch(PlayerInteractEvent $event) { if ($event->getAction() !== PlayerInteractEvent::RIGHT_CLICK_BLOCK) { return; } $player = $event->getPlayer(); $block = $event->getBlock(); $iusername = strtolower($player->getName()); if (isset($this->queue[$iusername])) { $queue = $this->queue[$iusername]; $item = Item::fromString($queue[0]); $item->setCount($queue[1]); $ev = new ShopCreationEvent($block, $item, $queue[2], $queue[3]); $this->getServer()->getPluginManager()->callEvent($ev); if ($ev->isCancelled()) { $player->sendMessage($this->getMessage("shop-create-failed")); unset($this->queue[$iusername]); return; } $result = $this->provider->addShop($block, [$block->getX(), $block->getY(), $block->getZ(), $block->getLevel()->getFolderName(), $item->getID(), $item->getDamage(), $item->getName(), $queue[1], $queue[2], $queue[3]]); if ($result) { if ($queue[3] !== -2) { $pos = $block; if ($queue[3] !== -1) { $pos = $block->getSide($queue[3]); } $this->items[$pos->getLevel()->getFolderName()][] = $dis = new ItemDisplayer($pos, $item, $block); $dis->spawnToAll($pos->getLevel()); } $player->sendMessage($this->getMessage("shop-created")); } else { $player->sendMessage($this->getMessage("shop-already-exist")); } if ($event->getItem()->canBePlaced()) { $this->placeQueue[$iusername] = true; } unset($this->queue[$iusername]); return; } elseif (isset($this->removeQueue[$iusername])) { $shop = $this->provider->getShop($block); foreach ($this->items as $level => $arr) { foreach ($arr as $key => $displayer) { $link = $displayer->getLinked(); if ($link->getX() === $shop[0] and $link->getY() === $shop[1] and $link->getZ() === $shop[2] and $link->getLevel()->getFolderName() === $shop[3]) { $displayer->despawnFromAll(); unset($this->items[$key]); break 2; } } } $this->provider->removeShop($block); unset($this->removeQueue[$iusername]); $player->sendMessage($this->getMessage("shop-removed")); if ($event->getItem()->canBePlaced()) { $this->placeQueue[$iusername] = true; } return; } if (($shop = $this->provider->getShop($block)) !== false) { if ($this->getConfig()->get("enable-double-tap")) { $now = time(); if (isset($this->tap[$iusername]) and $now - $this->tap[$iusername] < 1) { $this->buyItem($player, $shop); unset($this->tap[$iusername]); } else { $this->tap[$iusername] = $now; $player->sendMessage($this->getMessage("tap-again", [$shop[7], $shop[6], $shop[8]])); } } else { $this->buyItem($player, $shop); } if ($event->getItem()->canBePlaced()) { $this->placeQueue[$iusername] = true; } } }
public function getItem($string) : Item { $e = explode(":", $string); $id = $e[0]; if (is_numeric($id)) { $damage = 0; if (count($e) > 1) { $damage = $e[1]; } return new Item($id, $damage, 1, 1); } else { $item = Item::fromString($id); if ($item->getId() !== Item::AIR) { $item->setCount(1); return $item; } } return new Item(0); }