org.bukkit.event.inventory.InventoryType Java Examples

The following examples show how to use org.bukkit.event.inventory.InventoryType. 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: CraftContainer.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
public static String getNotchInventoryType(InventoryType type) {
    switch (type) {
        case WORKBENCH:
            return "minecraft:crafting_table";
        case FURNACE:
            return "minecraft:furnace";
        case DISPENSER:
            return "minecraft:dispenser";
        case ENCHANTING:
            return "minecraft:enchanting_table";
        case BREWING:
            return "minecraft:brewing_stand";
        case BEACON:
            return "minecraft:beacon";
        case ANVIL:
            return "minecraft:anvil";
        case HOPPER:
            return "minecraft:hopper";
        case DROPPER:
            return "minecraft:dropper";
        case SHULKER_BOX:
            return "minecraft:shulker_box";
        default:
            return "minecraft:chest";
    }
}
 
Example #2
Source File: AnvilRenameListener.java    From MineableSpawners with MIT License 6 votes vote down vote up
@EventHandler (ignoreCancelled = true)
public void onAnvilRename(InventoryClickEvent e) {
  if (e.getInventory() == null || e.getInventory().getType() == null) {
    return;
  }

  if (e.getCurrentItem() == null || e.getCurrentItem().getType() == null) {
    return;
  }

  if (e.getInventory().getType() != InventoryType.ANVIL || e.getCurrentItem().getType() != XMaterial.SPAWNER.parseMaterial()) {
    return;
  }

  if (!plugin.getConfigurationHandler().getBoolean("anvil", "prevent-anvil")) {
    return;
  }

  Player player = (Player) e.getWhoClicked();
  e.setCancelled(true);
  player.sendMessage(plugin.getConfigurationHandler().getMessage("anvil", "prevented"));
}
 
Example #3
Source File: PlayerData.java    From SkyWarsReloaded with GNU General Public License v3.0 6 votes vote down vote up
public PlayerData(final Player p) {
  	if (SkyWarsReloaded.getCfg().debugEnabled()) {
      	Util.get().logToFile(ChatColor.RED + "[skywars] " + ChatColor.YELLOW + "Creating " + p.getName() + "'s Datafile");
  	}
  	this.beingRestored = false;
      this.uuid = p.getUniqueId();
      this.sb = p.getScoreboard();
      this.health = p.getHealth();
      this.food = p.getFoodLevel();
      this.sat = p.getSaturation();
if (!SkyWarsReloaded.getCfg().displayPlayerExeperience()) {
	xp = p.getExp();
}
      inv = Bukkit.createInventory(null, InventoryType.PLAYER, p.getName());
      inv.setContents(p.getInventory().getContents());
  	if (SkyWarsReloaded.getCfg().debugEnabled()) {
  		Util.get().logToFile(ChatColor.RED + "[skywars] " + ChatColor.YELLOW + p.getName() + "'s Datafile has been created");
  	}
  }
 
Example #4
Source File: SilentOpenChest.java    From SuperVanish with Mozilla Public License 2.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onChestClose(InventoryCloseEvent e) {
    if (!(e.getPlayer() instanceof Player))
        return;
    final Player p = (Player) e.getPlayer();
    if (!playerStateInfoMap.containsKey(p)) return;
    if (!(p.getInventory().getType() == InventoryType.CHEST ||
            plugin.getVersionUtil().isOneDotXOrHigher(11)
                    && isShulkerBox(p.getInventory()))) {
        return;
    }
    new BukkitRunnable() {
        @Override
        public void run() {
            StateInfo stateInfo = playerStateInfoMap.get(p);
            if (stateInfo == null) return;
            restoreState(stateInfo, p);
            playerStateInfoMap.remove(p);
        }
    }.runTaskLater(plugin, 1);
}
 
