Пример #1
0
  /**
   * Places Blocks of a predetermined type just above the highest Block at each corner of the given
   * Chunk
   *
   * @param chunk The given Chunk
   */
  public static void markCorners(Chunk chunk) {
    // Get the highest Block (should be empty) at the South-West corner
    Block block = chunk.getBlock(0, 127, 0);
    // Move down until a non-empty Block is found
    while (block.getTypeId() == 0) block = block.getRelative(BlockFace.DOWN);
    // Change the empty Block just above the Block found
    block.getRelative(BlockFace.UP).setTypeId(cornerID);

    // Get the highest Block (should be empty) at the South-East corner
    block = chunk.getBlock(0, 127, 15);
    // Move down until a non-empty Block is found
    while (block.getTypeId() == 0) block = block.getRelative(BlockFace.DOWN);
    // Change the empty Block just above the Block found
    block.getRelative(BlockFace.UP).setTypeId(cornerID);

    // Get the highest Block (should be empty) at the North-West corner
    block = chunk.getBlock(15, 127, 0);
    // Move down until a non-empty Block is found
    while (block.getTypeId() == 0) block = block.getRelative(BlockFace.DOWN);
    // Change the empty Block just above the Block found
    block.getRelative(BlockFace.UP).setTypeId(cornerID);

    // Get the highest Block (should be empty) at the North-East corner
    block = chunk.getBlock(15, 127, 15);
    // Move down until a non-empty Block is found
    while (block.getTypeId() == 0) block = block.getRelative(BlockFace.DOWN);
    // Change the empty Block just above the Block found
    block.getRelative(BlockFace.UP).setTypeId(cornerID);
  }
 private void getDestination(int id, Player p) {
   // get the destination sign
   Sign s = getDestinationSign(id);
   if (s != null) {
     String line1 = s.getLine(1);
     String line2 = s.getLine(2);
     String line3 = s.getLine(3);
     if (line1.isEmpty() || line2.isEmpty() || line3.isEmpty()) {
       TARDISMessage.send(p, "JUNK_LINES");
       return;
     }
     World w = plugin.getServer().getWorld(line1);
     int x = TARDISNumberParsers.parseInt(line2);
     int z = TARDISNumberParsers.parseInt(line3);
     // load the chunk
     Chunk chunk = w.getChunkAt(x, z);
     while (!chunk.isLoaded()) {
       w.loadChunk(chunk);
     }
     int y = w.getHighestBlockYAt(x, z);
     Location d = new Location(w, x, y, z);
     // TODO check destination
     if (plugin.getPluginRespect().getRespect(d, new Parameters(p, FLAG.getNoMessageFlags()))) {
       while (!chunk.isLoaded()) {
         chunk.load();
       }
       d.setY(getActualHighestY(d));
       plugin.getGeneralKeeper().setJunkDestination(d);
     }
   }
 }
  /**
   * Populates the world whit planets
   *
   * @param world the world to work on
   * @param random the random to use
   * @param source the source chunk
   */
  @Override
  public void populate(World world, Random random, Chunk source) {
    if (populateDepth > MAX_POPULATE_DEPTH) {
      return;
    }
    populateDepth++;
    int planetX, planetY, planetZ, size;

    for (int i = 0; i < NUMBER_OFF_PLANETS; i++) {

      planetY = random.nextInt(world.getMaxHeight());
      size = random.nextInt(MAX_SIZE - MIN_SIZE) + MIN_SIZE;
      if (planetY + size > world.getMaxHeight() || planetY - size < 0) {
        continue;
        // Reject this planet
      }
      planetX = random.nextInt(16) + (source.getX() << 4);
      planetZ = random.nextInt(16) + (source.getZ() << 4);

      this.makePlanet(
          world,
          planetX,
          planetY,
          planetZ,
          size,
          TOP_LAYER_BLOCK[random.nextInt(TOP_LAYER_BLOCK.length)],
          ALLOWED_BLOCKS[random.nextInt(ALLOWED_BLOCKS.length)],
          SPECIAL_BLOCKS[random.nextInt(SPECIAL_BLOCKS.length)]);
    }
    populateDepth--;
  }
