use of org.spongepowered.api.item.inventory.ItemStack in project HuskyCrates-Sponge by codeHusky.
the class Key method execute.
@Override
public CommandResult execute(CommandSource commandSource, CommandContext commandContext) throws CommandException {
if (commandContext.getOne("type").isPresent()) {
String type = commandContext.<String>getOne("type").get();
Optional<Player> player = commandContext.getOne("player");
VirtualCrate virtualCrate = HuskyCrates.instance.getCrateUtilities().getVirtualCrate(type);
int quantity = commandContext.getOne("quantity").isPresent() ? commandContext.<Integer>getOne("quantity").get() : 1;
if (virtualCrate == null) {
commandSource.sendMessage(Text.of("Invalid crate id: " + type + ". Please check your config."));
return CommandResult.empty();
}
if (!player.isPresent()) {
commandSource.sendMessage(Text.of("You need to be in game or specify a player for this command to work."));
return CommandResult.empty();
}
ItemStack keyItemStack = virtualCrate.getCrateKey(quantity);
InventoryTransactionResult.Type mainInventory = player.get().getInventory().offer(keyItemStack.copy()).getType();
if (!mainInventory.equals(InventoryTransactionResult.Type.SUCCESS)) {
InventoryTransactionResult.Type enderInventory = player.get().getEnderChestInventory().offer(keyItemStack.copy()).getType();
if (!enderInventory.equals(InventoryTransactionResult.Type.SUCCESS)) {
commandSource.sendMessage(Text.of("Couldn't give key to " + player.get().getName() + " because of a full inventory and enderchest"));
HuskyCrates.instance.logger.info("Couldn't give key to " + player.get().getName() + " because of a full inventory and enderchest");
} else {
if (player.isPresent()) {
player.get().sendMessage(Text.of("You have been given 1 or more ", TextSerializers.FORMATTING_CODE.deserialize(virtualCrate.displayName), " key(s), but some have been placed in your Ender Chest."));
} else {
commandSource.sendMessage(Text.of("You have been given 1 or more ", TextSerializers.FORMATTING_CODE.deserialize(virtualCrate.displayName), " key(s), but some have been placed in your Ender Chest."));
}
}
}
} else {
commandSource.sendMessage(Text.of("Usage: /crate key <id> [player] [count]"));
}
return CommandResult.success();
}
use of org.spongepowered.api.item.inventory.ItemStack in project Skree by Skelril.
the class CatacombsListener method onRightClick.
@Listener
public void onRightClick(InteractBlockEvent.Secondary.MainHand event, @First Player player) {
Optional<CatacombsInstance> optInst = manager.getApplicableZone(player);
if (!optInst.isPresent()) {
return;
}
CatacombsInstance inst = optInst.get();
if (inst.hasUsedPhantomClock()) {
return;
}
Optional<ItemStack> optHeldItem = player.getItemInHand(HandTypes.MAIN_HAND);
if (!optHeldItem.isPresent()) {
return;
}
ItemStack held = optHeldItem.get();
if (held.getItem() != CustomItemTypes.PHANTOM_CLOCK) {
return;
}
Task.builder().execute(() -> {
tf(player).inventory.decrStackSize(tf(player).inventory.currentItem, 1);
inst.setUsedPhantomClock(true);
inst.getPlayerMessageChannel(PlayerClassifier.SPECTATOR).send(Text.of(TextColors.GOLD, "A Phantom Clock has been used to increase wave speed!"));
}).delayTicks(1).submit(SkreePlugin.inst());
event.setUseBlockResult(Tristate.FALSE);
}
use of org.spongepowered.api.item.inventory.ItemStack in project Skree by Skelril.
the class TheForgeInstance method getProduce.
private List<ItemStack> getProduce() {
Map<ItemStack, Integer> results = state.getResults();
int quantityToProduce = getQuantityToProduce();
List<ItemStack> produce = new ArrayList<>();
while (!results.isEmpty() && quantityToProduce > 0) {
ItemStack stackToMake = Probability.pickOneOf(results.keySet());
int supply = results.get(stackToMake);
if (supply >= quantityToProduce) {
results.put(stackToMake, supply - quantityToProduce);
for (int i = 0; i < quantityToProduce; ++i) {
produce.add(newItemStack(stackToMake));
}
quantityToProduce = 0;
} else {
results.remove(stackToMake);
for (int i = 0; i < supply; ++i) {
produce.add(newItemStack(stackToMake));
}
quantityToProduce = quantityToProduce - supply;
}
}
return produce;
}
use of org.spongepowered.api.item.inventory.ItemStack in project Skree by Skelril.
the class InventoryCurse method accept.
@Override
public void accept(Player player) {
ItemStack stack = newItemStack(targetType, Probability.getRandom(targetAmt));
Optional<ItemStack> optHeld = player.getItemInHand(HandTypes.MAIN_HAND);
if (optHeld.isPresent() && !isSimilar(optHeld.get(), stack)) {
new ItemDropper(player.getLocation()).dropStacks(Lists.newArrayList(optHeld.get()), SpawnTypes.DROPPED_ITEM);
}
player.setItemInHand(HandTypes.MAIN_HAND, stack);
}
use of org.spongepowered.api.item.inventory.ItemStack in project Skree by Skelril.
the class TempleOfFateInstance method rewardPlayer.
public void rewardPlayer(Player player) {
boolean participated = participants.contains(player);
remove(player);
if (!participated) {
return;
}
for (ItemStack stack : dropTable.getDrops(1)) {
player.getInventory().offer(stack);
}
}
Aggregations