Search in sources :

Example 1 with HumanEntity

use of org.bukkit.entity.HumanEntity in project AuthMeReloaded by AuthMe.

the class PlayerListener method onPlayerInventoryOpen.

@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onPlayerInventoryOpen(InventoryOpenEvent event) {
    final HumanEntity player = event.getPlayer();
    if (listenerService.shouldCancelEvent(player)) {
        event.setCancelled(true);
        /*
             * @note little hack cause InventoryOpenEvent cannot be cancelled for
             * real, cause no packet is sent to server by client for the main inv
             */
        bukkitService.scheduleSyncDelayedTask(player::closeInventory, 1);
    }
}
Also used : HumanEntity(org.bukkit.entity.HumanEntity) EventHandler(org.bukkit.event.EventHandler)

Example 2 with HumanEntity

use of org.bukkit.entity.HumanEntity in project AuthMeReloaded by AuthMe.

the class PlayerListenerTest method shouldAllowInventoryOpen.

@Test
public void shouldAllowInventoryOpen() {
    // given
    HumanEntity player = mock(Player.class);
    InventoryView transaction = mock(InventoryView.class);
    given(transaction.getPlayer()).willReturn(player);
    InventoryOpenEvent event = new InventoryOpenEvent(transaction);
    given(event.getPlayer()).willReturn(player);
    given(listenerService.shouldCancelEvent(player)).willReturn(false);
    // when
    listener.onPlayerInventoryOpen(event);
    // then
    assertThat(event.isCancelled(), equalTo(false));
    verifyZeroInteractions(bukkitService);
}
Also used : InventoryOpenEvent(org.bukkit.event.inventory.InventoryOpenEvent) InventoryView(org.bukkit.inventory.InventoryView) HumanEntity(org.bukkit.entity.HumanEntity) Test(org.junit.Test)

Example 3 with HumanEntity

use of org.bukkit.entity.HumanEntity in project xAuth by CypherX.

the class xAuthPlayerListener method onInventoryClick.

@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onInventoryClick(final InventoryClickEvent event) {
    if (!plugin.getConfig().getBoolean("guest.hide-inventory")) {
        HumanEntity entity = event.getWhoClicked();
        if (entity instanceof Player) {
            xAuthPlayer p = plyrMngr.getPlayer(((Player) entity).getName());
            if (plyrMngr.isRestricted(p, event)) {
                plyrMngr.sendNotice(p);
                event.setCancelled(true);
            }
        }
    }
}
Also used : Player(org.bukkit.entity.Player) com.cypherx.xauth.xAuthPlayer(com.cypherx.xauth.xAuthPlayer) com.cypherx.xauth.xAuthPlayer(com.cypherx.xauth.xAuthPlayer) HumanEntity(org.bukkit.entity.HumanEntity) EventHandler(org.bukkit.event.EventHandler)

Example 4 with HumanEntity

use of org.bukkit.entity.HumanEntity in project Denizen-For-Bukkit by DenizenScript.

the class ItemRecipeFormedScriptEvent method onRecipeFormed.

@EventHandler
public void onRecipeFormed(PrepareItemCraftEvent event) {
    HumanEntity humanEntity = event.getView().getPlayer();
    if (dEntity.isNPC(humanEntity)) {
        return;
    }
    Recipe eRecipe = event.getRecipe();
    if (eRecipe == null || eRecipe.getResult() == null) {
        return;
    }
    inventory = event.getInventory();
    result = new dItem(eRecipe.getResult());
    recipe = new dList();
    for (ItemStack itemStack : inventory.getMatrix()) {
        if (itemStack != null) {
            recipe.add(new dItem(itemStack).identify());
        } else {
            recipe.add(new dItem(Material.AIR).identify());
        }
    }
    player = dEntity.getPlayerFrom(humanEntity);
    resultChanged = false;
    cancelled = false;
    fire();
    if (cancelled) {
        inventory.setResult(null);
    } else if (resultChanged) {
        inventory.setResult(result.getItemStack());
    }
}
Also used : net.aufdemrand.denizen.objects.dItem(net.aufdemrand.denizen.objects.dItem) Recipe(org.bukkit.inventory.Recipe) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) HumanEntity(org.bukkit.entity.HumanEntity) ItemStack(org.bukkit.inventory.ItemStack) EventHandler(org.bukkit.event.EventHandler)

