当前位置: 首页>>代码示例>>Java>>正文


Java Cancellable类代码示例

本文整理汇总了Java中org.spongepowered.api.event.Cancellable的典型用法代码示例。如果您正苦于以下问题:Java Cancellable类的具体用法?Java Cancellable怎么用?Java Cancellable使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Cancellable类属于org.spongepowered.api.event包,在下文中一共展示了Cancellable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onInternalEvent

import org.spongepowered.api.event.Cancellable; //导入依赖的package包/类
@Listener
public void onInternalEvent(Event evt) {
    InternalScriptEvent event = (InternalScriptEvent) clone();
    event.internal = evt;
    event.event_type = new TextTag(evt.getClass().getTypeName());
    if (evt instanceof Cancellable) {
        event.cancelled = ((Cancellable) evt).isCancelled();
    }
    else {
        event.cancelled = false;
    }
    // TODO: Decipher cause system, allow cause tracking here
    /*
    Map<String, Object> causes = evt.getCause().getContext().;
    event.cause = new MapTag();
    for (Map.Entry<String, Object> tc : causes.entrySet()) {
        event.cause.getInternal().put(tc.getKey(), new TextTag(tc.getValue().toString()));
    }
    */
    event.run();
    if (evt instanceof Cancellable) {
        ((Cancellable) evt).setCancelled(event.cancelled);
    }
}
 
开发者ID:DenizenScript,项目名称:Denizen2Sponge,代码行数:25,代码来源:InternalScriptEvent.java

示例2: callEventAsync

import org.spongepowered.api.event.Cancellable; //导入依赖的package包/类
@Override
public <T extends Event> Future<T> callEventAsync(final T event, final UUID target) {
    if (event instanceof Returnable || event instanceof Cancellable) {
        return pool.submit(new Callable<T>() {
            @Override
            public T call() throws Exception {
                EventPacket packet = new EventPacket(nodeClient.getConnectionInfo().getUuid(), event, target, true);
                nodeClient.writePacket(packet);
                final BlockingQueue<T> packetBlockingQueue = new SynchronousQueue<T>();
                callbackEvents.put(packet.getEventId(), (BlockingQueue<Event>) packetBlockingQueue);
                return packetBlockingQueue.take();
            }
        });
    }
    else {
        return pool.submit(new Callable<T>() {
            @Override
            public T call() throws Exception {
                nodeClient.writePacket(new EventPacket(nodeClient.getConnectionInfo().getUuid(), event, target, false));
                return event;
            }
        });
    }
}
 
开发者ID:thomas15v,项目名称:CrossEvents,代码行数:25,代码来源:EventService.java

示例3: post

