예제 #1
0
파일: MPlugin.java 프로젝트: vivi7865/mcore
 public void postEnable() {
   log(
       Txt.parse(
           "=== ENABLE <g>COMPLETE <i>(Took <h>"
               + (System.currentTimeMillis() - timeEnableStart)
               + "ms<i>) ==="));
 }
예제 #2
0
파일: Coll.java 프로젝트: RFSMassacre/mcore
  @Override
  public synchronized void loadFromRemote(Object oid) {
    String id = this.fixId(oid);

    this.clearIdentifiedChanges(id);

    Entry<JsonElement, Long> entry = null;
    try {
      entry = this.getDriver().load(this, id);
    } catch (Exception e) {
      MCore.get()
          .log(
              Txt.parse(
                  "<b>Database could not load entity. You edited a file manually and made wrong JSON?"));
      MCore.get().log(Txt.parse("<k>Error: <v>%s", e.getMessage()));
      MCore.get().log(Txt.parse("<k>Entity: <v>%s", id));
      MCore.get().log(Txt.parse("<k>Collection: <v>%s", this.getName()));
      return;
    }
    if (entry == null) return;

    JsonElement raw = entry.getKey();
    if (raw == null) return;

    Long mtime = entry.getValue();
    if (mtime == null) return;

    E entity = this.get(id, false);
    if (entity != null) {
      // It did already exist
      this.copy(this.getGson().fromJson(raw, this.getEntityClass()), entity);
    } else {
      // Create first
      entity = this.createNewInstance();

      // Copy over data first
      this.copy(this.getGson().fromJson(raw, this.getEntityClass()), entity);

      // Then attach!
      this.attach(entity, oid, false);
    }

    this.lastRaw.put(id, raw);
    this.lastMtime.put(id, mtime);
    this.lastDefault.remove(id);
  }
예제 #3
0
파일: MPlugin.java 프로젝트: vivi7865/mcore
 public void log(Level level, Object... msg) {
   String imploded = Txt.implode(msg, " ");
   ConsoleCommandSender sender = Bukkit.getConsoleSender();
   if (level == Level.INFO && sender != null) {
     Bukkit.getConsoleSender().sendMessage(this.logPrefixColored + imploded);
   } else {
     Logger.getLogger("Minecraft").log(level, this.logPrefixPlain + imploded);
   }
 }
예제 #4
0
파일: Coll.java 프로젝트: RFSMassacre/mcore
  protected boolean examineHasLocalAlter(String id, E entity) {
    JsonElement lastRaw = this.lastRaw.get(id);
    JsonElement currentRaw = null;

    try {
      currentRaw = this.getGson().toJsonTree(entity, this.getEntityClass());
    } catch (Exception e) {
      MCore.get()
          .log(
              Txt.parse(
                  "<b>Database examineHasLocalAlter failed convert current entity to JSON tree."));
      MCore.get().log(Txt.parse("<k>Error: <v>%s", e.getMessage()));
      MCore.get().log(Txt.parse("<k>Entity: <v>%s", id));
      MCore.get().log(Txt.parse("<k>Collection: <v>%s", this.getName()));
      throw e;
    }

    return !MStore.equal(lastRaw, currentRaw);
  }
예제 #5
0
파일: MPlugin.java 프로젝트: vivi7865/mcore
  public boolean preEnable() {
    timeEnableStart = System.currentTimeMillis();

    this.logPrefixColored =
        Txt.parse(
            "<teal>[<aqua>%s %s<teal>] <i>",
            this.getDescription().getName(), this.getDescription().getVersion());
    this.logPrefixPlain = ChatColor.stripColor(this.logPrefixColored);

    log("=== ENABLE START ===");

    // Create Gson
    this.gson = this.getGsonBuilder().create();

    // Listener
    Bukkit.getPluginManager().registerEvents(this, this);

    return true;
  }
  @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))));
    }
  }
예제 #7
0
파일: MPlugin.java 프로젝트: vivi7865/mcore
 public void suicide() {
   log(Txt.parse("<b>Now I suicide!"));
   Bukkit.getPluginManager().disablePlugin(this);
 }
  @Override
  public void perform() {
    UPlayer newLeader = this.arg(0, ARUPlayer.getStartAny(sender));
    if (newLeader == null) return;

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

    UPlayer targetFactionCurrentLeader = targetFaction.getLeader();

    // We now have uplayer and the target faction
    if (this.senderIsConsole || usender.isUsingAdminMode() || Perm.LEADER_ANY.has(sender, false)) {
      // Do whatever you wish
    } else {
      // Follow the standard rules
      if (usender.getRole() != Rel.LEADER || targetFaction != usenderFaction) {
        sender.sendMessage(Txt.parse("<b>你必须是公会会长才能操作 %s.", this.getDesc()));
        return;
      }

      if (newLeader.getFaction() != usenderFaction) {
        msg("%s<i> 不是公会成员.", newLeader.describeTo(usender, true));
        return;
      }

      if (newLeader == usender) {
        msg("<b>目标不能是你自己.");
        return;
      }
    }

    // only run event when newLeader isn't actually in the faction
    if (newLeader.getFaction() != targetFaction) {
      FactionsEventMembershipChange event =
          new FactionsEventMembershipChange(
              sender, newLeader, targetFaction, MembershipChangeReason.LEADER);
      event.run();
      if (event.isCancelled()) return;
    }

    // if target player is currently leader, demote and replace him
    if (targetFactionCurrentLeader == newLeader) {
      targetFaction.promoteNewLeader();
      msg(
          "<i>You have demoted %s<i> from the position of faction leader.",
          newLeader.describeTo(usender, true));
      newLeader.msg(
          "<i>You have been demoted from the position of faction leader by %s<i>.",
          usender.describeTo(newLeader, true));
      return;
    }

    // Perform the switching
    if (targetFactionCurrentLeader != null) {
      targetFactionCurrentLeader.setRole(Rel.OFFICER);
    }
    newLeader.setFaction(targetFaction);
    newLeader.setRole(Rel.LEADER);
    msg("<i>你提升 %s<i> 成为公会会长.", newLeader.describeTo(usender, true));

    // Inform all players
    for (UPlayer uplayer : UPlayerColls.get().get(sender).getAllOnline()) {
      uplayer.msg(
          "%s<i> gave %s<i> the leadership of %s<i>.",
          senderIsConsole
              ? "A server admin"
              : RelationUtil.describeThatToMe(usender, uplayer, true),
          newLeader.describeTo(uplayer),
          targetFaction.describeTo(uplayer));
    }
  }
예제 #9
0
 @Override
 public boolean execute(CommandSender sender, String commandLabel, String[] args) {
   if (!plugin.isEnabled()) return false;
   this.mcommand.execute(sender, Txt.tokenizeArguments(Txt.implode(args, " ")));
   return true;
 }