Пример #4
0
 @Override
 public boolean a(IBlockAccess iblockaccess, int x, int y, int z, int face) {
   int index = CustomBlock.getIndex(x, y, z);
   Chunk chunk = ((World) iblockaccess).getChunkAt(x >> 4, z >> 4).bukkitChunk;
   if (chunk.getClass().equals(SpoutCraftChunk.class)) {
     TIntIntHashMap powerOverrides = ((SpoutCraftChunk) chunk).powerOverrides;
     if (powerOverrides.containsKey(index)) {
       int powerbits = powerOverrides.get(index);
       switch (face) {
         case 0:
           return (powerbits & (1 << 0)) != 0;
         case 1:
           return (powerbits & (1 << 1)) != 0;
         case 2:
           return (powerbits & (1 << 2)) != 0;
         case 3:
           return (powerbits & (1 << 3)) != 0;
         case 4:
           return (powerbits & (1 << 4)) != 0;
         case 5:
           return (powerbits & (1 << 5)) != 0;
         default:
           return parent.a(iblockaccess, x, y, z, face);
       }
     }
   }
   return parent.a(iblockaccess, x, y, z, face);
 }
Пример #5
0
  public static boolean SpawnCustomTrees(
      World world, Random rand, WorldConfig worldSettings, int x, int y, int z) {

    if (!worldSettings.HasCustomTrees) return false;

    Chunk chunk = world.getWorld().getChunkAt(x >> 4, z >> 4);

    BiomeBase localBiomeBase =
        world.getWorldChunkManager().getBiome(chunk.getX() * 16 + 16, chunk.getZ() * 16 + 16);

    boolean objectSpawned = false;
    int spawnattemps = 0;
    while (!objectSpawned && spawnattemps < worldSettings.objectSpawnRatio) {
      CustomObject SelectedObject =
          worldSettings.Objects.get(rand.nextInt(worldSettings.Objects.size()));

      spawnattemps++;

      if (SelectedObject.branch
          || !SelectedObject.canSpawnInBiome(localBiomeBase)
          || !SelectedObject.tree) continue;

      int randomRoll = rand.nextInt(100);

      if (randomRoll < SelectedObject.rarity) {
        if (CustomObjectGen.ObjectCanSpawn(world, x, y, z, SelectedObject))
          objectSpawned =
              GenerateCustomObject(world, rand, worldSettings, x, y, z, SelectedObject, true);
      }
    }
    return objectSpawned;
  }
Пример #6
0
  @Override
  public void populate(World world, Random rand, Chunk chunk) {
    int x, y, z;
    Block block;

    for (x = 0; x < 16; ++x) {
      for (z = 0; z < 16; ++z) {
        for (y = 80; chunk.getBlock(x, y, z).getType() == Material.AIR; --y) ;
        block = chunk.getBlock(x, y, z);
        if (block != null) {
          // snow on snow biomes
          if ((block.getBiome() == Biome.FROZEN_OCEAN)
              || (block.getBiome() == Biome.FROZEN_RIVER)
              || (block.getBiome() == Biome.ICE_DESERT)
              || (block.getBiome() == Biome.ICE_MOUNTAINS)
              || (block.getBiome() == Biome.ICE_PLAINS)
              || (block.getBiome() == Biome.TUNDRA)
              || (block.getBiome() == Biome.EXTREME_HILLS)) {
            if ((block.getType() == Material.RED_ROSE)
                || (block.getType() == Material.YELLOW_FLOWER)
                || (block.getType() == Material.LONG_GRASS)
                || (block.getType() == Material.CACTUS)
                || (block.getType() == Material.SUGAR_CANE_BLOCK)) {
            } else if ((block.getType() == Material.STATIONARY_WATER)
                || (block.getType() == Material.WATER)) {
              block.setType(Material.ICE);
            } else {
              block.getRelative(0, 1, 0).setTypeId(Material.SNOW.getId());
            }
          }
        }
      }
    }
  }
Пример #7
0
  @Override
  public void populate(World world, Random random, Chunk chunk) {
    int x = chunk.getX();
    int z = chunk.getZ();

    int rx = x * 16;
    int rz = z * 16;

    // Cactuses
    if (ConfigManager.isGenerateCactuses(plugin, world)) {
      this.placeCactuses(world, rx, rz, random);
    }

    // Shrubs
    if (ConfigManager.isGenerateShrubs(plugin, world)) {
      this.placeShrubs(world, rx, rz, random);
    }

    // Set biome for proper weather effect
    for (int i = 0; i < 16; i++) {
      for (int j = 0; j < 16; j++) {
        world.setBiome(rx + j, rz + i, Biome.DESERT);
      }
    }
  }
