Search in sources :

Example 6 with HumanEntity

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

the class CommonMethods method damageBy.

public static void damageBy(org.bukkit.entity.Entity entity, org.bukkit.entity.Entity damager, double damage) {
    DamageSourceHandle source;
    if (damager instanceof Player) {
        source = DamageSourceHandle.playerAttack((HumanEntity) damager);
    } else if (damager instanceof LivingEntity) {
        source = DamageSourceHandle.mobAttack((LivingEntity) damager);
    } else {
        source = DamageSourceHandle.byName("generic");
    }
    CommonNMS.getHandle(entity).damageEntity(source, (float) damage);
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) DamageSourceHandle(com.bergerkiller.generated.net.minecraft.server.DamageSourceHandle) HumanEntity(org.bukkit.entity.HumanEntity)

Example 7 with HumanEntity

use of org.bukkit.entity.HumanEntity in project Essentials by drtshock.

the class EssentialsAntiBuildListener method onCraftItemEvent.

@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onCraftItemEvent(final CraftItemEvent event) {
    HumanEntity entity = event.getWhoClicked();
    if (entity instanceof Player) {
        final User user = ess.getUser((Player) entity);
        final ItemStack item = event.getRecipe().getResult();
        if (prot.getSettingBool(AntiBuildConfig.disable_use) && !user.canBuild() && !user.isAuthorized("essentials.build")) {
            if (!metaPermCheck(user, "craft", item.getTypeId(), item.getDurability())) {
                event.setCancelled(true);
                if (ess.getSettings().warnOnBuildDisallow()) {
                    user.sendMessage(tl("antiBuildCraft", item.getType().toString()));
                }
            }
        }
    }
}
Also used : Player(org.bukkit.entity.Player) User(com.earth2me.essentials.User) HumanEntity(org.bukkit.entity.HumanEntity) ItemStack(org.bukkit.inventory.ItemStack) EventHandler(org.bukkit.event.EventHandler)

Example 8 with HumanEntity

use of org.bukkit.entity.HumanEntity in project Essentials by drtshock.

the class EssentialsPlayerListener method onInventoryClickEvent.

@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onInventoryClickEvent(final InventoryClickEvent event) {
    Player refreshPlayer = null;
    final Inventory top = event.getView().getTopInventory();
    final InventoryType type = top.getType();
    if (type == InventoryType.PLAYER) {
        final User user = ess.getUser((Player) event.getWhoClicked());
        final InventoryHolder invHolder = top.getHolder();
        if (invHolder != null && invHolder instanceof HumanEntity) {
            final User invOwner = ess.getUser((Player) invHolder);
            if (user.isInvSee() && (!user.isAuthorized("essentials.invsee.modify") || invOwner.isAuthorized("essentials.invsee.preventmodify") || !invOwner.getBase().isOnline())) {
                event.setCancelled(true);
                refreshPlayer = user.getBase();
            }
        }
    } else if (type == InventoryType.ENDER_CHEST) {
        final User user = ess.getUser((Player) event.getWhoClicked());
        if (user.isEnderSee() && (!user.isAuthorized("essentials.enderchest.modify"))) {
            event.setCancelled(true);
            refreshPlayer = user.getBase();
        }
    } else if (type == InventoryType.WORKBENCH) {
        User user = ess.getUser((Player) event.getWhoClicked());
        if (user.isRecipeSee()) {
            event.setCancelled(true);
            refreshPlayer = user.getBase();
        }
    } else if (type == InventoryType.CHEST && top.getSize() == 9) {
        final User user = ess.getUser((Player) event.getWhoClicked());
        final InventoryHolder invHolder = top.getHolder();
        if (invHolder != null && invHolder instanceof HumanEntity && user.isInvSee()) {
            event.setCancelled(true);
            refreshPlayer = user.getBase();
        }
    }
    if (refreshPlayer != null) {
        final Player player = refreshPlayer;
        ess.scheduleSyncDelayedTask(new Runnable() {

            @Override
            public void run() {
                player.updateInventory();
            }
        }, 1);
    }
}
Also used : Player(org.bukkit.entity.Player) InventoryType(org.bukkit.event.inventory.InventoryType) HumanEntity(org.bukkit.entity.HumanEntity) InventoryHolder(org.bukkit.inventory.InventoryHolder) Inventory(org.bukkit.inventory.Inventory) EventHandler(org.bukkit.event.EventHandler)

Example 9 with HumanEntity

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

the class PlayerCraftsItemScriptEvent method onCraftItem.

@EventHandler
public void onCraftItem(CraftItemEvent event) {
    HumanEntity humanEntity = event.getWhoClicked();
    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());
        }
    }
    this.player = dEntity.getPlayerFrom(humanEntity);
    this.resultChanged = false;
    this.cancelled = false;
    fire();
    if (cancelled) {
        event.setCancelled(true);
    } else if (resultChanged) {
        event.setCurrentItem(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 10 with HumanEntity

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

the class PlayerListenerTest method shouldCancelInventoryOpen.

@Test
public void shouldCancelInventoryOpen() {
    // 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(true);
    // when
    listener.onPlayerInventoryOpen(event);
    // then
    assertThat(event.isCancelled(), equalTo(true));
    TestHelper.runSyncDelayedTaskWithDelay(bukkitService);
    verify(player).closeInventory();
}
Also used : InventoryOpenEvent(org.bukkit.event.inventory.InventoryOpenEvent) InventoryView(org.bukkit.inventory.InventoryView) HumanEntity(org.bukkit.entity.HumanEntity) Test(org.junit.Test)

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