Example #5
Source File: ClearInventoryAction.java    From UHC with MIT License 6 votes vote down vote up
@Override
protected void run(Player player) {
    final PlayerInventory inv = player.getInventory();

    // clear main inventory
    contents = inv.getContents();
    inv.clear();

    // clear armour slots
    armourContents = inv.getArmorContents();
    inv.setArmorContents(null);

    // clear if they have something on their cursour currently
    onCursor = player.getItemOnCursor();
    player.setItemOnCursor(new ItemStack(Material.AIR));

    // if they have a crafting inventory open clear items from it too
    // stops storing items in crafting slots bypassing clear inventories
    final InventoryView openInventory = player.getOpenInventory();
    if (openInventory.getType() == InventoryType.CRAFTING) {
        crafting = Optional.of(openInventory.getTopInventory().getContents());
        openInventory.getTopInventory().clear();
    } else {
        crafting = Optional.absent();
    }
}
 
Example #6
Source File: PlayerListener.java    From BedWars with GNU Lesser General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onInventoryClick(InventoryClickEvent event) {
    if (event.isCancelled()) {
        return;
    }

    if (event.getClickedInventory() == null) {
        return;
    }

    if (event.getClickedInventory().getType() == InventoryType.PLAYER) {
        Player p = (Player) event.getWhoClicked();
        if (Main.isPlayerInGame(p)) {
            GamePlayer gPlayer = Main.getPlayerGameProfile(p);
            Game game = gPlayer.getGame();
            if (game.getStatus() == GameStatus.WAITING || gPlayer.isSpectator) {
                event.setCancelled(true);
            }
        }
    }
}
 
Example #7
Source File: Recipes.java    From ProRecipes with GNU General Public License v2.0 6 votes vote down vote up
@EventHandler
public void furnaceShiftClickFix(InventoryClickEvent event){
	final Player p = (Player)event.getWhoClicked();
	if(p != null){
		//p.sendMessage("Clicked");
		if(event.getInventory().getType().equals(InventoryType.FURNACE)){
		//	p.sendMessage("It's a furnace");
			if(event.isShiftClick()){
			//	p.sendMessage("Update ivnentory");
				new BukkitRunnable(){

					@Override
					public void run() {
						p.updateInventory();
						
					}
					
				}.runTaskLater(ProRecipes.getPlugin(), 0);
				
			}
		}
	}
	
}
 
Example #8
Source File: Menu.java    From TrMenu with MIT License 6 votes vote down vote up
public void setValues(String name, List<String> title, int titleUpdate, InventoryType inventoryType, HashMap<Integer, Integer> rows, HashMap<Button, Loc> buttons, String openRequirement, List<AbstractAction> openDenyActions, String closeRequirement, List<AbstractAction> closeDenyActions, String keepOpenRequirement, List<String> openCommands, List<AbstractAction> openActions, List<AbstractAction> closeActions, boolean lockPlayerInv, boolean updateInventory, boolean transferArgs, int forceTransferArgsAmount, List<String> bindItemLore, List<String> dependExpansions) {
    this.name = name;
    this.titles = title;
    this.titleUpdate = titleUpdate;
    this.titleIndex = new HashMap<>();
    this.shapeIndex = new HashMap<>();
    this.type = inventoryType;
    this.rows = rows;
    this.buttons = buttons;
    this.openRequirement = openRequirement;
    this.openDenyActions = openDenyActions;
    this.closeRequirement = closeRequirement;
    this.closeDenyActions = closeDenyActions;
    this.keepOpenRequirement = keepOpenRequirement;
    this.openCommands = openCommands;
    this.openActions = openActions;
    this.closeActions = closeActions;
    this.lockPlayerInv = lockPlayerInv;
    this.updateInventory = updateInventory;
    this.transferArgs = transferArgs;
    this.forceTransferArgsAmount = forceTransferArgsAmount;
    this.bindItemLore = bindItemLore != null && !bindItemLore.isEmpty() ? TLocale.Translate.setColored(bindItemLore) : bindItemLore;
    this.dependExpansions = dependExpansions;
    checkDepends();
}
 