Пример #8
0
  // When a chunk unloads, remove its monsters, excluding Withers
  // EnderDragon is NOT a monster, it is a ComplexLivingEntity (LEAVE ENDER ALONE)
  // Hoping this cuts down on lag?
  @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
  public void onChunkUnload(ChunkUnloadEvent event) {
    Chunk chunk = event.getChunk();
    for (Entity entity : chunk.getEntities()) {
      if (!entity.isDead() && entity instanceof Monster) {
        Monster monster = (Monster) entity;

        Boolean remove = true;

        if (monster.getCustomName() != null) {
          remove = false;
        }
        if (monster.getType() == EntityType.WITHER) {
          remove = false;
        }
        for (ItemStack item : monster.getEquipment().getArmorContents()) {
          if (item != null) {
            remove = false;
            break;
          }
        }
        if ((monster.getEquipment().getItemInHand() != null)
            || (monster.getType() == EntityType.SKELETON
                && monster.getEquipment().getItemInHand().getType() != Material.BOW)) {
          remove = false;
        }
        if (remove) {
          if (monster.getVehicle() instanceof Chicken) {
            monster.getVehicle().remove();
          }
          monster.remove();
        }
      }
    }
  }
Пример #9
0
 public static void loadBlocks(Chunk chunk) {
   ResultSet r = null;
   try {
     r =
         (new SQLQuery(
                 "select l.world,l.x,l.y,l.z,b.dayPlaced,b.id from £.locations l, £.nonnatural b where l.id=b.location and l.chunkx="
                     + chunk.getX()
                     + " and l.chunkz="
                     + chunk.getZ()
                     + ";",
                 msqlc))
             .excecuteQuery();
   } catch (MySQLSyntaxErrorException e1) {
     e1.printStackTrace();
   }
   try {
     while (r.next()) {
       GregorianCalendar g = new GregorianCalendar();
       g.setTime(r.getDate(5));
       BlockManager.loadBlock(
           (new Location(Bukkit.getWorld(r.getString(1)), r.getInt(2), r.getInt(3), r.getInt(4)))
               .getBlock(),
           g,
           r.getInt(6));
     }
   } catch (SQLException e) {
     e.printStackTrace();
   }
 }
Пример #10
0
 /** Counts: - EnderDragons - EnderCrystals */
 private void countEntities() {
   if (this.endWorld.getEnvironment() == Environment.THE_END) {
     this.plugin.getLogger().info("Counting existing EDs in " + this.endWorld.getName() + "...");
     for (final EndChunk c : this.chunks.getSafeChunksList()) {
       if (this.endWorld.isChunkLoaded(c.getX(), c.getZ())) {
         final Chunk chunk = this.endWorld.getChunkAt(c.getX(), c.getZ());
         for (final Entity e : chunk.getEntities()) {
           if (e.getType() == EntityType.ENDER_DRAGON) {
             final EnderDragon ed = (EnderDragon) e;
             if (!this.dragons.containsKey(ed.getUniqueId())) {
               ed.setMaxHealth(this.config.getEdHealth());
               ed.setHealth(ed.getMaxHealth());
               this.dragons.put(ed.getUniqueId(), new HashMap<String, Double>());
               this.loadedDragons.add(ed.getUniqueId());
             }
           } else if (e.getType() == EntityType.ENDER_CRYSTAL) {
             c.addCrystalLocation(e);
           }
         }
       } else {
         this.endWorld.loadChunk(c.getX(), c.getZ());
         c.resetSavedDragons();
         this.endWorld.unloadChunkRequest(c.getX(), c.getZ());
       }
     }
     this.plugin
         .getLogger()
         .info("Done, " + this.getNumberOfAliveEnderDragons() + " EnderDragon(s) found.");
   }
 }
Пример #11
0
  /**
   * Removes ownership of the current Chunk from the Player
   *
   * @param player The Player selling the Chunk
   */
  public static void sell(Player player) {
    // Cancel if the Player does not have permission to use the command
    if (!MyChunks.hasPermission(player, "own")) {
      player.sendMessage(permissionMsg);
      return;
    }

    // Retrieve the OwnedChunk that the Player is in
    String world = player.getWorld().getName();
    Chunk chunk = player.getLocation().getBlock().getChunk();
    int x = chunk.getX();
    int z = chunk.getZ();
    OwnedChunk ownedChunk = MyChunks.findOwnedChunk(world, x, z);

    // Cancel if the Chunk is not owned
    if (ownedChunk == null) {
      player.sendMessage(MyChunks.doNotOwnMsg);
      return;
    }

    // Cancel if the OwnedChunk is owned by someone else
    if (!ownedChunk.owner.equals(player.getName()))
      if (MyChunks.hasPermission(player, "admin")) Econ.sell(player, ownedChunk.owner);
      else {
        player.sendMessage(MyChunks.doNotOwnMsg);
        return;
      }
    else Econ.sell(player);

    MyChunks.removeOwnedChunk(world, x, z);
  }
