本文整理汇总了PHP中pocketmine\command\CommandSender::getInventory方法的典型用法代码示例。如果您正苦于以下问题:PHP CommandSender::getInventory方法的具体用法?PHP CommandSender::getInventory怎么用?PHP CommandSender::getInventory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pocketmine\command\CommandSender
的用法示例。
在下文中一共展示了CommandSender::getInventory方法的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: onCommand
public function onCommand(CommandSender $sender, Command $cmd, $label, array $sub)
{
$n = $sender->getName();
$mm = "[SubInventory] ";
$si = $this->si;
$ik = $this->isKorean();
if ($n == "CONSOLE") {
$sender->sendMessage($mm . ($ik ? "게임내에서만 사용가능합니다." : "Please run this command in-game"));
return true;
}
$getInv = [];
$inv = $sender->getInventory();
if (!isset($si[$n])) {
$si[$n] = [];
}
$getInv = [];
foreach ($inv->getContents() as $gI) {
if ($gI->getID() !== 0 and $gI->getCount() > 0) {
$getInv[] = [$gI->getID(), $gI->getDamage(), $gI->getCount()];
}
}
$setInv = [];
foreach ($si[$n] as $sI) {
$setInv[] = Item::get($sI[0], $sI[1], $sI[2]);
}
$si[$n] = $getInv;
$inv->setContents($setInv);
if ($this->si !== $si) {
$this->si = $si;
$this->saveYml();
}
$sender->sendMessage($mm . ($ik ? "인벤토리가 교체되었습니다." : "Inventory is change"));
return true;
}
示例3: onCommand
public function onCommand(CommandSender $sender, Command $command, $label, array $args)
{
if (!$sender instanceof Player) {
return;
}
if (strtolower($command->getName()) == "clearinv") {
$sender->getInventory()->clearAll();
$sender->sendMessage(TextFormat::RED . "인벤토리가 초기화 되었습니다.");
}
}
示例4: onCommand
public function onCommand(CommandSender $sender, Command $command, $label, array $args)
{
if (!$sender instanceof Player) {
return;
}
$getItemHand = $sender->getInventory()->getItemInHand();
$ItemCode = $getItemHand->getId();
if (strtolower($command->getName()) == "bancraft") {
if (!isset($args[0])) {
$sender->sendMessage(TextFormat::AQUA . "/bancraft <add|remove|reset|list>");
$sender->sendMessage(TextFormat::GOLD . "/bancraft add - 들고있는 아이템 조합을 벤합니다");
$sender->sendMessage(TextFormat::GOLD . "/bancraft remove - 들고있는 아이템 조합벤을 풉니다");
$sender->sendMessage(TextFormat::GOLD . "/bancraft reset - 금지된 조합법들을 초기화 합니다");
$sender->sendMessage(TextFormat::GOLD . "/bancraft list - 금지된 조합법 목록을 확인 합니다");
return;
}
switch (strtolower($args[0])) {
case "add":
$getItemHand = $sender->getInventory()->getItemInHand();
$banItem = $getItemHand->getId() . ":" . $getItemHand->getDamage();
array_push($this->configData["CraftBan"], $banItem);
$sender->sendMessage(TextFormat::RED . $banItem . "를 벤하였습니다");
break;
case "reset":
$this->configData["CraftBan"] = [];
$sender->sendMessage(TextFormat::RED . "조합 금지 리스트 초기화");
break;
case "remove":
$getItemHand = $sender->getInventory()->getItemInHand();
$banItem = $getItemHand->getId() . ":" . $getItemHand->getDamage();
unset($this->configData["CraftBan"][array_search($getItemHand, $this->configData["CraftBan"])]);
$sender->sendMessage(TextFormat::RED . $banItem . "를 초기화 시켰습니다");
case "list":
foreach ($this->configData["CraftBan"] as $banlist) {
$sender->getPlayer()->sendMessage(TextFormat::AQUA . $banlist);
$sender->sendMessage(TextFormat::RED . "금지된 조합목록을 불러옵니다");
}
}
}
$this->config->save();
$this->config->setAll($this->configData);
}
示例5: execute
public function execute(CommandSender $sender, $label, array $args)
{
if (!$sender instanceof Player) {
$sender->sendMessage($this->plugin->system["messages"]["inGame"]);
return false;
}
$user = mb_strtolower($sender->getName());
if ($this->plugin->money[$user] < $this->plugin->system["rouletteNeed"]) {
$sender->sendMessage(TextFormat::RED . $this->plugin->system["messages"]["moneyNotEnough"]);
return false;
}
$this->plugin->money[$user] = $this->plugin->money[$user] - $this->plugin->system["rouletteNeed"];
$inv = $sender->getInventory();
$itemId = $this->canBeGiven[random(count($this->canBeGiven) + 1)];
$item = Item::get($itemId);
$inv->addItem(clone $item);
$sender->sendMessage(TextFormat::GREEN . $this->plugin->system["messages"]["rouletteHit"]);
return true;
}
示例6: onCommand
public function onCommand(CommandSender $sender, Command $cmd, $label, array $sub)
{
$mm = "[SortInventory] ";
$ik = $this->isKorean();
if ($sender->getName() == "CONSOLE") {
$sender->sendMessage($mm . ($ik ? "게임내에서만 사용가능합니다." : "Please run this command in-game"));
return true;
}
$inv = $sender->getInventory();
$save = [];
foreach ($inv->getContents() as $i) {
$save[] = $i->getID() . " " . $i->getDamage() . " " . $i->getCount();
}
asort($save);
$sort = [];
foreach ($save as $ii) {
$i = explode(" ", $ii);
$sort[] = Item::get($i[0], $i[1], $i[2]);
}
$inv->setContents($sort);
$sender->sendMessage($mm . ($ik ? "인벤토리를 정렬했습니다." : "Sort the inventory."));
return true;
}
示例7: onCommand
public function onCommand(CommandSender $sender, Command $cmd, $label, array $args)
{
$cfg = $this->getConfig();
$holding = $cfg->get("sneak-on-item");
$noholding = $cfg->get("sneak-off-item");
if ($cmd->getName() === "isneak") {
if ($sender->hasPermission("isneak.command")) {
if (!isset($args[0]) || count($args) > 1) {
$sender->sendMessage("§b> §cUsage: §7/isneak §c<§7on §c| §7off§c>");
return true;
}
switch (strtolower($args[0])) {
case "on":
if ($sender instanceof Player) {
$sender->getInventory()->remove(Item::get($holding));
$sender->getInventory()->remove(Item::get($noholding));
$sender->getInventory()->addItem(Item::get($holding));
$sender->getInventory()->addItem(Item::get($noholding));
$sender->sendTip("§6ItemSneaking Enabled");
}
break;
case "off":
if ($sender instanceof Player) {
$sender->getInventory()->remove(Item::get($holding));
$sender->getInventory()->remove(Item::get($noholding));
$this->disableSneak($sender);
$sender->sendTip("§6ItemSneaking Disabled");
}
break;
}
return true;
} else {
$sender->sendMessage("§cYou don't have permission for this command.");
}
}
}
示例8: onCommand
public function onCommand(CommandSender $sender, Command $command, $label, array $params)
{
$username = strtolower($sender->getName());
$player = $this->getServer()->getPlayer($username);
if (!$player instanceof Player) {
$sender->sendMessage("Use this command in game!");
return true;
}
switch ($command->getName()) {
case "cart":
$action = array_shift($params);
$id = implode("", $params);
$allpurchases = @mysqli_query($this->link, "SELECT * FROM `" . $this->getConfig()->get("mysql_table") . "` WHERE `" . $this->getConfig()->get("mysql_column_username") . "`='{$username}'") or die("FAILED TO USE MYSQL COMMAND! QUERY 5");
$purchasesbyid = @mysqli_query($this->link, "SELECT * FROM `" . $this->getConfig()->get("mysql_table") . "` WHERE `" . $this->getConfig()->get("mysql_column_row_id") . "`='{$id}' AND `" . $this->getConfig()->get("mysql_column_username") . "`='" . $sender->getName() . "'") or die("FAILED TO USE MYSQL COMMAND! QUERY 6");
if (empty($action)) {
if (@mysqli_num_rows($allpurchases)) {
$sender->sendMessage("======== Your shopping cart ========");
while ($ap = @mysqli_fetch_assoc($allpurchases)) {
$item = preg_replace("/^([0-9]+):([0-9]+)/", "\$1", $ap[$this->getConfig()->get("mysql_column_item_id")]);
$damage = preg_replace("/^([0-9]+):([0-9]+)/", "\$2", $ap[$this->getConfig()->get("mysql_column_item_id")]);
$fullitem = Item::get($item, $damage, $ap[$this->getConfig()->get("mysql_column_items_count")]);
$fullitem = preg_replace("/x([0-9]+)/s", "", $fullitem);
$fullitem = str_replace("Item ", "", $fullitem);
$sender->sendMessage($ap[$this->getConfig()->get("mysql_column_row_id")] . ". Item: {$fullitem} | Count: " . $ap[$this->getConfig()->get("mysql_column_items_count")]);
}
} else {
$sender->sendMessage("Your shopping cart is empty!");
}
return true;
} elseif ($action == "get") {
if ($id != "all") {
if (!empty($id)) {
if (@mysqli_num_rows($purchasesbyid)) {
$pbi = @mysqli_fetch_array($purchasesbyid);
$item = preg_replace("/^([0-9]+):([0-9]+)/", "\$1", $pbi[$this->getConfig()->get("mysql_column_item_id")]);
$damage = preg_replace("/^([0-9]+):([0-9]+)/", "\$2", $pbi[$this->getConfig()->get("mysql_column_item_id")]);
$fullitem = Item::get($item, $damage, $pbi[$this->getConfig()->get("mysql_column_items_count")]);
$sender->getInventory()->addItem($fullitem);
#$this->getServer()->dispatchCommand(new ConsoleCommandSender(),"give $username ".$pbi[$this->getConfig()->get("mysql_column_item_id")]." ".$pbi[$this->getConfig()->get("mysql_column_items_count")]); // This method of give things was used in beta version of plugin
@mysqli_query($this->link, "DELETE FROM `" . $this->getConfig()->get("mysql_table") . "` WHERE `" . $this->getConfig()->get("mysql_column_row_id") . "`='{$id}'") or die("FAILED TO USE MYSQL COMMAND! QUERY 7");
$sender->sendMessage("These goods were moved to your inventory!");
if ($this->getConfig()->get("enable_logger")) {
$this->getLogger()->info($sender->getName() . " gained " . $fullitem . " by '/cart get " . $pbi[$this->getConfig()->get("mysql_column_row_id")] . "'");
}
} else {
$sender->sendMessage("Unknown purchase ID!");
}
return true;
} else {
return false;
}
} else {
if (@mysqli_num_rows($allpurchases)) {
while ($ap = @mysqli_fetch_assoc($allpurchases)) {
$item = preg_replace("/^([0-9]+):([0-9]+)/", "\$1", $ap[$this->getConfig()->get("mysql_column_item_id")]);
$damage = preg_replace("/^([0-9]+):([0-9]+)/", "\$2", $ap[$this->getConfig()->get("mysql_column_item_id")]);
$fullitem = Item::get($item, $damage, $ap[$this->getConfig()->get("mysql_column_items_count")]);
$sender->getInventory()->addItem($fullitem);
if ($this->getConfig()->get("enable_logger")) {
$this->getLogger()->info($sender->getName() . " gained " . $fullitem . " by '/cart get all'");
}
#$this->getServer()->dispatchCommand(new ConsoleCommandSender(),"give $username ".$ap[$this->getConfig()->get("mysql_column_item_id")]." ".$ap[$this->getConfig()->get("mysql_column_items_count")]); // This method of give things was used in beta version of plugin
}
@mysqli_query($this->link, "DELETE FROM `" . $this->getConfig()->get("mysql_table") . "` WHERE `" . $this->getConfig()->get("mysql_column_username") . "`='{$username}'") or die("FAILED TO USE MYSQL COMMAND! QUERY 8");
$sender->sendMessage("All your goods were moved to your inventory!");
} else {
$sender->sendMessage("Your shopping cart is empty!");
}
return true;
}
} else {
$sender->sendMessage("Unknown subcommand!");
}
return true;
break;
}
}
示例9: onCommand
public function onCommand(CommandSender $sender, Command $command, $label, array $args)
{
if ($sender->hasPermission("AdvancedItemEffects.command")) {
if (!$sender instanceof Player) {
$sender->sendMessage("This command can only be used in-game");
return true;
}
if (!isset($args[0])) {
$args[0] = "help";
}
$inv = $sender->getInventory();
$hand = $inv->getItemInHand();
switch (strtolower($args[0])) {
case "addtoitem":
case "ati":
if (count($args) !== 4) {
$sender->sendMessage("Usage: /aie <addToItem/ati> <Effect Id> <Duration> <Amplifier>");
return true;
} elseif (!is_numeric($args[1]) || !is_numeric($args[2]) || !is_numeric($args[3])) {
$sender->sendMessage("Usage: /aie <addToItem/ati> <Effect Id> <Duration> <Amplifier>");
return true;
} elseif ($hand->getId() === 0) {
$sender->sendMessage("Please hold the item in hand");
return true;
}
$nbt = $hand->getNamedTag();
if (!$nbt instanceof Compound) {
$nbt = new Compound("", []);
}
$args[2] *= 20;
array_shift($args);
$nbt->AdvancedItemEffects = new String("AdvancedItemEffects", implode(" ", $args));
$hand->setNamedTag($nbt);
$inv->setItemInHand($hand);
$sender->sendMessage("Effect added to this item");
break;
case "delfromitem":
case "dfi":
if ($hand->getId() === 0) {
$sender->sendMessage("Please hold the item in hand");
return true;
}
$nbt = $hand->getNamedTag();
if (!$nbt instanceof Compound) {
$sender->sendMessage("That item does not have an NBT tag");
return true;
}
if (!isset($nbt->AdvancedItemEffects)) {
$sender->sendMessage("That item does not have any custom enchantment");
return;
}
unset($nbt->AdvancedItemEffects);
$hand->setNamedTag($nbt);
$inv->setItemInHand($hand);
$sender->sendMessage("Effect removed from this item");
break;
case "addtoenchantment":
case "ate":
if (count($args) !== 4) {
$sender->sendMessage("Usage: /aie <addToEnchantment/ate> <Effect Id> <Duration> Amplifier>");
return true;
} elseif (!is_numeric($args[1]) || !is_numeric($args[2]) || !is_numeric($args[3])) {
$sender->sendMessage("Usage: /aie <addToEnchantment/ate> <Effect Id> <Duration> <Amplifier>");
return true;
} elseif ($hand->getId() === 0) {
$sender->sendMessage("Please hold the item in hand");
return true;
}
$nbt = $hand->getNamedTag();
if ($hand->getEnchantments() === []) {
$sender->sendMessage("That item does not have any enchantments");
return true;
}
$args[2] *= 20;
array_shift($args);
foreach ($hand->getEnchantments() as $e) {
$this->data->set($e->getId() . " " . $e->getLevel(), implode(" ", $args));
$sender->sendMessage("Added effect for " . new TranslationContainer($e->getName()) . " {$e->getLevel()}");
}
$this->data->save();
break;
case "delfromenchantment":
case "dfe":
if ($hand->getId() === 0) {
$sender->sendMessage("Please hold the item in hand");
return true;
}
if ($hand->getEnchantments() === []) {
$sender->sendMessage("That item does not have any enchantments");
return true;
}
foreach ($hand->getEnchantments() as $e) {
$this->data->remove($e->getId() . " " . $e->getLevel());
$sender->sendMessage("Removed effect for " . new TranslationContainer($e->getName()) . " {$e->getLevel()}");
}
$this->data->save();
break;
case "help":
$sender->sendMessage("AdvancedItemEffectsPE Commands\nAdd effect to item: /aie <ati> <Effect Id> <Duration> <Amplifier>\nDelete effect from item: /aie <dfi>\nAdd to enchantment: /aie <ate> <Effect Id> <Duration> <Amplifier>\n Delete from enchantment: /aie <dfe>");
break;
//.........这里部分代码省略.........
示例10: onCommand
public function onCommand(CommandSender $entity, Command $cmd, $label, array $args)
{
switch ($cmd->getName()) {
case "shop":
$entity->sendMessage($this->messages["shop-command"]);
return true;
break;
case "price":
if (isset($args[0])) {
if (isset($this->config[$args[0]])) {
$id = $args[0];
$thing = $this->config[$args[0]];
$price = $thing["price"];
$entity->sendMessage(str_replace(["%id%", "%price%"], [$id, $price], $this->messages["price"]));
return true;
} else {
$entity->sendMessage($this->messages["not-found"]);
return true;
}
} else {
return false;
}
break;
case "buy":
if (isset($args[0])) {
if (isset($args[1])) {
if (isset($this->config[$args[0]])) {
if (is_numeric($args[1]) && $args[1] > 0) {
$thing = $this->config[$args[0]];
$price = $thing["price"];
$id = $thing["id"];
$data = $thing["data"];
$colv = $args[1];
$sum = $price * $colv;
if ($entity->getInventory()->canAddItem(Item::get($id, $data, $colv))) {
if (($moneyNow = $this->EconomyS->myMoney($entity->getName())) >= $sum) {
$entity->getInventory()->addItem(Item::get($id, $data, $colv));
$this->EconomyS->setMoney($entity->getName(), $moneyNow - $sum);
$entity->sendMessage(str_replace(["%amount%", "%name%", "%sum%"], [$colv, $args[0], $sum], $this->messages["sucses-buy"]));
return true;
} else {
$entity->sendMessage($this->messages["no-money"]);
return true;
}
} else {
$entity->sendMessage($this->messages["cannot-add"]);
}
} else {
$entity->sendMessage($this->messages["math-erorr"]);
return true;
}
} else {
$entity->sendMessage($this->messages["not-found"]);
return true;
}
} else {
return false;
}
} else {
return false;
}
break;
case "sell":
if (isset($args[0])) {
if (isset($args[1])) {
if (isset($this->config[$args[0]])) {
if (is_numeric($args[1]) && $args[1] > 0) {
$thing = $this->config[$args[0]];
$price = $thing["price"];
$id = $thing["id"];
$data = $thing["data"];
$colv = $args[1];
$sum = $price * $colv;
$item = new Item($id, $data, $colv);
$moneyNow = $this->EconomyS->myMoney($entity->getName());
if ($entity->getInventory()->contains($item)) {
$this->EconomyS->setMoney($entity->getName(), $moneyNow + $sum);
$entity->getInventory()->removeItem(Item::get($id, $data, $colv));
$entity->sendMessage(str_replace(["%amount%", "%name%", "%sum%"], [$colv, $args[0], $sum], $this->messages["sucses-sell"]));
return true;
} else {
$entity->sendMessage($this->messages["no-sell"]);
return true;
}
} else {
$entity->sendMessage($this->messages["math-erorr"]);
return true;
}
} else {
$entity->sendMessage($this->messages["not-found"]);
return true;
}
} else {
return false;
}
} else {
return false;
}
break;
default:
//.........这里部分代码省略.........
示例11: onCommand
public function onCommand(CommandSender $sender, Command $command, $label, array $params)
{
switch ($command->getName()) {
case "npc":
switch (strtolower(array_shift($params))) {
case "create":
case "c":
if (!$sender instanceof Player) {
$sender->sendMessage(TextFormat::RED . "Please run this command in-game.");
return true;
}
if (!$sender->hasPermission("npc.command.npc.create")) {
$sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.generic.permission"));
return true;
}
$name = implode(" ", $params);
if (trim($name) === "") {
$sender->sendMessage(TextFormat::RED . "Usage: /npc create <name>");
return true;
}
$location = new Location($sender->getX(), $sender->getY(), $sender->getZ(), -1, -1, $sender->getLevel());
$npc = new NPC($this, clone $location, $name, $sender->getSkinData(), $sender->getSkinId(), $sender->getInventory()->getItemInHand());
$this->npc[$npc->getId()] = $npc;
foreach ($sender->getLevel()->getPlayers() as $player) {
$npc->spawnTo($player);
}
if ($this->getConfig()->get("save-on-change")) {
$this->save();
}
return true;
case "remove":
case "r":
if (!$sender->hasPermission("npc.command.npc.remove")) {
$sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.generic.permission"));
return true;
}
$id = array_shift($params);
if (!is_numeric($id)) {
$sender->sendMessage(TextFormat::RED . "Usage: /npc remove <id>");
return true;
}
foreach ($this->npc as $key => $npc) {
if ($id == $npc->getId()) {
$npc->remove();
unset($this->npc[$key]);
$sender->sendMessage("Removed NPC " . TextFormat::AQUA . $npc->getName());
if ($this->getConfig()->get("save-on-change")) {
$this->save();
}
return true;
}
}
$sender->sendMessage("Could not find NPC " . TextFormat::RED . $id);
return true;
case "list":
case "ls":
case "l":
if (!$sender->hasPermission("npc.command.npc.list")) {
$sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.generic.permission"));
return true;
}
$page = array_shift($params);
if (!is_numeric($page)) {
$page = 1;
}
$max = ceil(count($this->npc) / 5);
$page = (int) $page;
$page = max(1, min($page, $max));
$output = "Showing NPC list (page {$page}/{$max}): \n";
$n = 0;
foreach ($this->npc as $id => $npc) {
$current = (int) ceil(++$n / 5);
if ($current === $page) {
$output .= "#" . $npc->getId() . " (" . round($npc->x, 2) . ":" . round($npc->y, 2) . ":" . round($npc->z, 2) . ":" . $npc->getLevel()->getName() . "): " . $npc->getName() . "\n";
} elseif ($current > $page) {
break;
}
}
$output = substr($output, 0, -1);
$sender->sendMessage($output);
return true;
case "message":
case "msg":
case "m":
if (!$sender->hasPermission("npc.command.npc.message")) {
$sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.generic.permission"));
return true;
}
$message = trim(implode(" ", $params));
$this->msgQueue[$sender->getName()] = $message;
$sender->sendMessage("Touch NPC you want to set message.");
if ($this->getConfig()->get("save-on-change")) {
$this->save();
}
return true;
case "command":
case "cmd":
if (!$sender->hasPermission("npc.command.npc.command")) {
$sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.generic.permission"));
return true;
//.........这里部分代码省略.........
示例12: onCommand
public function onCommand(CommandSender $sender, Command $command, $label, array $params)
{
switch ($command->getName()) {
case "exchange":
if (!$sender instanceof Player) {
$sender->sendMessage("[ExchangeItem] Please run this command in-game.");
return true;
}
$player = array_shift($params);
if (trim($player) === "") {
$sender->sendMessage("[ExchangeItem] Usage: " . $command->getUsage());
return true;
}
if (count($params) === 0) {
switch ($player) {
case "accept":
if (isset($this->acception[$sender->getName()])) {
$requester = $this->getServer()->getPlayerExact($this->acception[$sender->getName()]["requester"]);
if ($requester === null) {
$sender->sendMessage("[ExchangeItem] The requester is currently offline.");
} else {
$item = $this->acception[$sender->getName()]["item"];
$exchange = $this->acception[$sender->getName()]["exchange"];
$i = Item::get($item[0], $item[1], $item[2]);
$e = Item::get($exchange[0], $exchange[1], $exchange[2]);
if ($e->getId() !== 0 and !$sender->getInventory()->contains($e)) {
$requester->sendMessage("[ExchangeItem] Target player doesn't have enough item. Request cancelled.");
$sender->sendMessage("[ExchangeItem] You don't have enough item. Request cancelled.");
// TODO cancel request
return true;
}
if ($i->getId() !== 0 and !$requester->getInventory()->contains($i)) {
$sender->sendMessage("[ExchangeItem] Requester doesn't have enough item. Request cancelled.");
$requester->sendMessage("[ExchangeItem] You don't have enough item to exchange. Request cancelled.");
return true;
}
$sender->getInventory()->addItem($i);
$requester->getInventory()->removeItem($i);
$sender->getInventory()->removeItem($e);
$requester->getInventory()->addItem($e);
$requester->sendMessage("[ExchangeItem] You have exchanged the item with " . $sender->getName());
$sender->sendMessage("[ExchangeItem] You have exchanged the item with " . $requester->getName());
}
} else {
$sender->sendMessage("[ExchangeItem] You have no request to accept.");
return true;
}
return true;
case "decline":
if (isset($this->acception[$sender->getName()])) {
unset($this->acception[$sender->getName()]);
unset($this->request[$this->acception[$sender->getName()]["target"]]);
$sender->sendMessage("[ExchangeItem] Your request have been cancelled.");
} else {
$sender->sendMessage("[ExchangeItem] You have no request to decline.");
return true;
}
case "cancel":
if (isset($this->request[$sender->getName()])) {
unset($this->acception[$this->request[$sender->getName()]]);
unset($this->request[$sender->getName()]);
$sender->sendMessage("[ExchangeItem] You have cancelled the request.");
return true;
} else {
$sender->sendMessage("[ExchangeItem] You have no request to cancel.");
return true;
}
case "item":
if (isset($this->acception[$sender->getName()])) {
$item = $this->acception[$sender->getName()]["item"];
$exchange = $this->acception[$sender->getName()]["exchange"];
$i = Item::get($item[0], $item[1], $item[2]);
$e = Item::get($exchange[0], $exchange[1], $exchange[2]);
$sender->sendMessage("You have requested exchange to " . $this->acception[$sender->getName()]["target"] . "\nYou have to give " . $i->getCount() . " of " . $i->getName() . "\nExchanging with " . $e->getCount() . " of " . $e->getName());
} elseif (isset($this->request[$sender->getName()])) {
$item = $this->acception[$sender->getName()]["item"];
$exchange = $this->acception[$sender->getName()]["exchange"];
$i = Item::get($item[0], $item[1], $item[2]);
$e = Item::get($exchange[0], $exchange[1], $exchange[2]);
$sender->sendMessage("You have got an request from " . $this->acception[$sender->getName()]["target"] . "\nYou have to give : " . $e->getCount() . " of " . $e->getName() . "\nExchanging with " . $i->getCount() . " of " . $i->getName());
} else {
$sender->sendMessage("[ExchangeItem] You don't have any request.");
}
break;
default:
$sender->sendMessage("[ExchangeItem] Usage: " . $command->getUsage());
return true;
}
}
$item = array_shift($params);
$count = array_shift($params);
if (trim($item) === "" or !is_numeric($count)) {
$sender->sendMessage("[ExchangeItem] Usage: /exchange <player> <item> <count>");
}
if (isset($this->request[$sender->getName()])) {
$sender->sendMessage("[ExchangeItem] You already have a request ongoing.");
return true;
}
$playerInst = $this->getServer()->getPlayer($player);
if ($playerInst === null) {
//.........这里部分代码省略.........
示例13: onCommand
public function onCommand(CommandSender $sender, Command $command, $label, array $params)
{
switch ($command->getName()) {
case "itemcloud":
if (!$sender instanceof Player) {
$sender->sendMessage("Please run this command in-game");
return true;
}
$sub = array_shift($params);
switch ($sub) {
case "register":
if (!$sender->hasPermission("itemcloud.command.register")) {
$sender->sendMessage(TextFormat::RED . "You don't have permission to use this command.");
return true;
}
if (isset($this->clouds[strtolower($sender->getName())])) {
$sender->sendMessage("[ItemCloud] You already have your ItemCloud account");
break;
}
$this->clouds[strtolower($sender->getName())] = new ItemCloud([], $sender->getName());
$sender->sendMessage("[ItemCloud] Registered to the ItemCloud account");
break;
case "upload":
if (!$sender->hasPermission("itemcloud.command.upload")) {
$sender->sendMessage(TextFormat::RED . "You don't have permission to use this command.");
return true;
}
if (!isset($this->clouds[strtolower($sender->getName())])) {
$sender->sendMessage("[ItemCloud] Please register to the ItemCloud service first.");
break;
}
$item = array_shift($params);
$amount = array_shift($params);
if (trim($item) === "" or !is_numeric($amount)) {
usage:
$sender->sendMessage("Usage: /itemcloud upload <item ID[:item damage]> <count>");
break;
}
$amount = (int) $amount;
$item = Item::fromString($item);
$item->setCount($amount);
$count = 0;
foreach ($sender->getInventory()->getContents() as $i) {
if ($i->getID() == $item->getID() and $i->getDamage() == $item->getDamage()) {
$count += $i->getCount();
}
}
if ($amount <= $count) {
$this->clouds[strtolower($sender->getName())]->addItem($item->getID(), $item->getDamage(), $amount, true);
$sender->sendMessage("[ItemCloud] Uploaded your item to ItemCloud account.");
} else {
$sender->sendMessage("[ItemCloud] You don't have enough item to upload.");
}
break;
case "download":
if (!$sender->hasPermission("itemcloud.command.download")) {
$sender->sendMessage(TextFormat::RED . "You don't have permission to use this command.");
return true;
}
$name = strtolower($sender->getName());
if (!isset($this->clouds[$name])) {
$sender->sendMessage("[ItemCloud] Please register to the ItemCloud first.");
break;
}
$item = array_shift($params);
$amount = array_shift($params);
if (trim($item) === "" or !is_numeric($amount)) {
usage2:
$sender->sendMessage("Usage: /itemcloud download <item ID[:item damage]> <count>");
break;
}
$amount = (int) $amount;
$item = Item::fromString($item);
$item->setCount($amount);
if (!$this->clouds[$name]->itemExists($item->getID(), $item->getDamage(), $amount)) {
$sender->sendMessage("[ItemCloud] You don't have enough item in your account.");
break;
}
if ($sender->getInventory()->canAddItem($item)) {
$this->clouds[$name]->removeItem($item->getID(), $item->getDamage(), $amount);
$sender->getInventory()->addItem($item);
$sender->sendMessage("[ItemCloud] You have downloaded items from the ItemCloud account.");
} else {
$sender->sendMessage("[ItemCloud] You have no space to download items.");
}
break;
case "list":
if (!$sender->hasPermission("itemcloud.command.list")) {
$sender->sendMessage(TextFormat::RED . "You don't have permission to use this command.");
return true;
}
$name = strtolower($sender->getName());
if (!isset($this->clouds[$name])) {
$sender->sendMessage("[ItemCloud] Please register to the ItemCloud first.");
break;
}
$output = "[ItemCloud] Item list : \n";
foreach ($this->clouds[$name]->getItems() as $item => $count) {
$output .= "{$item} : {$count}\n";
}
//.........这里部分代码省略.........
示例14: onCommand
public function onCommand(CommandSender $sender, Command $command, $label, array $args)
{
switch ($command->getName()) {
case 'nothing':
return true;
break;
case 'rca':
if (count($args) < 2) {
$sender->sendMessage("Please enter a player and a command.");
return false;
}
$player = $this->getServer()->getPlayer($tuv = array_shift($args));
if (!($player == null)) {
$commandForSudo = trim(implode(" ", $args));
$this->getServer()->dispatchCommand($player, $commandForSudo);
return true;
break;
}
$sender->sendMessage(TextFormat::RED . "Player not found.");
return true;
break;
case "slapper":
if ($sender instanceof Player) {
$name = trim(implode(" ", $args));
$defaultName = $sender->getDisplayName();
if ($name == null) {
$name = $defaultName;
}
$senderSkin = $sender->getSkinData();
$IsSlim = $sender->isSkinSlim();
$playerX = $sender->getX();
$playerY = $sender->getY();
$playerZ = $sender->getZ();
$outX = round($playerX, 1);
$outY = round($playerY, 1);
$outZ = round($playerZ, 1);
$playerLevel = $sender->getLevel()->getName();
$playerYaw = $sender->getYaw();
$playerPitch = $sender->getPitch();
$humanInv = $sender->getInventory();
$pHealth = $sender->getHealth();
$nbt = new Compound();
$motion = new Vector3(0, 0, 0);
$nbt->Pos = new Enum("Pos", [new Double("", $playerX), new Double("", $playerY), new Double("", $playerZ)]);
$nbt->Motion = new Enum("Motion", [new Double("", $motion->x), new Double("", $motion->y), new Double("", $motion->z)]);
$nbt->Rotation = new Enum("Rotation", [new Float("", $playerYaw), new Float("", $playerPitch)]);
$nbt->Health = new Short("Health", $pHealth);
$nbt->Inventory = new Enum("Inventory", $humanInv);
$nbt->NameTag = new String("name", $name);
$nbt->Invulnerable = new Byte("Invulnerable", 1);
$nbt->CustomTestTag = new Byte("CustomTestTag", 1);
$nbt->Skin = new Compound("Skin", ["Data" => new String("Data", $senderSkin), "Slim" => new Byte("Slim", $IsSlim)]);
$clonedHuman = Entity::createEntity("Human", $sender->getLevel()->getChunk($playerX >> 4, $playerZ >> 4), $nbt);
$Inv = $clonedHuman->getInventory();
$sender->sendMessage(TextFormat::GREEN . "[" . TextFormat::YELLOW . "Slapper" . TextFormat::GREEN . "] " . "Human entity spawned with name " . TextFormat::WHITE . "\"" . TextFormat::BLUE . $name . TextFormat::WHITE . "\"");
$pHelm = $humanInv->getHelmet();
$pChes = $humanInv->getChestplate();
$pLegg = $humanInv->getLeggings();
$pBoot = $humanInv->getBoots();
$Inv->setHelmet($pHelm);
$Inv->setChestplate($pChes);
$Inv->setLeggings($pLegg);
$Inv->setBoots($pBoot);
$clonedHuman->getInventory()->setHeldItemSlot($sender->getInventory()->getHeldItemSlot());
$clonedHuman->getInventory()->setItemInHand($sender->getInventory()->getItemInHand());
$clonedHuman->spawnToAll();
return true;
} else {
$sender->sendMessage("This command only works in game.");
return true;
}
}
}
示例15: onCommand
public function onCommand(CommandSender $sender, Command $command, $label, array $args)
{
switch (strtolower($command->getName())) {
case 'nothing':
return true;
break;
case 'rca':
if (count($args) < 2) {
$sender->sendMessage("Please enter a player and a command.");
return true;
}
$player = $this->getServer()->getPlayer(array_shift($args));
if (!($player === null)) {
$this->getServer()->dispatchCommand($player, trim(implode(" ", $args)));
return true;
break;
}
$sender->sendMessage(TextFormat::RED . "Player not found.");
return true;
break;
case "slapper":
if ($sender instanceof Player) {
$type = array_shift($args);
$name = str_replace("{color}", "§", str_replace("{line}", "\n", trim(implode(" ", $args))));
if ($type === null || $type === "" || $type === " ") {
return false;
}
$defaultName = $sender->getDisplayName();
if ($name == null) {
$name = $defaultName;
}
$senderSkin = $sender->getSkinData();
$isSlim = $sender->isSkinSlim();
$playerX = $sender->getX();
$playerY = $sender->getY();
$playerZ = $sender->getZ();
$playerYaw = $sender->getYaw();
$playerPitch = $sender->getPitch();
$humanInv = $sender->getInventory();
$theOne = "Blank";
$nameToSay = "Human";
$didMatch = "No";
foreach (["Chicken", "ZombiePigman", "Pig", "Sheep", "Cow", "Mooshroom", "MushroomCow", "Wolf", "Enderman", "Spider", "Skeleton", "PigZombie", "Creeper", "Slime", "Silverfish", "Villager", "Zombie", "Human", "Player", "Squid", "Bat", "CaveSpider", "LavaSlime"] as $entityType) {
if (strtolower($type) === strtolower($entityType)) {
$didMatch = "Yes";
$theOne = $entityType;
}
}
$typeToUse = "Nothing";
if ($theOne === "Human") {
$typeToUse = "SlapperHuman";
}
if ($theOne === "Player") {
$typeToUse = "SlapperHuman";
}
if ($theOne === "Pig") {
$typeToUse = "SlapperPig";
}
if ($theOne === "Bat") {
$typeToUse = "SlapperBat";
}
if ($theOne === "Cow") {
$typeToUse = "SlapperCow";
}
if ($theOne === "Sheep") {
$typeToUse = "SlapperSheep";
}
if ($theOne === "MushroomCow") {
$typeToUse = "SlapperMushroomCow";
}
if ($theOne === "Mooshroom") {
$typeToUse = "SlapperMushroomCow";
}
if ($theOne === "LavaSlime") {
$typeToUse = "SlapperLavaSlime";
}
if ($theOne === "Enderman") {
$typeToUse = "SlapperEnderman";
}
if ($theOne === "Zombie") {
$typeToUse = "SlapperZombie";
}
if ($theOne === "Creeper") {
$typeToUse = "SlapperCreeper";
}
if ($theOne === "Skeleton") {
$typeToUse = "SlapperSkeleton";
}
if ($theOne === "Silverfish") {
$typeToUse = "SlapperSilverfish";
}
if ($theOne === "Chicken") {
$typeToUse = "SlapperChicken";
}
if ($theOne === "Villager") {
$typeToUse = "SlapperVillager";
}
if ($theOne === "CaveSpider") {
$typeToUse = "SlapperCaveSpider";
}
//.........这里部分代码省略.........