本文整理汇总了Java中org.spongepowered.api.item.inventory.query.QueryOperationTypes类的典型用法代码示例。如果您正苦于以下问题:Java QueryOperationTypes类的具体用法?Java QueryOperationTypes怎么用?Java QueryOperationTypes使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
QueryOperationTypes类属于org.spongepowered.api.item.inventory.query包,在下文中一共展示了QueryOperationTypes类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:Zerthick,项目名称:PlayerShopsRPG,代码行数:24,代码来源:InventoryUtils.java
示例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() + '!'));
}
}));
}
}
开发者ID:Zerthick,项目名称:ProtectionPerms,代码行数:22,代码来源:EquipItemListener.java
示例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() + '!'));
}
}));
}
}
开发者ID:Zerthick,项目名称:ProtectionPerms,代码行数:22,代码来源:CraftItemListener.java
示例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);
}
开发者ID:CubeEngine,项目名称:modules-main,代码行数:39,代码来源:ClearInventoryCommand.java
示例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!");
}
开发者ID:GreWeMa,项目名称:gwm_Crates,代码行数:16,代码来源:Utils.java
示例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;
}
开发者ID:TBlueF,项目名称:RottenFood,代码行数:14,代码来源:RottenFood.java
示例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() + '!'));
}
}
}));
}
}
开发者ID:Zerthick,项目名称:ProtectionPerms,代码行数:29,代码来源:SmeltItemListener.java
示例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));
}
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:31,代码来源:AbstractChildrenInventory.java
示例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);
}
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:16,代码来源:AbstractChildrenInventory.java
示例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();
}
开发者ID:CubeEngine,项目名称:modules-main,代码行数:41,代码来源:PlayerData.java
示例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);
}
开发者ID:CubeEngine,项目名称:modules-extra,代码行数:12,代码来源:Network.java
示例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);
}
}
开发者ID:CubeEngine,项目名称:modules-extra,代码行数:29,代码来源:ChangeInventoryReport.java
示例13: QueryOperationRegistryModule
import org.spongepowered.api.item.inventory.query.QueryOperationTypes; //导入依赖的package包/类
public QueryOperationRegistryModule() {
super(QueryOperationTypes.class);
}
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:4,代码来源:QueryOperationRegistryModule.java
示例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);
}
开发者ID:CubeEngine,项目名称:modules-main,代码行数:53,代码来源:PlayerData.java
示例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!");
}
开发者ID:CubeEngine,项目名称:modules-main,代码行数:56,代码来源:LockerCommands.java
示例16: executeBuy
import org.spongepowered.api.item.inventory.query.QueryOperationTypes; //导入依赖的package包/类
private void executeBuy(MarketSignData data, Player player, UniqueAccount account)
{
if (!player.hasPermission(module.perms().INTERACT_BUY.getId()))
{
i18n.send(ACTION_BAR, player, NEGATIVE, "You are not allowed to use buy market signs!");
return;
}
if (data.getStock() != null && data.getStock() < data.getAmount())
{
i18n.send(ACTION_BAR, player, NEGATIVE, "This market sign is {text:Sold Out:color=DARK_RED}!");
return;
}
if (account.withdraw(es.getDefaultCurrency(), getPrice(data), Cause.of(EventContext.empty(), player)).getResult() != ResultType.SUCCESS)
{
i18n.send(ACTION_BAR, player, NEGATIVE, "You can't afford these items!");
return;
}
ItemStack copy = data.getItem().copy();
copy.setQuantity(data.getAmount());
player.getInventory().offer(copy);
int remaining = copy.getQuantity();
if (remaining != 0)
{
player.getInventory().query(QueryOperationTypes.ITEM_STACK_IGNORE_QUANTITY.of(copy)).poll(data.getAmount() - remaining);
i18n.send(ACTION_BAR, player, NEGATIVE, "You don't have enough space in your inventory for these items!");
return;
}
if (!data.isAdminOwner())
{
es.getOrCreateAccount(data.getOwner()).get().deposit(es.getDefaultCurrency(), getPrice(data), Cause.of(EventContext.empty(), player));
}
if (data.getStock() != null)
{
data.setStock(data.getStock() - data.getAmount());
}
i18n.send(player, POSITIVE, "You bought {amount}x {input#item} for {txt#price}.",
data.getAmount(), data.getItem().getTranslation(), formatPrice(data));
}
开发者ID:CubeEngine,项目名称:modules-extra,代码行数:46,代码来源:MarketSignManager.java
示例17: executeFill
import org.spongepowered.api.item.inventory.query.QueryOperationTypes; //导入依赖的package包/类
private void executeFill(MarketSignData data, Player player, ItemStack item, Location<World> loc, boolean all)
{
//all
if ((data.isAdminOwner() || !data.isOwner(player.getUniqueId()))
&& !player.hasPermission(module.perms().EDIT_PLAYER_OTHER.getId()) ||
data.getSignType() == SignType.SELL)
{
return;
}
if (isInEditMode(loc))
{
// TODO viewers of inventory?
i18n.send(ACTION_BAR, player, NEGATIVE, "This signs inventory is being edited right now!");
return;
}
ItemStack copy = item.copy();
int quantity = item.getQuantity();
if (all)
{
Inventory slots = player.getInventory().query(QueryOperationTypes.ITEM_STACK_IGNORE_QUANTITY.of(copy));
quantity = slots.totalItems();
}
if (data.getMax() != -1)
{
int max = data.getMax() - data.getStock();
if (quantity > max)
{
quantity = max;
i18n.send(ACTION_BAR, player, NEGATIVE, "The market sign cannot hold all your items!");
}
if (max <= 0)
{
i18n.send(ACTION_BAR, player, NEGATIVE, "The market sign inventory is full!");
return;
}
}
data.setStock(data.getStock() + quantity);
if (all)
{
player.getInventory().query(QueryOperationTypes.ITEM_STACK_IGNORE_QUANTITY.of(copy)).poll(quantity);
i18n.send(ACTION_BAR, player, POSITIVE, "Added all ({amount}) {name#material} to the stock!", quantity,
item.getTranslation().get(player.getLocale()));
}
else
{
item.setQuantity(item.getQuantity() - quantity);
player.setItemInHand(HandTypes.MAIN_HAND, item.getQuantity() == 0 ? null : item);
i18n.send(ACTION_BAR, player, POSITIVE, "Added {amount}x {name#material} to the stock!", quantity,
item.getTranslation().get(player.getLocale()));
}
}
开发者ID:CubeEngine,项目名称:modules-extra,代码行数:54,代码来源:MarketSignManager.java
示例18: giveSelectionTool
import org.spongepowered.api.item.inventory.query.QueryOperationTypes; //导入依赖的package包/类
public void giveSelectionTool(Player user)
{
ItemStack found = null;
Inventory axes = user.getInventory().query(QueryOperationTypes.ITEM_TYPE.of(ItemTypes.WOODEN_AXE));
for (Inventory slot : axes.slots())
{
Optional<ItemStack> itemStack = slot.peek();
if (itemStack.isPresent())
{
Optional<Text> display = itemStack.get().get(Keys.DISPLAY_NAME);
if (display.isPresent())
{
if ("Selector-Tool".equals(display.get().toPlain()))
{
found = itemStack.get();
slot.clear();
break;
}
}
}
}
Optional<ItemStack> itemInHand = user.getItemInHand(HandTypes.MAIN_HAND);
if (found == null)
{
found = game.getRegistry().createBuilder(ItemStack.Builder.class).itemType(COAL).quantity(1).build();
found.offer(COAL_TYPE, CoalTypes.CHARCOAL);
found.offer(ITEM_ENCHANTMENTS, Arrays.asList(Enchantment.builder().type(EnchantmentTypes.BINDING_CURSE).level(1).build()));
found.offer(DISPLAY_NAME, Text.of(TextColors.BLUE, "Selector-Tool"));
found.offer(ITEM_LORE, Arrays.asList(Text.of("created by ", user.getName())));
user.setItemInHand(HandTypes.MAIN_HAND, found);
if (itemInHand.isPresent())
{
if (user.getInventory().offer(itemInHand.get()).getType() != InventoryTransactionResult.Type.SUCCESS)
{
SpawnUtil.spawnItem(itemInHand.get(), user.getLocation());
}
}
i18n.send(user, POSITIVE, "Received a new region selector tool");
return;
}
user.setItemInHand(HandTypes.MAIN_HAND, found);
itemInHand.ifPresent(stack -> user.getInventory().offer(stack));
i18n.send(user, POSITIVE, "Found a region selector tool in your inventory!");
}
开发者ID:CubeEngine,项目名称:modules-extra,代码行数:48,代码来源:SelectorCommand.java
示例19: playerInteract
import org.spongepowered.api.item.inventory.query.QueryOperationTypes; //导入依赖的package包/类
@Listener
public void playerInteract(final InteractBlockEvent.Secondary event, @First Player player)
{
if (!player.getItemInHand(HandTypes.MAIN_HAND).map(i -> i.getType().equals(ItemTypes.FEATHER)).orElse(false))
{
return;
}
if (!player.hasPermission(FLY_FEATHER.getId()))
{
i18n.send(player, NEGATIVE, "You dont have permission to use this!");
player.offer(Keys.CAN_FLY, false); //Disable when player is flying
player.offer(Keys.IS_FLYING, false);
return;
}
//I Believe I Can Fly ...
player.offer(Keys.CAN_FLY, !player.get(Keys.CAN_FLY).get());
if (player.get(Keys.CAN_FLY).get())
{
final ItemStack feather = ItemStack.of(ItemTypes.FEATHER, -1);
player.getInventory().query(QueryOperationTypes.ITEM_STACK_IGNORE_QUANTITY.of(feather)).poll(1);
player.setVelocity(player.getVelocity().add(0, 1, 0));
player.setLocation(player.getLocation().add(0, 0.05, 0)); //make sure the player stays flying
player.offer(Keys.IS_FLYING, true);
i18n.send(player, POSITIVE, "You can now fly!");
Task flymore = new Task(Fly.class, tm)
{
public void run()//2 feather/min
{
if (!player.get(Keys.IS_FLYING).get())
{
player.offer(Keys.CAN_FLY, false);
this.cancelTask();
return;
}
if (player.getInventory().contains(ItemTypes.FEATHER))
{
player.getInventory().query(feather).poll(1);
}
else
{
player.offer(Keys.CAN_FLY, false);
this.cancelTask();
}
}
};
flymore.scheduleAsyncRepeatingTask(1000 * 30, 1000 * 30);
Task oldTask = this.tasks.put(player, flymore);
if (oldTask != null)
{
oldTask.cancelTask();
}
}
else
{//or not
player.offer(Keys.FALL_DISTANCE, 0f);
i18n.send(player, NEUTRAL, "You cannot fly anymore!");
}
}
开发者ID:CubeEngine,项目名称:modules-extra,代码行数:61,代码来源:FlyListener.java
示例20: repair
import org.spongepowered.api.item.inventory.query.QueryOperationTypes; //导入依赖的package包/类
public void repair(RepairRequest request)
{
double price = request.getPrice();
RepairBlockInventory inventory = request.getInventory();
Player player = inventory.player;
if (withdrawPlayer(player, price))
{
boolean itemsBroken = false;
boolean repairFail = false;
boolean looseEnch = false;
ItemStack item;
int amount;
for (Map.Entry<Integer, ItemStack> entry : request.getItems().entrySet())
{
item = entry.getValue();
if (this.rand.nextInt(100) >= this.config.breakPercentage)
{
if (this.rand.nextInt(100) >= this.config.failPercentage)
{
repairItem(entry.getValue());
}
else
{
repairFail = true;
}
Optional<List<Enchantment>> enchs = entry.getValue().get(Keys.ITEM_ENCHANTMENTS);
if (enchs.isPresent() && !enchs.get().isEmpty())
{
if (this.rand.nextInt(100) < this.config.looseEnchantmentsPercentage)
{
looseEnch = true;
entry.getValue().remove(Keys.ITEM_ENCHANTMENTS);
}
}
}
else
{
itemsBroken = true;
amount = item.getQuantity();
item.setQuantity(amount - 1);
repairItem(item);
}
inventory.inventory.query(QueryOperationTypes.INVENTORY_PROPERTY.of(SlotIndex.of(entry.getKey()))).set(entry.getValue());
}
if (itemsBroken)
{
i18n.send(player, NEGATIVE, "You broke some of your items when repairing!");
player.playSound(BLOCK_ANVIL_BREAK, player.getLocation().getPosition(), 1, 0);
}
if (repairFail)
{
i18n.send(player, NEGATIVE, "You failed to repair some of your items!");
player.playSound(ENTITY_PLAYER_BURP,player.getLocation().getPosition(), 1,0);
}
if (looseEnch)
{
i18n.send(player, NEGATIVE, "Oh no! Some of your items lost their magical power.");
player.playSound(SoundTypes.ENTITY_GHAST_SCREAM, player.getLocation().getPosition(), 1);
}
i18n.send(player, POSITIVE, "You paid {txt#amount} to repair your items!", economy.getDefaultCurrency().format(new BigDecimal(price)));
if (this.config.costPercentage > 100)
{
i18n.send(player, POSITIVE, "Thats {decimal#percent:2}% of the normal price!", this.config.costPercentage);
}
else if (this.config.costPercentage < 100)
{
i18n.send(player, POSITIVE, "Thats {decimal#percent:2}% less then the normal price!", 100 - this.config.costPercentage);
}
}
else
{
i18n.send(player, NEGATIVE, "You don't have enough money to repair these items!");
}
}
开发者ID:CubeEngine,项目名称:modules-extra,代码行数:75,代码来源:RepairBlock.java
注:本文中的org.spongepowered.api.item.inventory.query.QueryOperationTypes类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论