Trying to make my own version of shops with signs. Here is the desired layout for a sign: [ShopSign] <- Identifies as a shop 264 <- Name of item 200 <- Buy price 100 <- Sell price Code: @EventHandler public void onSignClick(PlayerInteractEvent e){ Player p = e.getPlayer(); Block b = e.getClickedBlock(); if(b.getState() instanceof Sign){ BlockState s = b.getState(); Sign sign = (Sign) s; if(sign.getLine(0).equalsIgnoreCase("[ShopSign]")){ String ID = sign.getLine(1).toUpperCase(); String price = sign.getLine(2); String resale = sign.getLine(3); Item i = new Item(); } } } How do I tell bukkit that line 1 will be the item ID?
Could just use Material.getString(ID); Then you could use items names. Make sure you do a null check though.
Yeah but if you really just want to use a item id, Code: String itemId = s.getLine(0); int id; try{ id = Integer.parInteger(itemId); }catch(Exception e){ p.sendMessage("Invalid item id"); } ItemStack customItem = new ItemStack(id);
@_Cookie_ matchMaterial(String) will first try to parse it as an integer and getting it by the ID, if it fails then it will try by name, I think it would be better to use it because IDs can chance and are less human-readable, but whatever. If you use Material.matchMaterial("345") you should get the material or not depending on the ID you pass
While that method is cool, it is deprecated for using it with "345." which means that functionality may get removed in the future, so it would probably best to just do that part yourself to ensure compatibility across future versions.
@RingOfStorms matchMaterial is not deprecated, getMateria(int) is, and that is because he wants to use a number ID (called magic number in the docs) instead of using a name, this is his decision and has nothing to do with matchMaterial, deprecation in magic number methods it's because IDs may change from version to version, the solution for this is simple, use the material name instead of the ID, which is also what matchMaterial does.
The only reason I suggested using itemID's instead of Item names, is since he asked for it. Or I would of stuck with using item names. So lets just let him decide on what he wants to use since he has the facts and how he wants to future proof his plugins for, which he can base his decision on thanks to you two.