use of org.spongepowered.api.item.inventory.ItemStack in project Skree by Skelril.
the class WaveDropInstruction method apply.
@Override
public Optional<Instruction<UnbindCondition, Boss<Zombie, CatacombsBossDetail>>> apply(UnbindCondition condition, Boss<Zombie, CatacombsBossDetail> boss) {
int wave = boss.getDetail().getWave();
Collection<ItemStack> drops = dropTable.getDrops(wave, wave * .5 * modifier);
drops.addAll(foodDropTable.getDrops(1, .5 * modifier));
Optional<Zombie> optEnt = boss.getTargetEntity();
if (optEnt.isPresent()) {
Task.builder().execute(() -> {
new ItemDropper(optEnt.get().getLocation()).dropStacks(drops, SpawnTypes.DROPPED_ITEM);
}).delayTicks(1).submit(SkreePlugin.inst());
}
return Optional.empty();
}
use of org.spongepowered.api.item.inventory.ItemStack in project TotalEconomy by Erigitic.
the class TEJobManager method onPlayerFish.
/**
* Used for the catch option in jobs. Will check if the job has the catch node and if it does it will check if the
* item that was caught is present in the config of the player's job. If it is, it will grab the job exp reward as
* well as the pay.
*
* @param event FishingEvent.Stop
*/
@Listener
public void onPlayerFish(FishingEvent.Stop event) {
if (event.getCause().first(Player.class).isPresent()) {
// no transaction, so execution can stop
if (event.getItemStackTransaction().size() == 0) {
return;
}
Transaction<ItemStackSnapshot> itemTransaction = event.getItemStackTransaction().get(0);
ItemStack itemStack = itemTransaction.getFinal().createStack();
Player player = event.getCause().first(Player.class).get();
UUID playerUUID = player.getUniqueId();
String playerJob = getPlayerJob(player);
Optional<TEJob> optPlayerJob = getJob(playerJob, true);
if (optPlayerJob.isPresent()) {
if (itemStack.get(FishData.class).isPresent()) {
FishData fishData = itemStack.get(FishData.class).get();
String fishName = fishData.type().get().getName();
Optional<TEActionReward> reward = Optional.empty();
List<String> sets = optPlayerJob.get().getSets();
for (String s : sets) {
Optional<TEJobSet> optSet = getJobSet(s);
if (!optSet.isPresent()) {
logger.warn("[TE] Job " + getPlayerJob(player) + " has nonexistent set \"" + s + "\"");
continue;
}
reward = optSet.get().getRewardFor("catch", fishName);
}
if (reward.isPresent()) {
int expAmount = reward.get().getExpReward();
BigDecimal payAmount = reward.get().getMoneyReward();
boolean notify = accountConfig.getNode(playerUUID.toString(), "jobnotifications").getBoolean();
TEAccount playerAccount = (TEAccount) accountManager.getOrCreateAccount(player.getUniqueId()).get();
if (notify) {
notifyPlayer(player, payAmount);
}
addExp(player, expAmount);
playerAccount.deposit(totalEconomy.getDefaultCurrency(), payAmount, Cause.of(NamedCause.of("TotalEconomy", totalEconomy.getPluginContainer())));
checkForLevel(player);
}
}
}
}
}
use of org.spongepowered.api.item.inventory.ItemStack in project HuskyCrates-Sponge by codeHusky.
the class VirtualCrate method getCrateItem.
/***
* Retrieve the crate chest.
* @since 0.10.2
* @param quantity the quantity of chests you want.
* @return the ItemStack with the chest.
*/
public ItemStack getCrateItem(int quantity) {
ItemStack stacky = ItemStack.builder().itemType(crateBlockItemType).quantity(quantity).add(Keys.DISPLAY_NAME, TextSerializers.FORMATTING_CODE.deserialize(displayName)).build();
ArrayList<Text> itemLore = new ArrayList<>();
itemLore.add(Text.of(TextColors.WHITE, "A placeable ", TextSerializers.FORMATTING_CODE.deserialize(displayName), TextColors.WHITE, " crate."));
itemLore.add(Text.of(TextColors.DARK_GRAY, "HuskyCrates"));
stacky.offer(Keys.ITEM_LORE, itemLore);
return ItemStack.builder().fromContainer(stacky.toContainer().set(DataQuery.of("UnsafeData", "crateID"), id)).build();
}
use of org.spongepowered.api.item.inventory.ItemStack in project HuskyCrates-Sponge by codeHusky.
the class CrateRewardHolderParser method fromConfig.
public static CrateRewardHolder fromConfig(ConfigurationNode holderNode, VirtualCrate vc) {
ItemStack dispItem = itemFromNode(holderNode);
CrateReward reward = new CrateReward(null, "CODE ERROR, CONTACT DEVELOPER", false);
boolean dispAwardSimilar = false;
String name;
boolean single = false;
SharedLangData langData = HuskyCrates.instance.langData;
if (!holderNode.getNode("huskydata", "lang").isVirtual()) {
langData = new SharedLangData(vc.langData, holderNode.getNode("huskydata", "lang"));
}
//System.out.println(dispItem.get(Keys.DISPLAY_NAME));
if (holderNode.getNode("huskydata", "reward").getNode("overrideRewardName").isVirtual()) {
//System.out.println("Virtual");
if (dispItem.get(Keys.DISPLAY_NAME).isPresent()) {
name = dispItem.get(Keys.DISPLAY_NAME).get().toPlain();
} else {
name = dispItem.getItem().getName();
}
} else {
//System.out.println("Real");
name = holderNode.getNode("huskydata", "reward").getNode("overrideRewardName").getString("strings, please.");
}
if (!holderNode.getNode("huskydata", "reward").getNode("treatAsSingle").isVirtual()) {
single = holderNode.getNode("huskydata", "reward").getNode("treatAsSingle").getBoolean();
}
if (holderNode.getNode("huskydata", "reward", "type").getString().equalsIgnoreCase("item")) {
ItemStack rewardItem;
if (holderNode.getNode("huskydata", "reward").getNode("overrideItem").isVirtual()) {
ItemStack rr = dispItem.copy();
if (!holderNode.getNode("huskydata", "reward").getNode("overrideCount").isVirtual()) {
rr.setQuantity(holderNode.getNode("huskydata", "reward").getNode("overrideCount").getInt());
}
reward = new CrateReward(rr, name, single);
dispAwardSimilar = true;
} else {
reward = new CrateReward(itemFromNode(holderNode.getNode("huskydata", "reward", "overrideItem")), name, single);
}
} else if (holderNode.getNode("huskydata", "reward", "type").getString().equalsIgnoreCase("command")) {
reward = new CrateReward(holderNode.getNode("huskydata", "reward", "command").getString("/say You didn't set a command or something..."), name, single);
} else {
System.out.println("?! Invalid Reward Type !? " + holderNode.getNode("huskydata", "reward", "type").getString());
}
return new CrateRewardHolder(dispItem, reward, holderNode.getNode("huskydata", "weight").getDouble(1), dispAwardSimilar, langData);
}
use of org.spongepowered.api.item.inventory.ItemStack in project HuskyCrates-Sponge by codeHusky.
the class NullCrateView method getInventory.
@Override
public Inventory getInventory() {
Inventory woop = Inventory.builder().property(InventoryDimension.PROPERTY_NAME, InventoryDimension.of(9, 1)).property(InventoryTitle.PROPERTY_NAME, InventoryTitle.of(Text.of(TextColors.DARK_RED, "INVALID CRATE TYPE!"))).listener(ClickInventoryEvent.class, evt -> evt.setCancelled(true)).build(plugin);
woop.offer(ItemStack.of(ItemTypes.BARRIER, 256 * 2 + 64));
for (Inventory e : woop.slots()) {
ItemStack b = e.peek().get();
b.setQuantity(1);
e.set(b);
}
return woop;
}
Aggregations