/**
  * @priority LOWEST
  */
 public function onEntityInteract(EntityDamageEvent $ev)
 {
     if ($ev->isCancelled()) {
         return;
     }
     if (!$ev instanceof EntityDamageByEntityEvent) {
         return;
     }
     $giver = $ev->getDamager();
     if (!$giver instanceof Player) {
         return;
     }
     $taker = $ev->getEntity();
     if (!$taker instanceof TraderNpc) {
         return;
     }
     $ev->setCancelled();
     // OK, now what...
     if ($giver->isCreative() || $giver->isSpectator()) {
         $giver->sendMessage(mc::_("No purchases while in %1% mode.", MPMU::gamemodeStr($giver->getGamemode())));
         return;
     }
     $shop = $taker->namedtag->shop->getValue();
     if (!isset($this->keepers[$shop])) {
         $this->owner->getLogger()->error(mc::_("Invalid shop %5% for NPC at %1%,%2%,%3% (%4%)", $taker->floorX(), $taker->floorY(), $taker->floorZ(), $taker->getLevel()->getName(), $shop));
         $giver->sendMessage(mc::_("Sorry, shop is closed!"));
         return;
     }
     $hand = $giver->getInventory()->getItemInHand();
     if ($this->owner->getCurrency() !== false ? $hand->getId() == $this->owner->getCurrency() : $hand->getId() == Item::GOLD_INGOT) {
         // OK, we want to buy stuff...
         $this->owner->getServer()->getScheduler()->scheduleDelayedTask(new PluginCallbackTask($this->owner, [$this, "startTrade"], [$giver, $taker, $shop]), 10);
     } else {
         if ($this->owner->isWeapon($hand)) {
             $this->shopMsg($giver, $shop, "under-attack");
             $giver->attack($this->keepers[$shop]["attack"], new EntityDamageByEntityEvent($taker, $giver, EntityDamageEvent::CAUSE_ENTITY_ATTACK, $this->keepers[$shop]["attack"], 1.0));
         } else {
             $this->shopMsg($giver, $shop, "help-info");
         }
     }
 }
 /**
  * @priority LOWEST
  */
 public function onPlayerPayment(EntityDamageEvent $ev)
 {
     if ($ev->isCancelled()) {
         return;
     }
     if (!$ev instanceof EntityDamageByEntityEvent) {
         return;
     }
     $giver = $ev->getDamager();
     $taker = $ev->getEntity();
     if (!$giver instanceof Player) {
         return;
     }
     if ($giver->isCreative() || $giver->isSpectator()) {
         return;
     }
     $hand = $giver->getInventory()->getItemInHand();
     if ($hand->getId() == $this->owner->getCurrency() && $this->owner->getCurrency()) {
         if ($taker instanceof Player) {
             if ($taker->isCreative() || $taker->isSpectator()) {
                 $giver->sendMessage(mc::_("No trading possible, %1% is in %2% mode", $taker->getDisplayName(), MPMU::gamemodeStr($taker->getGamemode())));
                 return;
             }
             $ev->setCancelled();
             // OK, we want to pay, not to fight!
             $this->onPlayerPaid($giver, $taker);
         }
         //else paying an Entity!
         return;
     }
     if (isset($this->goods[$hand->getId()])) {
         if ($taker instanceof Player) {
             if ($taker->isCreative() || $taker->isSpectator()) {
                 $giver->sendMessage(mc::_("No trading possible, %1% is in %2% mode", $taker->getDisplayName(), MPMU::gamemodeStr($taker->getGamemode())));
                 return;
             }
             $ev->setCancelled();
             // OK, we are trading
             $this->onPlayerTrade($giver, $taker);
         }
         //else trading with entity...
         return;
     }
 }
Exemple #3
0
 public function playerTouchSign(PlayerInteractEvent $ev)
 {
     if ($ev->getBlock()->getId() != Block::SIGN_POST && $ev->getBlock()->getId() != Block::WALL_SIGN) {
         return;
     }
     //echo "TOUCHED\n";
     $sign = $ev->getPlayer()->getLevel()->getTile($ev->getBlock());
     if (!$sign instanceof Sign) {
         return;
     }
     //echo __METHOD__.",".__LINE__."\n";
     $lines = $sign->getText();
     //print_r($lines);
     //print_r($this->texts);
     if (!isset($this->texts[$lines[0]])) {
         return;
     }
     //echo __METHOD__.",".__LINE__."\n";
     if ($ev->getPlayer()->isCreative() || $ev->getPlayer()->isSpectator()) {
         $ev->getPlayer()->sendMessage(mc::_("No trading possible, while in %1% mode", MPMU::gamemodeStr($ev->getPlayer()->getGamemode())));
         return;
     }
     $this->activateSign($ev->getPlayer(), $sign);
 }