Пример #12
0
  @Override
  public void run() {
    long worldTime = world.getTime();

    if (worldTime < 13000 || worldTime > 23000) {
      return;
    }

    spawn:
    for (Chunk chunk : world.getLoadedChunks()) {
      if (this.random.nextInt(100) == 1) {
        int x = (chunk.getX() * 16) + this.random.nextInt(12) + 2;
        int z = (chunk.getZ() * 16) + this.random.nextInt(12) + 2;
        int y = world.getHighestBlockYAt(x, z);

        Location spawnLocation = new Location(world, x, y, z);

        for (Entity entity : this.world.getLivingEntities()) {
          if (!entity.isDead() && entity.getLocation().distanceSquared(spawnLocation) < 1024) {
            continue spawn;
          }
        }

        EntityGiantZombie entity = new EntityGiantZombie(world);

        entity.setPositionRotation(x, y, z, 0, 90);
        ((CraftWorld) world).getHandle().addEntity(entity, SpawnReason.CUSTOM);
        entity.p(null);
      }
    }
  }
Пример #13
0
 public FakeBlock(Location location, Material material) {
   this.location = location;
   this.material = material;
   Chunk chunk = location.getChunk();
   chunkx = chunk.getX();
   chunkz = chunk.getZ();
 }
  private void radialRemoval(SnipeData v) {
    final Chunk targetChunk = getTargetBlock().getChunk();
    int entityCount = 0;
    int chunkCount = 0;

    entityCount += removeEntities(targetChunk);

    int radius = Math.round(v.getBrushSize() / 16);

    for (int x = targetChunk.getX() - radius; x <= targetChunk.getX() + radius; x++) {
      for (int z = targetChunk.getZ() - radius; z <= targetChunk.getZ() + radius; z++) {
        entityCount += removeEntities(getWorld().getChunkAt(x, z));
        chunkCount++;
      }
    }
    v.sendMessage(
        ChatColor.GREEN
            + "Removed "
            + ChatColor.RED
            + entityCount
            + ChatColor.GREEN
            + " entities out of "
            + ChatColor.BLUE
            + chunkCount
            + ChatColor.GREEN
            + " chunks.");
  }
Пример #15
0
  private BlockVector correctBlockVector(BlockVector vector, Chunk chunk) {

    vector.setX(vector.getBlockX() & 0xF + (chunk.getX() << 4));
    vector.setZ(vector.getBlockZ() & 0xF + (chunk.getZ() << 4));
    vector.setY(vector.getBlockY() & 0xFF);
    return vector;
  }
Пример #16
0
 private boolean set(final String key, final Object value) {
   RedisConnection<String, String> redis = ChunkControl.getPlugin().redis();
   return redis.hset(
       String.format("chunk:%s:%d", key, chunk.getX()),
       String.format("%d", chunk.getZ()),
       String.valueOf(value));
 }
  private void radialRemoval(final SnipeData v) {
    final Chunk _targetChunk = this.getTargetBlock().getChunk();
    int _entityCount = 0;
    int _chunkCount = 0;

    _entityCount += this.removeEntities(_targetChunk);

    for (int _x = _targetChunk.getX() - v.getBrushSize();
        _x <= _targetChunk.getX() + v.getBrushSize();
        _x++) {
      for (int _z = _targetChunk.getZ() - v.getBrushSize();
          _z <= _targetChunk.getZ() + v.getBrushSize();
          _z++) {
        _entityCount += removeEntities(this.getWorld().getChunkAt(_x, _z));
        _chunkCount++;
      }
    }
    v.sendMessage(
        ChatColor.GREEN
            + "Removed "
            + ChatColor.RED
            + _entityCount
            + ChatColor.GREEN
            + " entities out of "
            + ChatColor.BLUE
            + _chunkCount
            + ChatColor.GREEN
            + " chunks.");
  }
