Search in sources :

Example 11 with HumanEntity

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

the class PlayerListenerTest method shouldAllowInventoryClickEvent.

@Test
public void shouldAllowInventoryClickEvent() {
    // given
    InventoryClickEvent event = mock(InventoryClickEvent.class);
    HumanEntity player = mock(Player.class);
    given(event.getWhoClicked()).willReturn(player);
    given(listenerService.shouldCancelEvent(player)).willReturn(false);
    // when
    listener.onPlayerInventoryClick(event);
    // then
    verify(event, only()).getWhoClicked();
}
Also used : InventoryClickEvent(org.bukkit.event.inventory.InventoryClickEvent) HumanEntity(org.bukkit.entity.HumanEntity) Test(org.junit.Test)

Example 12 with HumanEntity

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

the class PlayerListenerTest method shouldCancelInventoryClickEvent.

@Test
public void shouldCancelInventoryClickEvent() {
    // given
    InventoryClickEvent event = mock(InventoryClickEvent.class);
    HumanEntity player = mock(Player.class);
    given(event.getWhoClicked()).willReturn(player);
    given(listenerService.shouldCancelEvent(player)).willReturn(true);
    // when
    listener.onPlayerInventoryClick(event);
    // then
    verify(event).setCancelled(true);
}
Also used : InventoryClickEvent(org.bukkit.event.inventory.InventoryClickEvent) HumanEntity(org.bukkit.entity.HumanEntity) Test(org.junit.Test)

Example 13 with HumanEntity

use of org.bukkit.entity.HumanEntity in project TotalFreedomMod by TotalFreedom.

the class MobBlocker method onCreatureSpawn.

@EventHandler(priority = EventPriority.NORMAL)
public void onCreatureSpawn(CreatureSpawnEvent event) {
    if (!ConfigEntry.MOB_LIMITER_ENABLED.getBoolean()) {
        return;
    }
    final Entity spawned = event.getEntity();
    if (spawned instanceof EnderDragon) {
        if (ConfigEntry.MOB_LIMITER_DISABLE_DRAGON.getBoolean()) {
            event.setCancelled(true);
            return;
        }
    } else if (spawned instanceof Ghast) {
        if (ConfigEntry.MOB_LIMITER_DISABLE_GHAST.getBoolean()) {
            event.setCancelled(true);
            return;
        }
    } else if (spawned instanceof Slime) {
        if (ConfigEntry.MOB_LIMITER_DISABLE_SLIME.getBoolean()) {
            event.setCancelled(true);
            return;
        }
    } else if (spawned instanceof Giant) {
        if (ConfigEntry.MOB_LIMITER_DISABLE_GIANT.getBoolean()) {
            event.setCancelled(true);
            return;
        }
    } else if (spawned instanceof Bat) {
        event.setCancelled(true);
        return;
    }
    int mobLimiterMax = ConfigEntry.MOB_LIMITER_MAX.getInteger();
    if (mobLimiterMax <= 0) {
        return;
    }
    int mobcount = 0;
    for (Entity entity : event.getLocation().getWorld().getLivingEntities()) {
        if (!(entity instanceof HumanEntity)) {
            mobcount++;
        }
    }
    if (mobcount > mobLimiterMax) {
        event.setCancelled(true);
    }
}
Also used : HumanEntity(org.bukkit.entity.HumanEntity) Entity(org.bukkit.entity.Entity) EnderDragon(org.bukkit.entity.EnderDragon) Bat(org.bukkit.entity.Bat) Ghast(org.bukkit.entity.Ghast) HumanEntity(org.bukkit.entity.HumanEntity) Slime(org.bukkit.entity.Slime) Giant(org.bukkit.entity.Giant) EventHandler(org.bukkit.event.EventHandler)

Example 14 with HumanEntity

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

the class EssentialsPlayerListener method onPlayerQuit.

@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerQuit(final PlayerQuitEvent event) {
    final User user = ess.getUser(event.getPlayer());
    if (ess.getSettings().allowSilentJoinQuit() && user.isAuthorized("essentials.silentquit")) {
        event.setQuitMessage(null);
    } else if (ess.getSettings().isCustomQuitMessage() && event.getQuitMessage() != null) {
        final Player player = event.getPlayer();
        event.setQuitMessage(ess.getSettings().getCustomQuitMessage().replace("{PLAYER}", player.getDisplayName()).replace("{USERNAME}", player.getName()));
    }
    user.startTransaction();
    if (ess.getSettings().removeGodOnDisconnect() && user.isGodModeEnabled()) {
        user.setGodModeEnabled(false);
    }
    if (user.isVanished()) {
        user.setVanished(false);
    }
    user.setLogoutLocation();
    if (user.isRecipeSee()) {
        user.getBase().getOpenInventory().getTopInventory().clear();
    }
    for (HumanEntity viewer : user.getBase().getInventory().getViewers()) {
        if (viewer instanceof Player) {
            User uviewer = ess.getUser((Player) viewer);
            if (uviewer.isInvSee()) {
                uviewer.getBase().closeInventory();
            }
        }
    }
    user.updateActivity(false);
    if (!user.isHidden()) {
        user.setLastLogout(System.currentTimeMillis());
    }
    user.stopTransaction();
    user.dispose();
}
Also used : Player(org.bukkit.entity.Player) HumanEntity(org.bukkit.entity.HumanEntity) EventHandler(org.bukkit.event.EventHandler)

Example 15 with HumanEntity

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

the class EssentialsPlayerListener method onInventoryCloseEvent.

@EventHandler(priority = EventPriority.MONITOR)
public void onInventoryCloseEvent(final InventoryCloseEvent 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.getPlayer());
        user.setInvSee(false);
        refreshPlayer = user.getBase();
    } else if (type == InventoryType.ENDER_CHEST) {
        final User user = ess.getUser((Player) event.getPlayer());
        user.setEnderSee(false);
        refreshPlayer = user.getBase();
    } else if (type == InventoryType.WORKBENCH) {
        final User user = ess.getUser((Player) event.getPlayer());
        if (user.isRecipeSee()) {
            user.setRecipeSee(false);
            event.getView().getTopInventory().clear();
            refreshPlayer = user.getBase();
        }
    } else if (type == InventoryType.CHEST && top.getSize() == 9) {
        final InventoryHolder invHolder = top.getHolder();
        if (invHolder != null && invHolder instanceof HumanEntity) {
            final User user = ess.getUser((Player) event.getPlayer());
            user.setInvSee(false);
            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)

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