Bug en essayant de faire un mur

Greg159357

Programmeur
24 Mars 2014
15
0
1
22
Bonjour, j'étais actuellement entrain de programmer, je teste mon plugin, et je m’aperçois que la création de murs est effectuée (je ne vois pas d'erreurs dans la console), mais que si je m'y approche, je serveur crash. Je vous donne mon code pour faire mes murs (ce code est censé faire un carré de 8000 cubes en périmètre) :

Code:
World world = plugin.getServer().getWorld("STD");
                plugin.getServer().broadcastMessage(ChatColor.GOLD + "[WARNING] There can be lags !");
                for (int y = 0; y != 128; y++) {
                    for (int x = -1000; x != 1000; x++) {
                        world.getBlockAt(x, y, -1000).setType(Material.GLASS);
                    }
                } 
                for (int y = 0; y != 128; y++) {
                    for (int z = -1000; z != 1000; z++) {
                        world.getBlockAt(-1000, y, z).setType(Material.GLASS);
                    }
                }
                for (int y = 0; y != 128; y++) {
                    for (int x = -1000; x != 1000; x++) {
                        world.getBlockAt(x, y, 1000).setType(Material.GLASS);
                    }
                }
                for (int y = 0; y != 128; y++) {
                    for (int z = -1000; z != 1000; z++) {
                        world.getBlockAt(1000, y, z).setType(Material.GLASS);
                    }
                }

Merci de votre réponse !
Je code sous GNU / Linux Ubuntu, avec NetBeans 7.4, et je test mon plugin sous Windows 7 x64 avec Java 7.
 
Le crash classique dans ce genre de problème c'est que tu crée des Block dans des Chunk qui ne sont pas généré et au moment ou le serveur génère les chunck il comprend pas pourquoi il y a déjà des block donc sa crash.
 
Merci pour ta réponse. Du coup que devrais-je rajouter (ou plus-tôt comment générer des chuncks normalement) ?
 
Un code à étudié pour la génération des chunck sinon le plus simple est de les générés en étant en jeu.

Code:
  public void run()
  {
    int unsavedChunks = getUnsavedChunks();
    if (unsavedChunks > 200)
      this.waitingForChunks = true;
    if ((this.waitingForChunks) && (unsavedChunks < 50)) {
      this.waitingForChunks = false;
      System.gc();
    }
    if (this.waitingForChunks) {
      if (unsavedChunks != this.lastChunkCount)
        this.plugin.getLogger().info("Unsaved chunks: " + unsavedChunks);
      this.lastChunkCount = unsavedChunks;
      return;
    }
    if (this.pausing) {
      if (Runtime.getRuntime().freeMemory() > 20971520L) {
        if (this.delay-- <= 0) {
          this.pausing = false;
          this.plugin.getLogger().info("Enough memory is available to continue.");
        } else {
          return;
        }
      } else {
        this.delay = 20;
        return;
      }
    } else if (Runtime.getRuntime().freeMemory() < 10485760L) {
      this.pausing = true;
      this.delay = 20;
      this.plugin.getLogger().severe("Less than 10MB of memory is available. Pausing until memory is freed.");
      return;
    }
    for (int x = -1; x <= 1; x++)
      for (int z = -1; z <= 1; z++)
        this.world.loadChunk(this.currentX + x, this.currentZ + z);
    for (int x = -1; x <= 1; x++)
      for (int z = -1; z <= 1; z++)
        this.world.unloadChunk(this.currentX + x, this.currentZ + z, true, false);
    this.currentX += 1;
    if (this.currentX >= this.maxX) {
      this.currentX = this.minX;
      this.currentZ += 1;
      if (this.currentZ >= this.maxZ) {
        if (this.wasSpawnLoaded)
          this.world.setKeepSpawnInMemory(true);
        forceSave(false);
        this.plugin.finishedTask();
      }
    }
  }

Et un peu de doc en plus: http://jd.bukkit.org/rb/doxygen/d6/de4/ChunkGenerator_8java_source.html