Example #9
Source File: ChestProtectListener.java    From ShopChest with MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onItemMove(InventoryMoveItemEvent e) {
    if ((e.getSource().getType().equals(InventoryType.CHEST)) && (!e.getInitiator().getType().equals(InventoryType.PLAYER))) {

        if (e.getSource().getHolder() instanceof DoubleChest) {
            DoubleChest dc = (DoubleChest) e.getSource().getHolder();
            Chest r = (Chest) dc.getRightSide();
            Chest l = (Chest) dc.getLeftSide();

            if (shopUtils.isShop(r.getLocation()) || shopUtils.isShop(l.getLocation())) e.setCancelled(true);

        } else if (e.getSource().getHolder() instanceof Chest) {
            Chest c = (Chest) e.getSource().getHolder();

            if (shopUtils.isShop(c.getLocation())) e.setCancelled(true);
        }
    }
}
 
Example #10
Source File: ExploitEvents.java    From uSkyBlock with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onVillagerTrade(InventoryOpenEvent event) {
    if (!plugin.getWorldManager().isSkyAssociatedWorld(event.getPlayer().getWorld())) {
        return;
    }
    if (!(event.getPlayer() instanceof Player)) {
        return;
    }
    if (!anyVillagerTradingAllowed && event.getInventory().getType() == InventoryType.MERCHANT) {
        event.setCancelled(true);
        event.getPlayer().sendMessage(tr("\u00a7eVillager-trading isn't allowed."));
        return;
    }
    if (visitorVillagerTradingProtected
            && event.getPlayer() instanceof Player
            && !(event.getPlayer().hasPermission("usb.mod.bypassprotection"))
            && event.getInventory().getType() == InventoryType.MERCHANT
            && !plugin.playerIsOnIsland((Player)event.getPlayer())) {
        event.setCancelled(true);
        event.getPlayer().sendMessage(tr("\u00a7eTrading isn't allowed on other islands. Do it in spawn."));
    }
}
 
Example #11
Source File: ListenerInventories.java    From CombatLogX with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority=EventPriority.HIGH, ignoreCancelled=true)
public void onTag(PlayerTagEvent e) {
    Player player = e.getPlayer();
    InventoryView openView = player.getOpenInventory();
    if(openView == null) return;

    Inventory topInv = openView.getTopInventory();
    if(topInv == null) return;

    InventoryType type = openView.getType();
    if(type == InventoryType.CRAFTING) return;

    player.closeInventory();
    String message = this.plugin.getLanguageMessageColoredWithPrefix("cheat-prevention.inventory.force-closed");
    this.plugin.sendMessage(player, message);
}
 
Example #12
Source File: StoreListener.java    From skRayFall with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Remove the store/unstore event possibility when an inventory is closed.
 *
 * @param evt The InventoryCloseEvent used to remove the possibility of a store/unstore
 *            event
 */
@EventHandler
public void onClose(InventoryCloseEvent evt) {
    if (evt.getView().getBottomInventory().getType() == InventoryType.PLAYER
            && (evt.getView().getTopInventory().getType() == InventoryType.CHEST
            || evt.getView().getTopInventory().getType() == InventoryType.ENDER_CHEST
            || evt.getView().getTopInventory().getType() == InventoryType.HOPPER
            || evt.getView().getTopInventory().getType() == InventoryType.DISPENSER
            || evt.getView().getTopInventory().getType() == InventoryType.DROPPER)) {
        if (storePossible.contains(evt.getPlayer())) {
            storePossible.remove(evt.getPlayer());
        } else if (unstorePossible.contains(evt.getPlayer())) {
            unstorePossible.remove(evt.getPlayer());
        }
    }
}
 
Example #13
Source File: InventoryUtils.java    From AACAdditionPro with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Calculates the distance between two raw slots.
 *
 * @param rawSlotOne    the first (raw) slot
 * @param rawSlotTwo    the second (raw) slot
 * @param inventoryType the inventory layout when the click happened.
 *
 * @return the distance between the two slots or -1 if locating the slots failed.
 */
public static double distanceBetweenSlots(final int rawSlotOne, final int rawSlotTwo, final InventoryType inventoryType)
{
    double[] locationOfFirstClick = InventoryUtils.locateSlot(rawSlotOne, inventoryType);
    double[] locationOfSecondClick = InventoryUtils.locateSlot(rawSlotTwo, inventoryType);

    if (locationOfFirstClick == null || locationOfSecondClick == null) {
        return -1;
    }

    return Math.hypot(locationOfFirstClick[0] - locationOfSecondClick[0], locationOfFirstClick[1] - locationOfSecondClick[1]);
}
 
