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 Skree by Skelril.
the class ScrollOfSummation method onRightClick.
@Listener
public void onRightClick(InteractBlockEvent.Secondary.MainHand event, @First Player player) {
Optional<ItemStack> optHeldItem = player.getItemInHand(HandTypes.MAIN_HAND);
if (!optHeldItem.isPresent()) {
return;
}
ItemStack held = optHeldItem.get();
if (held.getItem() != this) {
return;
}
net.minecraft.item.ItemStack[] pInv = tf(player).inventory.mainInventory;
Optional<ItemStack[]> optCompacted = new ItemCompactor(ImmutableList.of(CoalValueMap.inst(), IronValueMap.inst(), GoldValueMap.inst(), RedstoneValueMap.inst(), LapisValueMap.inst(), DiamondValueMap.inst(), EmeraldValueMap.inst(), CofferValueMap.inst())).execute((ItemStack[]) (Object[]) pInv);
if (optCompacted.isPresent()) {
Task.builder().execute(() -> {
ItemStack[] nInv = optCompacted.get();
for (int i = 0; i < pInv.length; ++i) {
pInv[i] = tf(nInv[i]);
}
tf(player).inventoryContainer.detectAndSendChanges();
tf(player).inventory.decrStackSize(tf(player).inventory.currentItem, 1);
player.sendMessage(Text.of(TextColors.GOLD, "The scroll glows brightly before turning to dust..."));
}).delayTicks(1).submit(SkreePlugin.inst());
event.setUseBlockResult(Tristate.FALSE);
}
}
use of org.spongepowered.api.item.inventory.ItemStack in project Skree by Skelril.
the class SkullOfTheFallen method onRightClick.
@Listener
public void onRightClick(InteractBlockEvent.Secondary.MainHand event, @First Player player) {
Optional<ItemStack> optHeldItem = player.getItemInHand(HandTypes.MAIN_HAND);
if (!optHeldItem.isPresent()) {
return;
}
if (this != optHeldItem.get().getItem()) {
return;
}
Location<World> pLoc = player.getLocation();
Optional<WorldService> optWorldService = Sponge.getServiceManager().provide(WorldService.class);
if (optWorldService.isPresent()) {
WorldService worldService = optWorldService.get();
WildernessWorldWrapper wrapper = worldService.getEffectWrapper(WildernessWorldWrapper.class).get();
Optional<Integer> optLevel = wrapper.getLevel(pLoc);
if (optLevel.isPresent()) {
int level = optLevel.get();
DecimalFormat df = new DecimalFormat("#,###.##");
player.sendMessages(Text.of(TextColors.YELLOW, "Wilderness level: " + level), Text.of(TextColors.YELLOW, "PvP Enabled: " + (wrapper.allowsPvP(level) ? "Yes" : "No")), Text.of(TextColors.YELLOW, "Mob damage: +" + df.format(wrapper.getDamageMod(level))), Text.of(TextColors.YELLOW, "Mob health: x" + df.format(wrapper.getHealthMod(level))), Text.of(TextColors.YELLOW, "Ore modifier: x" + df.format(wrapper.getOreMod(wrapper.getDropTier(level)))), Text.of(TextColors.YELLOW, "Drop modifier: x" + df.format(level * wrapper.getDropMod(wrapper.getDropTier(level)))));
} else {
player.sendMessage(Text.of(TextColors.RED, "You're not in a Wilderness world!"));
}
event.setUseBlockResult(Tristate.FALSE);
}
}
use of org.spongepowered.api.item.inventory.ItemStack in project Skree by Skelril.
the class MagicBlockStateHelper method dropItems.
protected static void dropItems(Location<World> loc, Cause cause) {
ItemStack ladder = ItemStackFactory.newItemStack((BlockType) CustomBlockTypes.MAGIC_LADDER);
ItemStack platform = ItemStackFactory.newItemStack((BlockType) CustomBlockTypes.MAGIC_PLATFORM);
Collection<ItemStack> drops = new ArrayList<>();
drops.addAll(newItemStackCollection(ladder, foundLadder));
drops.addAll(newItemStackCollection(platform, foundPlatform));
new ItemDropper(loc).dropStacks(drops, SpawnTypes.DROPPED_ITEM);
resetCounts();
}
use of org.spongepowered.api.item.inventory.ItemStack in project Skree by Skelril.
the class RedFeather method getHighestPoweredFeather.
public Optional<Clause<Integer, Clause<ItemStack, Clause<Integer, Long>>>> getHighestPoweredFeather(EntityPlayer player) {
net.minecraft.item.ItemStack[] itemStacks = player.inventory.mainInventory;
int index = -1;
ItemStack stack = null;
Clause<Integer, Long> details = new Clause<>(0, 0L);
for (int i = 0; i < itemStacks.length; ++i) {
ItemStack curStack = tf(itemStacks[i]);
Clause<Integer, Long> powerCooldown = getFeatherPower(curStack);
if (powerCooldown.getValue() > System.currentTimeMillis()) {
return Optional.empty();
}
if (powerCooldown.getKey() > details.getKey()) {
index = i;
details = powerCooldown;
stack = curStack;
}
}
return index != -1 ? Optional.of(new Clause<>(index, new Clause<>(stack, details))) : Optional.empty();
}
Aggregations