Пример #18
0
  @Override
  public void populate(World world, Random random, Chunk source) {
    ChunkSnapshot snapshot = source.getChunkSnapshot();

    if (random.nextInt(100) < CHANCE_OF_1) {
      {
        int x, z, x2, z2;
        if (random.nextBoolean()) {
          x = random.nextBoolean() ? 0 : 15;
          x2 = x == 0 ? 1 : 14;
          z2 = z = random.nextInt(14) + 1;
        } else {
          x2 = x = random.nextInt(14) + 1;
          z = random.nextBoolean() ? 0 : 15;
          z2 = z == 0 ? 1 : 14;
        }
        if (snapshot.getHighestBlockYAt(x, z) > FLOOR_HEIGHT + MAX_HEIGHT
            && snapshot.getHighestBlockYAt(x2, z2) <= FLOOR_HEIGHT + MIN_HEIGHT) {
          Material type =
              random.nextInt(100) < LIT_CHANCE ? Material.JACK_O_LANTERN : Material.PUMPKIN;
          source
              .getBlock(
                  x,
                  snapshot.getHighestBlockYAt(x2, z2)
                      + random.nextInt(MAX_HEIGHT - MIN_HEIGHT + 1)
                      + MIN_HEIGHT,
                  z)
              .setTypeIdAndData(type.getId(), getData(x, z, x2, z2, type), true);
        }
      }

      if (random.nextInt(100) < CHANCE_OF_2) {
        int x, z, x2, z2;
        if (random.nextBoolean()) {
          x = random.nextBoolean() ? 0 : 15;
          x2 = x == 0 ? 1 : 14;
          z2 = z = random.nextInt(14) + 1;
        } else {
          x2 = x = random.nextInt(14) + 1;
          z = random.nextBoolean() ? 0 : 15;
          z2 = z == 0 ? 1 : 14;
        }
        if (snapshot.getHighestBlockYAt(x, z) > FLOOR_HEIGHT + MAX_HEIGHT
            && snapshot.getHighestBlockYAt(x2, z2) <= FLOOR_HEIGHT + MIN_HEIGHT) {
          Material type =
              random.nextInt(100) < LIT_CHANCE ? Material.JACK_O_LANTERN : Material.PUMPKIN;
          source
              .getBlock(
                  x,
                  snapshot.getHighestBlockYAt(x2, z2)
                      + random.nextInt(MAX_HEIGHT - MIN_HEIGHT + 1)
                      + MIN_HEIGHT,
                  z)
              .setTypeIdAndData(type.getId(), getData(x, z, x2, z2, type), true);
        }
      }
    }
  }
Пример #19
0
 public boolean isWithin(Chunk chunk) {
   if (minCorner != null && maxCorner != null) {
     return chunk.getX() >= this.minCorner.getX()
         && chunk.getX() <= this.maxCorner.getX()
         && chunk.getZ() >= this.minCorner.getZ()
         && chunk.getZ() <= this.maxCorner.getZ();
   }
   return false;
 }
Пример #20
0
 public void updateChunks(World world, List<Chunk> chunks) {
   for (Chunk currentChunk : chunks) {
     net.minecraft.server.v1_8_R3.World mcWorld = ((CraftChunk) currentChunk).getHandle().world;
     for (EntityHuman eh : (List<EntityHuman>) mcWorld.players) {
       EntityPlayer ep = (EntityPlayer) eh;
       ep.chunkCoordIntPairQueue.add(
           new ChunkCoordIntPair(currentChunk.getX(), currentChunk.getZ()));
     }
   }
 }
 @EventHandler(priority = EventPriority.MONITOR)
 public void onPlayerTeleport(PlayerTeleportEvent event) {
   if (Settings.loadChunks() == true) {
     World world = event.getPlayer().getWorld();
     Chunk chunk = world.getChunkAt(event.getTo());
     int x = chunk.getX();
     int z = chunk.getZ();
     world.refreshChunk(x, z);
   }
 }
Пример #22
0
 public Town getTown(Location loc) {
   Chunk chunk = loc.getChunk();
   for (Town town : towns) {
     for (SimpleChunk chunk1 : town.getChunks()) {
       if (chunk.getX() == chunk1.getX() && chunk.getZ() == chunk1.getZ()) {
         return town;
       }
     }
   }
   return null;
 }
