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