本文整理汇总了Java中org.spongepowered.api.event.item.inventory.ClickInventoryEvent.setCancelled方法的典型用法代码示例。如果您正苦于以下问题:Java ClickInventoryEvent.setCancelled方法的具体用法?Java ClickInventoryEvent.setCancelled怎么用?Java ClickInventoryEvent.setCancelled使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.spongepowered.api.event.item.inventory.ClickInventoryEvent
的用法示例。
在下文中一共展示了ClickInventoryEvent.setCancelled方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onClickInventory
import org.spongepowered.api.event.item.inventory.ClickInventoryEvent; //导入方法依赖的package包/类
@Listener
public void onClickInventory(final ClickInventoryEvent event, @First Player player) {
//Make sure we have a transaction to validate
if (event.getTransactions().size() <= 0) {
return;
}
//Get the first transaction of this event
final SlotTransaction slotTransaction = event.getTransactions().get(0);
final Slot slot = slotTransaction.getSlot();
//If the player is interacting with a TileEntityCarrier
if (slot.parent() instanceof TileEntityCarrier) {
//If the final item is NONE (or amount is less) person is trying to withdraw (so we care about it)
if (slotTransaction.getFinal().getType() == ItemTypes.NONE || slotTransaction.getFinal().getCount() < slotTransaction.getOriginal().getCount()) {
//Then check to see if there's a lock
final Optional<Lock> lock = Latch.getLockManager().getLock(((TileEntityCarrier) slot.parent()).getLocation());
//If there's a donation lock the player CANNOT access
if (lock.isPresent() && lock.get().getLockType() == LockType.DONATION && !lock.get().canAccess(player.getUniqueId())) {
event.setCancelled(true);
}
}
}
}
示例2: onInteract
import org.spongepowered.api.event.item.inventory.ClickInventoryEvent; //导入方法依赖的package包/类
@Listener
@Exclude({ClickInventoryEvent.Close.class, ClickInventoryEvent.Open.class})
public void onInteract(ClickInventoryEvent event, @Root Player p) {
try {
//Get target inventory owner
Inventory inv = event.getTargetInventory();
if (!(inv instanceof CarriedInventory)) return;
CarriedInventory cinv = (CarriedInventory) inv;
if (!cinv.getCarrier().isPresent() || !(cinv.getCarrier().get() instanceof User)) return;
User t = (User) cinv.getCarrier().get();
//Check if player is in invsee & Cancel event if player doesn't have permission
UltimateUser up = UltimateCore.get().getUserService().getUser(p);
if (up.get(InventoryKeys.INVSEE_TARGET).isPresent() && up.get(InventoryKeys.INVSEE_TARGET).get().equals(t.getUniqueId())) {
if (!p.hasPermission("uc.inventory.invsee.modify")) {
event.getCursorTransaction().setValid(false);
event.setCancelled(true);
}
}
} catch (Exception ignore) {
}
}
示例3: cancelClick
import org.spongepowered.api.event.item.inventory.ClickInventoryEvent; //导入方法依赖的package包/类
@Listener(order = Order.LATE)
public void cancelClick(ClickInventoryEvent event) {
Container container = event.getTargetInventory();
if (FirstGuiPreview.FIRST_GUI_CONTAINERS.containsKey(container) ||
SecondGuiPreview.SECOND_GUI_CONTAINERS.containsKey(container)) {
event.setCancelled(true);
}
}
示例4: cancelClick
import org.spongepowered.api.event.item.inventory.ClickInventoryEvent; //导入方法依赖的package包/类
@Listener(order = Order.LATE)
public void cancelClick(ClickInventoryEvent event) {
Container container = event.getTargetInventory();
if (FirstOpenManager.FIRST_GUI_CONTAINERS.containsKey(container)) {
event.setCancelled(true);
}
}
示例5: fireClickEvent
import org.spongepowered.api.event.item.inventory.ClickInventoryEvent; //导入方法依赖的package包/类
private void fireClickEvent(ClickInventoryEvent e)
{
Optional<Player> optional = Sponge.getServer().getPlayer(playerUniqueId);
if (!optional.isPresent())
{
return;
}
Player player = optional.get();
CompletableFuture<Boolean> future = CompletableFuture.completedFuture(Boolean.TRUE);
for (SlotTransaction slotTransaction : e.getTransactions())
{
Slot slot = slotTransaction.getSlot();
SlotIndex pos = SpongeUnimplemented.getSlotOrdinal(slot);
if (SpongeUnimplemented.isSlotInInventory(slot, e.getTargetInventory()) && slotToListen.matches(pos))
{
e.setCancelled(true);
boolean allowAction = actionIntervalManager.allowAction(player, acceptableActionIntervalTick);
if (allowAction && itemsInSlots.containsKey(pos))
{
future = future.thenApplyAsync(p -> processClickEvent(e, player, pos) && p, executorService);
}
}
}
future.thenAccept(shouldKeepInventoryOpen ->
{
if (!shouldKeepInventoryOpen)
{
SpongeUnimplemented.closeInventory(player, plugin);
}
});
}
示例6: onInventoryClick
import org.spongepowered.api.event.item.inventory.ClickInventoryEvent; //导入方法依赖的package包/类
@Listener
public void onInventoryClick(ClickInventoryEvent event){
if (event.getTargetInventory().getName().get().equals(this.inv.getName().get())) {
if (event.getTransactions().size() > 0) {
Transaction<ItemStackSnapshot> clickTransaction = event.getTransactions().get(0);
ItemStack item = clickTransaction.getOriginal().createStack();
if (!item.getItem().equals(ItemTypes.NONE) && item.get(Keys.ITEM_LORE).isPresent()){
String flag = item.get(Keys.ITEM_LORE).get().get(1).toPlain().replace("§0", "");
if (RedProtect.get().cfgs.getDefFlags().contains(flag)){
if (RedProtect.get().cfgs.getBool("flags-configuration.change-flag-delay.enable")){
if (RedProtect.get().cfgs.getStringList("flags-configuration.change-flag-delay.flags").contains(flag)){
if (!RedProtect.get().changeWait.contains(this.region.getName()+flag)){
applyFlag(flag, item, event);
RPUtil.startFlagChanger(this.region.getName(), flag, this.player);
} else {
RPLang.sendMessage(player,RPLang.get("gui.needwait.tochange").replace("{seconds}", RedProtect.get().cfgs.getString("flags-configuration.change-flag-delay.seconds")));
event.setCancelled(true);
}
return;
} else {
applyFlag(flag, item, event);
return;
}
} else {
applyFlag(flag, item, event);
return;
}
}
event.setCancelled(true);
}
}
}
}
示例7: acceptsEvent
import org.spongepowered.api.event.item.inventory.ClickInventoryEvent; //导入方法依赖的package包/类
@Override
protected boolean acceptsEvent(ClickInventoryEvent event) {
if (event instanceof Shift.Primary || event instanceof Shift.Secondary) {
return getConsumedItemStacks(event.getTransactions()).size() > 1;
} else if (event instanceof Primary || event instanceof Secondary) {
if (event.getCursorTransaction().getFinal() == null) {
return false;
}
if (event.getTransactions().size() >= 2) {
//It is not possible to craft anymore items because
//at least one crafting ingredient got completely consumed.
return true;
} else if (event.getTransactions().size() >= 1) {
Set<ItemStack> consumedStacks = getConsumedItemStacks(event.getTransactions());
//An item stack was placed from the cursor into the inventory
if (consumedStacks.size() == 0) {
return false;
}
ItemStack consumed = consumedStacks.iterator().next();
ItemStack created = event.getCursorTransaction().getFinal().createStack();
return !(ItemStackComparators.ALL.compare(consumed, created) == 0);
}
} else if (event instanceof NumberPress || event instanceof Drop.Single) {
//Ugly, but it's the only thing that works
event.setCancelled(true);
}
return false;
}
示例8: accept
import org.spongepowered.api.event.item.inventory.ClickInventoryEvent; //导入方法依赖的package包/类
@Override
public void accept(ClickInventoryEvent event) {
Optional<Player> clicker = event.getCause().first(Player.class);
if (!clicker.isPresent()) return;
if (!VillagerShops.openShops.containsKey(clicker.get().getUniqueId())) return;
if (VillagerShops.actionUnstack.contains(clicker.get().getUniqueId())) {
event.getTransactions().forEach(action -> { action.setValid(false); });
event.getCursorTransaction().setCustom(ItemStackSnapshot.NONE);
event.getCursorTransaction().setValid(false);
event.setCancelled(true);
return;
}
int slotIndex=-1;
//thanks for this great API so far *eyes rolling*
//Inventory target = event.getTargetInventory().query(OrderedInventory.class); //not working
//items we added hold a slotum value, so we can simply check for that and retrieve the correct slot
//props to codeHusky for figuring the slotnum workaround...
Optional<Object> unsafeslot = event.getCursorTransaction().getDefault().toContainer().get(DataQuery.of("UnsafeData", "vShopSlotNum"));
if (unsafeslot.isPresent()) {
slotIndex = (int)unsafeslot.get();
}
//clear cursor
event.getCursorTransaction().setValid(false);
event.getCursorTransaction().setCustom(ItemStackSnapshot.NONE);
event.getTransactions().forEach(action -> { action.setValid(false); });
if (slotIndex >= 0) {
InteractionHandler.clickInventory(clicker.get(), slotIndex);
Sponge.getScheduler().createSyncExecutor(VillagerShops.getInstance())
.schedule(() -> {
VillagerShops.actionUnstack.remove(clicker.get().getUniqueId());
}, 50, TimeUnit.MILLISECONDS);
}
event.setCancelled(true);
}