/** * Returns the last Item id from the hashmap * * @return long */ private long getLastId() { long lastKey = 0; for (Map.Entry<Long, Item> entry : items.entrySet()) { Item item = entry.getValue(); if (item.getId() > lastKey) { lastKey = item.getId(); } } return lastKey; }
/** * Add a given item. The name (id) of the item should be unique in the room. * * @param it - Item to be added * @return true if the action was completed. */ public boolean addItem(Item it) { if (existsItem(it.getId())) { return false; } else { items.add(it); return true; } }
/** * Return true if the Item <> exists. * * @param id - Name of the item. * @return true if the room as an item with that name. */ public boolean existsItem(String id) { Iterator<Item> it = items.iterator(); while (it.hasNext()) { Item aux = it.next(); if (aux.getId().equalsIgnoreCase(id)) return true; } return false; // NO SE HA ENCONTRADO EL ITEM CON ESE ID }
@Override public boolean update(Item item) { Item oldItem = items.get(item.getId()); BigDecimal currentBid = oldItem.getCurrentBid(); boolean isSuccesful; if (item.getCurrentBid().compareTo(currentBid) > 0) { if (item.getExpiration() == null) { item.setExpirationDate(oldItem.getExpiration()); items.put(item.getId(), item); } else { items.put(item.getId(), item); } isSuccesful = true; } else { isSuccesful = false; } return isSuccesful; }
private int getFuelTime(ItemStack item) { if (item == null) { return 0; } // CUSTOM FUEL HERE // Lava should melt 128 items, not 100 if (Item.getId(item.getItem()) == org.bukkit.Material.LAVA_BUCKET.getId()) { return 25600; } else { return fuelTime(item); } }
public void tick() { int newID = contents[0] == null ? 0 : Item.getId(contents[0].getItem()); // Has the item been changed? if (newID != lastID) { // Then reset the progress! myCookTime = 0.0D; lastID = newID; // And, most important: change the melt speed meltSpeed = getMeltSpeed(contents[0]); } // So, can we now finally burn? if (canBurn() && !isBurning() && (getFuelTime(contents[1]) > 0)) { // I have no idea what "ticksForCurrentFuel" is good for, but it // works fine like this burnTime = ticksForCurrentFuel = getFuelTime(contents[1]); // Before we remove the item: how fast does it burn? burnSpeed = getBurnSpeed(contents[1]); // If it's a container item (lava bucket), we only consume its // contents (not like evil Notch!) // If it's not a container, consume it! Om nom nom nom! { contents[1].count--; // Let 0 be null if (contents[1].count <= 0) { contents[1] = null; } } } // Now, burning? if (isBurning()) { // Then move on burnTime--; // I'm using a double here because of the custom recipes. // The faster this fuel burns and the faster the recipe melts, the // faster we're done myCookTime += burnSpeed * meltSpeed; // Finished burning? if (myCookTime >= 200.0D) { myCookTime -= 200.0D; burn(); } } // If it's not burning, we reset the burning progress! else { myCookTime = 0.0D; } // And for the display (I'm using floor rather than round to not cause // the client to do shit when we not really reached 200): cookTime = (int) Math.floor(myCookTime); }
/** * Pick an item from the room and add it to the player's inventory. * * @param who - the player * @param id - the identifier of the item * @return true if the action was successfully performed. */ public boolean pickItem(Player who, String id) { if (!existsItem(id)) { return false; } else { Iterator<Item> it = items.iterator(); while (it.hasNext()) { Item aux = it.next(); if (aux.getId().equalsIgnoreCase(id)) if (who.addItem(aux)) { items.remove(aux); return true; } else return false; } } return false; }