private DummyWorldServer(CommonDummyDataManager datamanager, WorldSettings settings) {
   super(
       CommonUtil.getMCServer(),
       datamanager,
       getDummyName(),
       0,
       settings,
       CommonUtil.getMCServer().methodProfiler,
       Environment.NORMAL,
       null);
   datamanager.initialized = true;
   // dereference this dummy world again...
   WorldUtil.removeWorld(this.getWorld());
   // set some variables to null
   this.chunkProvider = this.chunkProviderServer = null;
   this.generator = null;
   this.entityList = null;
   this.tileEntityList = null;
   this.generator = null;
   WorldServerRef.playerManager.set(this, null);
   this.players = null;
   this.tracker = null;
   this.worldMaps = null;
   this.worldProvider = null;
   this.random = null;
 }
Example #2
0
  /**
   * Regenerates the spawn point for a world if it is not properly set<br>
   * Also updates the spawn position in the world configuration
   *
   * @param world to regenerate the spawn point for
   */
  public void fixSpawnLocation() {
    // Obtain the configuration and the set spawn position from it
    World world = spawnPoint.getWorld();
    if (world == null) {
      return;
    }

    Environment env = world.getEnvironment();
    if (env == Environment.NETHER || env == Environment.THE_END) {
      // Use a portal agent to generate the world spawn point
      Location loc = WorldUtil.findSpawnLocation(spawnPoint);
      if (loc == null) {
        return; // Failure?
      }
      spawnPoint = new Position(loc);
    } else {
      spawnPoint.setY(world.getHighestBlockYAt(spawnPoint));
    }

    // Minor offset
    spawnPoint.setX(0.5 + (double) spawnPoint.getBlockX());
    spawnPoint.setY(0.5 + (double) spawnPoint.getBlockY());
    spawnPoint.setZ(0.5 + (double) spawnPoint.getBlockZ());

    // Apply position to the world if same world
    if (!isOtherWorldSpawn()) {
      world.setSpawnLocation(
          spawnPoint.getBlockX(), spawnPoint.getBlockY(), spawnPoint.getBlockZ());
    }
  }
 public static MinecartMember getAt(Block railblock, boolean checkmoving) {
   if (railblock == null) return null;
   return getAt(
       WorldUtil.getNative(railblock.getWorld()),
       BlockUtil.getCoordinates(railblock),
       checkmoving);
 }
 public static MinecartMember spawn(Location at, int type) {
   MinecartMember mm =
       new MinecartMember(
           WorldUtil.getNative(at.getWorld()), at.getX(), at.getY(), at.getZ(), type);
   mm.yaw = at.getYaw();
   mm.pitch = at.getPitch();
   mm.world.addEntity(mm);
   return mm;
 }
 private static EntityMinecart findByID(UUID uuid) {
   EntityMinecart e;
   for (World world : WorldUtil.getWorlds()) {
     for (Object o : world.entityList) {
       if (o instanceof EntityMinecart) {
         e = (EntityMinecart) o;
         if (e.uniqueId.equals(uuid)) {
           return e;
         }
       }
     }
   }
   return null;
 }
Example #6
0
 public boolean updateLoadedChunks(World world) {
   this.loadedChunks.clear();
   final LongIterator iter = this.chunks.longIterator();
   while (iter.hasNext()) {
     long chunk = iter.next();
     if (WorldUtil.isLoaded(world, MathUtil.longHashMsw(chunk), MathUtil.longHashLsw(chunk))) {
       this.loadedChunks.add(chunk);
     }
   }
   if (OfflineGroupManager.lastUnloadChunk != null) {
     this.loadedChunks.remove(OfflineGroupManager.lastUnloadChunk);
   }
   return this.testFullyLoaded();
 }
  public static void replaceMinecarts(EntityMinecart toreplace, EntityMinecart with) {
    with.yaw = toreplace.yaw;
    with.pitch = toreplace.pitch;
    with.lastX = toreplace.lastX;
    with.lastY = toreplace.lastY;
    with.lastZ = toreplace.lastZ;
    with.locX = toreplace.locX;
    with.locY = toreplace.locY;
    with.locZ = toreplace.locZ;
    with.motX = toreplace.motX;
    with.motY = toreplace.motY;
    with.motZ = toreplace.motZ;
    with.b = toreplace.b;
    with.c = toreplace.c;
    with.fallDistance = toreplace.fallDistance;
    with.ticksLived = toreplace.ticksLived;
    with.uniqueId = toreplace.uniqueId;
    with.setDamage(toreplace.getDamage());
    ItemUtil.transfer(toreplace, with);
    with.setDerailedVelocityMod(toreplace.getDerailedVelocityMod());
    with.setFlyingVelocityMod(toreplace.getFlyingVelocityMod());
    // force removal in chunk
    with.dead = false;
    toreplace.dead = true;
    toreplace.ag = true;
    // Set the chunk coordinates
    if (toreplace.ah == 0 && toreplace.ai == 0 && toreplace.aj == 0) {
      // System.out.println("FUUU!");
    }
    with.ah = toreplace.ah;
    with.ai = toreplace.ai;
    with.aj = toreplace.aj;

    // preserve the Bukkit entity, simply swap the contents
    CraftMinecart bukkitEntity = bukkitEntityField.get(toreplace);
    if (bukkitEntity != null) {
      bukkitEntity.setHandle(with);
      bukkitEntityField.set(with, bukkitEntity);
    }

    // swap
    MinecartSwapEvent.call(toreplace, with);
    WorldUtil.getTracker(toreplace.world).untrackEntity(toreplace);
    toreplace.world.removeEntity(toreplace);
    with.world.addEntity(with);
    if (toreplace.passenger != null) toreplace.passenger.setPassengerOf(with);
  }
 @EventHandler(priority = EventPriority.MONITOR)
 public void onChunkLoad(ChunkLoadEvent event) {
   // Set the initial power state of all signs within this Chunk
   SignActionEvent info;
   try {
     for (BlockState state : WorldUtil.getBlockStates(event.getChunk())) {
       if (state instanceof Sign) {
         info = new SignActionEvent(state.getBlock());
         LogicUtil.addOrRemove(poweredBlocks, info.getBlock(), isPowered(info));
       }
     }
   } catch (Throwable t) {
     TrainCarts.plugin
         .getLogger()
         .log(
             Level.SEVERE,
             "Error while initializing sign power states in chunk "
                 + event.getChunk().getX()
                 + "/"
                 + event.getChunk().getZ(),
             t);
   }
 }
 /**
  * Gets this property for the block specified
  *
  * @param world the block is in
  * @param x - coordinate of the block
  * @param y - coordinate of the block
  * @param z - coordinate of the block
  * @return The property of the material
  */
 public T get(org.bukkit.World world, int x, int y, int z) {
   return get(WorldUtil.getBlockType(world, x, y, z));
 }
