本文整理汇总了Java中org.spongepowered.api.item.inventory.query.QueryOperationTypes类的典型用法代码示例。如果您正苦于以下问题:Java QueryOperationTypes类的具体用法?Java QueryOperationTypes怎么用?Java QueryOperationTypes使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
QueryOperationTypes类属于org.spongepowered.api.item.inventory.query包,在下文中一共展示了QueryOperationTypes类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: removeItem
import org.spongepowered.api.item.inventory.query.QueryOperationTypes; //导入依赖的package包/类
public static int removeItem(PlayerInventory inventory, ItemStack itemStack, int amount) {
int underflow = 0;
int total = amount;
int availableItems = getItemCount(inventory, itemStack);
if (amount > availableItems) {
underflow = amount - availableItems;
total = availableItems;
}
ItemStack copy = itemStack.copy();
while (total > 0) {
if (total > copy.getMaxStackQuantity()) {
inventory.query(QueryOperationTypes.ITEM_STACK_IGNORE_QUANTITY.of(copy)).poll(copy.getMaxStackQuantity());
total -= copy.getMaxStackQuantity();
} else {
inventory.query(QueryOperationTypes.ITEM_STACK_IGNORE_QUANTITY.of(copy)).poll(total);
total = 0;
}
}
return underflow;
}
示例2: onItemEquip
import org.spongepowered.api.item.inventory.query.QueryOperationTypes; //导入依赖的package包/类
@Listener
public void onItemEquip(ClickInventoryEvent event, @First Player player, @Getter("getTargetInventory") Inventory inventory) {
if (inventory.getArchetype() == InventoryArchetypes.PLAYER) {
Inventory equipmentSlots = inventory.query(QueryOperationTypes.INVENTORY_TYPE.of(EquipmentSlot.class));
equipmentSlots.slots().forEach(slot -> slot.peek().ifPresent(itemStack -> {
ItemType itemType = itemStack.getType();
String itemId = itemType.getId();
PermHandler ph = PermHandler.getInstance();
if (!ph.checkPerm(player, "protectionperms.item.equip." + itemId + ".on.self")) {
event.setCancelled(true);
player.sendMessage(ChatTypes.ACTION_BAR, Text.of(TextColors.RED, "You don't have permission to equip " + itemType.getName() + '!'));
}
}));
}
}
示例3: onItemCraft
import org.spongepowered.api.item.inventory.query.QueryOperationTypes; //导入依赖的package包/类
@Listener
public void onItemCraft(ClickInventoryEvent event, @First Player player, @Getter("getTargetInventory") Inventory inventory) {
if (inventory.getArchetype() == InventoryArchetypes.PLAYER || inventory.getArchetype() == InventoryArchetypes.WORKBENCH) {
Inventory craftingOutputs = inventory.query(QueryOperationTypes.INVENTORY_TYPE.of(CraftingOutput.class));
craftingOutputs.slots().forEach(slot -> slot.peek().ifPresent(itemStack -> {
ItemType itemType = itemStack.getType();
String itemId = itemType.getId();
PermHandler ph = PermHandler.getInstance();
if (!ph.checkPerm(player, "protectionperms.item.craft." + itemId)) {
event.setCancelled(true);
player.sendMessage(ChatTypes.ACTION_BAR, Text.of(TextColors.RED, "You don't have permission to craft " + itemType.getName() + '!'));
}
}));
}
}
示例4: clearinventory
import org.spongepowered.api.item.inventory.query.QueryOperationTypes; //导入依赖的package包/类
@Command(alias = {"ci", "clear"}, desc = "Clears the inventory")
public void clearinventory(CommandSource context, @Default User player,
@Flag(longName = "removeArmor", name = "ra") boolean removeArmor,
@ParameterPermission(value = "quiet", desc = "Prevents the other player being notified when his inventory got cleared")
@Flag boolean quiet,
@Flag boolean force)
{
//sender.sendTranslated(NEGATIVE, "That awkward moment when you realize you do not have an inventory!");
boolean self = context.getIdentifier().equals(player.getIdentifier());
if (!self)
{
if (!context.hasPermission(COMMAND_CLEARINVENTORY_OTHER.getId()))
{
throw new PermissionDeniedException(COMMAND_CLEARINVENTORY_OTHER);
}
if (player.hasPermission(COMMAND_CLEARINVENTORY_PREVENT.getId())
&& !(force && context.hasPermission(COMMAND_CLEARINVENTORY_FORCE.getId())))
{
i18n.send(context, NEGATIVE, "You are not allowed to clear the inventory of {user}", player);
return;
}
}
player.getInventory().query(QueryOperationTypes.INVENTORY_TYPE.of(InventoryRow.class)).clear();
if (removeArmor)
{
player.getInventory().query(QueryOperationTypes.INVENTORY_TYPE.of(EquipmentInventory.class)).clear();
}
if (self)
{
i18n.send(context, POSITIVE, "Your inventory has been cleared!");
return;
}
if (player.isOnline() && player.hasPermission(COMMAND_CLEARINVENTORY_NOTIFY.getId()) && !quiet)
{
i18n.send(player.getPlayer().get(), NEUTRAL, "Your inventory has been cleared by {sender}!", context);
}
i18n.send(context, POSITIVE, "The inventory of {user} has been cleared!", player);
}
示例5: castToOrdered
import org.spongepowered.api.item.inventory.query.QueryOperationTypes; //导入依赖的package包/类
public static OrderedInventory castToOrdered(Inventory inventory) {
Inventory result = inventory.query(QueryOperationTypes.INVENTORY_TYPE.of(OrderedInventory.class));
if (result instanceof OrderedInventory) {
return (OrderedInventory) result;
}
if (result instanceof EmptyInventory) {
throw new RuntimeException("Inventory can not be casted to Ordered Inventory!");
}
for (Inventory sub_inventory : inventory) {
if (sub_inventory instanceof OrderedInventory) {
return (OrderedInventory) sub_inventory;
}
}
throw new RuntimeException("Inventory can not be casted to Ordered Inventory!");
}
示例6: countItems
import org.spongepowered.api.item.inventory.query.QueryOperationTypes; //导入依赖的package包/类
public int countItems(Inventory i, ItemType type){
int count = 0;
for (Inventory isl : i.query(QueryOperationTypes.ITEM_TYPE.of(type)).slots()){
Slot sl = (Slot) isl;
Optional<ItemStack> ois = sl.peek();
if (ois.isPresent()){
count += ois.get().getQuantity();
}
}
return count;
}
示例7: onItemSmelt
import org.spongepowered.api.item.inventory.query.QueryOperationTypes; //导入依赖的package包/类
@Listener
public void onItemSmelt(ClickInventoryEvent event, @First Player player, @Getter("getTargetInventory") Inventory inventory) {
if (inventory.getArchetype() == InventoryArchetypes.FURNACE) {
Inventory smeltingInputs = inventory.query(QueryOperationTypes.INVENTORY_TYPE.of(InputSlot.class));
PermHandler ph = PermHandler.getInstance();
smeltingInputs.slots().forEach(slot -> slot.peek().ifPresent(itemStack -> {
ItemType itemType = itemStack.getType();
String itemId = itemType.getId();
if (slot instanceof FuelSlot) {
if (!ph.checkPerm(player, "protectionperms.item.fuel." + itemId)) {
event.setCancelled(true);
player.sendMessage(ChatTypes.ACTION_BAR, Text.of(TextColors.RED, "You don't have permission to use " + itemType.getName() + " as fuel!"));
}
} else {
if (!ph.checkPerm(player, "protectionperms.item.smelt." + itemId)) {
event.setCancelled(true);
player.sendMessage(ChatTypes.ACTION_BAR, Text.of(TextColors.RED, "You don't have permission to smelt " + itemType.getName() + '!'));
}
}
}));
}
}
示例8: peekOffer
import org.spongepowered.api.item.inventory.query.QueryOperationTypes; //导入依赖的package包/类
@Override
public PeekedOfferTransactionResult peekOffer(ItemStack itemStack) {
checkNotNull(itemStack, "itemStack");
final PeekedOfferTransactionResult peekResult;
final Set<Inventory> processed = new HashSet<>();
final Inventory inventory = query(QueryOperationTypes.ITEM_STACK_IGNORE_QUANTITY.of(itemStack));
if (inventory instanceof AbstractChildrenInventory) {
peekResult = ((AbstractChildrenInventory) inventory).peekOffer(itemStack, processed, true);
if (peekResult.isSuccess()) {
if (!peekResult.getRejectedItem().isPresent()) {
return peekResult;
}
itemStack = peekResult.getRejectedItem().get();
}
} else {
peekResult = null;
}
final PeekedOfferTransactionResult peekResult1 = peekOffer(itemStack, processed, false);
if (peekResult == null || !peekResult.isSuccess()) {
return peekResult1;
} else if (!peekResult1.isSuccess()) {
return peekResult;
}
return new PeekedOfferTransactionResult(InventoryTransactionResult.Type.SUCCESS,
ImmutableList.<SlotTransaction>builder()
.addAll(peekResult.getTransactions())
.addAll(peekResult1.getTransactions())
.build(),
peekResult1.getRejectedItem().orElse(null));
}
示例9: offerFast
import org.spongepowered.api.item.inventory.query.QueryOperationTypes; //导入依赖的package包/类
@Override
public FastOfferResult offerFast(ItemStack stack) {
checkNotNull(stack, "stack");
final Set<Inventory> processed = new HashSet<>();
final Inventory inventory = query(QueryOperationTypes.ITEM_STACK_IGNORE_QUANTITY.of(stack));
if (inventory instanceof AbstractChildrenInventory) {
final FastOfferResult offerResult = ((AbstractChildrenInventory) inventory).offerFast(stack, processed, true);
final Optional<ItemStack> rejectedItem = offerResult.getRejectedItem();
if (!rejectedItem.isPresent()) {
return offerResult;
}
stack = rejectedItem.get();
}
return offerFast(stack, processed, false);
}
示例10: applyFromPlayer
import org.spongepowered.api.item.inventory.query.QueryOperationTypes; //导入依赖的package包/类
public void applyFromPlayer(Player player)
{
Inventory playerInventory = player.getInventory();
this.heldItemSlot = ((Hotbar)playerInventory.query(QueryOperationTypes.INVENTORY_TYPE.of(Hotbar.class))).getSelectedSlotIndex();
this.maxHealth = player.get(Keys.MAX_HEALTH).get();
this.health = player.get(Keys.HEALTH).get();
this.foodLevel = player.get(Keys.FOOD_LEVEL).get();
this.saturation = player.get(Keys.SATURATION).get();
this.exhaustion = player.get(Keys.EXHAUSTION).get();
this.exp = player.get(Keys.TOTAL_EXPERIENCE).get();
this.fireTicks = player.get(Keys.FIRE_TICKS).orElse(0);
this.activePotionEffects = player.get(Keys.POTION_EFFECTS).orElse(emptyList());
this.inventory = new HashMap<>();
int i = 0;
for (Inventory slot : playerInventory.slots())
{
Optional<ItemStack> item = slot.peek();
if (item.isPresent())
{
this.inventory.put(i, item.get());
}
i++;
}
this.enderChest = new HashMap<>();
/* TODO EnderChest
i = 0;
for (Inventory slot : player.getEnderChest().slots())
{
Optional<ItemStack> item = slot.peek();
if (item.isPresent())
{
this.enderChest.put(i, item.get());
}
i++;
}
*/
this.gameMode = player.get(Keys.GAME_MODE).get();
}
示例11: queryFiltered
import org.spongepowered.api.item.inventory.query.QueryOperationTypes; //导入依赖的package包/类
private Inventory queryFiltered(List<ItemStack> filters, Inventory inventory) {
if (filters.isEmpty()) {
return inventory;
}
QueryOperation[] ops = new QueryOperation[filters.size()];
for (int i = 0; i < filters.size(); i++) {
ItemStack filter = filters.get(i);
ops[i] = QueryOperationTypes.ITEM_STACK_IGNORE_QUANTITY.of(filter);
}
return inventory.query(ops);
}
示例12: listen
import org.spongepowered.api.item.inventory.query.QueryOperationTypes; //导入依赖的package包/类
@Listener
public void listen(ClickInventoryEvent event)
{
List<SlotTransaction> upperTransactions = new ArrayList<>();
int upperSize = event.getTargetInventory().iterator().next().capacity();
for (SlotTransaction transaction : event.getTransactions())
{
Integer affectedSlot = transaction.getSlot().getInventoryProperty(SlotIndex.class).map(SlotIndex::getValue).orElse(-1);
boolean upper = affectedSlot != -1 && affectedSlot < upperSize;
if (upper)
{
upperTransactions.add(transaction);
}
}
Inventory te = event.getTargetInventory().query(QueryOperationTypes.TYPE.of(BlockCarrier.class));
if (!(te instanceof BlockCarrier))
{
te = te.first();
}
if (te instanceof BlockCarrier)
{
Action action = this.observe(event);
action.addData(INVENTORY_CHANGES, Observe.transactions(upperTransactions));
action.addData(Report.LOCATION, Observe.location(((BlockCarrier) te).getLocation()));
this.report(action);
}
}
示例13: QueryOperationRegistryModule
import org.spongepowered.api.item.inventory.query.QueryOperationTypes; //导入依赖的package包/类
public QueryOperationRegistryModule() {
super(QueryOperationTypes.class);
}
示例14: applyToPlayer
import org.spongepowered.api.item.inventory.query.QueryOperationTypes; //导入依赖的package包/类
public void applyToPlayer(Player player)
{
Inventory inv = player.getInventory();
((Hotbar)inv.query(QueryOperationTypes.INVENTORY_TYPE.of(Hotbar.class))).setSelectedSlotIndex(heldItemSlot);
player.offer(Keys.MAX_HEALTH, maxHealth);
player.offer(Keys.HEALTH, health);
player.offer(Keys.FOOD_LEVEL, foodLevel);
player.offer(Keys.SATURATION, saturation);
player.offer(Keys.EXHAUSTION, exhaustion);
player.offer(Keys.TOTAL_EXPERIENCE, exp);
if (fireTicks != 0)
{
player.offer(Keys.FIRE_TICKS, fireTicks);
}
player.remove(Keys.POTION_EFFECTS);
player.offer(Keys.POTION_EFFECTS, activePotionEffects);
int i = 0;
for (Inventory slot : inv.slots())
{
ItemStack item = inventory.get(i);
if (item != null)
{
slot.set(item);
}
else
{
slot.clear();
}
i++;
}
/* TODO EnderChet
i = 0;
for (Inventory slot : player.getEnderChest().slots())
{
ItemStack item = enderChest.get(i);
if (item != null)
{
slot.set(item);
}
else
{
slot.clear();
}
i++;
}
*/
player.offer(Keys.GAME_MODE, gameMode);
}
示例15: key
import org.spongepowered.api.item.inventory.query.QueryOperationTypes; //导入依赖的package包/类
@Alias(value = "ckey")
@Command(desc = "creates a KeyBook or invalidates previous KeyBooks")
@Restricted(value = Player.class, msg = "This command can only be used in game")
public void key(Player context, @Flag boolean invalidate, @Flag boolean persist)
{
if (!this.module.getConfig().allowKeyBooks)
{
i18n.send(context, NEGATIVE, "KeyBooks are deactivated!");
return;
}
if (persist)
{
this.persist(context);
}
if (invalidate)
{
this.manager.commandListener.submitLockAction(context, (lock, loc, entity) -> {
if (!lock.isOwner(context))
{
i18n.send(context, NEGATIVE, "This is not your protection!");
return;
}
if (lock.hasPass())
{
i18n.send(context, NEUTRAL, "You cannot invalidate KeyBooks for password protected locks.");
i18n.send(context, POSITIVE, "Change the password to invalidate them!");
return;
}
lock.invalidateKeyBooks();
Optional<TileEntity> te = loc.getTileEntity();
if (te.isPresent() && te.get() instanceof Carrier)
{
// TODO check if this is working
Sponge.getCauseStackManager().pushCause(context);
((Carrier) te.get()).getInventory().<Container>query(QueryOperationTypes.INVENTORY_TYPE.of(Container.class)).getViewers().forEach(Player::closeInventory);
}
});
i18n.send(context, POSITIVE, "Right click a protection to invalidate old KeyBooks for it!");
return;
}
this.manager.commandListener.submitLockAction(context, (lock, loc, entity) -> {
if (!lock.isOwner(context) && !context.hasPermission(module.perms().CMD_KEY_OTHER.getId()))
{
i18n.send(context, NEGATIVE, "This is not your protection!");
return;
}
if (lock.isPublic())
{
i18n.send(context, NEUTRAL, "This protection is public!");
return;
}
lock.attemptCreatingKeyBook(context, true);
});
i18n.send(context, POSITIVE, "Right click a protection to with a book to create a new KeyBook!");
}