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();
}
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);
}
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);
}
}
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();
}
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);
}
}
Aggregations