Пример #23
0
  /**
   * Removes a friend from an owned chunk Called when landlord remfriend is executed
   *
   * @param sender who executed the command
   * @param args given with command
   * @return boolean
   */
  @Override
  public boolean execute(CommandSender sender, String[] args, String label) {
    if (!(sender instanceof Player)) {
      sender.sendMessage(
          Fonctions.replaceColor(Landlord.getMessages().getString("noConsole"))); // mess
    } else {
      if (args.length < 2) {
        sender.sendMessage(
            Fonctions.replaceColor(Landlord.getMessages().getString("usageLandUnfriend"))); // mess
        return true;
      }
      Player player = (Player) sender;
      if (!player.hasPermission("landlord.player.own")) {
        player.sendMessage(
            Fonctions.replaceColor(Landlord.getMessages().getString("noPermission"))); // mess
        return true;
      }

      Chunk currChunk = player.getLocation().getChunk();
      /*
       * *************************************
       * mark for possible change    !!!!!!!!!
       * *************************************
       */
      Friend frd = Friend.friendFromOfflinePlayer(getOfflinePlayer(args[1]));
      OwnedLand land =
          OwnedLand.getLandFromDatabase(
              currChunk.getX(), currChunk.getZ(), currChunk.getWorld().getName());
      if (land == null
          || (!land.ownerUUID().equals(player.getUniqueId())
              && !player.hasPermission("landlord.admin.modifyfriends"))) {
        player.sendMessage(
            Fonctions.replaceColor(Landlord.getMessages().getString("noOwner"))); // mess
        return true;
      }
      if (!land.removeFriend(frd)) {
        player.sendMessage(
            Fonctions.replaceColor(Landlord.getMessages().getString("playerNotFriendLand"))
                .replaceAll("%pseudo%", args[1])); // mess
        return true;
      }
      if (plugin.getConfig().getBoolean("options.particleEffects", true)) { // conf
        land.highlightLand(player, Effect.VILLAGER_THUNDERCLOUD, 2);
      }
      plugin.getDatabase().save(land);
      if (plugin.getConfig().getBoolean("options.soundEffects", true)) { // conf
        player.playSound(player.getLocation(), Sound.ZOMBIE_INFECT, 10, .5f);
      }
      player.sendMessage(
          Fonctions.replaceColor(Landlord.getMessages().getString("playerIsNoLongerFriendLand"))
              .replaceAll("%pseudo%", args[1])); // mess
    }
    return true;
  }
Пример #24
0
  /**
   * ********************************************************** getPos()
   * **********************************************************
   */
  public void getPos(Player player, Command cmd, String label, String[] args) {
    Location loc = player.getLocation();
    World world = loc.getWorld();
    Chunk chunk = loc.getChunk();

    this.plugin.chat.info(player, "World  : " + world.getName());
    this.plugin.chat.info(player, "Chunk  : x=" + chunk.getX() + " z=" + chunk.getZ());
    this.plugin.chat.info(
        player,
        "Coords : x=" + loc.getBlockX() + " y=" + loc.getBlockY() + " z=" + loc.getBlockZ());
  }
Пример #25
0
 public boolean isInTownTerrority(Location loc) {
   Chunk chunk = loc.getChunk();
   for (Town town : towns) {
     for (SimpleChunk chunk1 : town.getChunks()) {
       if (chunk.getX() == chunk1.getX() && chunk.getZ() == chunk1.getZ()) {
         return true;
       }
     }
   }
   return false;
 }
Пример #26
0
  // Return false if unimplemented
  @Override
  public int getChunkMap(TileFlags map) {
    map.clear();
    if (world == null) return -1;
    int cnt = 0;
    // Mark loaded chunks
    for (Chunk c : world.getLoadedChunks()) {
      map.setFlag(c.getX(), c.getZ(), true);
      cnt++;
    }
    File f = world.getWorldFolder();
    File regiondir = new File(f, "region");
    File[] lst = regiondir.listFiles();
    if (lst != null) {
      byte[] hdr = new byte[4096];
      for (File rf : lst) {
        if (!rf.getName().endsWith(".mca")) {
          continue;
        }
        String[] parts = rf.getName().split("\\.");
        if ((!parts[0].equals("r")) && (parts.length != 4)) continue;

        RandomAccessFile rfile = null;
        int x = 0, z = 0;
        try {
          x = Integer.parseInt(parts[1]);
          z = Integer.parseInt(parts[2]);
          rfile = new RandomAccessFile(rf, "r");
          rfile.read(hdr, 0, hdr.length);
        } catch (IOException iox) {
          Arrays.fill(hdr, (byte) 0);
        } catch (NumberFormatException nfx) {
          Arrays.fill(hdr, (byte) 0);
        } finally {
          if (rfile != null) {
            try {
              rfile.close();
            } catch (IOException iox) {
            }
          }
        }
        for (int i = 0; i < 1024; i++) {
          int v = hdr[4 * i] | hdr[4 * i + 1] | hdr[4 * i + 2] | hdr[4 * i + 3];
          if (v == 0) continue;
          int xx = (x << 5) | (i & 0x1F);
          int zz = (z << 5) | ((i >> 5) & 0x1F);
          if (!map.setFlag(xx, zz, true)) {
            cnt++;
          }
        }
      }
    }
    return cnt;
  }
