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


Java Cancellable.setCancelled方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: 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

示例11: 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

示例12: doSpectatorCheck

import org.spongepowered.api.event.Cancellable; //导入方法依赖的package包/类
private void doSpectatorCheck(Cancellable event, UUID player) {
    Optional<Challenger> ch = CommonCore.getChallenger(player);
    if (ch.isPresent() && ch.get().isSpectating()) {
        event.setCancelled(true);
    }
}
 
开发者ID:caseif,项目名称:Inferno,代码行数:7,代码来源:PlayerWorldListener.java

示例13: handleBlockDoorUse

import org.spongepowered.api.event.Cancellable; //导入方法依赖的package包/类
public void handleBlockDoorUse(Cancellable event, Player user, Location<World> clickedDoor)
{
    if (this.getLockType() == PUBLIC)
    {
        this.doorUse(user, clickedDoor);
        event.setCancelled(true);
        return; // Allow everything
    }
    if (this.handleAccess(user, clickedDoor, event))
    {
        this.doorUse(user, clickedDoor);
        event.setCancelled(true);
        return;
    }
    if (event.isCancelled()) return;

    if (this.model.getValue(TABLE_LOCKS.OWNER_ID).equals(user.getUniqueId())) return; // Its the owner
    switch (this.getLockType())
    {
        case PRIVATE: // block changes
            break;
        case GUARDED:
        case DONATION:
        case FREE:
        default: // Not Allowed for doors
            throw new IllegalStateException();
    }
    AccessListModel access = this.getAccess(user);
    if (access == null || !(access.canIn() && access.canOut()) || user.hasPermission(
        module.perms().ACCESS_OTHER.getId())) // No access Or not full access
    {
        event.setCancelled(true);
        if (user.hasPermission(module.perms().SHOW_OWNER.getId()))
        {
            i18n.send(ACTION_BAR, user, NEGATIVE, "A magical lock from {user} prevents you from using this door!", this.getOwner());
        }
        else
        {
            i18n.send(ACTION_BAR, user, NEGATIVE, "A magical lock prevents you from using this door!");
        }
        return;
    } // else has access
    this.doorUse(user, clickedDoor);
    event.setCancelled(true);
}
 
开发者ID:CubeEngine,项目名称:modules-main,代码行数:46,代码来源:Lock.java

示例14: handleInventoryOpen

import org.spongepowered.api.event.Cancellable; //导入方法依赖的package包/类
public void handleInventoryOpen(Cancellable event, Inventory protectedInventory, Location<World> soundLocation, Player user)
{
    if (soundLocation != null && user.hasPermission(module.perms().SHOW_OWNER.getId()))
    {
        i18n.send(ACTION_BAR, user, NEUTRAL, "This inventory is protected by {user}", this.getOwner());
    }
    if (this.handleAccess(user, soundLocation, event) || event.isCancelled()) return;
    boolean in;
    boolean out;
    switch (this.getLockType())
    {
        default: throw new IllegalStateException();
        case PUBLIC: return; // Allow everything
        case PRIVATE: // block changes
        case GUARDED:
            in = false;
            out = false;
            break;
        case DONATION:
            in = true;
            out = false;
            break;
        case FREE:
            in = false;
            out = true;
    }
    AccessListModel access = this.getAccess(user);
    if (access == null && this.getLockType() == LockType.PRIVATE && !user.hasPermission(module.perms().ACCESS_OTHER.getId()))
    {
        event.setCancelled(true); // private & no access
        if (user.hasPermission(module.perms().SHOW_OWNER.getId()))
        {
            i18n.send(ACTION_BAR, user, NEGATIVE, "A magical lock from {user} prevents you from accessing this inventory!", this.getOwner());
        }
        else
        {
            i18n.send(ACTION_BAR, user, NEGATIVE, "A magical lock prevents you from accessing this inventory!");
        }
    }
    else // Has access access -> new InventoryGuard
    {
        if (access != null)
        {
            in = in || access.canIn();
            out = out || access.canOut();
        }
        this.notifyUsage(user);
        if ((in && out) || user.hasPermission(module.perms().ACCESS_OTHER.getId())) return; // Has full access
        if (protectedInventory == null) return; // Just checking else do lock
        InventoryGuardFactory igf = module.getInventoryGuardFactory();
        igf.prepareInv(protectedInventory, user.getUniqueId());
        if (!in)
        {
            igf.blockPutInAll();
        }
        if (!out)
        {
            igf.blockTakeOutAll();
        }

        igf.submitInventory(Locker.class, false);
        this.notifyUsage(user);
        updateAccess();
    }
}
 
开发者ID:CubeEngine,项目名称:modules-main,代码行数:66,代码来源:Lock.java


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