/** * @param p - The player buying an item. * @param item - The item the player wants to buy. */ public static void buyItem(Player p, Item item) { String key = item.getItemId() + ":" + item.getDamage(); int amount = ITEMS.getInt(key, 0); if (amount == -1) { p.sendMessage(WShop.PRE + "The server does not sell that item at this time."); return; } if (amount < item.getAmount()) { p.sendMessage(WShop.PRE + "The server does not have that much of " + key); return; } // end if double price = PRICES.getDouble(key + "_buy", -1); if (price == -1) { p.sendMessage(WShop.PRE + "The server does not sell that item at this time." + key); return; } if (canPay(p, price)) { payPlayer(p, -price); // Make sure we charge them here, not pay them. Negate the price. p.giveItem(item); ITEMS.setInt(key, amount - item.getAmount()); p.sendMessage( WShop.PRE + "Bought an item. ID:" + item.getItemId() + ", Damage:" + item.getDamage() + ", Amount:" + item.getAmount() + ", Cost:" + price); } else { p.sendMessage(WShop.PRE + "You do not have enough money to buy " + key); return; } } // end buyItem
/** * @param p - The player trying to sell. * @param item - The item to sell, commonly the players help item. */ public static void sellItem(Player p, Item item) { String key = item.getItemId() + ":" + item.getDamage(); double price = PRICES.getDouble(key + "_sell", -1); if (price == -1) { p.sendMessage(WShop.PRE + "The server does not buy that item at this time."); return; } int amount = ITEMS.getInt(key, 0); p.getInventory().removeItem(item); ITEMS.setInt(key, amount + item.getAmount()); payPlayer(p, price); return; } // end sellItem
public void Save() { String numkey = "sign-amount"; String signprefix = "sign-"; // clear properties file int num = mPropertiesFile.getInt(numkey, 0); for (int i = 0; i < num; ++i) { mPropertiesFile.removeKey(signprefix + i); } // save num = mSensorList.size(); mPropertiesFile.setInt(numkey, num); for (int i = 0; i < mSensorList.size(); ++i) { mPropertiesFile.setString(signprefix + i, mSensorList.get(i).serialize()); } }