Example #10
0
 /**
  * Gets the tracker entry of the entity specified
  *
  * @param entity to get it for
  * @return entity tracker entry, or null if none is set
  */
 public static EntityTrackerEntry getTrackerEntry(Entity entity) {
   return (EntityTrackerEntry) WorldUtil.getTracker(entity.world).trackedEntities.get(entity.id);
 }
  @SuppressWarnings("rawtypes")
  public static MinecartMember getAt(World world, ChunkCoordinates coord, boolean checkmoving) {
    net.minecraft.server.Chunk chunk = WorldUtil.getChunk(world, coord.x >> 4, coord.z >> 4);
    if (chunk != null) {
      MinecartMember mm;
      MinecartMember result = null;
      for (List list : chunk.entitySlices) {
        for (Object e : list) {
          if (e instanceof MinecartMember) {
            mm = (MinecartMember) e;
            if (mm.getBlockX() != coord.x) continue;
            if (mm.getBlockY() != coord.y) continue;
            if (mm.getBlockZ() != coord.z) continue;
            result = mm;
            if (result.isHeadingTo(coord)) return result;
          }
        }
      }
      if (result == null && checkmoving) {
        Block b = world.getWorld().getBlockAt(coord.x, coord.y, coord.z);
        int id = b.getTypeId();

        // get the two connected rails to check
        if (BlockUtil.isRails(id)) {
          BlockFace[] possible = FaceUtil.getFaces(BlockUtil.getRails(b).getDirection());
          MinecartMember mm1 = getAt(Util.getRailsBlock(b.getRelative(possible[0])), false);
          MinecartMember mm2 = getAt(Util.getRailsBlock(b.getRelative(possible[1])), false);
          if (mm1 != null && mm2 != null && mm1.group == mm2.group) {
            Location loc = b.getLocation();
            return mm1.distance(loc) < mm2.distance(loc) ? mm1 : mm2;
          } else if (isHeadingTo(mm1, coord)) {
            return mm1;
          } else if (isHeadingTo(mm2, coord)) {
            return mm2;
          } else {
            return null;
          }
        } else if (Util.isPressurePlate(id)) {
          // check all directions
          MinecartMember mm1 = getAt(Util.getRailsBlock(b.getRelative(BlockFace.NORTH)), false);
          MinecartMember mm2 = getAt(Util.getRailsBlock(b.getRelative(BlockFace.SOUTH)), false);
          MinecartMember mm3 = getAt(Util.getRailsBlock(b.getRelative(BlockFace.EAST)), false);
          MinecartMember mm4 = getAt(Util.getRailsBlock(b.getRelative(BlockFace.WEST)), false);
          if (mm1 != null && mm2 != null && mm1.group == mm2.group) {
            Location loc = b.getLocation();
            return mm1.distance(loc) < mm2.distance(loc) ? mm1 : mm2;
          } else if (mm3 != null && mm4 != null && mm3.group == mm4.group) {
            Location loc = b.getLocation();
            return mm3.distance(loc) < mm4.distance(loc) ? mm3 : mm4;
          } else if (isHeadingTo(mm1, coord)) {
            return mm1;
          } else if (isHeadingTo(mm2, coord)) {
            return mm2;
          } else if (isHeadingTo(mm3, coord)) {
            return mm3;
          } else if (isHeadingTo(mm4, coord)) {
            return mm4;
          } else {
            return null;
          }
        }
      }
      return result;
    }
    return null;
  }
 public static MinecartMember getAt(
     org.bukkit.World world, ChunkCoordinates coord, boolean checkmoving) {
   return getAt(WorldUtil.getNative(world), coord, checkmoving);
 }
Example #13
0
 public void addAllChunks(World world) {
   for (org.bukkit.Chunk chunk : WorldUtil.getChunks(world)) {
     addChunk(chunk);
   }
 }
Example #14
0
 public void updateHunger(World world) {
   for (Player player : WorldUtil.getPlayers(world)) {
     updateHunger(player);
   }
 }