Ejemplo n.º 1
0
  public SpongeCoremod() {
    // This MUST be the first line in the constructor, to prevent
    // JavaVersionCheckUtils from being passed through the transformer
    // chain, and thereby triggering Mixin to switch to PREINIT.
    Launch.classLoader.addTransformerExclusion("org.spongepowered.launch.JavaVersionCheckUtils");

    try {
      JavaVersionCheckUtils.ensureJava8();
    } catch (Exception e) {
      e.printStackTrace();
      this.clearSecurityManager();
      Runtime.getRuntime().exit(1);
    }

    // Let's get this party started
    MixinBootstrap.init();
    MixinEnvironment.setCompatibilityLevel(MixinEnvironment.CompatibilityLevel.JAVA_8);

    // Add pre-init mixins
    MixinEnvironment.getEnvironment(Phase.PREINIT)
        .addConfiguration("mixins.forge.preinit.json")
        .registerTokenProviderClass("org.spongepowered.mod.SpongeCoremod$TokenProvider");

    SpongeLaunch.initialize();
    SpongeImpl.getGlobalConfig(); // Load config

    MixinEnvironment.getEnvironment(Phase.INIT)
        .addConfiguration("mixins.forge.init.json")
        .registerTokenProviderClass("org.spongepowered.mod.SpongeCoremod$TokenProvider");

    // Add default mixins
    MixinEnvironment.getDefaultEnvironment()
        .addConfiguration("mixins.common.api.json")
        .addConfiguration("mixins.common.core.json")
        .addConfiguration("mixins.common.bungeecord.json")
        .addConfiguration("mixins.common.eulashutdown.json")
        .addConfiguration("mixins.common.timings.json")
        .addConfiguration("mixins.forge.core.json")
        .addConfiguration("mixins.forge.entityactivation.json")
        .addConfiguration("mixins.forge.bungeecord.json")
        .registerTokenProviderClass("org.spongepowered.mod.SpongeCoremod$TokenProvider");

    Launch.classLoader.addClassLoaderExclusion("org.spongepowered.api.event.cause.Cause");
    Launch.classLoader.addClassLoaderExclusion("org.spongepowered.api.event.cause.NamedCause");
    Launch.classLoader.addClassLoaderExclusion("org.spongepowered.api.event.Cancellable");
    Launch.classLoader.addClassLoaderExclusion(
        "org.spongepowered.api.eventgencore.annotation.PropertySettings");

    // Transformer exclusions
    Launch.classLoader.addTransformerExclusion("ninja.leaping.configurate.");
    Launch.classLoader.addTransformerExclusion("org.apache.commons.lang3.");
    Launch.classLoader.addTransformerExclusion("org.spongepowered.mod.interfaces.IMixinEvent");
    Launch.classLoader.addTransformerExclusion("org.spongepowered.common.launch.");

    SpongeSuperclassRegistry.registerSuperclassModification(
        "org.spongepowered.api.entity.ai.task.AbstractAITask",
        "org.spongepowered.common.entity.ai.SpongeEntityAICommonSuperclass");
    SpongeSuperclassRegistry.registerSuperclassModification(
        "org.spongepowered.api.event.cause.entity.damage.source.common.AbstractDamageSource",
        "org.spongepowered.common.event.damage.SpongeCommonDamageSource");
    SpongeSuperclassRegistry.registerSuperclassModification(
        "org.spongepowered.api.event.cause.entity.damage.source.common.AbstractEntityDamageSource",
        "org.spongepowered.common.event.damage.SpongeCommonEntityDamageSource");
    SpongeSuperclassRegistry.registerSuperclassModification(
        "org.spongepowered.api.event.cause.entity.damage.source.common.AbstractIndirectEntityDamageSource",
        "org.spongepowered.common.event.damage.SpongeCommonIndirectEntityDamageSource");
  }
