use of org.spongepowered.api.item.inventory.ItemStack in project Skree by Skelril.
the class MarketUntrackItemComand 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();
Optional<ItemStack> held = ((Player) src).getItemInHand(HandTypes.MAIN_HAND);
if (!held.isPresent()) {
src.sendMessage(Text.of(TextColors.RED, "You are not holding an item."));
return CommandResult.empty();
}
ItemStack item = held.get();
if (service.remItem(item)) {
src.sendMessage(Text.of(TextColors.YELLOW, "Your held item is no longer being tracked."));
} else {
src.sendMessage(Text.of(TextColors.RED, "Your held item is not tracked."));
return CommandResult.empty();
}
return CommandResult.success();
}
use of org.spongepowered.api.item.inventory.ItemStack in project Skree by Skelril.
the class HymnOfSummation 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();
player.sendMessage(Text.of(TextColors.GOLD, "The hymn glows brightly..."));
}).delayTicks(1).submit(SkreePlugin.inst());
event.setUseBlockResult(Tristate.FALSE);
}
}
use of org.spongepowered.api.item.inventory.ItemStack in project Skree by Skelril.
the class PactScroll method onEntityInteract.
@Listener
public void onEntityInteract(InteractEntityEvent.Primary event, @Root Player player) {
Entity targetEntity = event.getTargetEntity();
if (!(targetEntity instanceof Player)) {
return;
}
Player targetPlayer = (Player) targetEntity;
Optional<ItemStack> optItemStack = player.getItemInHand(HandTypes.MAIN_HAND);
if (!optItemStack.isPresent()) {
return;
}
ItemStack itemStack = optItemStack.get();
if (itemStack.getItem() != this) {
return;
}
pactMap.putIfAbsent(player.getUniqueId(), new ArrayList<>());
List<UUID> pacts = pactMap.get(player.getUniqueId());
if (pacts.contains(targetPlayer.getUniqueId())) {
pacts.remove(targetPlayer.getUniqueId());
player.sendMessage(Text.of(TextColors.YELLOW, "Your pact with ", targetPlayer.getName(), " has been broken!"));
} else {
pacts.add(targetPlayer.getUniqueId());
player.sendMessage(Text.of(TextColors.YELLOW, "You've formed a pact with ", targetPlayer.getName(), "."));
player.sendMessage(Text.of(TextColors.YELLOW, "You will no longer be able to damage ", targetPlayer.getName(), ", unless attacked first."));
player.sendMessage(Text.of(TextColors.YELLOW, "You must carry a pact scroll for the pact to remain in effect."));
player.sendMessage(Text.of(TextColors.YELLOW, "All pacts will automatically be reset upon disconnect."));
}
event.setCancelled(true);
}
use of org.spongepowered.api.item.inventory.ItemStack in project Skree by Skelril.
the class PactScroll method onBlockInteract.
@Listener
public void onBlockInteract(InteractBlockEvent.Secondary.MainHand event, @Root Player player) {
Optional<ItemStack> optItemStack = player.getItemInHand(HandTypes.MAIN_HAND);
if (!optItemStack.isPresent()) {
return;
}
ItemStack itemStack = optItemStack.get();
if (itemStack.getItem() != this) {
return;
}
UserStorageService userService = Sponge.getServiceManager().provideUnchecked(UserStorageService.class);
PaginationService pagination = Sponge.getServiceManager().provideUnchecked(PaginationService.class);
List<Text> result = pactMap.getOrDefault(player.getUniqueId(), new ArrayList<>()).stream().map(userService::get).filter(Optional::isPresent).map(Optional::get).sorted((a, b) -> a.getName().compareToIgnoreCase(b.getName())).map(a -> Text.of((a.isOnline() ? TextColors.GREEN : TextColors.RED), a.getName())).collect(Collectors.toList());
pagination.builder().contents(result).title(Text.of(TextColors.GOLD, "Pact Members")).padding(Text.of(" ")).sendTo(player);
event.setUseBlockResult(Tristate.FALSE);
}
use of org.spongepowered.api.item.inventory.ItemStack in project Skree by Skelril.
the class MagicWand method onRightClick.
@Listener
public void onRightClick(InteractBlockEvent.Secondary.MainHand event, @First Player player) {
boolean survival = player.get(Keys.GAME_MODE).orElse(GameModes.CREATIVE) == GameModes.SURVIVAL;
Optional<ItemStack> optHeldItem = player.getItemInHand(HandTypes.MAIN_HAND);
if (!optHeldItem.isPresent()) {
return;
}
if (optHeldItem.get().getItem() != this) {
return;
}
event.setUseBlockResult(Tristate.FALSE);
Optional<Location<World>> optLoc = event.getTargetBlock().getLocation();
if (!optLoc.isPresent()) {
return;
}
Location<World> loc = optLoc.get();
BlockType targetType = loc.getBlockType();
if (targetType == CustomBlockTypes.MAGIC_LADDER) {
MagicBlockStateHelper.startLadder(loc);
} else if (targetType == CustomBlockTypes.MAGIC_PLATFORM) {
MagicBlockStateHelper.startPlatform(loc);
} else {
return;
}
if (!survival) {
MagicBlockStateHelper.resetCounts();
return;
}
MagicBlockStateHelper.dropItems(loc, event.getCause());
}
Aggregations