use of org.spongepowered.api.item.inventory.ItemStack in project Skree by Skelril.
the class ButterFingersCurse method accept.
@Override
public void accept(Player player) {
List<ItemStack> drops = new ArrayList<>();
while (true) {
Optional<ItemStack> optDrop = player.getInventory().poll();
if (!optDrop.isPresent()) {
break;
}
drops.add(optDrop.get());
}
Collections.shuffle(drops);
new ItemDropper(player.getLocation()).dropStacks(drops, SpawnTypes.DROPPED_ITEM);
}
use of org.spongepowered.api.item.inventory.ItemStack in project Skree by Skelril.
the class WildernessWorldWrapper method onEntityDeath.
@Listener
public void onEntityDeath(DestructEntityEvent.Death event) {
Entity entity = event.getTargetEntity();
Location<World> loc = entity.getLocation();
Optional<Integer> optLevel = getLevel(loc);
if (!optLevel.isPresent()) {
return;
}
int level = optLevel.get();
if (entity instanceof Monster) {
DropTable dropTable;
if (entity.getLocation().getExtent().getDimension() == DimensionTypes.NETHER || entity instanceof Wither) {
dropTable = netherMobDropTable;
} else {
dropTable = commonDropTable;
}
Optional<EntityDamageSource> optDamageSource = event.getCause().first(EntityDamageSource.class);
if (optDamageSource.isPresent()) {
Entity srcEntity;
if (optDamageSource.get() instanceof IndirectEntityDamageSource) {
srcEntity = ((IndirectEntityDamageSource) optDamageSource.get()).getIndirectSource();
} else {
srcEntity = optDamageSource.get().getSource();
}
int dropTier = level;
if (srcEntity instanceof Player) {
Optional<ItemStack> optHeldItem = ((Player) srcEntity).getItemInHand(HandTypes.MAIN_HAND);
if (optHeldItem.isPresent()) {
Optional<ItemEnchantment> optLooting = EnchantmentUtil.getHighestEnchantment(optHeldItem.get(), Enchantments.LOOTING);
if (optLooting.isPresent()) {
dropTier += optLooting.get().getLevel();
}
}
dropTier = getDropTier(dropTier);
Collection<ItemStack> drops = dropTable.getDrops((entity instanceof Boss ? 5 : 1) * dropTier, getDropMod(dropTier, ((Monster) entity).getHealthData().maxHealth().get(), entity.getType()));
int times = 1;
Optional<ModifierService> optService = Sponge.getServiceManager().provide(ModifierService.class);
if (optService.isPresent()) {
ModifierService service = optService.get();
if (service.isActive(Modifiers.DOUBLE_WILD_DROPS)) {
times *= 2;
}
}
ItemDropper dropper = new ItemDropper(loc);
for (int i = 0; i < times; ++i) {
dropper.dropStacks(drops, SpawnTypes.DROPPED_ITEM);
}
}
}
if (entity.getType() == EntityTypes.ENDERMITE && Probability.getChance(20)) {
entity.getWorld().triggerExplosion(Explosion.builder().location(entity.getLocation()).shouldBreakBlocks(true).radius(4F).build(), Cause.source(SkreePlugin.container()).build());
}
}
GRAVE_STONE.createGraveFromDeath(event);
}
use of org.spongepowered.api.item.inventory.ItemStack in project Skree by Skelril.
the class WildernessWorldWrapper method getPoolItemDrop.
private ItemStackSnapshot getPoolItemDrop(ItemStackSnapshot snapshot) {
Map<String, QuantityBoundedItemStackConfig> replacementMapping = config.getDropAmplificationConfig().getItemReplacementMapping();
ItemStackConfig replacementItem = replacementMapping.get(snapshot.getType().getId());
if (replacementItem != null) {
return ((ItemStack) (Object) replacementItem.toNSMStack()).createSnapshot();
}
return snapshot;
}
use of org.spongepowered.api.item.inventory.ItemStack in project Skree by Skelril.
the class MarketBuyCommand method execute.
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
if (!(src instanceof Player)) {
src.sendMessage(Text.of("You must be a player to use this command!"));
return CommandResult.empty();
}
Optional<MarketService> optService = Sponge.getServiceManager().provide(MarketService.class);
if (!optService.isPresent()) {
src.sendMessage(Text.of(TextColors.DARK_RED, "The market service is not currently running."));
return CommandResult.empty();
}
MarketService service = optService.get();
Player player = (Player) src;
if (!canBuyOrSell(player)) {
player.sendMessage(Text.of(TextColors.RED, "You cannot buy or sell from this area."));
return CommandResult.empty();
}
String itemName = args.<String>getOne("item").get();
List<String> targetItems;
if (itemName.endsWith("#armor")) {
String armorType = itemName.replace("#armor", " ");
targetItems = Lists.newArrayList(armorType + "helmet", armorType + "chestplate", armorType + "leggings", armorType + "boots");
} else {
targetItems = Lists.newArrayList(itemName);
}
BigDecimal price = BigDecimal.ZERO;
for (String anItem : targetItems) {
Optional<BigDecimal> optPrice = service.getPrice(anItem);
if (!optPrice.isPresent()) {
src.sendMessage(Text.of(TextColors.RED, "That item is not available for purchase."));
return CommandResult.empty();
}
price = price.add(optPrice.get());
}
Optional<Integer> optAmt = args.getOne("amount");
int amt = Math.max(1, optAmt.isPresent() ? optAmt.get() : 0);
price = price.multiply(BigDecimal.valueOf(amt));
BigDecimal funds = MarketImplUtil.getMoney(player);
BigDecimal newBalance = funds.subtract(price);
if (newBalance.compareTo(BigDecimal.ZERO) < 0) {
BigDecimal neededAmt = newBalance.multiply(BigDecimal.valueOf(-1));
src.sendMessage(Text.of(TextColors.RED, "You do not have enough money to purchase that item(s)."));
src.sendMessage(Text.of(TextColors.RED, "You need an additional ", TextColors.WHITE, format(neededAmt), TextColors.RED, "."));
return CommandResult.empty();
}
List<Clause<String, Integer>> newStocks = new ArrayList<>();
for (String anItem : targetItems) {
Optional<Integer> optStock = service.getStock(anItem);
if (optStock.orElse(0) < amt) {
src.sendMessage(Text.of(TextColors.RED, "There is not enough stock to satisfy your order."));
return CommandResult.empty();
}
newStocks.add(new Clause<>(anItem, optStock.get() - amt));
}
// Accumulate items
List<ItemStack> itemStacks = new ArrayList<>(targetItems.size());
for (String anItem : targetItems) {
Optional<ItemStack> stack = service.getItem(anItem);
if (!stack.isPresent()) {
// TODO Auto reporting
src.sendMessage(Text.of(TextColors.RED, "An item stack could not be resolved, please report this!"));
return CommandResult.empty();
}
int total = amt;
while (total > 0) {
int increment = Math.min(total, stack.get().getMaxStackQuantity());
total -= increment;
itemStacks.add(newItemStack(stack.get(), increment));
}
}
// Alright, all items have been found
if (!MarketImplUtil.setBalanceTo(player, newBalance, Cause.source(SkreePlugin.container()).build())) {
// TODO Auto reporting
src.sendMessage(Text.of(TextColors.RED, "Failed to adjust your balance, please report this!"));
return CommandResult.empty();
}
Clause<Boolean, List<Clause<ItemStack, Integer>>> transactions = MarketImplUtil.giveItems(player, itemStacks, Cause.source(SkreePlugin.container()).build());
if (!transactions.getKey()) {
// TODO Auto reporting
src.sendMessage(Text.of(TextColors.RED, "Failed to give all items, please report this!"));
return CommandResult.empty();
}
// Items have been given process stocks
for (Clause<String, Integer> stock : newStocks) {
service.setStock(stock.getKey(), stock.getValue());
}
if (!service.logTransactionByStack(player.getUniqueId(), transactions.getValue())) {
// TODO Auto reporting
// Not critical, continue
src.sendMessage(Text.of(TextColors.RED, "Failed to log transactions, please report this!"));
}
player.sendMessage(Text.of(TextColors.YELLOW, "Item(s) purchased for ", TextColors.WHITE, format(price), TextColors.YELLOW, "!"));
return CommandResult.success();
}
use of org.spongepowered.api.item.inventory.ItemStack in project Skree by Skelril.
the class MarketSellCommand method execute.
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
if (!(src instanceof Player)) {
src.sendMessage(Text.of("You must be a player to use this command!"));
return CommandResult.empty();
}
Optional<MarketService> optService = Sponge.getServiceManager().provide(MarketService.class);
if (!optService.isPresent()) {
src.sendMessage(Text.of(TextColors.DARK_RED, "The market service is not currently running."));
return CommandResult.empty();
}
MarketService service = optService.get();
Player player = (Player) src;
if (!canBuyOrSell(player)) {
player.sendMessage(Text.of(TextColors.DARK_RED, "You cannot buy or sell from this area."));
return CommandResult.empty();
}
Optional<ItemStack> filter = Optional.empty();
QueryMode mode = QueryMode.HELD;
if (args.hasAny("a")) {
mode = QueryMode.EVERYTHING;
} else if (args.hasAny("h")) {
mode = QueryMode.HOT_BAR;
}
if (mode != QueryMode.HELD && !args.hasAny("u")) {
filter = player.getItemInHand(HandTypes.MAIN_HAND);
if (!filter.isPresent()) {
src.sendMessage(Text.of(TextColors.RED, "You're not holding an item to filter with!"));
return CommandResult.empty();
}
}
Clause<BigDecimal, List<Integer>> changes = MarketImplUtil.getChanges(player, service, mode, filter.orElse(null));
if (changes.getValue().isEmpty()) {
src.sendMessage(Text.of(TextColors.RED, "No sellable items found" + (filter.isPresent() ? " that matched the filter" : "") + "!"));
return CommandResult.empty();
}
List<Clause<ItemStack, Integer>> transactions = MarketImplUtil.removeAtPos(player, changes.getValue());
if (!service.logTransactionByStack(player.getUniqueId(), transactions)) {
// TODO Auto reporting
// Not critical, continue
src.sendMessage(Text.of(TextColors.DARK_RED, "Failed to log transactions, please report this!"));
}
BigDecimal newBalance = changes.getKey().add(MarketImplUtil.getMoney(player));
if (!MarketImplUtil.setBalanceTo(player, newBalance, Cause.source(SkreePlugin.container()).build())) {
// TODO Auto reporting
src.sendMessage(Text.of(TextColors.DARK_RED, "Failed to adjust your balance, please report this!"));
return CommandResult.empty();
}
// Process new stocks
for (Clause<ItemStack, Integer> transaction : transactions) {
service.setStock(transaction.getKey(), service.getStock(transaction.getKey()).orElse(0) + -(transaction.getValue()));
}
player.sendMessage(Text.of(TextColors.YELLOW, "Item(s) sold for: ", TextColors.WHITE, MarketImplUtil.format(changes.getKey()), TextColors.YELLOW, "!"));
return CommandResult.success();
}
Aggregations