public Chunk getOrCreateChunk(int x, int z) {
    random.setSeed((long) x * 341873128712L + (long) z * 132897987541L);

    Chunk chunk;

    // Get default biome data for chunk
    CustomBiomeGrid biomegrid = new CustomBiomeGrid();
    biomegrid.biome = new BiomeGenBase[256];
    world.getWorldChunkManager().getBiomeGenAt(biomegrid.biome, x << 4, z << 4, 16, 16, false);

    // Try extended block method (1.2+)
    short[][] xbtypes =
        generator.generateExtBlockSections(
            CraftServer.instance().getWorld(world.provider.dimensionId),
            this.random,
            x,
            z,
            biomegrid);
    if (xbtypes != null) {
      chunk = new Chunk(this.world, x, z);

      ExtendedBlockStorage[] csect = chunk.getBlockStorageArray();
      int scnt = Math.min(csect.length, xbtypes.length);

      // Loop through returned sections
      for (int sec = 0; sec < scnt; sec++) {
        if (xbtypes[sec] == null) {
          continue;
        }
        byte[] secBlkID = new byte[4096]; // Allocate blk ID bytes
        byte[] secExtBlkID = (byte[]) null; // Delay getting extended ID nibbles
        short[] bdata = xbtypes[sec];
        // Loop through data, 2 blocks at a time
        for (int i = 0, j = 0; i < bdata.length; i += 2, j++) {
          short b1 = bdata[i];
          short b2 = bdata[i + 1];
          byte extb = (byte) ((b1 >> 8) | ((b2 >> 4) & 0xF0));

          secBlkID[i] = (byte) b1;
          secBlkID[(i + 1)] = (byte) b2;

          if (extb != 0) { // If extended block ID data
            if (secExtBlkID == null) { // Allocate if needed
              secExtBlkID = new byte[2048];
            }
            secExtBlkID[j] = extb;
          }
        }
        // Build chunk section
        csect[sec] = new ExtendedBlockStorage(sec << 4, false); // , secBlkID, secExtBlkID);
      }
    } else { // Else check for byte-per-block section data
      byte[][] btypes =
          generator.generateBlockSections(getWorld(world), this.random, x, z, biomegrid);

      if (btypes != null) {
        chunk = new Chunk(this.world, x, z);

        ExtendedBlockStorage[] csect = chunk.getBlockStorageArray();
        int scnt = Math.min(csect.length, btypes.length);

        for (int sec = 0; sec < scnt; sec++) {
          if (btypes[sec] == null) {
            continue;
          }
          csect[sec] = new ExtendedBlockStorage(sec << 4, false); // , btypes[sec], null);
        }
      } else { // Else, fall back to pre 1.2 method
        @SuppressWarnings("deprecation")
        byte[] types = generator.generate(getWorld(world), this.random, x, z);
        int ydim = types.length / 256;
        int scnt = ydim / 16;

        chunk = new Chunk(this.world, x, z); // Create empty chunk

        ExtendedBlockStorage[] csect = chunk.getBlockStorageArray();

        scnt = Math.min(scnt, csect.length);
        // Loop through sections
        for (int sec = 0; sec < scnt; sec++) {
          ExtendedBlockStorage cs = null; // Add sections when needed
          byte[] csbytes = (byte[]) null;

          for (int cy = 0; cy < 16; cy++) {
            int cyoff = cy | (sec << 4);

            for (int cx = 0; cx < 16; cx++) {
              int cxyoff = (cx * ydim * 16) + cyoff;

              for (int cz = 0; cz < 16; cz++) {
                byte blk = types[cxyoff + (cz * ydim)];

                if (blk != 0) { // If non-empty
                  if (cs == null) { // If no section yet, get one
                    cs = csect[sec] = new ExtendedBlockStorage(sec << 4, true);
                    csbytes = cs.getBlockLSBArray();
                  }
                  csbytes[(cy << 8) | (cz << 4) | cx] = blk;
                }
              }
            }
          }
          // If section built, finish prepping its state
          if (cs != null) {
            cs.getYLocation();
          }
        }
      }
    }
    // Set biome grid
    byte[] biomeIndex = chunk.getBiomeArray();
    for (int i = 0; i < biomeIndex.length; i++) {
      biomeIndex[i] = (byte) (biomegrid.biome[i].biomeID & 0xFF);
    }
    // Initialize lighting
    chunk.generateSkylightMap();

    return chunk;
  }
