Пример #1
0
  @Override
  public synchronized void loadFromRemoteFixed(String id, Entry<JsonObject, Long> remoteEntry) {
    if (!Factions.get().isDatabaseInitialized()) {
      super.loadFromRemoteFixed(id, remoteEntry);
      return;
    }

    MPlayer mplayer = null;

    // Before
    String beforeId = null;
    if (mplayer == null) mplayer = this.id2entity.get(id);
    if (mplayer != null) beforeId = mplayer.getFactionId();

    // Super
    super.loadFromRemoteFixed(id, remoteEntry);

    // After
    String afterId = null;
    if (mplayer == null) mplayer = this.id2entity.get(id);
    if (mplayer != null) afterId = mplayer.getFactionId();

    // Perform
    if (mplayer != null) mplayer.updateFactionIndexes(beforeId, afterId);
  }
  @Override
  public void perform() {
    Double amount = this.arg(0, ARDouble.get());
    if (amount == null) return;

    UPlayer from = this.arg(1, ARUPlayer.getStartAny(sender));
    if (from == null) return;

    Faction to = this.arg(2, ARFaction.get(sender));
    if (to == null) return;

    boolean success = Econ.transferMoney(usender, from, to, amount);

    if (success && MConf.get().logMoneyTransactions) {
      Factions.get()
          .log(
              ChatColor.stripColor(
                  Txt.parse(
                      "%s transferred %s from the player \"%s\" to the faction \"%s\"",
                      usender.getName(),
                      Money.format(amount),
                      from.describeTo(null),
                      to.describeTo(null))));
    }
  }
 @Override
 public void perform() {
   Factions.get()
       .getOuterCmdFactions()
       .cmdFactionsRank
       .execute(sender, MUtil.list(this.arg(0), this.rankName, this.arg(1)));
 }
Пример #4
0
  @Override
  public void perform() {
    // Args
    Faction faction = this.arg(0, ARFaction.get(usender), usenderFaction);
    if (faction == null) return;

    // FPerm
    if (!FPerm.DISBAND.has(usender, faction, true)) return;

    // Verify
    if (faction.getFlag(FFlag.PERMANENT)) {
      msg("<i>This faction is designated as permanent, so you cannot disband it.");
      return;
    }

    // Event
    EventFactionsDisband event = new EventFactionsDisband(me, faction);
    event.run();
    if (event.isCancelled()) return;

    // Merged Apply and Inform

    // Run event for each player in the faction
    for (UPlayer uplayer : faction.getUPlayers()) {
      EventFactionsMembershipChange membershipChangeEvent =
          new EventFactionsMembershipChange(
              sender,
              uplayer,
              FactionColls.get().get(faction).getNone(),
              MembershipChangeReason.DISBAND);
      membershipChangeEvent.run();
    }

    // Inform all players
    for (UPlayer uplayer : UPlayerColls.get().get(usender).getAllOnline()) {
      String who = usender.describeTo(uplayer);
      if (uplayer.getFaction() == faction) {
        uplayer.msg("<h>%s<i> disbanded your faction.", who);
      } else {
        uplayer.msg("<h>%s<i> disbanded the faction %s.", who, faction.getName(uplayer));
      }
    }

    if (MConf.get().logFactionDisband) {
      Factions.get()
          .log(
              Txt.parse(
                  "<i>The faction <h>%s <i>(<h>%s<i>) was disbanded by <h>%s<i>.",
                  faction.getName(), faction.getId(), usender.getDisplayName()));
    }

    faction.detach();
  }
  @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;
  }
Пример #6
0
  @Override
  public void perform() throws MassiveException {
    // Args
    int page = this.readArg();
    final MPlayer msender = this.msender;

    // NOTE: The faction list is quite slow and mostly thread safe.
    // We run it asynchronously to spare the primary server thread.

    // Pager Create
    final Pager<Faction> pager =
        new Pager<Faction>(
            this,
            "Faction List",
            page,
            new Stringifier<Faction>() {
              @Override
              public String toString(Faction faction, int index) {
                if (faction.isNone()) {
                  return Txt.parse(
                      "<i>Factionless<i> %d online",
                      FactionColl.get().getNone().getMPlayersWhereOnline(true).size());
                } else {
                  return Txt.parse(
                      "%s<i> %d/%d online, %d/%d/%d",
                      faction.getName(msender),
                      faction.getMPlayersWhereOnline(true).size(),
                      faction.getMPlayers().size(),
                      faction.getLandCount(),
                      faction.getPowerRounded(),
                      faction.getPowerMaxRounded());
                }
              }
            });

    Bukkit.getScheduler()
        .runTaskAsynchronously(
            Factions.get(),
            new Runnable() {
              @Override
              public void run() {
                // Pager Items
                final List<Faction> factions =
                    FactionColl.get().getAll(FactionListComparator.get());
                pager.setItems(factions);

                // Pager Message
                pager.message();
              }
            });
  }
