Example #1
0
  @Override
  public synchronized void setTrue(int x, int y, int z, World world) {
    if (world == null) return;

    int cx = x / 16;
    int cz = z / 16;

    int ix = Math.abs(x) % 16;
    int iz = Math.abs(z) % 16;

    String key = world.getName() + "," + cx + "," + cz;

    if (!store.containsKey(key)) {
      loadChunk(cx, cz, world);
    }

    ChunkStore cStore = store.get(key);

    if (cStore == null) {
      cStore = ChunkStoreFactory.getChunkStore(world, cx, cz);
      store.put(key, cStore);
    }

    cStore.setTrue(ix, y, iz);
  }
Example #2
0
  @Override
  public synchronized void saveChunk(int cx, int cz, World world) {
    if (world == null) return;

    boolean unloaded = false;
    if (!store.containsKey(world.getName() + "," + cx + "," + cz)) {
      List<Entity> tempSpawnedMobs = new ArrayList<Entity>(spawnedMobs);
      for (Entity entity : tempSpawnedMobs) {
        if (!isEntityInChunk(entity, cx, cz, world)) continue;

        loadChunk(cx, cz, world);
        unloaded = true;
        break;
      }

      if (!unloaded) {
        List<Entity> tempSpawnedPets = new ArrayList<Entity>(spawnedPets);
        for (Entity entity : tempSpawnedPets) {
          if (!isEntityInChunk(entity, cx, cz, world)) continue;

          loadChunk(cx, cz, world);
          unloaded = true;
          break;
        }
      }
    }

    if (!store.containsKey(world.getName() + "," + cx + "," + cz) && unloaded) {
      ChunkStore cStore = ChunkStoreFactory.getChunkStore(world, cx, cz);
      store.put(world.getName() + "," + cx + "," + cz, cStore);
    }

    if (store.containsKey(world.getName() + "," + cx + "," + cz)) {
      ChunkStore out = store.get(world.getName() + "," + cx + "," + cz);

      List<Entity> tempSpawnedMobs = new ArrayList<Entity>(spawnedMobs);
      for (Entity entity : tempSpawnedMobs) {
        if (!isEntityInChunk(entity, cx, cz, world)) continue;

        out.addSpawnedMob(entity.getUniqueId());
      }

      List<Entity> tempSpawnedPets = new ArrayList<Entity>(spawnedPets);
      for (Entity entity : tempSpawnedPets) {
        if (!isEntityInChunk(entity, cx, cz, world)) continue;

        out.addSpawnedPet(entity.getUniqueId());
      }

      if (!out.isDirty()) return;

      writeChunkStore(world, cx, cz, out);
    }
  }
Example #3
0
 @Override
 public synchronized void writeChunkStore(World world, int x, int z, ChunkStore data) {
   if (!data.isDirty()) {
     return;
   }
   try {
     mcMMOSimpleRegionFile rf = getSimpleRegionFile(world, x, z);
     ObjectOutputStream objectStream = new ObjectOutputStream(rf.getOutputStream(x, z));
     objectStream.writeObject(data);
     objectStream.flush();
     objectStream.close();
     data.setDirty(false);
   } catch (IOException e) {
     throw new RuntimeException("Unable to write chunk meta data for " + x + ", " + z, e);
   }
 }
Example #4
0
 @Override
 public boolean add(Chunk chunk) {
   if (synchronous) {
     destination.put(chunk);
     return true;
   } else {
     return super.add(chunk);
   }
 }
Example #5
0
  @Override
  public synchronized boolean isTrue(int x, int y, int z, World world) {
    if (world == null) return false;

    int cx = x / 16;
    int cz = z / 16;
    String key = world.getName() + "," + cx + "," + cz;

    if (!store.containsKey(key)) {
      loadChunk(cx, cz, world);
    }

    if (!store.containsKey(key)) {
      return false;
    }

    ChunkStore check = store.get(key);
    int ix = Math.abs(x) % 16;
    int iz = Math.abs(z) % 16;

    return check.isTrue(ix, y, iz);
  }
Example #6
0
  @Override
  public synchronized void loadChunk(int cx, int cz, World world) {
    if (world == null) return;

    if (store.containsKey(world.getName() + "," + cx + "," + cz)) return;

    ChunkStore in = null;

    UUID key = world.getUID();
    if (!this.oldData.containsKey(key))
      this.oldData.put(key, (new File(world.getWorldFolder(), "mcmmo_data")).exists());

    if (this.oldData.containsKey(key) && oldData.get(key))
      convertChunk(new File(world.getWorldFolder(), "mcmmo_data"), cx, cz, world, true);

    try {
      in = readChunkStore(world, cx, cz);
    } catch (Exception e) {
    }

    if (in != null) {
      store.put(world.getName() + "," + cx + "," + cz, in);

      List<UUID> mobs = in.getSpawnedMobs();
      List<UUID> pets = in.getSpawnedPets();

      if (mobs.isEmpty() && pets.isEmpty()) return;

      for (LivingEntity entity : world.getLivingEntities()) {
        if (mobs.contains(entity.getUniqueId())) addSpawnedMob(entity);

        if (pets.contains(entity.getUniqueId())) addSpawnedPet(entity);
      }

      in.clearSpawnedMobs();
      in.clearSpawnedPets();
    }
  }
Example #7
0
  @Override
  public synchronized void setFalse(int x, int y, int z, World world) {
    if (world == null) return;

    int cx = x / 16;
    int cz = z / 16;

    int ix = Math.abs(x) % 16;
    int iz = Math.abs(z) % 16;

    String key = world.getName() + "," + cx + "," + cz;

    if (!store.containsKey(key)) {
      loadChunk(cx, cz, world);
    }

    ChunkStore cStore = store.get(key);

    if (cStore == null) {
      return; // No need to make a store for something we will be setting to false
    }

    cStore.setFalse(ix, y, iz);
  }