Пример #27
0
 public Location getSurfaceAt(Location origin) {
   Chunk chunky = origin.getChunk();
   int x = origin.getBlockX(),
       z = origin.getBlockZ(),
       surface = 0,
       envid = origin.getWorld().getEnvironment().getId();
   Set dimmap =
       Sets.newHashSet(envid == 0 ? new int[] {1, 2, 3, 7, 15, 16} : envid == -1 ? 87 : 121);
   for (int y = 0; y != 256; y++)
     if (dimmap.contains(chunky.getBlock(x, y, z).getTypeId())) surface = y;
   return chunky.getBlock(x, surface, z).getLocation();
 }
Пример #28
0
  /**
   * Gives ownership of the current Chunk to the Player
   *
   * @param player The Player buying the Chunk
   */
  public static void buy(Player player) {
    // Cancel if the Player does not have permission to use the command
    if (!MyChunks.hasPermission(player, "own")) {
      player.sendMessage(permissionMsg);
      return;
    }

    // Retrieve the OwnedChunk that the Player is in
    Chunk chunk = player.getLocation().getBlock().getChunk();
    String world = player.getWorld().getName();
    int x = chunk.getX();
    int z = chunk.getZ();
    OwnedChunk ownedChunk = MyChunks.getOwnedChunk(world, x, z);

    // If the owner of the OwnedChunk is not blank then the Chunk is already claimed
    if (ownedChunk.owner != null) {
      player.sendMessage(claimedMsg);
      return;
    }

    ownedChunk.owner = player.getName();

    int limit = MyChunks.getOwnLimit(player);
    int owned = 0;

    // Don't check how many are owned if the Player is not limited
    if (limit != -1) {
      // Retrieve the ChunkCounter value of the Player
      Object object = MyChunks.chunkCounter.get(player.getName());
      if (object != null) owned = (Integer) object;

      // Cancel if the Player owns their maximum limit
      if (owned >= limit) {
        player.sendMessage(limitMsg);
        return;
      }
    }

    // Charge the Player only if they don't have the 'chunkown.free' node
    if (MyChunks.hasPermission(player, "free")) player.sendMessage(buyFreeMsg);
    else if (!Econ.buy(player)) {
      // Delete the OwnedChunk because the Player could not afford it
      MyChunks.removeOwnedChunk(world, x, z);
      return;
    }

    // Increment the ChunkCounter of the Player
    MyChunks.chunkCounter.put(ownedChunk.owner, owned + 1);

    markCorners(chunk);
    MyChunks.save();
  }
Пример #29
0
  public FrameInfo(Frame type, ItemFrame frame) {
    this.type = type;
    id = frame.getUniqueId();

    Location loc = frame.getLocation();
    Chunk chunk = loc.getChunk();

    worldId = chunk.getWorld().getUID();
    chunk_x = chunk.getX();
    chunk_z = chunk.getZ();

    instance = new WeakReference<ItemFrame>(frame);
  }
Пример #30
0
 @Override
 public void populate(World world, Random random, Chunk source) {
   for (int x = 0; x < 16; x++) {
     for (int z = 0; z < 16; z++) {
       int chance = random.nextInt(100);
       if (chance < 33) {
         Block handle = world.getHighestBlockAt(x + source.getX() * 16, z + source.getZ() * 16);
         if (handle.getRelative(BlockFace.DOWN).getType().equals(Material.GRASS)) {
           handle.setTypeIdAndData(Material.LONG_GRASS.getId(), (byte) 1, false);
         }
       }
     }
   }
 }