import org.spongepowered.api.event.Cancellable; //导入依赖的package包/类
private boolean post(Event event, Collection<RegisteredListener<?>> listeners,
        ThrowableConsumer<RegisteredListener, Exception> handler) {
    checkNotNull(event, "event");
    final CauseStack causeStack = CauseStack.currentOrEmpty();
    for (RegisteredListener listener : listeners) {
        // Add the calling plugin to the cause stack
        causeStack.pushCause(listener.getPlugin());
        try (CauseStack.Frame ignored = causeStack.pushCauseFrame()) {
            if (event instanceof AbstractEvent) {
                ((AbstractEvent) event).currentOrder = listener.getOrder();
            }
            handler.accept(listener);
        } catch (Throwable e) {
            this.logger.error("Could not pass {} to {}", event.getClass().getSimpleName(),
                    listener.getPlugin(), e);
        }
        causeStack.popCause();
    }
    if (event instanceof AbstractEvent) {
        ((AbstractEvent) event).currentOrder = null;
    }
    return event instanceof Cancellable && ((Cancellable) event).isCancelled();
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:24,代码来源:LanternEventManager.java

示例4: write

import org.spongepowered.api.event.Cancellable; //导入依赖的package包/类
@Override
public int write(String name, ClassWriter cw, MethodVisitor mv, Method method, int locals) {
    if (this.state == Tristate.UNDEFINED) {
        return locals;
    }
    if (!Cancellable.class.isAssignableFrom(method.getParameters()[0].getType())) {
        throw new IllegalStateException("Attempted to filter a non-cancellable event type by its cancellation status");
    }
    mv.visitVarInsn(ALOAD, 1);
    mv.visitTypeInsn(CHECKCAST, Type.getInternalName(Cancellable.class));
    mv.visitMethodInsn(INVOKEINTERFACE, Type.getInternalName(Cancellable.class), "isCancelled", "()Z", true);
    Label success = new Label();
    if (this.state == Tristate.TRUE) {
        mv.visitJumpInsn(IFNE, success);
    } else {
        mv.visitJumpInsn(IFEQ, success);
    }
    mv.visitInsn(ACONST_NULL);
    mv.visitInsn(ARETURN);
    mv.visitLabel(success);
    return locals;
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:23,代码来源:CancellationEventFilterDelegate.java

示例5: createFor

import org.spongepowered.api.event.Cancellable; //导入依赖的package包/类
private PlayerCombatParser createFor(Cancellable event) {
  return new PlayerCombatParser() {
    @Override
    public void processPvP(Player attacker, Player defender) {
      Optional<PvPService> optService = Sponge.getServiceManager().provide(PvPService.class);
      if (optService.isPresent()) {
        PvPService service = optService.get();
        if (service.getPvPState(attacker).allowByDefault() && service.getPvPState(defender).allowByDefault()) {
          return;
        }
      }

      attacker.sendMessage(Text.of(TextColors.RED, "PvP is opt-in only in build worlds!"));

      event.setCancelled(true);
    }
  };
}
 
开发者ID:Skelril,项目名称:Skree,代码行数:19,代码来源:BuildWorldWrapper.java

示例6: createFor

import org.spongepowered.api.event.Cancellable; //导入依赖的package包/类
private PlayerCombatParser createFor(Cancellable event) {
  return new PlayerCombatParser() {
    @Override
    public void processPvP(Player attacker, Player defender) {
      if (pactMap.getOrDefault(attacker.getUniqueId(), new ArrayList<>()).contains(defender.getUniqueId())) {
        if (hasPactScroll(attacker) && hasPactScroll(defender)) {
          event.setCancelled(true);
        }
      } else if (pactMap.getOrDefault(defender.getUniqueId(), new ArrayList<>()).contains(attacker.getUniqueId())) {
        if (hasPactScroll(attacker) && hasPactScroll(defender)) {
          event.setCancelled(true);
          pactMap.get(defender.getUniqueId()).remove(attacker.getUniqueId());

          defender.sendMessage(Text.of(TextColors.DARK_RED, "Your pact with ", attacker.getName(), " has been broken!"));
        }
      }
    }
  };
}
 
开发者ID:Skelril,项目名称:Skree,代码行数:20,代码来源:PactScroll.java

示例7: createFor

import org.spongepowered.api.event.Cancellable; //导入依赖的package包/类
private PlayerCombatParser createFor(Cancellable event) {
  return new PlayerCombatParser() {
    @Override
    public void processPvP(Player attacker, Player defender) {
      Optional<PvPService> optService = Sponge.getServiceManager().provide(PvPService.class);
      if (optService.isPresent()) {
        PvPService service = optService.get();
        if (service.getPvPState(attacker).allowByDefault() && service.getPvPState(defender).allowByDefault()) {
          return;
        }
      }

      attacker.sendMessage(Text.of(TextColors.RED, "PvP is opt-in only in this area!"));

      event.setCancelled(true);
    }
  };
}
 
开发者ID:Skelril,项目名称:Skree,代码行数:19,代码来源:ZonePvPListener.java

示例8: createFor

import org.spongepowered.api.event.Cancellable; //导入依赖的package包/类
private PlayerCombatParser createFor(Cancellable event, JungleRaidInstance inst) {
  return new PlayerCombatParser() {
    @Override
    public void processPvP(Player attacker, Player defender) {
      if (inst.getState() != JungleRaidState.IN_PROGRESS) {
        attacker.sendMessage(Text.of(TextColors.RED, "You can't attack players right now!"));
        event.setCancelled(true);
        return;
      }

      if (inst.isFriendlyFire(attacker, defender)) {
        attacker.sendMessage(Text.of(TextColors.RED, "Don't hit your team mates!"));
        event.setCancelled(true);
        return;
      }

      if (event instanceof DamageEntityEvent) {
        inst.recordAttack(attacker, defender);

        attacker.sendMessage(Text.of(TextColors.YELLOW, "You've hit ", defender.getName(), "!"));
      }
    }
  };
}
 
开发者ID:Skelril,项目名称:Skree,代码行数:25,代码来源:JungleRaidListener.java

示例9: createFor

import org.spongepowered.api.event.Cancellable; //导入依赖的package包/类
private PlayerCombatParser createFor(Cancellable event, SkyWarsInstance inst) {
  return new PlayerCombatParser() {
    @Override
    public void processPvP(Player attacker, Player defender, @Nullable Entity indirectSource) {
      if (inst.getState() != SkyWarsState.IN_PROGRESS) {
        attacker.sendMessage(Text.of(TextColors.RED, "You can't attack players right now!"));
        event.setCancelled(true);
        return;
      }

      if (inst.isFriendlyFire(attacker, defender)) {
        attacker.sendMessage(Text.of(TextColors.RED, "Don't hit your team mates!"));
        event.setCancelled(true);
        return;
      }

      if (indirectSource instanceof Snowball && event instanceof CollideEntityEvent.Impact) {
        Optional<SkyWarsPlayerData> optData = inst.getPlayerData(defender);
        if (optData.isPresent()) {
          SkyWarsPlayerData data = optData.get();
          data.stopFlight(3000 + (1000 * Probability.getRandom(5)));
          data.stopDefrost(15000);
        }
      } else if (!(event instanceof DamageEntityEvent)) {
        return;
      }
      attacker.sendMessage(Text.of(TextColors.YELLOW, "You've hit ", defender.getName(), "!"));
    }
  };
}
 
开发者ID:Skelril,项目名称:Skree,代码行数:31,代码来源:SkyWarsListener.java

示例10: checkLoginStatus

import org.spongepowered.api.event.Cancellable; //导入依赖的package包/类
protected void checkLoginStatus(Cancellable event, Player player) {
    if (settings.getGeneral().isBypassPermission() && player.hasPermission(PomData.ARTIFACT_ID + ".bypass")) {
        return;
    }

    if (settings.getGeneral().isCommandOnlyProtection()) {
        //check if the user is already registered
        if (!plugin.getDatabase().getAccount(player).isPresent()
                && player.hasPermission(PomData.ARTIFACT_ID + ".registerRequired")) {
            event.setCancelled(true);
        }
    } else if (!plugin.getDatabase().isLoggedIn(player)) {
        event.setCancelled(true);
    }
}
 
开发者ID:games647,项目名称:FlexibleLogin,代码行数:16,代码来源:AbstractPreventListener.java

示例11: checkSetting

import org.spongepowered.api.event.Cancellable; //导入依赖的package包/类
public Tristate checkSetting(Cancellable event, Player player, List<Region> regionsAt, Supplier<Permission> perm, Function<RegionConfig.Settings, Tristate> func, Tristate defaultTo)
{
    Permission permission = perm.get();
    if (player != null && permission != null && player.hasPermission(permission.getId()))
    {
        event.setCancelled(false);
        return Tristate.TRUE;
    }
    Tristate allow = UNDEFINED;
    for (Region region : regionsAt)
    {
        allow = allow.and(func.apply(region.getSettings()));
        if (allow != UNDEFINED)
        {
            if (allow == FALSE)
            {
                event.setCancelled(true);
                return FALSE;
            }
            break;
        }
    }
    if (allow == TRUE)
    {
        event.setCancelled(false);
    }
    if (allow == UNDEFINED)
    {
        return defaultTo;
    }
    return allow;
}
 
开发者ID:CubeEngine,项目名称:modules-main,代码行数:33,代码来源:SettingsListener.java

示例12: handleAccess

import org.spongepowered.api.event.Cancellable; //导入依赖的package包/类
public boolean handleAccess(Player user, Location soundLocation, Cancellable event)
{
    Boolean keyBookUsed = this.checkForKeyBook(user, soundLocation);
    if (this.isOwner(user)) return true;
    if (keyBookUsed != null && !keyBookUsed)
    {
        event.setCancelled(true);
        return false;
    }
    return keyBookUsed != null || this.checkForUnlocked(user) || user.hasPermission(
        module.perms().ACCESS_OTHER.getId());
}
 
开发者ID:CubeEngine,项目名称:modules-main,代码行数:13,代码来源:Lock.java

示例13: handleEntityInteract

import org.spongepowered.api.event.Cancellable; //导入依赖的package包/类
public void handleEntityInteract(Cancellable event, Player user)
{
    if (user.hasPermission(module.perms().SHOW_OWNER.getId()))
    {
        i18n.send(ACTION_BAR, user, NEUTRAL, "This entity is protected by {user}", this.getOwner());
    }
    if (this.getLockType() == PUBLIC) return;
    if (this.handleAccess(user, null, event))
    {
        this.notifyUsage(user);
        return;
    }
    if (event.isCancelled())
    {
        return;
    }
    AccessListModel access = this.getAccess(user);
    if (access == null && this.getLockType() == LockType.PRIVATE)
    {
        event.setCancelled(true); // private & no access
        if (user.hasPermission(module.perms().SHOW_OWNER.getId()))
        {
            i18n.send(ACTION_BAR, user, NEGATIVE, "Magic from {user} repelled your attempts to reach this entity!", this.getOwner());
        }
        else
        {
            i18n.send(ACTION_BAR, user, NEGATIVE, "Magic repelled your attempts to reach this entity!");
        }
    }
    this.notifyUsage(user);
}
 
开发者ID:CubeEngine,项目名称:modules-main,代码行数:32,代码来源:Lock.java

示例14: handleBlockBreak

import org.spongepowered.api.event.Cancellable; //导入依赖的package包/类
public void handleBlockBreak(Cancellable event, Player user)
{
    if (this.model.getValue(TABLE_LOCKS.OWNER_ID).equals(user.getUniqueId())
        || user.hasPermission(module.perms().BREAK_OTHER.getId()))
    {
        this.delete(user);
        return;
    }
    event.setCancelled(true);
    i18n.send(ACTION_BAR, user, NEGATIVE, "Magic prevents you from breaking this protection!");
}
 
开发者ID:CubeEngine,项目名称:modules-main,代码行数:12,代码来源:Lock.java

示例15: handleBlockInteract

import org.spongepowered.api.event.Cancellable; //导入依赖的package包/类
public void handleBlockInteract(Cancellable event, Player user)
{
    if (user.hasPermission(module.perms().SHOW_OWNER.getId()))
    {
        i18n.send(ACTION_BAR, user, NEUTRAL, "This block is protected by {user}", this.getOwner());
    }
    if (this.getLockType() == PUBLIC) return;
    if (this.handleAccess(user, null, event))
    {
        this.notifyUsage(user);
        return;
    }
    event.setCancelled(true);
    i18n.send(ACTION_BAR, user, NEGATIVE, "Magic prevents you from interacting with this block!");
}
 
开发者ID:CubeEngine,项目名称:modules-main,代码行数:16,代码来源:Lock.java


注:本文中的org.spongepowered.api.event.Cancellable类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。