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