本文整理汇总了PHP中pocketmine\event\player\PlayerInteractEvent::getAction方法的典型用法代码示例。如果您正苦于以下问题:PHP PlayerInteractEvent::getAction方法的具体用法?PHP PlayerInteractEvent::getAction怎么用?PHP PlayerInteractEvent::getAction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pocketmine\event\player\PlayerInteractEvent
的用法示例。
在下文中一共展示了PlayerInteractEvent::getAction方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: compassTracker
public function compassTracker(PlayerInteractEvent $ev)
{
$p = $ev->getPlayer();
if ($p->getInventory()->getItemInHand()->getId() === 345 && $ev->getAction() === PlayerInteractEvent::RIGHT_CLICK_AIR) {
if (in_array($ev->getPlayer()->getName(), $this->compass)) {
$p->sendMessage("§c§lYou cant use this for 3 minutes!");
$ev->setCancelled(true);
return;
}
if (!in_array($ev->getPlayer()->getName(), $this->compass)) {
array_push($this->compass, $ev->getPlayer()->getName());
$p->sendTip("§c§lYou cant use this for 3 minutes!");
$task = new Task($this, $ev->getPlayer());
$this->getServer()->getScheduler()->scheduleDelayedTask($task, 3600);
$pickqv = [];
$distSqMap = [];
foreach ($p->getLevel()->getPlayers() as $player) {
asort($distSqMap);
}
foreach ($distSqMap as $id => $distSq) {
$p->sendMessage("§b§l" . $picked[$id]->getDisplayName() . " §fis §c" . round(sqrt($distSq)) . " §fblocks from you.");
}
}
}
}
示例2: onInteract
/**
* @param PlayerInteractEvent $event
*
* @priority LOW
*/
public function onInteract(PlayerInteractEvent $event)
{
if ($event->getAction() !== PlayerInteractEvent::RIGHT_CLICK_BLOCK) {
return;
}
$player = $event->getPlayer();
$gamer = $this->hub->getGamerForPlayer($player);
$item = $event->getItem();
$block = $event->getBlock();
if ($block instanceof SignPost) {
$sign = $block->getLevel()->getTile($block);
if (!$sign instanceof Sign) {
unset($sign);
}
}
foreach ($this->hub->getJoinMethods() as $method) {
if (!$method->isLevelCorrect($player->getLevel())) {
continue;
}
if ($method instanceof KeyJoinMethod) {
if ($method->key === null or $method->key->equals($item, true, false)) {
if ($method->lock === null or $method->lock->equals($block)) {
$gamer->setModule($this->hub->getModule($method->target));
return;
}
}
} elseif (isset($sign) and $method instanceof SignJoinMethod) {
if ($method->matches($sign)) {
$gamer->setModule($this->hub->getModule($method->target));
return;
}
}
}
}
示例3: PlayerInteractEvent
public function PlayerInteractEvent(PlayerInteractEvent $ev)
{
$item = $ev->getItem();
$block = $ev->getBlock();
$player = $ev->getPlayer();
if ($ev->getAction() == PlayerInteractEvent::RIGHT_CLICK_BLOCK && $ev->getFace() !== 255) {
if ($player->hasPermission("worldedit.command.setpos2") && $item->getID() == $this->getData("tool-id", Item::IRON_HOE)) {
$player->sendMessage("[WorldEditor]Pos2 지점을 선택했어요 ({$block->x}, {$block->y}, {$block->z})");
self::$pos[$player->getName()][1] = $block->floor();
$ev->setCancelled();
return;
}
} elseif ($ev->getAction() == PlayerInteractEvent::LEFT_CLICK_AIR && $player->hasPermission("worldedit.command.setpos1") && $item->getID() == $this->getData("tool-id", Item::IRON_HOE)) {
$player->sendMessage("[WorldEditor]Pos1 지점을 선택했어요 ({$block->x}, {$block->y}, {$block->z})");
self::$pos[$player->getName()][0] = $block->floor();
return;
}
}
示例4: onPlayerInteract
public function onPlayerInteract(PlayerInteractEvent $event)
{
if ($event->getAction() !== PlayerInteractEvent::RIGHT_CLICK_BLOCK) {
return;
}
$loc = $this->getLocationByPosition($event->getBlock());
if (!isset($this->shops[$loc])) {
return;
}
$shopData = $this->shops[$loc];
if ($event->getItem()->isPlaceable()) {
array_push($this->placeQueue, $event->getPlayer());
}
$event->setCancelled();
if (!$event->getPlayer()->hasPermission("exchange.use")) {
$event->getPlayer()->sendMessage(TextFormat::RED . self::getTranslation("NO_PERMISSION_USE"));
return;
}
if (!$event->getPlayer()->getInventory()->contains(Item::get($shopData["from"]["id"], $shopData["from"]["damage"], $shopData["from"]["count"]))) {
$event->getPlayer()->sendMessage(TextFormat::RED . self::getTranslation("INSUFFICIENT_ITEM"));
return;
}
if (!$event->getPlayer()->getInventory()->canAddItem(Item::get($shopData["to"]["id"], $shopData["to"]["damage"], $shopData["to"]["count"]))) {
$event->getPlayer()->sendMessage(TextFormat::RED . self::getTranslation("INSUFFICIENT_INVENTORY"));
return;
}
if (!isset($this->doubleTap[$event->getPlayer()->getName()])) {
$this->setDoubleTap($event->getPlayer(), $loc);
return;
}
if ($this->doubleTap[$event->getPlayer()->getName()]["id"] !== $loc) {
$this->setDoubleTap($event->getPlayer(), $loc);
return;
}
if ($this->doubleTap[$event->getPlayer()->getName()]["time"] - microtime(true) >= 1.5) {
$this->setDoubleTap($event->getPlayer(), $loc);
return;
}
unset($this->doubleTap[$event->getPlayer()->getName()]);
$event->getPlayer()->sendMessage(TextFormat::AQUA . self::getTranslation("EXCHANGED"));
if (count($event->getPlayer()->getInventory()->removeItem(Item::get($shopData["from"]["id"], $shopData["from"]["damage"], $shopData["from"]["count"]))) <= 0) {
$event->getPlayer()->getInventory()->addItem(Item::get($shopData["to"]["id"], $shopData["to"]["damage"], $shopData["to"]["count"]));
}
}
示例5: onPlayerInteract
public function onPlayerInteract(PlayerInteractEvent $event)
{
if ($event->getAction() === PlayerInteractEvent::RIGHT_CLICK_BLOCK) {
$this->permissionCheck($event);
}
}
示例6: onTouch
public function onTouch(PlayerInteractEvent $event)
{
if ($event->getAction() !== PlayerInteractEvent::RIGHT_CLICK_BLOCK) {
return;
}
$block = $event->getBlock();
$loc = $block->getX() . ":" . $block->getY() . ":" . $block->getZ() . ":" . $block->getLevel()->getName();
if (isset($this->sell[$loc])) {
$sell = $this->sell[$loc];
$player = $event->getPlayer();
if ($player->getGamemode() % 2 === 1) {
$player->sendMessage($this->getMessage("creative-mode"));
$event->setCancelled();
return;
}
if (!$player->hasPermission("economysell.sell.sell")) {
$player->sendMessage($this->getMessage("no-permission-sell"));
$event->setCancelled();
return;
}
$cnt = 0;
foreach ($player->getInventory()->getContents() as $item) {
if ($item->getID() == $sell["item"] and $item->getDamage() == $sell["meta"]) {
$cnt += $item->getCount();
}
}
if (!isset($sell["itemName"])) {
$item = $this->getItem($sell["item"], $sell["meta"], $sell["amount"]);
if ($item === false) {
$item = $sell["item"] . ":" . $sell["meta"];
} else {
$item = $item[0];
}
$this->sell[$loc]["itemName"] = $item;
$sell["itemName"] = $item;
}
$now = microtime(true);
if ($this->getConfig()->get("enable-double-tap")) {
if (!isset($this->tap[$player->getName()]) or $now - $this->tap[$player->getName()][1] >= 1.5 or $this->tap[$player->getName()][0] !== $loc) {
$this->tap[$player->getName()] = [$loc, $now];
$player->sendMessage($this->getMessage("tap-again", [$sell["itemName"], $sell["cost"], $sell["amount"]]));
return;
} else {
unset($this->tap[$player->getName()]);
}
}
if ($cnt >= $sell["amount"]) {
$this->removeItem($player, new Item($sell["item"], $sell["meta"], $sell["amount"]));
EconomyAPI::getInstance()->addMoney($player, $sell["cost"], true, "EconomySell");
$player->sendMessage($this->getMessage("sold-item", array($sell["amount"], $sell["item"] . ":" . $sell["meta"], $sell["cost"])));
} else {
$player->sendMessage($this->getMessage("no-item"));
}
$event->setCancelled(true);
if ($event->getItem()->isPlaceable()) {
$this->placeQueue[$player->getName()] = true;
}
}
}
示例7: onPlayerInteract
public function onPlayerInteract(PlayerInteractEvent $event)
{
if ($event->getAction() !== PlayerInteractEvent::RIGHT_CLICK_BLOCK) {
return;
}
$dispenserId = $this->getDispenserId($event->getBlock());
if (!isset($this->dispensers[$dispenserId])) {
return;
}
if ($this->useOld && $event->getItem()->isPlaceable() || !$this->useOld && $event->getItem()->canBePlaced()) {
$this->itemPlaceList[$event->getPlayer()->getName()] = true;
}
$event->setCancelled(true);
if (!$event->getPlayer()->hasPermission("potiondispenser.use")) {
$event->getPlayer()->sendMessage(TextFormat::RED . $this->getTranslation("NO_PERMISSION_USE"));
return;
}
if (!isset($this->doubleTap[$event->getPlayer()->getName()])) {
$this->setDoubleTap($event->getPlayer(), $dispenserId);
return;
}
if ($this->doubleTap[$event->getPlayer()->getName()]["id"] !== $dispenserId) {
$this->setDoubleTap($event->getPlayer(), $dispenserId);
return;
}
if ($this->doubleTap[$event->getPlayer()->getName()]["time"] - microtime(true) >= 1.5) {
$this->setDoubleTap($event->getPlayer(), $dispenserId);
return;
}
unset($this->doubleTap[$event->getPlayer()->getName()]);
if ($event->getPlayer()->hasEffect($this->dispensers[$dispenserId]["name"])) {
$event->getPlayer()->sendMessage(TextFormat::RED . $this->getTranslation("ALREADY_HAS_EFFECT"));
return;
}
$api = EconomyAPI::getInstance();
if ($api->myMoney($event->getPlayer()) >= $this->dispensers[$dispenserId]["cost"]) {
if ($this->dispensers[$dispenserId]["cost"] > 0) {
$api->reduceMoney($event->getPlayer(), $this->dispensers[$dispenserId]["cost"], true, "PotionDispenser");
} else {
$api->addMoney($event->getPlayer(), -$this->dispensers[$dispenserId]["cost"], true, "PotionDispenser");
}
$event->getPlayer()->sendMessage(TextFormat::AQUA . $this->getTranslation("BOUGHT"));
if ($this->dispensers[$dispenserId]["name"] === "clear") {
$event->getPlayer()->removeAllEffects();
$event->getPlayer()->sendTip($this->getTranslation("BOUGHT_COLOR_NAME_MONEY", TextFormat::WHITE, $this->getTranslation("CLEAR"), $this->dispensers[$dispenserId]["cost"], $api->getMonetaryUnit()));
} else {
$effect = Effect::getEffect($this->dispensers[$dispenserId]["name"]);
$effect->setAmplifier($this->dispensers[$dispenserId]["amplifier"])->setDuration($this->dispensers[$dispenserId]["duration"]);
$event->getPlayer()->addEffect($effect);
$effectColor = $effect->getColor();
$event->getPlayer()->sendTip($this->getTranslation("BOUGHT_COLOR_NAME_MONEY", $this->getTextFormatFromColor($effectColor[0], $effectColor[1], $effectColor[2]), $this->getServer()->getLanguage()->translate(new TextContainer($effect->getName())), $this->dispensers[$dispenserId]["cost"], $api->getMonetaryUnit()));
}
} else {
$event->getPlayer()->sendMessage(TextFormat::RED . $this->getTranslation("NO_MONEY"));
}
}
示例8: onPlayerTouch
public function onPlayerTouch(PlayerInteractEvent $event)
{
if ($event->getAction() !== PlayerInteractEvent::RIGHT_CLICK_BLOCK) {
return;
}
$block = $event->getBlock();
$loc = $block->getX() . ":" . $block->getY() . ":" . $block->getZ() . ":" . $block->getLevel()->getFolderName();
if (isset($this->shop[$loc])) {
$shop = $this->shop[$loc];
$player = $event->getPlayer();
if ($player->getGamemode() % 2 == 1) {
$player->sendMessage($this->getMessage("invalid-gamemode"));
$event->setCancelled();
return;
}
if (!$player->hasPermission("economyshop.shop.buy")) {
$player->sendMessage($this->getMessage("no-permission-buy"));
$event->setCancelled();
return;
}
if (!$player->getInventory()->canAddItem(Item::get($shop["item"], $shop["meta"]))) {
$player->sendMessage($this->getMessage("full-inventory"));
return;
}
$money = EconomyAPI::getInstance()->myMoney($player);
if ($shop["price"] > $money) {
$player->sendMessage($this->getMessage("no-money-buy", [$shop["item"] . ":" . $shop["meta"], $shop["price"], "%3"]));
$event->setCancelled(true);
if ($event->getItem()->isPlaceable()) {
$this->placeQueue[$player->getName()] = true;
}
return;
} else {
if (!isset($shop["itemName"])) {
$item = $this->getItem($shop["item"], $shop["meta"], $shop["amount"]);
if ($item === false) {
$item = $shop["item"] . ":" . $shop["meta"];
} else {
$item = $item[0];
}
$this->shop[$loc]["itemName"] = $item;
$shop["itemName"] = $item;
}
$now = microtime(true);
if ($this->getConfig()->get("enable-double-tap")) {
if (!isset($this->tap[$player->getName()]) or $now - $this->tap[$player->getName()][1] >= 1.5 or $this->tap[$player->getName()][0] !== $loc) {
$this->tap[$player->getName()] = [$loc, $now];
$player->sendMessage($this->getMessage("tap-again", [$shop["itemName"], $shop["price"], $shop["amount"]]));
return;
} else {
unset($this->tap[$player->getName()]);
}
}
$player->getInventory()->addItem(new Item($shop["item"], $shop["meta"], $shop["amount"]));
EconomyAPI::getInstance()->reduceMoney($player, $shop["price"], true, "EconomyShop");
$player->sendMessage($this->getMessage("bought-item", [$shop["amount"], $shop["itemName"], $shop["price"]]));
$event->setCancelled(true);
if ($event->getItem()->isPlaceable()) {
$this->placeQueue[$player->getName()] = true;
}
}
}
}
示例9: onInteract
public function onInteract(PlayerInteractEvent $e)
{
$p = $e->getPlayer();
if ($e->getAction() === $e::LEFT_CLICK_BLOCK) {
}
}
示例10: onmotion
public function onmotion(PlayerInteractEvent $event)
{
$player = $event->getPlayer();
$name = $player->getName();
$hitem = $player->getInventory()->getItemInHand();
if ($hitem->getID() == 351 and $hitem->getDamage() == 5 and isset($this->joinedpvp[$name])) {
$directionVector = $player->getDirectionVector()->multiply(3);
$player->setMotion($directionVector);
} elseif ($hitem->getID() == 351 and $hitem->getDamage() == 6) {
$directionVector = $player->getDirectionVector()->multiply(5);
$player->setMotion($directionVector);
/////////////////
/////////////////
} elseif ($event->getAction() === PlayerInteractEvent::RIGHT_CLICK_AIR and isset($this->joinedpvp[$name])) {
if ($hitem->getID() == 351 and $hitem->getDamage() == 1) {
$directionVector = $player->getDirectionVector()->multiply(3);
$player->setMotion($directionVector);
} elseif ($hitem->getID() == 351 and $hitem->getDamage() == 2) {
$directionVector = $player->getDirectionVector()->multiply(5);
$player->setMotion($directionVector);
}
}
}
示例11: onPlayerInteract
public function onPlayerInteract(PlayerInteractEvent $event)
{
$where = $event->getTouchVector();
$teamBelong = false;
foreach ($this->option["teamCore"] as $team => $axis) {
if ($axis["x"] == $where . getX() and $axis["y"] == $where . getY() and $axis["z"] == $where . getZ()) {
$teamBelong = $team;
}
}
if ($teamBelong === false) {
//the block is not a core.
return;
}
if ($event->getBlock()->getId() == 0) {
//problem in setup!
return;
}
$player = $event->getPlayer();
$teamPlayer = $this->plugin->teamInfo[mb_strtolower($player->getName())];
if (!isset($teamPlayer)) {
$player->sendMessage($this->plugin->system["messages"]["notInTeam"]);
return;
}
if ($teamBelong == $teamPlayer) {
//the player attacks its own core.
$player->sendMessage($this->plugin->system["messages"]["yourCore"]);
return;
}
$action = $event->getAction();
if ($action != PlayerInteractEvent::LEFT_CLICK_BLOCK or $action != PlayerInteractEvent::RIGHT_CLICK_BLOCK) {
return;
}
$inv = $player->getInventory();
$item = $inv->getItemInHand();
$handItemId = $item->getId();
$damage = 5;
switch ($handItemId) {
case 283:
//gold sword
$damage = 55;
break;
case 284:
//gold tools
//gold tools
case 285:
case 286:
$damage = 50;
break;
case 276:
//diamond sword
$damage = 45;
break;
case 275:
//diamond tools
//diamond tools
case 274:
case 273:
$damage = 40;
break;
case 276:
//iron sword
$damage = 35;
break;
case 256:
//iron tools
//iron tools
case 257:
case 258:
$damage = 30;
break;
case 276:
//stone sword
$damage = 25;
break;
case 256:
//stone tools
//stone tools
case 257:
case 258:
$damage = 20;
break;
case 283:
//wood sword
$damage = 15;
break;
case 284:
//wood tools
//wood tools
case 285:
case 286:
$damage = 10;
break;
case 290:
//wood hoe
//wood hoe
case 291:
//stone hoe
//stone hoe
case 292:
//iron hoe
//.........这里部分代码省略.........
示例12: PlayerInteractEvent
public function PlayerInteractEvent(PlayerInteractEvent $ev)
{
if ($ev->getFace() == 255 || $ev->getAction() != PlayerInteractEvent::RIGHT_CLICK_BLOCK) {
return;
}
$item = $ev->getItem();
$player = $ev->getPlayer();
$pos = $ev->getBlock()->getSide($ev->getFace());
if ($item->getId() === Item::SPAWN_EGG) {
$entity = self::create($item->getDamage(), $pos);
if ($entity != null) {
$entity->spawnToAll();
}
if ($player->isSurvival()) {
$item->count--;
$player->getInventory()->setItemInHand($item);
}
$ev->setCancelled();
} elseif ($item->getId() === Item::MONSTER_SPAWNER) {
self::$spawn["{$pos->x}:{$pos->y}:{$pos->z}:{$pos->level->getFolderName()}"] = ["radius" => 5, "mob-list" => ["Cow", "Pig", "Sheep", "Chicken", "Zombie", "Creeper", "Skeleton", "Spider", "PigZombie", "Enderman"]];
}
}
示例13: onPlayerInteract
public function onPlayerInteract(PlayerInteractEvent $event)
{
if ($this->isValidPlayer($event->getPlayer())) {
$player = $this->players[$event->getPlayer()->getName()];
$skill = $player->getSkillByItem($event->getItem());
if ($skill !== null) {
$event->setCancelled();
}
if ($event->getAction() === PlayerInteractEvent::RIGHT_CLICK_BLOCK) {
return;
}
/**
* @var $skill Skill
*/
if ($skill !== null) {
$player->useSkill($skill, $event);
}
}
}
示例14: onTouch
public function onTouch(PlayerInteractEvent $event)
{
if (!$event->getAction()) {
return;
}
if ($event->getPlayer()->isOp()) {
return;
}
if ($this->checkSpawn($event->getBlock(), 5)) {
$this->message($event->getPlayer(), $this->get("cannot-spawn-modify"));
$event->setCancelled();
}
}
示例15: onInteract
public function onInteract(PlayerInteractEvent $event)
{
if ($this->status === self::STAT_GAME_IN_PROGRESS) {
$player = $event->getPlayer();
$item = $player->getInventory()->getItemInHand();
if ($event->getAction() === PlayerInteractEvent::RIGHT_CLICK_BLOCK) {
if ($item->getId() === self::GUN_ID) {
$this->players[$player->getName()][0]->shoot();
}
} elseif ($event->getAction() === PlayerInteractEvent::RIGHT_CLICK_AIR) {
if ($item->getId() === self::GRENADE_ID) {
$this->players[$player->getName()][1]->lob($event->getTouchVector());
$player->getInventory()->removeItem(Item::get(self::GRENADE_ID, 0, 1));
}
}
}
}