Пример #7
0
  public void clean() {
    for (MPlayer mplayer : this.getAll()) {
      String factionId = mplayer.getFactionId();
      if (FactionColl.get().containsId(factionId)) continue;

      mplayer.resetFactionData();

      String message =
          Txt.parse(
              "<i>Reset data for <h>%s <i>. Unknown factionId <h>%s",
              mplayer.getDisplayName(IdUtil.getConsole()), factionId);
      Factions.get().log(message);
    }
  }
Пример #8
0
  @Override
  public synchronized MPlayer removeAtLocalFixed(String id) {
    if (!Factions.get().isDatabaseInitialized()) return super.removeAtLocalFixed(id);

    MPlayer mplayer = this.id2entity.get(id);

    if (mplayer != null) {
      String beforeId = mplayer.getFactionId();
      String afterId = null;
      mplayer.updateFactionIndexes(beforeId, afterId);
    }

    return super.removeAtLocalFixed(id);
  }
Пример #9
0
  @Override
  public void perform() {
    // Args
    UPlayer uplayer = this.arg(0, ARUPlayer.getStartAny(sender));
    if (uplayer == null) return;

    Boolean newInvited = this.arg(1, ARBoolean.get(), !usenderFaction.isInvited(uplayer));
    if (newInvited == null) return;

    // Allready member?
    if (uplayer.getFaction() == usenderFaction) {
      msg("%s<i> is already a member of %s", uplayer.getName(), usenderFaction.getName());
      msg(
          "<i>You might want to: "
              + Factions.get().getOuterCmdFactions().cmdFactionsKick.getUseageTemplate(false));
      return;
    }

    // FPerm
    if (!FPerm.INVITE.has(usender, usenderFaction, true)) return;

    // Event
    FactionsEventInvitedChange event =
        new FactionsEventInvitedChange(sender, uplayer, usenderFaction, newInvited);
    event.run();
    if (event.isCancelled()) return;
    newInvited = event.isNewInvited();

    // Apply
    usenderFaction.setInvited(uplayer, newInvited);

    // Inform
    if (newInvited) {
      uplayer.msg(
          "%s<i> invited you to %s",
          usender.describeTo(uplayer, true), usenderFaction.describeTo(uplayer));
      usenderFaction.msg(
          "%s<i> invited %s<i> to your faction.",
          usender.describeTo(usenderFaction, true), uplayer.describeTo(usenderFaction));
    } else {
      uplayer.msg(
          "%s<i> revoked your invitation to <h>%s<i>.",
          usender.describeTo(uplayer), usenderFaction.describeTo(uplayer));
      usenderFaction.msg(
          "%s<i> revoked %s's<i> invitation.",
          usender.describeTo(usenderFaction), uplayer.describeTo(usenderFaction));
    }
  }
  @Override
  public void perform() {
    Double amount = this.arg(0, ARDouble.get());
    if (amount == null) return;

    Faction from = this.arg(1, ARFaction.get(sender), myFaction);
    if (from == null) return;

    FPlayer to = fme;

    boolean success = Econ.transferMoney(fme, from, to, amount);

    if (success && MConf.get().logMoneyTransactions) {
      Factions.get()
          .log(
              ChatColor.stripColor(
                  Txt.parse(
                      "%s withdrew %s from the faction bank: %s",
                      fme.getName(), Money.format(from, amount), from.describeTo(null))));
    }
  }
Пример #11
0
  public void considerRemovePlayerMillis() {
    // If the config option is 0 or below that means the server owner want it disabled.
    if (MConf.get().removePlayerMillisDefault <= 0.0) return;

    // For each of the offline players...
    // NOTE: If the player is currently online it's most definitely not inactive.
    // NOTE: This check catches some important special cases like the @console "player".
    final Collection<MPlayer> mplayersOffline = this.getAllOffline();

    Bukkit.getScheduler()
        .runTaskAsynchronously(
            Factions.get(),
            new Runnable() {
              @Override
              public void run() {
                for (MPlayer mplayer : mplayersOffline) {
                  mplayer.considerRemovePlayerMillis(true);
                }
              }
            });
  }
  public void econLandRewardRoutine() {
    if (!Econ.isEnabled()) return;

    double econLandReward = MConf.get().econLandReward;
    if (econLandReward == 0.0) return;

    Factions.get().log("Running econLandRewardRoutine...");
    for (Faction faction : this.getAll()) {
      int landCount = faction.getLandCount();
      if (!faction.getFlag(MFlag.getFlagPeaceful()) && landCount > 0) {
        List<MPlayer> players = faction.getMPlayers();
        int playerCount = players.size();
        double reward = econLandReward * landCount / playerCount;
        for (MPlayer player : players) {
          Econ.modifyMoney(
              player,
              reward,
              "own " + landCount + " faction land divided among " + playerCount + " members");
        }
      }
    }
  }
Пример #13
0
 public BoardColl(String name) {
   super(name, Board.class, MStore.getDb(ConfServer.dburi), Factions.get(), false, true, true);
 }
 @Override
 public Plugin getPlugin() {
   return Factions.get();
 }
Пример #15
0
 public OldConfColl(String name) {
   super(name, OldConf.class, MStore.getDb(), Factions.get());
 }
 private FactionColl() {
   super(Const.COLLECTION_FACTION, Faction.class, MStore.getDb(), Factions.get());
 }