Example #14
Source File: GUIListener.java    From EnchantmentsEnhance with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Prevents item glitched into menu.
 *
 * @param e
 */
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onInventoryClick(InventoryClickEvent e) {
    if ((e.getInventory().getType() != InventoryType.CRAFTING) && (e.getInventory().getType() != InventoryType.PLAYER)) {
        if ((e.getClick().equals(ClickType.NUMBER_KEY)) && (e.getWhoClicked().getInventory().getItem(e.getHotbarButton()) != null)) {
            Player player = (Player) e.getWhoClicked();
            String playerName = player.getName();
            GUIAbstract gui = GUIManager.getMap().get(playerName);
            if (gui != null && gui.getInventory().equals(e.getInventory())) {
                e.setCancelled(true);
            }
        }
    }
}
 
Example #15
Source File: ClassesTest.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@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 #16
Source File: WrapperPlayServerOpenWindow.java    From PacketWrapper with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Set the window type to use for display. 
 * @param value - new value.
*/
public void setInventoryType(InventoryType value) {
	int id = inventoryByID.indexOf(value);
	
	if (id > 0)
		handle.getIntegers().write(1, id);
	else
		throw new IllegalArgumentException("Cannot find the ID of " + value);
}
 
Example #17
Source File: RecipeBuilder.java    From ProRecipes with GNU General Public License v2.0 5 votes vote down vote up
@EventHandler
public void inventoryDrag(InventoryDragEvent event){
	if(!event.getInventory().getType().equals(InventoryType.WORKBENCH))return;
	if(!event.getWhoClicked().hasMetadata("recipeBuilder"))return;
	String step = event.getWhoClicked().getMetadata("recipeBuilder").get(0).asString();
	if(step.contains("itemRequest")){
		
			event.setCancelled(true);
			
		}
}
 
Example #18
Source File: InventoryClick.java    From AACAdditionPro with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a dummy {@link InventoryClick} to use as a starting data point.
 */
public static InventoryClick dummyClick()
{
    return new InventoryClick(Bukkit.createInventory(null, InventoryType.CHEST), new double[]{
            0,
            0
    }, ClickType.CREATIVE);
}
 
Example #19
Source File: Recipes.java    From ProRecipes with GNU General Public License v2.0 5 votes vote down vote up
@EventHandler
public void onLick(final InventoryClickEvent event){
	//LOL TO THE METHOD NAME
	if(event.getClickedInventory() != null && event.getClickedInventory().getType().equals(InventoryType.WORKBENCH)){
		//System.out.println(event.getAction());
		switch(event.getAction()){
		case PLACE_ONE:
		case PLACE_SOME:
		case PLACE_ALL:
			ItemStack to = event.getInventory().getItem(event.getSlot()) != null ? event.getInventory().getItem(event.getSlot()).clone() : null;
			if(to != null){
				
				final CraftingInventory i = (CraftingInventory) event.getInventory();
				ProRecipes.getPlugin().getServer().getScheduler().runTaskLater(ProRecipes.getPlugin(), new Runnable(){

					@Override
					public void run() {
						//System.out.println("Calling prepare!");
						callPrepare(i, event.getView());
						
					}
					
				}, 0);
				
			}
		}
	}
	
}
 
Example #20
Source File: UhcItems.java    From UhcCore with GNU General Public License v3.0 5 votes vote down vote up
public static void openTeamReplyInviteInventory(Player player, UhcTeam team){
	Inventory inv = Bukkit.createInventory(null, InventoryType.HOPPER, Lang.TEAM_INVENTORY_REPLY_INVITE);

	inv.addItem(createTeamSkullItem(team, false));
	inv.addItem(GameItem.TEAM_INVITE_ACCEPT.getItem(ChatColor.DARK_GRAY + team.getTeamName()));
	inv.addItem(GameItem.TEAM_INVITE_DENY.getItem(ChatColor.DARK_GRAY + team.getTeamName()));

	player.openInventory(inv);
}
 