Ejemplo n.º 2
0
  /**
   * Builds an XML report of the timings to be uploaded for parsing.
   *
   * @param sender Who to report to
   */
  static void reportTimings(CommandSource sender) {
    Platform platform = SpongeImpl.getGame().getPlatform();
    JsonObjectBuilder builder =
        JSONUtil.objectBuilder()
            // Get some basic system details about the server
            .add(
                "version",
                platform
                    .getImplementation()
                    .getVersion()
                    .orElse(platform.getMinecraftVersion().getName() + "-DEV"))
            .add("maxplayers", SpongeImpl.getGame().getServer().getMaxPlayers())
            .add("start", TimingsManager.timingStart / 1000)
            .add("end", System.currentTimeMillis() / 1000)
            .add("sampletime", (System.currentTimeMillis() - TimingsManager.timingStart) / 1000);
    if (!TimingsManager.privacy) {
      builder
          .add("server", getServerName())
          .add("motd", SpongeImpl.getGame().getServer().getMotd().toPlain())
          .add("online-mode", SpongeImpl.getGame().getServer().getOnlineMode())
          .add("icon", MinecraftServer.getServer().getServerStatusResponse().getFavicon());
    }

    final Runtime runtime = Runtime.getRuntime();
    RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean();
    builder.add(
        "system",
        JSONUtil.objectBuilder()
            .add("timingcost", getCost())
            .add("name", System.getProperty("os.name"))
            .add("version", System.getProperty("os.version"))
            .add("jvmversion", System.getProperty("java.version"))
            .add("arch", System.getProperty("os.arch"))
            .add("maxmem", runtime.maxMemory())
            .add("cpu", runtime.availableProcessors())
            .add("runtime", ManagementFactory.getRuntimeMXBean().getUptime())
            .add("flags", RUNTIME_FLAG_JOINER.join(runtimeBean.getInputArguments()))
            .add(
                "gc",
                JSONUtil.mapArrayToObject(
                    ManagementFactory.getGarbageCollectorMXBeans(),
                    (input) -> {
                      return JSONUtil.singleObjectPair(
                          input.getName(),
                          JSONUtil.arrayOf(input.getCollectionCount(), input.getCollectionTime()));
                    })));

    Set<BlockType> blockTypeSet = Sets.newHashSet();
    Set<EntityType> entityTypeSet = Sets.newHashSet();

    int size = HISTORY.size();
    TimingHistory[] history = new TimingHistory[size + 1];
    int i = 0;
    for (TimingHistory timingHistory : HISTORY) {
      blockTypeSet.addAll(timingHistory.blockTypeSet);
      entityTypeSet.addAll(timingHistory.entityTypeSet);
      history[i++] = timingHistory;
    }

    history[i] = new TimingHistory(); // Current snapshot
    blockTypeSet.addAll(history[i].blockTypeSet);
    entityTypeSet.addAll(history[i].entityTypeSet);

    JsonObjectBuilder handlersBuilder = JSONUtil.objectBuilder();
    for (TimingIdentifier.TimingGroup group : TimingIdentifier.GROUP_MAP.values()) {
      for (TimingHandler id : group.handlers) {
        if (!id.timed && !id.isSpecial()) {
          continue;
        }
        handlersBuilder.add(id.id, JSONUtil.arrayOf(group.id, id.name));
      }
    }

    builder.add(
        "idmap",
        JSONUtil.objectBuilder()
            .add(
                "groups",
                JSONUtil.mapArrayToObject(
                    TimingIdentifier.GROUP_MAP.values(),
                    (group) -> {
                      return JSONUtil.singleObjectPair(group.id, group.name);
                    }))
            .add("handlers", handlersBuilder)
            .add(
                "worlds",
                JSONUtil.mapArrayToObject(
                    TimingHistory.worldMap.entrySet(),
                    (entry) -> {
                      return JSONUtil.singleObjectPair(entry.getValue(), entry.getKey());
                    }))
            .add(
                "tileentity",
                JSONUtil.mapArrayToObject(
                    blockTypeSet,
                    (blockType) -> {
                      return JSONUtil.singleObjectPair(
                          Block.getIdFromBlock((Block) blockType), blockType.getId());
                    }))
            .add(
                "entity",
                JSONUtil.mapArrayToObject(
                    entityTypeSet,
                    (entityType) -> {
                      return JSONUtil.singleObjectPair(
                          ((SpongeEntityType) entityType).entityTypeId, entityType.getId());
                    })));

    // Information about loaded plugins

    builder.add(
        "plugins",
        JSONUtil.mapArrayToObject(
            SpongeImpl.getGame().getPluginManager().getPlugins(),
            (plugin) -> {
              return JSONUtil.objectBuilder()
                  .add(
                      plugin.getId(),
                      JSONUtil.objectBuilder()
                          .add("version", plugin.getVersion().orElse(""))
                          .add("description", plugin.getDescription().orElse(""))
                          .add("website", plugin.getUrl().orElse(""))
                          .add("authors", AUTHOR_LIST_JOINER.join(plugin.getAuthors())))
                  .build();
            }));

    // Information on the users Config

    builder.add(
        "config",
        JSONUtil.objectBuilder()
            .add("sponge", serializeConfigNode(SpongeImpl.getGlobalConfig().getRootNode())));

    new TimingsExport(sender, builder.build(), history).start();
  }