1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Solved Help EntityInventoryChangeEvent isnt working well

Discussion in 'Development' started by Defications2po, Jun 26, 2017.

  1. Defications2po

    Defications2po Witch

    Messages:
    51
    So i have not been working on stuff lately. And i recently started learning gui's. SO ye i got stuff out the way i know how to send a chest inv to a player. Then i wanted to cancel the event when the player taps on the given item so there 2 options to use and i chose EntityInventoryChangeEvent because InventoryTransactionEvent is hard. But my brother asked a friend if he could help cuz that friend was good at gui's We mest around with the code and we got our way around it. But it does not cancel when i take the Item out of the Inventory.
    Sorry for the useless paragraph
    Heres my code.
    PHP:
    public function onTap(EntityInventoryChangeEvent $ev)
    {
        
    $p $ev->getEntity();
        if (
    $p instanceof Player) {
            if (
    $ev->getNewItem()->getCustomName() == "§e(!) §7Factions Realm" ){
                
    $ev->setCancelled(true);
                
    $p->sendMessage("§aWE UP IN THIS BITCH");
            }
            if (
    $ev->getNewItem()->getCustomName() == "§e(!) §cDevelopment Realm" ){
                
    $ev->setCancelled(true);
                
    $p->sendMessage("§aWE UP IN THIS BITCH");
            }
        }
    }
     
  2. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
    Did you registerEvents? did you add the classes to your uses? this code seems prefect to me... o_O
     
  3. Defications2po

    Defications2po Witch

    Messages:
    51
    These are my eevnts
    PHP:
    //player
    use pocketmine\nbt\tag\IntTag;
    use 
    pocketmine\nbt\tag\StringTag;
    use 
    pocketmine\Player;
    //inventory
    use pocketmine\inventory\Inventory;
    use 
    pocketmine\event\inventory\InventoryTransactionEvent;
    use 
    pocketmine\inventory\ChestInventory;
    use 
    pocketmine\inventory\DoubleChestInventory;
    //events
    use pocketmine\event\player\PlayerMoveEvent;
    use 
    pocketmine\event\entity\EntityInventoryChangeEvent;
    use 
    pocketmine\event\player\PlayerItemHeldEvent;
    use 
    pocketmine\event\server\DataPacketReceiveEvent;
    use 
    pocketmine\event\player\PlayerChatEvent;
    use 
    pocketmine\event\entity\EntityTeleportEvent;
    use 
    pocketmine\event\entity\ProjectileHitEvent;
    use 
    pocketmine\event\entity\EntityShootBowEvent;
    use 
    pocketmine\event\entity\EntityDamageByEntityEvent;
    use 
    pocketmine\event\entity\EntityDamageByChildEntityEvent;
    use 
    pocketmine\event\entity\EntityDamageEvent;
    use 
    pocketmine\event\player\PlayerItemConsumeEvent;
    use 
    pocketmine\event\block\BlockBreakEvent;
    use 
    pocketmine\event\block\BlockPlaceEvent;
    use 
    pocketmine\event\player\PlayerRespawnEvent;
    use 
    pocketmine\event\player\PlayerDeathEvent;
    use 
    pocketmine\event\player\PlayerQuitEvent;
    use 
    pocketmine\event\player\PlayerKickEvent;
    use 
    pocketmine\event\player\PlayerCommandPreprocessEvent;
    use 
    pocketmine\event\player\PlayerInteractEvent;
    use 
    pocketmine\event\player\PlayerPreLoginEvent;
    use 
    pocketmine\event\player\PlayerLoginEvent;
    use 
    pocketmine\event\player\PlayerJoinEvent;
    use 
    pocketmine\event\entity\EntityLevelChangeEvent;
    use 
    pocketmine\event\level\LevelLoadEvent;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\event\player\PlayerBedEnterEvent;
    use 
    pocketmine\event\player\PlayerDropItemEvent;
    use 
    pocketmine\event\player\PlayerHungerChangeEvent;
    //items
    use pocketmine\item\Slimeball;
    use 
    pocketmine\item\Item;
    //commands
    use pocketmine\command\CommandExecutor;
    use 
    pocketmine\command\ConsoleCommandExecutor;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\ConsoleCommandSender;
    //utils
    use pocketmine\tile\Tile;
    use 
    pocketmine\utils\TextFormat;
    use 
    pocketmine\utils\config;
    use 
    pocketmine\utils\TextFormat as Color;
    use 
    pocketmine\utils\TextFormat as TF;
    use 
    pocketmine\utils\TextFormat as MT;
    use 
    pocketmine\utils\TextFormat as C;
    use 
    pocketmine\utils\BinaryStream;
    use 
    pocketmine\utils\Binary;
    //entity
    use pocketmine\entity\Entity;
    use 
    pocketmine\entity\Effect;
    use 
    pocketmine\entity\Arrow;
    //level
    use pocketmine\level\sound\BlazeShootSound;
    use 
    pocketmine\level\sound\GhastShootSound;
    use 
    pocketmine\level\sound\EndermanTeleportSound;
    use 
    pocketmine\level\sound\AnvilFallSound;
    use 
    pocketmine\level\particle\FloatingTextParticle;
    use 
    pocketmine\level\particle\ExplodeParticle;
    use 
    pocketmine\level\particle\BubbleParticle;
    use 
    pocketmine\level\particle\Particle;
    use 
    pocketmine\level\particle\DustParticle;
    use 
    pocketmine\level\Position;
    use 
    pocketmine\level\Location;
    use 
    pocketmine\level\format\Chunk;
    use 
    pocketmine\level\format\FullChunk;
    use 
    pocketmine\level\Level;
    //block
    use pocketmine\block\IronOre;
    use 
    pocketmine\block\GoldOre;
    use 
    pocketmine\block\Block;
    //plugin
    use pocketmine\plugin\PluginBase;
    use 
    pocketmine\plugin\PluginManager;
    use 
    pocketmine\plugin\Plugin;
    //server
    use pocketmine\Server;
    //network
    use pocketmine\network\protocol\AddEntityPacket;
    use 
    pocketmine\network\protocol\PlayerActionPacket;
    use 
    pocketmine\network\protocol\MovePlayerPacket;
    use 
    pocketmine\network\protocol\BlockEventPacket;
    //math
    use pocketmine\math\Vector3;
    use 
    pocketmine\math\Math;
    use 
    pocketmine\math\AxisAlignedBB;
    //scheduler
    use pocketmine\scheduler\PluginTask;
    use 
    pocketmine\scheduler\CallbackTask;
    //nbt
    use pocketmine\nbt\tag\DoubleTag;
    use 
    pocketmine\nbt\NBT;
    use 
    pocketmine\nbt\tag\FloatTag;
    use 
    pocketmine\nbt\tag\ListTag;
    use 
    pocketmine\nbt\tag\CompoundTag;
    //permission
    use pocketmine\permission\Permission;
     
  4. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    So the event doesn't cancel but the message is still sent?
     
  5. Kenn Fatt

    Kenn Fatt Slime

    Messages:
    82
    GitHub:
    kennfatt
    So what do you want? Canceling an event when player try to pickup an item? I dont get it
     
  6. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
    its a EntityINVENTORYChangeEvent , when player makes a change in their inventory or chest inventory whatever inventory this event is trigged , he cant cancell it but am sure he isnt using it the right way or something
     
  7. Defications2po

    Defications2po Witch

    Messages:
    51
    i fixed it. There was a typo in registerEvents()
     
  8. Kenn Fatt

    Kenn Fatt Slime

    Messages:
    82
    GitHub:
    kennfatt
    Just tips, on every Event bracket or if, you should put this
    PHP:
    echo "Yay my code is working! thanks god" PHP_EOL;
    it will HELP you from stressed issue and protect you from headache.

    for example
    PHP:
    public function onMove(PlayerMoveEvent $event) {
     echo 
    "Yay my code is working! thanks god" PHP_EOL;
    }
    Its look simple but yes, you must do that.
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.