Example 5 with HumanEntity

use of org.bukkit.entity.HumanEntity in project BKCommonLib by bergerhealer.

the class EntityNetworkController method makeVisible.

/**
     * Ensures that the Entity is displayed to the viewer
     *
     * @param viewer to display this Entity for
     */
public void makeVisible(Player viewer) {
    // We just made it visible - do not try to remove it
    setRemoveNextTick(viewer, false);
    // Spawn packet
    PacketUtil.sendPacket(viewer, getSpawnPacket());
    // Meta Data
    initMetaData(viewer);
    // Velocity
    if (this.isMobile()) {
        PacketUtil.sendPacket(viewer, PacketType.OUT_ENTITY_VELOCITY.newInstance(entity.getEntityId(), this.velSynched.vector()));
    }
    // Passenger/Vehicle information
    if (entity.isInsideVehicle()) {
        Logging.LOGGER_DEBUG.warnOnce("is it required to send a separate vehicle packet?");
    }
    List<org.bukkit.entity.Entity> passengers = this.passengersSynched.get();
    if (!passengers.isEmpty()) {
        PacketUtil.sendPacket(viewer, getMountPacket(passengers));
    }
    // Potential leash
    Entity leashHolder = entity.getLeashHolder();
    if (leashHolder != null) {
        PacketUtil.sendPacket(viewer, PacketType.OUT_ENTITY_ATTACH.newInstance(leashHolder, entity.getEntity()));
    }
    // Human entity sleeping action
    if (entity.getEntity() instanceof HumanEntity && ((HumanEntity) entity.getEntity()).isSleeping()) {
        PacketUtil.sendPacket(viewer, PacketType.OUT_BED.newInstance((HumanEntity) entity.getEntity(), entity.loc.block()));
    }
    // Initial entity head rotation
    int headRot = headRotLive.get();
    if (headRot != 0) {
        PacketUtil.sendPacket(viewer, getHeadRotationPacket(headRot));
    }
}
Also used : HumanEntity(org.bukkit.entity.HumanEntity) Entity(org.bukkit.entity.Entity) CommonEntity(com.bergerkiller.bukkit.common.entity.CommonEntity) HumanEntity(org.bukkit.entity.HumanEntity)

Aggregations

HumanEntity (org.bukkit.entity.HumanEntity)15 EventHandler (org.bukkit.event.EventHandler)9 Player (org.bukkit.entity.Player)6 Test (org.junit.Test)4 ItemStack (org.bukkit.inventory.ItemStack)3 net.aufdemrand.denizen.objects.dItem (net.aufdemrand.denizen.objects.dItem)2 net.aufdemrand.denizencore.objects.dList (net.aufdemrand.denizencore.objects.dList)2 Entity (org.bukkit.entity.Entity)2 InventoryClickEvent (org.bukkit.event.inventory.InventoryClickEvent)2 InventoryOpenEvent (org.bukkit.event.inventory.InventoryOpenEvent)2 InventoryType (org.bukkit.event.inventory.InventoryType)2 Inventory (org.bukkit.inventory.Inventory)2 InventoryHolder (org.bukkit.inventory.InventoryHolder)2 InventoryView (org.bukkit.inventory.InventoryView)2 Recipe (org.bukkit.inventory.Recipe)2 CommonEntity (com.bergerkiller.bukkit.common.entity.CommonEntity)1 DamageSourceHandle (com.bergerkiller.generated.net.minecraft.server.DamageSourceHandle)1 com.cypherx.xauth.xAuthPlayer (com.cypherx.xauth.xAuthPlayer)1 User (com.earth2me.essentials.User)1 Bat (org.bukkit.entity.Bat)1