Esempio n. 1
0
 @Override
 public World getWorld(UUID uid) {
   return worlds.get(uid);
 }
Esempio n. 2
0
 public World getWorld(int dimID) {
   return worlds.get(dimID);
 }
Esempio n. 3
0
  @Override
  public World createWorld(WorldCreator creator) {
    if (creator == null) {
      throw new IllegalArgumentException("Creator may not be null");
    }

    String name = creator.name();
    World world = getWorld(name);

    //		WorldType type = WorldType.parseWorldType(creator.type().getName());

    if (world != null) { // Existing forge world
      return world;
    }

    if (firstBukkitWorld) {
      DimensionManager.registerProviderType(
          CraftWorldProvider.ProviderID, CraftWorldProvider.class, false);
      firstBukkitWorld = false;
    }

    int dimension = -1000;

    if (CraftWorldProvider.hasDimensionIdForName(name)) {
      dimension = CraftWorldProvider.getDimensionIdForName(name);
    } else {
      dimension = DimensionManager.getNextFreeDimId();
      CraftWorldProvider.setDimensionIdForName(name, dimension);
    }

    DimensionManager.registerDimension(dimension, CraftWorldProvider.ProviderID);

    CraftWorldProvider wp = (CraftWorldProvider) DimensionManager.createProviderFor(dimension);
    wp.setName(creator.name());

    File folder = new File(getWorldContainer(), wp.getDimName());
    if ((folder.exists()) && (!folder.isDirectory())) {
      throw new IllegalArgumentException(
          "File exists with the name '" + name + "' and isn't a folder");
    }

    ChunkGenerator generator = creator.generator();
    boolean generateStructures = creator.generateStructures();

    AnvilSaveConverter converter = new AnvilSaveConverter(folder);
    if (converter.isOldMapFormat(wp.getDimensionName())) {
      getLogger().info("Converting world '" + name + "'");
      converter.convertMapFormat(name, new ConvertingProgressUpdate(theServer));
    }

    WorldType type = WorldType.parseWorldType(creator.type().getName());

    // WorldServer internal = new WorldServer(theServer, new
    // AnvilSaveHandler(getWorldContainer().getParentFile(), name, true), name, dimension, new
    // WorldSettings(creator.seed(), EnumGameType.getByID(getDefaultGameMode().getValue()),
    // generateStructures, false, type), theServer.theProfiler);
    // WorldServerMulti internal = new WorldServerMulti(theServer, new
    // AnvilSaveHandler(getWorldContainer()                , name, true), name, dimension, new
    // WorldSettings(creator.seed(), EnumGameType.getByID(getDefaultGameMode().getValue()),
    // generateStructures, false,    type), theServer.theProfiler, creator.environment(),
    // generator);
    WorldServer internal =
        new WorldServerMulti(
            theServer,
            new AnvilSaveHandler(getWorldContainer(), wp.getDimName(), true),
            name,
            dimension,
            new WorldSettings(
                creator.seed(),
                EnumGameType.getByID(getDefaultGameMode().getValue()),
                generateStructures,
                false,
                type),
            worlds.get(0).getHandle(),
            theServer.theProfiler);

    internal.addWorldAccess((IWorldAccess) new WorldManager(theServer, internal));
    internal.difficultySetting = 1;
    internal.provider = wp;

    wp.registerWorld(internal);

    // DimensionManager.setWorld(dimension, internal);  not necessary, done in constructor of
    // WorldServer
    worlds.cacheIfNotPresent(dimension);
    if (generator != null) {
      (worlds.get(dimension))
          .getPopulators()
          .addAll(generator.getDefaultPopulators(worlds.get(dimension)));
    }

    pluginManager.callEvent(new WorldInitEvent((worlds.get(dimension))));
    System.out.print(
        "Preparing start region for level "
            + (theServer.worldServers.length - 1)
            + " (Seed: "
            + internal.getSeed()
            + ")");

    if (DimensionManager.shouldLoadSpawn(dimension)) {
      short short1 = 196;
      long i = System.currentTimeMillis();
      for (int j = -short1; j <= short1; j += 16) {
        for (int k = -short1; k <= short1; k += 16) {
          long l = System.currentTimeMillis();

          if (l < i) {
            i = l;
          }

          if (l > i + 1000L) {
            int i1 = (short1 * 2 + 1) * (short1 * 2 + 1);
            int j1 = (j + short1) * (short1 * 2 + 1) + k + 1;

            System.out.println("Preparing spawn area for " + name + ", " + (j1 * 100 / i1) + "%");
            i = l;
          }

          ChunkCoordinates chunkcoordinates = internal.getSpawnPoint();
          internal.theChunkProviderServer.provideChunk(
              chunkcoordinates.posX + j >> 4, chunkcoordinates.posZ + k >> 4);
        } //
      }
    }

    MinecraftForge.EVENT_BUS.post(new WorldEvent.Load(internal));
    pluginManager.callEvent(new WorldLoadEvent(worlds.get(dimension)));
    return worlds.get(dimension);
  }
