org.bukkit.entity.HumanEntity Java Examples
The following examples show how to use
org.bukkit.entity.HumanEntity.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GuiListener.java From IF with The Unlicense | 6 votes |
/** * Handles the disabling of the plugin * * @param event the event fired * @since 0.5.19 */ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onPluginDisable(@NotNull PluginDisableEvent event) { Plugin thisPlugin = JavaPlugin.getProvidingPlugin(getClass()); if (event.getPlugin() != thisPlugin) { return; } int counter = 0; //callbacks might open GUIs, eg. in nested menus int maxCount = 10; while (!activeGuiInstances.isEmpty() && counter++ < maxCount) { for (Gui gui : new ArrayList<>(activeGuiInstances)) { for (HumanEntity viewer : gui.getViewers()) { viewer.closeInventory(); } } } if (counter == maxCount) { thisPlugin.getLogger().warning("Unable to close GUIs on plugin disable: they keep getting opened " + "(tried: " + maxCount + " times)"); } }
Example #2
Source File: ControllableOcelotBase.java From EntityAPI with GNU Lesser General Public License v3.0 | 6 votes |
@Override public BehaviourItem[] getDefaultTargetingBehaviours() { return new BehaviourItem[]{ new BehaviourItem(1, new BehaviourFloat(this)), new BehaviourItem(2, new BehaviourSit(this)), new BehaviourItem(3, new BehaviourTempt(this, Material.RAW_FISH, true, 0.6D)), new BehaviourItem(4, new BehaviourAvoidEntity(this, HumanEntity.class, 16.0F, 0.8D, 1.33D)), new BehaviourItem(5, new BehaviourFollowTamer(this, 10.0F, 5.0F)), new BehaviourItem(6, new BehaviourSitOnBlock(this, 1.33D)), new BehaviourItem(7, new BehaviourLeapAtTarget(this, 0.3F)), new BehaviourItem(8, new BehaviourOcelotAttack(this)), new BehaviourItem(9, new BehaviourBreed(this, 0.8D)), new BehaviourItem(10, new BehaviourRandomStroll(this, 0.8D)), new BehaviourItem(11, new BehaviourLookAtNearestEntity(this, HumanEntity.class, 10.0F)), }; }
Example #3
Source File: KitLoading.java From AnnihilationPro with MIT License | 6 votes |
@EventHandler(priority=EventPriority.HIGHEST, ignoreCancelled=true) public void StopClicking(InventoryClickEvent event) { HumanEntity entity = event.getWhoClicked(); ItemStack stack = event.getCurrentItem(); InventoryType top = event.getView().getTopInventory().getType(); if (stack != null && (entity instanceof Player)) { if (top == InventoryType.PLAYER || top == InventoryType.WORKBENCH || top == InventoryType.CRAFTING) return; if(KitUtils.isSoulbound(stack)) event.setCancelled(true); } }
Example #4
Source File: InventoryMenu.java From EchoPet with GNU General Public License v3.0 | 6 votes |
@EventHandler public void onInvClick(InventoryClickEvent event) { HumanEntity human = event.getWhoClicked(); if (human instanceof Player) { Player player = (Player) human; Inventory inv = event.getView().getTopInventory(); if (inv.getHolder() != null && inv.getHolder() instanceof InventoryMenu && event.getRawSlot() >= 0 && event.getRawSlot() < size) { InventoryMenu menu = (InventoryMenu) inv.getHolder(); event.setCancelled(true); MenuIcon icon = slots.get(event.getSlot()); if (icon != null) { icon.onClick(player); player.closeInventory(); } } } }
Example #5
Source File: GuiPageElement.java From InventoryGui with MIT License | 6 votes |
@Override public ItemStack getItem(HumanEntity who, int slot) { if (((pageAction == PageAction.FIRST || pageAction == PageAction.LAST) && gui.getPageAmount() < 3) || (pageAction == PageAction.NEXT && gui.getPageNumber() + 1 >= gui.getPageAmount()) || (pageAction == PageAction.PREVIOUS && gui.getPageNumber() == 0)) { return gui.getFiller() != null ? gui.getFiller().getItem(who, slot) : null; } if (pageAction == PageAction.PREVIOUS) { setNumber(gui.getPageNumber()); } else if (pageAction == PageAction.NEXT) { setNumber(gui.getPageNumber() + 2); } else if (pageAction == PageAction.LAST) { setNumber(gui.getPageAmount()); } return super.getItem(who, slot).clone(); }
Example #6
Source File: ListenerInventories.java From CombatLogX with GNU General Public License v3.0 | 6 votes |
@EventHandler(priority=EventPriority.HIGH, ignoreCancelled=true) public void onOpenInventory(InventoryOpenEvent e) { FileConfiguration config = this.expansion.getConfig("cheat-prevention.yml"); if(!config.getBoolean("inventories.close-on-tag")) return; HumanEntity human = e.getPlayer(); if(!(human instanceof Player)) return; Player player = (Player) human; ICombatManager manager = this.plugin.getCombatManager(); if(!manager.isInCombat(player)) return; e.setCancelled(true); String message = this.plugin.getLanguageMessageColoredWithPrefix("cheat-prevention.inventory.no-opening"); this.plugin.sendMessage(player, message); }
Example #7
Source File: ControllableVillagerBase.java From EntityAPI with GNU Lesser General Public License v3.0 | 6 votes |
@Override public BehaviourItem[] getDefaultMovementBehaviours() { return new BehaviourItem[]{ new BehaviourItem(0, new BehaviourFloat(this)), new BehaviourItem(1, new BehaviourAvoidEntity(this, Zombie.class, 8.0F, 0.6D, 0.6D)), new BehaviourItem(1, new BehaviourTradeWithPlayer(this)), new BehaviourItem(1, new BehaviourLookAtTradingPlayer(this)), new BehaviourItem(2, new BehaviourMoveIndoors(this)), new BehaviourItem(3, new BehaviourRestrictOpenDoor(this)), new BehaviourItem(4, new BehaviourOpenDoor(this, true)), new BehaviourItem(5, new BehaviourMoveTowardsRestriction(this, 0.6D)), new BehaviourItem(6, new BehaviourMakeLove(this)), new BehaviourItem(7, new BehaviourTakeFlower(this)), new BehaviourItem(8, new BehaviourVillagerPlay(this, 0.32D)), new BehaviourItem(9, new BehaviourInteract(this, HumanEntity.class, 3.0F, 1.0F)), new BehaviourItem(9, new BehaviourInteract(this, Villager.class, 3.0F, 1.0F)), new BehaviourItem(9, new BehaviourRandomStroll(this, 0.6D)), new BehaviourItem(10, new BehaviourLookAtNearestEntity(this, InsentientEntity.class, 8.0F)) }; }
Example #8
Source File: ControllableCaveSpiderBase.java From EntityAPI with GNU Lesser General Public License v3.0 | 5 votes |
@Override public BehaviourItem[] getDefaultTargetingBehaviours() { return new BehaviourItem[]{ new BehaviourItem(1, new BehaviourHurtByTarget(this, true, false, true)), new BehaviourItem(2, new BehaviourMoveTowardsNearestAttackableTarget(this, HumanEntity.class, 0, true)) }; }
Example #9
Source File: CivilianListener.java From Civs with GNU General Public License v3.0 | 5 votes |
@EventHandler(ignoreCancelled = true) public void onCivilianDragItem(InventoryDragEvent event) { if (event.getView().getTopInventory().getHolder() instanceof Chest) { Location inventoryLocation = ((Chest) event.getView().getTopInventory().getHolder()).getLocation(); UnloadedInventoryHandler.getInstance().updateInventoryAtLocation(inventoryLocation); } if (ConfigManager.getInstance().getAllowSharingCivsItems()) { return; } ItemStack dragged = event.getOldCursor(); if (!CVItem.isCivsItem(dragged) || MenuManager.getInstance().hasMenuOpen(event.getWhoClicked().getUniqueId())) { return; } int inventorySize = event.getInventory().getSize(); for (int i : event.getRawSlots()) { if (i < inventorySize) { event.setCancelled(true); HumanEntity humanEntity = event.getWhoClicked(); humanEntity.sendMessage(Civs.getPrefix() + LocaleManager.getInstance().getTranslationWithPlaceholders((Player) humanEntity, LocaleConstants.PREVENT_CIVS_ITEM_SHARE)); return; } } }
Example #10
Source File: BukkitListener.java From HeavySpleef with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onFoodLevelChange(FoodLevelChangeEvent event) { HumanEntity entity = event.getEntity(); if (!(entity instanceof Player)) { return; } handlePlayerEvent((Player)entity, event); }
Example #11
Source File: PlayerListenerTest.java From AuthMeReloaded with GNU General Public License v3.0 | 5 votes |
@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); }
Example #12
Source File: CreativeModeListener.java From ShopChest with MIT License | 5 votes |
@EventHandler(priority = EventPriority.HIGHEST) public void onInventoryDrag(InventoryDragEvent e) { // Cancel any inventory drags if SelectClickType is set HumanEntity entity = e.getWhoClicked(); if (!(entity instanceof Player)) return; ClickType clickType = ClickType.getPlayerClickType((Player) entity); if (clickType instanceof SelectClickType) e.setCancelled(true); }
Example #13
Source File: ControllableChickenBase.java From EntityAPI with GNU Lesser General Public License v3.0 | 5 votes |
@Override public BehaviourItem[] getDefaultMovementBehaviours() { return new BehaviourItem[]{ new BehaviourItem(0, new BehaviourFloat(this)), new BehaviourItem(1, new BehaviourPanic(this, 1.4D)), new BehaviourItem(2, new BehaviourBreed(this, 1.0D)), new BehaviourItem(3, new BehaviourTempt(this, Material.SEEDS, false, 1.0D)), new BehaviourItem(4, new BehaviourFollowParent(this, 1.1D)), new BehaviourItem(5, new BehaviourRandomStroll(this, 1.0D)), new BehaviourItem(6, new BehaviourLookAtNearestEntity(this, HumanEntity.class, 6.0F)), new BehaviourItem(7, new BehaviourLookAtRandom(this)) }; }
Example #14
Source File: DynamicGuiElement.java From InventoryGui with MIT License | 5 votes |
/** * Query the element for a player * @param who The player * @return The GuiElement or null */ public GuiElement queryElement(HumanEntity who) { GuiElement element = getQuery().apply(who); if (element != null) { element.setGui(gui); element.setSlots(slots); } return element; }
Example #15
Source File: ControllableZombieBase.java From EntityAPI with GNU Lesser General Public License v3.0 | 5 votes |
@Override public BehaviourItem[] getDefaultTargetingBehaviours() { return new BehaviourItem[]{ new BehaviourItem(1, new BehaviourHurtByTarget(this, true)), new BehaviourItem(2, new BehaviourMoveTowardsNearestAttackableTarget(this, HumanEntity.class, 0, true)), new BehaviourItem(2, new BehaviourMoveTowardsNearestAttackableTarget(this, Villager.class, 0, false)) }; }
Example #16
Source File: ClassesTest.java From Skript with GNU General Public License v3.0 | 5 votes |
@Test public void test() { final Object[] random = { // Java (byte) 127, (short) 2000, -1600000, 1L << 40, -1.5f, 13.37, "String", // Skript SkriptColor.BLACK, StructureType.RED_MUSHROOM, WeatherType.THUNDER, new Date(System.currentTimeMillis()), new Timespan(1337), new Time(12000), new Timeperiod(1000, 23000), new Experience(15), new Direction(0, Math.PI, 10), new Direction(new double[] {0, 1, 0}), new EntityType(new SimpleEntityData(HumanEntity.class), 300), new CreeperData(), new SimpleEntityData(Snowball.class), new HorseData(Variant.SKELETON_HORSE), new WolfData(), new XpOrbData(50), // Bukkit - simple classes only GameMode.ADVENTURE, InventoryType.CHEST, DamageCause.FALL, // there is also at least one variable for each class on my test server which are tested whenever the server shuts down. }; for (final Object o : random) { Classes.serialize(o); // includes a deserialisation test } }
Example #17
Source File: HumanEntityCache.java From IF with The Unlicense | 5 votes |
/** * Stores this player's inventory in the cache. If the player was already stored, their cache will be overwritten. * Clears the player's inventory afterwards. * * @param humanEntity the human entity to keep in the cache */ public void storeAndClear(@NotNull HumanEntity humanEntity) { store(humanEntity); Inventory inventory = humanEntity.getInventory(); for (int i = 0; i < 36; i++) { inventory.clear(i); } }
Example #18
Source File: HumanEntityCache.java From IF with The Unlicense | 5 votes |
/** * Adds the given item stack to the human entity's cached inventory. The returned amount is the amount of items of * the provided item stack that could not be put into the cached inventory. This number will always be equal or * less than the amount of items in the provided item stack, but no less than zero. The item stack provided will not * be updated with this leftover amount. If the human entity provided is not in the human entity cache, this method * will return an {@link IllegalStateException}. The items will be added to the inventory in the same way as the * items are stored. The items may be added to an already existing item stack, but the item stack's amount will * never go over the maximum stack size. * * @param humanEntity the human entity to add the item to * @param item the item to add to the cached inventory * @return the amount of leftover items that couldn't be fit in the cached inventory * @throws IllegalStateException if the human entity's inventory is not cached * @since 0.6.1 */ protected int add(@NotNull HumanEntity humanEntity, @NotNull ItemStack item) { ItemStack[] items = inventories.get(humanEntity); if (items == null) { throw new IllegalStateException("The human entity '" + humanEntity.getUniqueId().toString() + "' does not have a cached inventory"); } int amountPutIn = 0; for (int i = 0; i < items.length; i++) { ItemStack itemStack = items[i]; if (itemStack == null) { items[i] = item.clone(); items[i].setAmount(item.getAmount() - amountPutIn); amountPutIn = item.getAmount(); break; } if (!itemStack.isSimilar(item)) { continue; } int additionalAmount = Math.min(itemStack.getMaxStackSize() - itemStack.getAmount(), item.getAmount()); itemStack.setAmount(itemStack.getAmount() + additionalAmount); amountPutIn += additionalAmount; if (amountPutIn == item.getAmount()) { break; } } return item.getAmount() - amountPutIn; }
Example #19
Source File: CraftInventoryWrapper.java From Thermos with GNU General Public License v3.0 | 5 votes |
@Override public List<HumanEntity> getViewers() { try { return inventory.getViewers(); } catch (AbstractMethodError ignored) { return Collections.emptyList(); } }
Example #20
Source File: ControllableSkeletonBase.java From EntityAPI with GNU Lesser General Public License v3.0 | 5 votes |
@Override public BehaviourItem[] getDefaultMovementBehaviours() { return new BehaviourItem[]{ new BehaviourItem(1, new BehaviourFloat(this)), new BehaviourItem(2, new BehaviourRestrictSun(this)), new BehaviourItem(3, new BehaviourFleeSun(this, 1.0D)), //new BehaviourItem(4, new BehaviourRangedAttack(this, 60, 15.0F, 1.0D)), new BehaviourItem(5, new BehaviourRandomStroll(this, 1.0D)), new BehaviourItem(6, new BehaviourLookAtNearestEntity(this, HumanEntity.class, 8.0F)), new BehaviourItem(6, new BehaviourLookAtRandom(this)) }; }
Example #21
Source File: InventoryGui.java From InventoryGui with MIT License | 5 votes |
/** * Go back one entry in the history * @param player The player to show the previous gui to * @return <tt>true</tt> if there was a gui to show; <tt>false</tt> if not */ public static boolean goBack(HumanEntity player) { Deque<InventoryGui> history = getHistory(player); history.pollLast(); if (history.isEmpty()) { return false; } InventoryGui previous = history.peekLast(); if (previous != null) { previous.show(player, false); } return true; }
Example #22
Source File: IconInventory.java From UHC with MIT License | 5 votes |
protected Collection<HumanEntity> getCurrentViewers() { final List<HumanEntity> viewers = Lists.newArrayList(); for (final Inventory openedInventory : openedInventories) { viewers.addAll(openedInventory.getViewers()); } return viewers; }
Example #23
Source File: InventoryGui.java From InventoryGui with MIT License | 5 votes |
/** * Add a new history entry to the end of the history * @param player The player to add the history entry for * @param gui The GUI to add to the history */ public static void addHistory(HumanEntity player, InventoryGui gui) { GUI_HISTORY.putIfAbsent(player.getUniqueId(), new ArrayDeque<>()); Deque<InventoryGui> history = getHistory(player); if (history.peekLast() != gui) { history.add(gui); } }
Example #24
Source File: PlayerEventListener.java From Hawk with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onInventoryCloseServerSide(InventoryCloseEvent e) { HumanEntity hE = e.getPlayer(); if(!(hE instanceof Player)) return; HawkPlayer pp = hawk.getHawkPlayer((Player) hE); pp.sendSimulatedAction(new Runnable() { @Override public void run() { pp.setInventoryOpen((byte)0); } }); }
Example #25
Source File: InventoryGui.java From InventoryGui with MIT License | 5 votes |
/** * Close the GUI for everyone viewing it * @param clearHistory Whether or not to close the GUI completely (by clearing the history) */ public void close(boolean clearHistory) { for (Inventory inventory : inventories.values()) { for (HumanEntity viewer : new ArrayList<>(inventory.getViewers())) { if (clearHistory) { clearHistory(viewer); } viewer.closeInventory(); } } }
Example #26
Source File: ControllableIronGolemBase.java From EntityAPI with GNU Lesser General Public License v3.0 | 5 votes |
@Override public BehaviourItem[] getDefaultMovementBehaviours() { return new BehaviourItem[]{ new BehaviourItem(1, new BehaviourMeleeAttack(this, true, 1.0D)), new BehaviourItem(2, new BehaviourMoveTowardsTarget(this, 32.0F)), new BehaviourItem(3, new BehaviourMoveThroughVillage(this, true, 0.6D)), new BehaviourItem(4, new BehaviourMoveTowardsRestriction(this, 1.0D)), new BehaviourItem(5, new BehaviourOfferFlower(this, LivingEntity.class)), new BehaviourItem(6, new BehaviourRandomStroll(this)), new BehaviourItem(7, new BehaviourLookAtNearestEntity(this, HumanEntity.class, 6.0F)), new BehaviourItem(8, new BehaviourLookAtRandom(this)) }; }
Example #27
Source File: ControllableHorseBase.java From EntityAPI with GNU Lesser General Public License v3.0 | 5 votes |
@Override public BehaviourItem[] getDefaultMovementBehaviours() { return new BehaviourItem[]{ new BehaviourItem(0, new BehaviourFloat(this)), new BehaviourItem(1, new BehaviourPanic(this, 1.2D)), new BehaviourItem(1, new BehaviourTameByRiding(this, 1.2D)), new BehaviourItem(2, new BehaviourBreed(this, 1.0D)), new BehaviourItem(4, new BehaviourFollowParent(this, 1.25D)), new BehaviourItem(6, new BehaviourRandomStroll(this, 0.7D)), new BehaviourItem(7, new BehaviourLookAtNearestEntity(this, HumanEntity.class, 6.0F)), new BehaviourItem(8, new BehaviourLookAtRandom(this)) }; }
Example #28
Source File: ControllableSkeletonBase.java From EntityAPI with GNU Lesser General Public License v3.0 | 5 votes |
@Override public BehaviourItem[] getDefaultTargetingBehaviours() { return new BehaviourItem[]{ new BehaviourItem(1, new BehaviourHurtByTarget(this, false)), new BehaviourItem(2, new BehaviourMoveTowardsNearestAttackableTarget(this, HumanEntity.class, 0, true)) }; }
Example #29
Source File: StaticGuiElement.java From InventoryGui with MIT License | 5 votes |
@Override public ItemStack getItem(HumanEntity who, int slot) { if (item == null) { return null; } ItemStack clone = item.clone(); gui.setItemText(clone, getText()); if (number > 0 && number <= 64) { clone.setAmount(number); } return clone; }
Example #30
Source File: PlayerEventHandler.java From GriefDefender with MIT License | 5 votes |
private void onInventoryOpen(Event event, Location location, Object target, HumanEntity player) { GDCauseStackManager.getInstance().pushCause(player); if (event instanceof InventoryOpenEvent) { final InventoryOpenEvent inventoryEvent = (InventoryOpenEvent) event; target = inventoryEvent.getView().getType(); } if (!GDFlags.INTERACT_INVENTORY || !GriefDefenderPlugin.getInstance().claimsEnabledForWorld(player.getWorld().getUID())) { return; } if (GriefDefenderPlugin.isTargetIdBlacklisted(Flags.INTERACT_INVENTORY.getName(), target, player.getWorld().getUID())) { return; } String targetId = GDPermissionManager.getInstance().getPermissionIdentifier(target); GDTimings.PLAYER_INTERACT_INVENTORY_OPEN_EVENT.startTiming(); final GDClaim claim = this.dataStore.getClaimAt(location); final GDPermissionUser user = PermissionHolderCache.getInstance().getOrCreateUser(player.getUniqueId()); if (user.getInternalPlayerData() != null && user.getInternalPlayerData().eventResultCache != null && user.getInternalPlayerData().eventResultCache.checkEventResultCache(claim, Flags.INTERACT_BLOCK_SECONDARY.getName()) == Tristate.TRUE) { GDPermissionManager.getInstance().processResult(claim, Flags.INTERACT_INVENTORY.getPermission(), "cache", Tristate.TRUE, user); GDTimings.PLAYER_INTERACT_INVENTORY_OPEN_EVENT.stopTiming(); return; } final Tristate result = GDPermissionManager.getInstance().getFinalPermission(event, location, claim, Flags.INTERACT_INVENTORY, player, target, user, TrustTypes.CONTAINER, true); if (result == Tristate.FALSE) { final Component message = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.PERMISSION_INVENTORY_OPEN, ImmutableMap.of( "player", claim.getOwnerDisplayName(), "block", targetId)); GriefDefenderPlugin.sendClaimDenyMessage(claim, player, message); ((Cancellable) event).setCancelled(true); } GDTimings.PLAYER_INTERACT_INVENTORY_OPEN_EVENT.stopTiming(); }