コード例 #1
0
  public static void floodSearch(Set<PS> set, Faction color, int max) {
    // Clean
    if (set == null) throw new NullPointerException("set");
    if (color == null) throw new NullPointerException("color");

    // Expand
    Set<PS> expansion = new LinkedHashSet<PS>();
    for (PS chunk : set) {
      Set<PS> neighbours =
          MUtil.set(
              chunk.withChunkX(chunk.getChunkX() + 1),
              chunk.withChunkX(chunk.getChunkX() - 1),
              chunk.withChunkZ(chunk.getChunkZ() + 1),
              chunk.withChunkZ(chunk.getChunkZ() - 1));

      for (PS neighbour : neighbours) {
        if (set.contains(neighbour)) continue;
        Faction faction = BoardColl.get().getFactionAt(neighbour);
        if (faction == null) continue;
        if (faction != color) continue;
        expansion.add(neighbour);
      }
    }
    set.addAll(expansion);

    // No Expansion?
    if (expansion.isEmpty()) return;

    // Reached Max?
    if (set.size() >= max) return;

    // Recurse
    floodSearch(set, color, max);
  }
コード例 #2
0
  @Override
  public Set<PS> getChunks() {
    // Common Startup
    final PS chunk = PS.valueOf(me.getLocation()).getChunk(true);
    final Set<PS> chunks = new LinkedHashSet<PS>();

    // What faction (aka color) resides there?
    // NOTE: Wilderness/None is valid.
    final Faction color = BoardColl.get().getFactionAt(chunk);

    // We start where we are!
    chunks.add(chunk);

    // Flood!
    int max = MConf.get().setFillMax;
    floodSearch(chunks, color, max);

    // Limit Reached?
    if (chunks.size() >= max) {
      msg("<b>Fill limit of <h>%d <b>reached.", max);
      return null;
    }

    // OK!
    return chunks;
  }
コード例 #3
0
ファイル: SCPlayerManager.java プロジェクト: xAnml/SCCore
  @EventHandler(priority = EventPriority.HIGHEST)
  public void onPlayerDamageByPlayer(final EntityDamageByEntityEvent e) {
    if (e.getEntity() instanceof Player == false || e.getDamager() instanceof Player == false)
      return;

    Player player = (Player) e.getEntity();
    Player target = (Player) e.getDamager();
    SCPlayer scp = getSCPlayer(player.getUniqueId());
    SCPlayer sct = getSCPlayer(target.getUniqueId());
    Faction faction = BoardColl.get().getFactionAt(PS.valueOf(target.getLocation().getChunk()));

    if (faction.getName().equalsIgnoreCase("Safezone")) {
      return;
    }

    final Faction pFaction = MPlayerColl.get().get(player).getFaction();
    final Faction tFaction = MPlayerColl.get().get(target).getFaction();

    if (pFaction.getRelationTo(tFaction) == Rel.MEMBER && !pFaction.isNone()) {
      return;
    }

    if (pFaction.getRelationTo(tFaction) == Rel.ALLY) {
      return;
    }

    scp.combatTag();
    sct.combatTag();
  }
コード例 #4
0
  @Override
  public void innerPerform() throws MassiveException {
    // Args
    MPlayer mplayer = this.readArg();
    boolean newValue = this.readArg(!ta.isPlayerIdGranted(mplayer.getId()));

    // MPerm
    if (!MPerm.getPermAccess().has(msender, hostFaction, true)) return;

    // Apply
    ta = ta.withPlayerId(mplayer.getId(), newValue);
    BoardColl.get().setTerritoryAccessAt(chunk, ta);

    // Inform
    this.sendAccessInfo();
  }
コード例 #5
0
  @Override
  public Faction get(Object oid) {
    Faction ret = super.get(oid);

    // We should only trigger automatic clean if the whole database system is initialized.
    // A cleaning can only be successful if all data is available.
    // Example Reason: When creating the special factions for the first time "createSpecialFactions"
    // a clean would be triggered otherwise.
    if (ret == null && Factions.get().isDatabaseInitialized()) {
      String message =
          Txt.parse(
              "<b>Non existing factionId <h>%s <b>requested. <i>Cleaning all boards and mplayers.",
              this.fixId(oid));
      Factions.get().log(message);

      BoardColl.get().clean();
      MPlayerColl.get().clean();
    }

    return ret;
  }