Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Tap and get enchant.

Comments in 'Plugin Development' started by Kripak, Oct 17, 2015.

  1. Kripak
    Offline

    Kripak New Member

    Joined:
    Jul 17, 2015
    Posts:
    45
    Minecraft User:
    Kripak
    As with tapas at a certain block enchant any thing? I used PlayerInteractEvent. Does not work :(

    Help me please. Thank you in advance.
  2. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    What's your Code?
  3. CavinMiana
    Offline

    CavinMiana Active Member

    Joined:
    Aug 26, 2015
    Posts:
    101
    Minecraft User:
    CavinMiana
    Well show the code were not mind readers.
    iDirtPlayzMC likes this.
  4. Kripak
    Offline

    Kripak New Member

    Joined:
    Jul 17, 2015
    Posts:
    45
    Minecraft User:
    Kripak
    My code:
    Code:
    <?php
    
    namespace EnchantItem;
    
    use pocketmine\event\player\PlayerInteractEvent;
    use pocketmine\item\Item;
    use pocketmine\item\enchantment\Enchantment;
    use pocketmine\item\enchantment\EnchantmentEntry;
    use pocketmine\item\enchantment\EnchantmentList;
    use pocketmine\utils\TextFormat;
    use pocketmine\event\Listener;
    use pocketmine\plugin\PluginBase;
    
    class EnchantItem extends PluginBase implements Listener{
    
    public function onEnable(){
    $this->getServer()->getPluginManager()->registerEvents($this, $this);
    }
    public function onTap(PlayerInteractEvent $event){
    $player = $event->getPlayer();
    if ($event->getBlock ()->getId () == Item::MOBSPAWNER) {
    $enchantment = Enchantment::getEnchantment(9);
    $enchantment->setLevel(1);
    $item->addEnchantment($enchantment);
    $p->sendMessage(TextFormat::RED."Предмет успешно зачарован !");
    }
    }
    }
  5. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    $item is undefined.
  6. Kripak
    Offline

    Kripak New Member

    Joined:
    Jul 17, 2015
    Posts:
    45
    Minecraft User:
    Kripak
    I want to do this: If any thing on the taps to mobspawner the thing enchanting. How to fix this error (what add)?
  7. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    You should learn PHP and the API.. You have to define $item. I don't know what Item you want to enchant, if you want to enchant the item in the player's Hand, use
    PHP:
    $item $player->getInventory()->getItemInHand();
  8. Kripak
    Offline

    Kripak New Member

    Joined:
    Jul 17, 2015
    Posts:
    45
    Minecraft User:
    Kripak
    I learned PHP. But I'm just a beginner developer of PM plugins.
  9. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    PHP:
    if ($event->getBlock ()->getId () == Item::MOBSPAWNER)
    Should be changed to:
    PHP:
    if($event->getBlock() instanceof MOBSPAWNER)
    or
    PHP:
    if($event->getBlock()->getId() == /*int*/)
  10. BalAnce
    Offline

    BalAnce Active Member

    Joined:
    Mar 10, 2015
    Posts:
    125
    Minecraft User:
    BalAnce
    you have to remove the item then add enchantment then send item to inventory or else no enchantment will show as well
  11. Artide
    Offline

    Artide Active Member

    Joined:
    Apr 20, 2015
    Posts:
    214
    Minecraft User:
    Artide5
    If you know php you should know that you need to define a variable before using a it.
  12. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    His code is correct, just the definition of $item was missing. His code works just as yours
    zombie_Power likes this.
  13. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Item::MONSTER_SPAWNER is already an int.
    (right, it isn't MOBSPAWNER but MonsterSpawner
  14. CaptainKenji17
    Offline

    CaptainKenji17 Active Member

    Joined:
    Apr 22, 2014
    Posts:
    252
    Minecraft User:
    CaptainKenji17
    1. Install TapToDo
    2. /t add enchant %p (Enchantment ID) (Power)
    3. Enjoy
  15. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    This is Plugin Development section not Plugin Requests.
    Last edited: Oct 29, 2015
    CaptainKenji17 likes this.
  16. TheMaks
    Offline

    TheMaks Active Member

    Joined:
    Jul 19, 2015
    Posts:
    58
    Minecraft User:
    TheMaks
    Code:
    <?php
    
    namespace EnchantItem;
    
    use pocketmine\event\player\PlayerInteractEvent;
    use pocketmine\item\Item;
    use pocketmine\item\enchantment\Enchantment;
    use pocketmine\item\enchantment\EnchantmentEntry;
    use pocketmine\item\enchantment\EnchantmentList;
    use pocketmine\utils\TextFormat;
    use pocketmine\event\Listener;
    use pocketmine\plugin\PluginBase;
    
    class EnchantItem extends PluginBase implements Listener{
    
    public function onEnable(){
    $this->getServer()->getPluginManager()->registerEvents($this, $this);
    }
    public function onTap(PlayerInteractEvent $event){
    $player = $event->getPlayer();
    if ($event->getBlock ()->getId () == Item::MOBSPAWNER) {
    $enchantment = Enchantment::getEnchantment(9);
    $enchantment->setLevel(1);
    $item->addEnchantment($enchantment);
    $p->sendMessage(TextFormat::RED."Предмет успешно зачарован !");
    }
    }
    }
    [/QUOTE]
    use :
    PHP:
    if($event->getBlock()->getId() == Block::get($id)){}
  17. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    well... $item is undefined.. fixed code :
    PHP:
    <?php

    namespace EnchantItem;

    use 
    pocketmine\event\player\PlayerInteractEvent;
    use 
    pocketmine\item\Item;
    use 
    pocketmine\item\enchantment\Enchantment;
    use 
    pocketmine\item\enchantment\EnchantmentEntry;
    use 
    pocketmine\item\enchantment\EnchantmentList;
    use 
    pocketmine\utils\TextFormat;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\block\Block;

    class 
    EnchantItem extends PluginBase implements Listener{

    public function 
    onEnable(){
    $this->getServer()->getPluginManager()->registerEvents($this$this);
    }
    public function 
    onTap(PlayerInteractEvent $event){
    $player $event->getPlayer();
    if (
    $event->getBlock() == Block::MONSTER_SPAWNER) {
    $enchantment Enchantment::getEnchantment(9);
    $enchantment->setLevel(1);
    $item $player->getInventory()->getItemInHand();
    $item->addEnchantment($enchantment);
    $p->sendMessage(TextFormat::RED."Предмет успешно зачарован !");
    }
    }
    }
    Skullex and SeifValkierks like this.
  18. TheMaks
    Offline

    TheMaks Active Member

    Joined:
    Jul 19, 2015
    Posts:
    58
    Minecraft User:
    TheMaks
    MOB_SPAWNER
  19. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    post edited, everything fixed.
    not MOB_SPAWNER it's MONSTER_SPAWNER check this
  20. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Stop copying wrong code...

Share This Page

Advertisement