Esempio n. 2
0
  /** Processes all the commands registered in the server and creates help topics for them. */
  public synchronized void initializeCommands() {
    // ** Load topics from highest to lowest priority order **
    Set<String> ignoredPlugins = new HashSet<String>(yaml.getIgnoredPlugins());

    // Don't load any automatic help topics if All is ignored
    if (ignoredPlugins.contains("All")) {
      return;
    }

    // Initialize help topics from the server's command map
    outer:
    for (Command command : server.getCommandMap().getCommands()) {
      if (commandInIgnoredPlugin(command, ignoredPlugins)) {
        continue;
      }

      // Register a topic
      for (Class c : topicFactoryMap.keySet()) {
        if (c.isAssignableFrom(command.getClass())) {
          HelpTopic t = topicFactoryMap.get(c).createTopic(command);
          if (t != null) addTopic(t);
          continue outer;
        }
        if (command instanceof PluginCommand
            && c.isAssignableFrom(((PluginCommand) command).getExecutor().getClass())) {
          HelpTopic t = topicFactoryMap.get(c).createTopic(command);
          if (t != null) addTopic(t);
          continue outer;
        }
      }
      addTopic(new GenericCommandHelpTopic(command));
    }

    // Initialize command alias help topics
    for (Command command : server.getCommandMap().getCommands()) {
      if (commandInIgnoredPlugin(command, ignoredPlugins)) {
        continue;
      }
      for (String alias : command.getAliases()) {
        if (!helpTopics.containsKey("/" + alias)) {
          addTopic(new CommandAliasHelpTopic("/" + alias, "/" + command.getLabel(), this));
        }
      }
    }

    // Initialize help topics from the server's fallback commands
    for (VanillaCommand command : server.getCommandMap().getFallbackCommands()) {
      if (!commandInIgnoredPlugin(command, ignoredPlugins)) {
        addTopic(new GenericCommandHelpTopic(command));
      }
    }

    // Add alias sub-index
    addTopic(
        new IndexHelpTopic(
            "Aliases",
            "Lists command aliases",
            null,
            Collections2.filter(
                helpTopics.values(), Predicates.instanceOf(CommandAliasHelpTopic.class))));

    // Initialize plugin-level sub-topics
    Map<String, Set<HelpTopic>> pluginIndexes = new HashMap<String, Set<HelpTopic>>();
    fillPluginIndexes(pluginIndexes, server.getCommandMap().getCommands());
    fillPluginIndexes(pluginIndexes, server.getCommandMap().getFallbackCommands());

    for (Map.Entry<String, Set<HelpTopic>> entry : pluginIndexes.entrySet()) {
      addTopic(
          new IndexHelpTopic(
              entry.getKey(),
              "All commands for " + entry.getKey(),
              null,
              entry.getValue(),
              "Below is a list of all " + entry.getKey() + " commands:"));
    }

    // Amend help topics from the help.yml file
    for (HelpTopicAmendment amendment : yaml.getTopicAmendments()) {
      if (helpTopics.containsKey(amendment.getTopicName())) {
        helpTopics
            .get(amendment.getTopicName())
            .amendTopic(amendment.getShortText(), amendment.getFullText());
        if (amendment.getPermission() != null) {
          helpTopics.get(amendment.getTopicName()).amendCanSee(amendment.getPermission());
        }
      }
    }
  }
 private org.bukkit.World getWorld(WorldServer world2) {
   return CraftServer.instance().getWorld(world2.provider.dimensionId);
 }
  @SuppressWarnings("unchecked")
  public void register(Command command, Map<String, Object> cmdParams) {
    String cmdName = command.getCommandName();

    log.devDebug("register() command=", command, ",cmdParams=", cmdParams);
    command.setPlugin(plugin);
    command.setCommandParameters(cmdParams);

    if (cmdParams.containsKey("name")) cmdName = (String) cmdParams.get("name");

    // we never load the same command twice
    if (loadedCommands.contains(cmdName)) return;

    CraftServer cs = (CraftServer) Bukkit.getServer();
    SimpleCommandMap commandMap = cs.getCommandMap();

    try {
      Constructor<PluginCommand> constructor =
          PluginCommand.class.getDeclaredConstructor(String.class, Plugin.class);
      constructor.setAccessible(true);

      // construct a new PluginCommand object
      PluginCommand pc = constructor.newInstance(cmdName, plugin);
      pc.setExecutor(command);
      pc.setLabel(cmdName);
      if (command.getUsage() != null) pc.setUsage(command.getUsage());

      // don't set Permission node, not all permission plugins behave
      // with superperms command permissions nicely.
      //			pc.setPermission(command.getCommandPermissionNode());

      // check for aliases defined in the configuration
      Object o = cmdParams.get("aliases");
      if (o != null) {
        List<String> aliases = null;
        if (o instanceof List) {
          aliases = (List<String>) o;
        } else if (o instanceof String) {
          aliases = new ArrayList<String>(2);
          aliases.add((String) o);
        } else log.warn("invalid aliases defined for command ", cmdName, ": ", o);

        if (aliases == null) aliases = new ArrayList<String>(1);

        aliases.add("hsp" + command.getCommandName()); // all commands have "hsp" prefix alias
        pc.setAliases(aliases);
      }
      // otherwise set whatever the command has defined
      else {
        List<String> aliases = new ArrayList<String>(5);
        String[] strAliases = command.getCommandAliases();
        if (strAliases != null) {
          for (String alias : strAliases) {
            aliases.add(alias);
          }
        }
        aliases.add("hsp" + command.getCommandName()); // all commands have "hsp" prefix alias
        pc.setAliases(aliases);
      }

      // register it
      commandMap.register("hsp", pc);
      loadedCommands.add(cmdName);

      Debug.getInstance().devDebug("register() command ", command, " registered");
    } catch (Exception e) {
      e.printStackTrace();
    }
  }