Esempio n. 4
0
 @Override
 public World getWorld(String name) {
   return worlds.get(name);
 }
Esempio n. 5
0
  public CraftServer(MinecraftServer server) {
    instance = this;
    configMan = server.getConfigurationManager();
    theServer = server;
    List<Integer> ids = Arrays.asList(DimensionManager.getIDs());
    Iterator<Integer> worldIter = ids.iterator();

    System.out.println("IS THE INSTANCE NULL? " + (instance == null ? "YES" : "NO"));
    this.pluginManager = new SimplePluginManager(this, commandMap);

    // pluginManager = new SimplePluginManager(this, commandMap);
    configuration = new YamlConfiguration();
    YamlConfiguration yml = new YamlConfiguration();
    try {
      yml.load(getClass().getClassLoader().getResourceAsStream("configurations/bukkit.yml"));
      if (!new File("bukkit.yml").exists()) {
        new File("bukkit.yml").createNewFile();
        yml.save("bukkit.yml");
      }
      configuration.load("bukkit.yml");
      configuration.addDefaults(yml);
      configuration.save("bukkit.yml");

    } catch (Exception e) {
      e.printStackTrace();
    }

    for (int id : ids) {
      worlds.get(id);
    }

    this.theLogger = BukkitContainer.bukkitLogger;
    // theLogger.info("Bukkit API for Vanilla, version " + apiVer + " starting up...");
    theLogger.info(
        "Starting BukkitForge "
            + BukkitContainer.BF_FULL_VERSION
            + "(CB-Version: "
            + BukkitContainer.CRAFT_VERSION
            + ").");

    Bukkit.setServer(this);
    this.theHelpMap = new SimpleHelpMap(this);
    this.theMessenger = new StandardMessenger();
    this.entityMetadata = new EntityMetadataStore();
    this.playerMetadata = new PlayerMetadataStore();
    this.worldMetadata = new WorldMetadataStore();
    this.warningState = Warning.WarningState.DEFAULT;
    this.console = (CraftConsoleCommandSender) CraftConsoleCommandSender.getInstance();

    CraftModRecipeHelper.saveCraftingManagerRecipes();

    HelpTopic myHelp =
        new CommandHelpTopic("bexec", "Run a command forcibly bukkit aliases", "", "");
    Bukkit.getServer().getHelpMap().addTopic(myHelp);

    loadPlugins();
    enablePlugins(PluginLoadOrder.STARTUP);

    // load plugin worlds - TODO

    theLogger.info("Loading PostWorld plugins...");
    enablePlugins(PluginLoadOrder.POSTWORLD);
    theLogger.info("Loaded plugins: ");
    for (Plugin i : pluginManager.getPlugins()) {
      theLogger.info(i.getName() + "- Enabled: " + i.isEnabled());
    }
    ForgeEventHandler.ready = true;
    commandMap.doneLoadingPlugins((ServerCommandManager) theServer.getCommandManager());
    if (!theServer.isDedicatedServer()) {
      EntityPlayer player =
          theServer.getConfigurationManager().getPlayerForUsername(theServer.getServerOwner());
      if (player != null) {
        player.sendChatToPlayer(
            ChatColor.GREEN
                + "CraftForge has finished loading! You may now enjoy a (relatively) lag-free game!");
        theServer.getCommandManager().executeCommand(player, "/plugins");
        (new PlayerTracker()).onPlayerLogin(player);
      }
    }
  }