@EventHandler public void onAnvilOpen(InventoryOpenEvent e) { if (e.getPlayer().equals(null)) { return; } if (e.getInventory().equals(null)) { return; } Game bw = io.github.yannici.bedwars.Main.getInstance().getGameManager() .getGameOfPlayer((Player) e.getPlayer()); if (bw == null) { return; } if (!Config.isGameEnabledXP(bw.getName())) { return; } if (e.getInventory().getType().equals(InventoryType.ANVIL)) { e.setCancelled(true); } }
@SuppressWarnings("unchecked") protected ChestGui(Plugin plugin, Config config) { if (config.has("type")) { type = config.getEnum("type", InventoryType.class); icons = new ConfigIcon[type.getDefaultSize()]; } else if (config.has("size")) { size = config.getInt("size"); if (size % 9 != 0) { plugin.getLogger().warning("In a gui: size must be a multiple of 9"); size = GuiSize.min(size); } icons = new ConfigIcon[size]; } else throw new InvalidConfigException("Both 'type' and 'size' are empty!"); updateInterval = config.getInt("update-interval", -1); title = config.getMessageStrRequired("title"); Collection<Map<String, Object>> iconsData = (Collection<Map<String, Object>>) config.getCollection("icons"); if (iconsData != null) { for (Map<String, Object> data : iconsData) { ConfigIcon item = ConfigIcon.deserialize(plugin, Config.wrap(data)); icons[(int) data.get("slot")] = item; } } }
@EventHandler (priority = EventPriority.HIGHEST, ignoreCancelled = false) public void onClose(InventoryCloseEvent event) { if (!(event.getInventory().getHolder() instanceof MenuLink)) return; final VPPlayer player = VanillaPlusCore.getPlayerManager().getPlayer((Player) event.getPlayer()); final MenuLink menu = ((MenuLink) event.getInventory().getHolder()); Bukkit.getScheduler().scheduleSyncDelayedTask(VanillaPlus.getInstance(), new Runnable() { @Override public void run() { if(player.getPlayer().getOpenInventory().getTopInventory().getType() == InventoryType.CRAFTING){ menu.getIconMenu().closed(player, menu); }else{ menu.getIconMenu().changed(player, menu); } } }); }
public CraftContainer(final Inventory inventory, final HumanEntity player, int id) { this(new InventoryView() { @Override public Inventory getTopInventory() { return inventory; } @Override public Inventory getBottomInventory() { return player.getInventory(); } @Override public HumanEntity getPlayer() { return player; } @Override public InventoryType getType() { return inventory.getType(); } }, id); }
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void equipWeaponEvent(InventoryDragEvent event) { if (Result.DENY.equals(event.getResult())) return; HumanEntity human = event.getWhoClicked(); Inventory inv = event.getInventory(); ItemStack prior = event.getOldCursor(); StandardGun priorGun = findGun(prior); // Don't really care what sort of drag, if we have a gun in inv and this was a gun, deny. if (priorGun != null && inv != null && !InventoryType.PLAYER.equals(inv.getType()) && priorGun.isLimitToOne() && priorGun.hasGun(human)) { event.setResult(Result.DENY); // yes this will prevent drag style of weapon in chest invs. Oh well. } }
public Menu(MessageManager messageManager, YamlConfiguration section) { ConfigurationSection settings = section.getConfigurationSection(Node.SETTINGS.get()); if(settings == null){ Error.MISSING_NODE.add(Node.SETTINGS.get()); title = new MComponent(VanillaPlusCore.getDefaultLang(), " "); icons = new Icon[37]; type = InventoryType.CHEST; refresh = 0; return; }else{ title = messageManager.getComponentManager().get(settings.getString(Node.NAME_PATH.get())); type = InventoryType.valueOf(settings.getString(Node.TYPE.get(), "CHEST")); if(type == InventoryType.CHEST) { int size = settings.getInt("ROWS"); if(size < 0 || size > 12) ErrorLogger.addError("ROWS must be between 0 and 12 inclulsive !"); icons = new Icon[9*size+1]; } else icons = new Icon[type.getDefaultSize()+1]; refresh = (byte) settings.getInt("REFRESH", 0); } }
@Test public void guiSignature() { ItemStack itemA = ItemFactory.createRandomItem(); ItemStack itemB = ItemFactory.createRandomItem(); GUISignature signature = new GUISignature(InventoryType.CHEST) .title("Serialize Test") .size(18) .addHandlerIndexes(1, 2, 3) .item(itemA, 0) .item(itemA, 1) .item(ItemFactory.createRandomItem(), 2) .item(itemB, 3) .item(itemB, 4) .item(ItemFactory.createRandomItem(), 5); StringWriter writer = new StringWriter(); GsonUtils.write(writer, signature, e -> { throw new AssertionError(e); }); GUISignature deserialized = GsonUtils.read(new StringReader(writer.toString()), GUISignature.class); assertEquals(signature, deserialized); }
public AddItemMenu(KingdomFactionsPlayer player, String type, String level, int buyPrice, int sellprice, boolean useDisplayname, String extraData, int limit) { this.type = type; this.level = level; this.buyPrice = buyPrice; this.sellprice = sellprice; this.useDisplayname = useDisplayname; this.playerName = player.getName(); this.extraData = extraData; this.limit = limit; player.sendMessage(ChatColor.RED + "" + ChatColor.BOLD + "Zet het item op het EERSTE slot!"); player.openInventory(Bukkit.createInventory(null, InventoryType.DISPENSER, "addItem " + player.getName())); Bukkit.getPluginManager().registerEvents(this, KingdomFactionsPlugin.getInstance()); }
public static boolean rowType(Integer row, Integer slot, Inventory inventory) { if (slot != null && row != null) { Integer mod = 9; if (inventory != null) { if (inventory.getType() == InventoryType.DISPENSER ||inventory.getType() == InventoryType.WORKBENCH || inventory.getType() == InventoryType.DROPPER) { mod = 3; } else if (inventory.getType() == InventoryType.CHEST || inventory.getType() == InventoryType.ENDER_CHEST || inventory.getType() == InventoryType.PLAYER){ mod = 9; } else { mod = inventory.getSize(); } } Integer calculate = row * mod; return slot >= calculate - mod && slot < calculate; } return false; }
/** * Event fired when a player clicks in the team selection GUI * * @param event Event */ @EventHandler public void onInventoryClick(InventoryClickEvent event) { if (this.game.getStatus().equals(Status.IN_GAME)) { event.getHandlers().unregister(this); } else if (event.getCurrentItem() != null && event.getCurrentItem().getItemMeta() != null && event.getView().getType() != InventoryType.PLAYER) { AbstractGui gui = this.playersGui.get(event.getWhoClicked().getUniqueId()); if (gui != null) { String action = gui.getAction(event.getSlot()); if (action != null) gui.onClick((Player) event.getWhoClicked(), event.getCurrentItem(), action, event.getClick()); event.setCancelled(true); } } }
/** * Check * * @return Click is valid */ private boolean validateClick(Player player, PlayerWrapper playerWrapper, Slot slot, ActionType actionType, ItemStack currentItem, InventoryType.SlotType slotType) { if (playerWrapper != null) { if (player != playerWrapper.getPlayer()) { return false; } if (!PlayerUtils.checkLevel(player, slot.getRequiredLevel())) { PlayerUtils.sendMessage(player, RPGInventory.getLanguage().getMessage("error.level", slot.getRequiredLevel())); return false; } if (!slot.isFree() && !playerWrapper.isBuyedSlot(slot.getName()) && !InventoryManager.buySlot(player, playerWrapper, slot)) { return false; } } return !((actionType == ActionType.GET && slot.getSlotType() != Slot.SlotType.ACTION || actionType == ActionType.DROP) && slot.isCup(currentItem) && slotType != InventoryType.SlotType.QUICKBAR); }
@Override public void onPacketSending(PacketEvent event) { Player player = event.getPlayer(); //noinspection ConstantConditions if (event.isCancelled() || !InventoryManager.playerIsLoaded(player) || isNotNeededHere(player)) { return; } WrapperPlayServerWindowItems packet = new WrapperPlayServerWindowItems(event.getPacket()); if (player.getOpenInventory().getType() == InventoryType.WORKBENCH) { List<ItemStack> contents = packet.getSlotData(); List<CraftExtension> extensions = CraftManager.getExtensions(player); for (CraftExtension extension : extensions) { for (int slot : extension.getSlots()) { contents.set(slot, extension.getCapItem()); } } packet.setSlotData(contents); } }
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH) public void onInventoryClick(InventoryClickEvent event) { final Player player = (Player) event.getWhoClicked(); //noinspection ConstantConditions if (!InventoryManager.playerIsLoaded(player) || event.getInventory().getType() != InventoryType.WORKBENCH || isNotNeededHere(player)) { return; } List<CraftExtension> extensions = CraftManager.getExtensions(player); for (CraftExtension extension : extensions) { for (int slot : extension.getSlots()) { if (slot == event.getRawSlot()) { event.setCancelled(true); PlayerUtils.updateInventory(player); return; } } } }
/** * {@inheritDoc} */ @Override public boolean matches(CraftingInventory craftingInventory, World world) { int width, heigth; //check boundaries for the crafting inventory InventoryType type = craftingInventory.getType(); switch(type) { case CRAFTING: width = heigth = 2; break; case WORKBENCH: width = heigth = 3; break; default: return false; //unknown crafting inventory type. } for (int w = 0; w <= width - this.width; w++) { for (int h = 0; h <= heigth - this.heigth; h++) { if (matrixMatch(craftingInventory, w, h, true)) { return true; } if (matrixMatch(craftingInventory, w, h, false)) { return true; } } } return false; }
public WorldRecipeHolder(CustomRecipesPlugin plugin, ItemStack result, MinecraftKey key, String group, Player callbackPlayer, UUID world) { this.plugin = plugin; this.result = result; this.key = key; this.group = group; this.world = world; this.callbackPlayer = callbackPlayer; this.dispenserInventory = plugin.getServer().createInventory(this, InventoryType.DISPENSER, "Create a world recipe!"); plugin.getServer().getPluginManager().registerEvents(this, plugin); }
public NBTRecipeHolder(CustomRecipesPlugin plugin, ItemStack result, MinecraftKey key, String group, Player callbackPlayer) { this.plugin = plugin; this.result = result; this.key = key; this.group = group; this.callbackPlayer = callbackPlayer; this.dispenserInventory = plugin.getServer().createInventory(this, InventoryType.DISPENSER, "Create an NBT recipe!"); plugin.getServer().getPluginManager().registerEvents(this, plugin); }
public CountRecipeHolder(CustomRecipesPlugin plugin, ItemStack result, MinecraftKey key, String group, Player callbackPlayer) { this.plugin = plugin; this.result = result; this.key = key; this.group = group; this.callbackPlayer = callbackPlayer; this.dispenserInventory = plugin.getServer().createInventory(this, InventoryType.DISPENSER, "Create a count recipe!"); plugin.getServer().getPluginManager().registerEvents(this, plugin); }
public void refresh(VPPlayer viewer, Inventory inv){ MenuLink ml = (MenuLink) ((inv.getHolder() instanceof MenuLink) ? inv.getHolder() : null); for (int i = 1; i < icons.length; i++) { if (icons[i] != null && !icons[i].isStatic()){ Icon icon = icons[i].getIcon(viewer); if(icon == null) { if(type == InventoryType.PLAYER) { ItemStack[] memory = viewer.getInventory(false); if(memory[i-1] != null) { inv.setItem(i-1, memory[i-1]); memory[i-1] = null; viewer.setInventory(memory, false); } }else inv.setItem(i-1, new ItemStack(Material.AIR)); continue; } if(icon.skullSelf()){ ItemStack item = inv.getItem(i-1); if(item != null && item.getType() == Material.SKULL_ITEM){ ItemMeta itemMeta = item.getItemMeta(); itemMeta.setLore(icon.getLores(ml == null ? viewer : ml.getView(), viewer.getLanguage())); itemMeta.setDisplayName(icon.getName(ml == null ? viewer : ml.getView(), viewer.getLanguage())); ((SkullMeta)itemMeta).setOwner(ml == null ? viewer.getName() : ml.getView().getName()); item.setItemMeta(itemMeta); continue; } } if(icon != null) inv.setItem(i-1, icon.getItemstack(ml == null ? viewer : ml.getView(), viewer.getLanguage())); } } }
public ShapedRecipeHolder(Player callbackPlayer, CustomRecipesPlugin plugin, ItemStack result, MinecraftKey key, String group) { this.plugin = plugin; this.dispenserInventory = plugin.getServer().createInventory(this, InventoryType.DISPENSER, "Create a shaped recipe!"); this.result = result; this.callbackPlayer = callbackPlayer; this.group = group; this.key = key; plugin.getServer().getPluginManager().registerEvents(this, plugin); }
public ShapelessRecipeHolder(CustomRecipesPlugin plugin, ItemStack result, MinecraftKey key, String group, Player callbackPlayer) { this.plugin = plugin; this.callbackPlayer = callbackPlayer; this.result = result; this.key = key; this.group = group; this.dispenserInventory = plugin.getServer().createInventory(this, InventoryType.DISPENSER, "Create a shapeless recipe!"); plugin.getServer().getPluginManager().registerEvents(this, plugin); }
/** * Initializes the gui by its type and title. * * @param type the type of the gui * @param title the title of the gui */ public ChestGui(InventoryType type, PlaceholderValue<String> title) { this.type = type; this.title = title; this.icons = new ConfigIcon[type.getDefaultSize()]; onSetup(); }
@Override public Inventory create(GUI gui, HumanEntity viewer) { GUISignature signature = gui.getSignature(); signature.title(titleCaught(signature.getTitle())); return signature.getType() == InventoryType.CHEST ? Bukkit.createInventory(null, signature.getSize(), signature.getTitle()) : Bukkit.createInventory(null, signature.getType(), signature.getTitle()); }
@Override public InventoryType getType() { InventoryType type = viewing.getType(); if (type == InventoryType.CRAFTING && player.getGameMode() == GameMode.CREATIVE) { return InventoryType.CREATIVE; } return type; }
public MinecraftInventory(InventoryHolder owner, int size, String title) { Validate.notNull(title, "Title cannot be null"); Validate.isTrue(title.length() <= 32, "Title cannot be longer than 32 characters"); this.items = new net.minecraft.item.ItemStack[size]; this.title = title; this.viewers = new ArrayList<HumanEntity>(); this.owner = owner; this.type = InventoryType.CHEST; }
public InventoryType getType() { // Thanks to Droppers extending Dispensers, order is important. if (inventory instanceof net.minecraft.inventory.InventoryCrafting) { return inventory.getSizeInventory() >= 9 ? InventoryType.WORKBENCH : InventoryType.CRAFTING; } else if (inventory instanceof net.minecraft.entity.player.InventoryPlayer) { return InventoryType.PLAYER; } else if (inventory instanceof net.minecraft.tileentity.TileEntityDropper) { return InventoryType.DROPPER; } else if (inventory instanceof net.minecraft.tileentity.TileEntityDispenser) { return InventoryType.DISPENSER; } else if (inventory instanceof net.minecraft.tileentity.TileEntityFurnace) { return InventoryType.FURNACE; } else if (inventory instanceof net.minecraft.inventory.ContainerEnchantTableInventory) { return InventoryType.ENCHANTING; } else if (inventory instanceof net.minecraft.tileentity.TileEntityBrewingStand) { return InventoryType.BREWING; } else if (inventory instanceof CraftInventoryCustom.MinecraftInventory) { return ((CraftInventoryCustom.MinecraftInventory) inventory).getType(); } else if (inventory instanceof net.minecraft.inventory.InventoryEnderChest) { return InventoryType.ENDER_CHEST; } else if (inventory instanceof net.minecraft.inventory.InventoryMerchant) { return InventoryType.MERCHANT; } else if (inventory instanceof net.minecraft.tileentity.TileEntityBeacon) { return InventoryType.BEACON; } else if (inventory instanceof net.minecraft.inventory.ContainerRepairInventory) { return InventoryType.ANVIL; } else if (inventory instanceof net.minecraft.tileentity.IHopper) { return InventoryType.HOPPER; } else { return InventoryType.CHEST; } }
@EventHandler public void onAnvil(InventoryClickEvent e) { if (e.getRawSlot() == 2 && e.getWhoClicked() instanceof Player && e.getInventory().getType() == InventoryType.ANVIL) { if (SlimefunManager.isItemSimiliar(e.getInventory().getContents()[0], SlimefunItems.ELYTRA, true)) return; if (SlimefunItem.getByItem(e.getInventory().getContents()[0]) != null && !SlimefunItem.isDisabled(e.getInventory().getContents()[0])) { e.setCancelled(true); Messages.local.sendTranslation((Player) e.getWhoClicked(), "anvil.not-working", true); } } }
public Inventory createInventory(InventoryType inventoryType, int size, String name) throws IndexOutOfBoundsException { if (size % 9 != 0 || size > 56) throw new IndexOutOfBoundsException("El tamaño es mayor que 56 o no es un múltiplo de 9"); name = Utils.colorize(name); switch (inventoryType){ case CHEST: return plugin.getServer().createInventory(null, size, name); case HOPPER: case DISPENSER: case DROPPER: return plugin.getServer().createInventory(null, inventoryType, name); default: return plugin.getServer().createInventory(null, size, name); } }
@EventHandler(priority = EventPriority.MONITOR) public void cloneCraftingWindow(final PlayerInteractEvent event) { if(!AntiGrief.CraftProtect.enabled()) { return; } if(!event.isCancelled() && event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getPlayer().getOpenInventory().getType() == InventoryType.CRAFTING /* nothing open */) { Block block = event.getClickedBlock(); if(block != null && block.getType() == Material.WORKBENCH && !event.getPlayer().isSneaking()) { // create the window ourself event.setCancelled(true); event.getPlayer().openWorkbench(null, true); // doesn't check reachable } } }
@EventHandler public void onInventoryClose(InventoryCloseEvent e) { if (!(e.getPlayer() instanceof Player)) return; final Player p = (Player) e.getPlayer(); if (!p.hasMetadata("shared_workbench")) return; if (e.getInventory().getType() == InventoryType.WORKBENCH) { // Workaround to get the accessed WorkBench final Block workbench = p.getTargetBlock((Set<Material>) null, 8); if (!workbench.hasMetadata("shared_players") || workbench.getType() != Material.WORKBENCH) { if (p.getOpenInventory().getTopInventory() != null) p.getOpenInventory().getTopInventory().clear(); p.removeMetadata("shared_workbench", Survival.instance); return; } @SuppressWarnings("unchecked") List<UUID> list = (workbench.getMetadata("shared_players").get(0).value() instanceof List<?>) ? (List<UUID>)workbench.getMetadata("shared_players").get(0).value() : new ArrayList<UUID>(); list.remove(p.getUniqueId()); if (list.isEmpty()) workbench.removeMetadata("shared_players", Survival.instance); else { e.getInventory().clear(); workbench.setMetadata("shared_players", new FixedMetadataValue(Survival.instance, list)); } } }
@Override public void setSize( Vector2i dimension ) { Validate.isTrue( inventory.getType() == InventoryType.CHEST, "Size can only be adjusted if the inventory is a chest!" ); ItemStack[] contents = inventory.getContents(); InventoryHolder holder = inventory.getHolder(); int stack = inventory.getMaxStackSize(); String title = inventory.getTitle(); inventory = Bukkit.createInventory( holder, dimension.getX() * dimension.getY(), title ); inventory.setContents( contents ); inventory.setMaxStackSize( stack ); }
public Optional<InventoryOpener> findOpener(InventoryType type) { Optional<InventoryOpener> opInv = this.openers.stream() .filter(opener -> opener.supports(type)) .findAny(); if(!opInv.isPresent()) { opInv = this.defaultOpeners.stream() .filter(opener -> opener.supports(type)) .findAny(); } return opInv; }
@EventHandler(priority = EventPriority.HIGH) public void inventoryClickEvent(final InventoryClickEvent event) { if (!event.isCancelled()) { if ( PermissionInterface.CheckEnabledWorld(event.getWhoClicked().getLocation()) ) { if ((event.getInventory().getType() == InventoryType.DISPENSER) && (event.getRawSlot() == 4) && ((event.getCurrentItem().getTypeId() == 388) || (event.getCursor().getTypeId() == 388))) { event.setCancelled(true); } } } }
@EventHandler public void onBlockInvOpen(InventoryOpenEvent e) { if (GameStatus.isState(gameStatus)) if (e.getInventory().getType() != InventoryType.PLAYER || e.getInventory().getType() != InventoryType.CHEST) e.setCancelled(!canOpenBlockInv); }
@Override public PlayerInventory getInventory() { if (inventory == null) { inventory = (PlayerInventoryMock) Bukkit.createInventory(this, InventoryType.PLAYER); } return inventory; }
@Override public Inventory createInventory(InventoryHolder owner, InventoryType type) { switch (type) { case PLAYER: PlayerInventoryMock inventory = new PlayerInventoryMock("Inventory"); return inventory; default: throw new UnimplementedOperationException("Inventory type not yet supported"); } }
@Override @Nullable protected Number[] get(Event e) { InventoryType container = ((InventoryClickEvent)e).getClickedInventory().getType(); if (container != InventoryType.CHEST || container != InventoryType.DISPENSER || container != InventoryType.DROPPER || container != InventoryType.WORKBENCH || container != InventoryType.ENDER_CHEST || container != InventoryType.PLAYER) { for (int i = 1; i < ((InventoryClickEvent)e).getClickedInventory().getSize() + 1; i++) { if (rowType(i, ((InventoryClickEvent)e).getSlot(), ((InventoryClickEvent)e).getInventory())) { return new Number[]{i}; } } } return null; }
/** * Disable barrier taking in the players inventories * * @param event Event */ @EventHandler public void onInventoryClick(InventoryClickEvent event) { if (event.getClickedInventory() != null && event.getClickedInventory().getType() == InventoryType.PLAYER && event.getCurrentItem() != null && event.getCurrentItem().getType() == Material.BARRIER) event.setCancelled(true); }
/** * Fill the lapis lazuli slot * * @param event Event */ @EventHandler public void onInventoryOpen(InventoryOpenEvent event) { if (event.getInventory().getType() == InventoryType.ENCHANTING) event.getInventory().setItem(1, new ItemStack(Material.INK_SACK, 64, (short) 4)); }
/** * Remove the lapis lazuli (duplication catch) * * @param event Event */ @EventHandler public void onInventoryClose(InventoryCloseEvent event) { if (event.getInventory().getType() == InventoryType.ENCHANTING) event.getInventory().setItem(1, null); }