Example #21
Source File: GuiInject.java    From AACAdditionPro with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onJoin(InventoryOpenEvent event)
{
    if (event.getView().getTitle().startsWith(AAC_GUI_TITLE)
        && event.getView().getType() == InventoryType.CHEST
        && InternalPermission.hasPermission(event.getPlayer(), InternalPermission.AAC_MANAGE))
    {
        event.getInventory().setItem(16, AACADDITIONPRO_ITEMSTACK);
    }
}
 
Example #22
Source File: EvtCraftClick.java    From skRayFall with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean check(Event evt) {
    final InventoryClickEvent e = (InventoryClickEvent) evt;
    if (InventoryType.CRAFTING == e.getInventory().getType()) {
        if (e.getSlotType() != InventoryType.SlotType.QUICKBAR
                && e.getSlotType() != InventoryType.SlotType.CONTAINER) {
            if (evtslotclick == null) {
                return true;
            } else return e.getSlot() == evtslotclick.getSingle().intValue();
        }
        return false;
    }
    return false;
}
 
Example #23
Source File: CraftInventory.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
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;
    }
}
 
Example #24
Source File: VillagerTradesListener.java    From Statz with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onVillagerTrade(final InventoryClickEvent event) {

    final PlayerStat stat = PlayerStat.VILLAGER_TRADES;

    // Thanks to Lolmewn for this code (https://bitbucket
    // .org/Lolmewn/stats/src/4eae2db1b21038a91b7d39181f27bdd3cd987324/src/main/java/nl/lolmewn/stats/stats/bukkit
    // /BukkitTrades.java?at=3.0&fileviewer=file-view-default)

    if (event.getInventory().getType() != InventoryType.MERCHANT) {
        return;
    }
    if (!event.getSlotType().equals(SlotType.RESULT)) {
        return;
    }
    if (!event.getAction().equals(InventoryAction.MOVE_TO_OTHER_INVENTORY)
            && !event.getAction().equals(InventoryAction.PICKUP_ALL)) {
        return;
    }
    if (!(event.getWhoClicked() instanceof Player)) {
        return;
    }

    Player player = (Player) event.getWhoClicked();

    // Do general check
    if (!plugin.doGeneralCheck(player, stat))
        return;

    ItemStack item = event.getCurrentItem();

    // Update value to new stat.
    plugin.getDataManager().setPlayerInfo(player.getUniqueId(), stat,
            StatzUtil.makeQuery("uuid", player.getUniqueId().toString(), "value", item.getAmount(), "world",
                    player.getWorld().getName(), "trade", item.getType().toString()));

}
 
Example #25
Source File: MapRatingsMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
public void rate(final MatchPlayer player, final int score) {
    if(!this.checkCanRate(player)) return;

    final Integer oldScore = this.playerRatings.put(player, score);

    InventoryView inv = player.getBukkit().getOpenInventory();
    if(inv.getTopInventory().getType() == InventoryType.HOPPER) {
        this.updateScoreButtons(player, inv.getTopInventory());
    }

    if(oldScore != null && score == oldScore) {
        player.sendWarning(PGMTranslations.t("rating.sameRating", player, score));
        return;
    }

    player.facet(MatchPlayerExecutor.class).callback(mapService.rate(new MapRating(
        player.getPlayerId(),
        getMatch().getMap().getDocument(),
        score,
        null
    )), CommandFutureCallback.onSuccess(player.getBukkit(), result -> {
        if(result.first.isOnline()) {
            result.first.getBukkit().closeInventory();
        }
        notifyRating(result.first, score, oldScore);
    }));
}
 
