本文整理匯總了PHP中pocketmine\item\Item::fromString方法的典型用法代碼示例。如果您正苦於以下問題:PHP Item::fromString方法的具體用法?PHP Item::fromString怎麽用?PHP Item::fromString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pocketmine\item\Item
的用法示例。
在下文中一共展示了Item::fromString方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: onCommand
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;
}
示例2: onEnable
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"]);
}
}
示例3: execute
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;
}
}
示例4: execute
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;
}
示例5: onCommand
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;
}
示例6: onSignChange
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]));
}
}
示例7: fromString
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);
}
示例8: execute
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;
}
示例9: onCommand
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;
}
示例10: onSCommand
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;
}
示例11: parsePreset
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;
}
}
示例12: onSCommand
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;
}
示例13: onEnable
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"));
}
}
示例14: onCommand
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;
}
示例15: execute
/**
* @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;
}