Example #26
Source File: CraftInventory.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
public InventoryType getType() {
    // Thanks to Droppers extending Dispensers, order is important.
    if (inventory instanceof InventoryCrafting) {
        return inventory.getSizeInventory() >= 9 ? InventoryType.WORKBENCH : InventoryType.CRAFTING;
    } else if (inventory instanceof InventoryPlayer) {
        return InventoryType.PLAYER;
    } else if (inventory instanceof TileEntityDropper) {
        return InventoryType.DROPPER;
    } else if (inventory instanceof TileEntityDispenser) {
        return InventoryType.DISPENSER;
    } else if (inventory instanceof TileEntityFurnace) {
        return InventoryType.FURNACE;
    } else if (this instanceof CraftInventoryEnchanting) {
        return InventoryType.ENCHANTING;
    } else if (inventory instanceof TileEntityBrewingStand) {
        return InventoryType.BREWING;
    } else if (inventory instanceof CraftInventoryCustom.MinecraftInventory) {
        return ((CraftInventoryCustom.MinecraftInventory) inventory).getType();
    } else if (inventory instanceof InventoryEnderChest) {
        return InventoryType.ENDER_CHEST;
    } else if (inventory instanceof InventoryMerchant) {
        return InventoryType.MERCHANT;
    } else if (inventory instanceof TileEntityBeacon) {
        return InventoryType.BEACON;
    } else if (this instanceof CraftInventoryAnvil) {
        return InventoryType.ANVIL;
    } else if (inventory instanceof IHopper) {
        return InventoryType.HOPPER;
    } else if (inventory instanceof TileEntityShulkerBox) {
        return InventoryType.SHULKER_BOX;
    } else {
        return InventoryType.CHEST;
    }
}
 
Example #27
Source File: CraftInventoryView.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
@Override
public InventoryType getType() {
    InventoryType type = viewing.getType();
    if (type == InventoryType.CRAFTING && player.getGameMode() == GameMode.CREATIVE) {
        return InventoryType.CREATIVE;
    }
    return type;
}
 
Example #28
Source File: QuestItemHandler.java    From BetonQuest with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onItemMove(final InventoryClickEvent event) {
    if (!(event.getWhoClicked() instanceof Player)) {
        return;
    }
    if (event.getWhoClicked().getGameMode() == GameMode.CREATIVE) {
        return;
    }
    final String playerID = PlayerConverter.getID((Player) event.getWhoClicked());
    ItemStack item;
    switch (event.getAction()) {
    case MOVE_TO_OTHER_INVENTORY:
        item = event.getCurrentItem();
        break;
    case PLACE_ALL:
    case PLACE_ONE:
    case PLACE_SOME:
    case SWAP_WITH_CURSOR:
        if (event.getClickedInventory().getType() != InventoryType.PLAYER) {
            item = event.getCursor();
        } else {
            item = null;
        }
        break;
    case HOTBAR_MOVE_AND_READD:
    case HOTBAR_SWAP:
        if (event.getClickedInventory().getType() != InventoryType.PLAYER) {
            item = event.getWhoClicked().getInventory().getItem(event.getHotbarButton());
        } else {
            item = null;
        }
        break;
    default:
        item = null;
        break;
    }
    if (item != null && (Journal.isJournal(playerID, item) || Utils.isQuestItem(item))) {
        event.setCancelled(true);
    }
}
 
Example #29
Source File: CraftInventoryCustom.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
public MinecraftInventory(InventoryHolder owner, int size, String title) {
    Validate.notNull(title, "Title cannot be null");
    this.items = NonNullList.withSize(size, ItemStack.EMPTY);
    this.title = title;
    this.viewers = new ArrayList<HumanEntity>();
    this.owner = owner;
    this.type = InventoryType.CHEST;
}
 
Example #30
Source File: TestVanillaMachinesListener.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
private InventoryClickEvent mockBrewingEvent(ItemStack item) {
    Player player = server.addPlayer();
    Inventory inv = TestUtilities.mockInventory(InventoryType.BREWING);
    Mockito.when(inv.getHolder()).thenReturn(Mockito.mock(BrewingStand.class));
    Mockito.when(inv.getSize()).thenReturn(5);

    InventoryView view = player.openInventory(inv);
    view.setCursor(item);
    InventoryClickEvent event = new InventoryClickEvent(view, SlotType.CONTAINER, 1, ClickType.LEFT, InventoryAction.PICKUP_ONE);
    listener.onPreBrew(event);
    return event;
}