public static void initDimension(int dim) { WorldServer overworld = getWorld(0); if (overworld == null) { throw new RuntimeException("Cannot Hotload Dim: Overworld is not Loaded!"); } try { DimensionManager.getProviderType(dim); } catch (Exception e) { System.err.println("Cannot Hotload Dim: " + e.getMessage()); return; // If a provider hasn't been registered then we can't hotload the dim } MinecraftServer mcServer = overworld.getMinecraftServer(); ISaveHandler savehandler = overworld.getSaveHandler(); WorldSettings worldSettings = new WorldSettings(overworld.getWorldInfo()); WorldServer world = (dim == 0 ? overworld : new WorldServerMulti( mcServer, savehandler, overworld.getWorldInfo().getWorldName(), dim, worldSettings, overworld, mcServer.theProfiler)); world.addWorldAccess(new WorldManager(mcServer, world)); MinecraftForge.EVENT_BUS.post(new WorldEvent.Load(world)); if (!mcServer.isSinglePlayer()) { world.getWorldInfo().setGameType(mcServer.getGameType()); } mcServer.func_147139_a(mcServer.func_147135_j()); }
@Override public boolean unloadWorld(World world, boolean save) { WorldServer handle = ((CraftWorld) world).getHandle(); WorldUnloadEvent ev = new WorldUnloadEvent(world); getPluginManager().callEvent(ev); if (ev.isCancelled()) return false; // cancelled DimensionManager.unloadWorld(handle.getWorldInfo().getDimension()); worlds.remove(handle.getWorldInfo().getDimension()); return true; }
@Override public World getWorld(UUID uid) { for (WorldServer w : theServer.worldServers) { //return null; UUID wUUID = new UUID(w.getSeed(), w.getWorldInfo().getDimension()); if (wUUID == uid) { return worlds.get(w.getWorldInfo().getDimension()); } //if (w.getWorldInfo().) } return null; }
public void transferPlayerToDimension(EntityPlayerMP par1EntityPlayerMP, int par2) { int var3 = par1EntityPlayerMP.dimension; WorldServer var4 = this.mcServer.worldServerForDimension(par1EntityPlayerMP.dimension); par1EntityPlayerMP.dimension = par2; WorldServer var5 = this.mcServer.worldServerForDimension(par1EntityPlayerMP.dimension); par1EntityPlayerMP.playerNetServerHandler.sendPacketToPlayer( new Packet9Respawn( par1EntityPlayerMP.dimension, (byte) par1EntityPlayerMP.worldObj.difficultySetting, var5.getWorldInfo().getTerrainType(), var5.getHeight(), par1EntityPlayerMP.theItemInWorldManager.getGameType())); var4.removeEntity(par1EntityPlayerMP); par1EntityPlayerMP.isDead = false; this.transferEntityToWorld(par1EntityPlayerMP, var3, var4, var5); this.func_72375_a(par1EntityPlayerMP, var4); par1EntityPlayerMP.playerNetServerHandler.setPlayerLocation( par1EntityPlayerMP.posX, par1EntityPlayerMP.posY, par1EntityPlayerMP.posZ, par1EntityPlayerMP.rotationYaw, par1EntityPlayerMP.rotationPitch); par1EntityPlayerMP.theItemInWorldManager.setWorld(var5); this.updateTimeAndWeatherForPlayer(par1EntityPlayerMP, var5); this.syncPlayerInventory(par1EntityPlayerMP); Iterator var6 = par1EntityPlayerMP.getActivePotionEffects().iterator(); while (var6.hasNext()) { PotionEffect var7 = (PotionEffect) var6.next(); par1EntityPlayerMP.playerNetServerHandler.sendPacketToPlayer( new Packet41EntityEffect(par1EntityPlayerMP.entityId, var7)); } }
/** par1 indicates if a log message should be output. */ protected void saveAllWorlds(boolean par1) { if (!this.worldIsBeingDeleted) { WorldServer[] aworldserver = this.worldServers; int i = aworldserver.length; for (int j = 0; j < i; ++j) { WorldServer worldserver = aworldserver[j]; if (worldserver != null) { if (!par1) { this.func_98033_al() .func_98233_a( "Saving chunks for level \'" + worldserver.getWorldInfo().getWorldName() + "\'/" + worldserver.provider.getDimensionName()); } try { worldserver.saveAllChunks(true, (IProgressUpdate) null); } catch (MinecraftException minecraftexception) { this.func_98033_al().func_98236_b(minecraftexception.getMessage()); } } } } }
/** par1 indicates if a log message should be output. */ protected void saveAllWorlds(boolean dontLog) { if (!this.worldIsBeingDeleted) { WorldServer[] var2 = this.worldServers; int var3 = var2.length; for (int var4 = 0; var4 < var3; ++var4) { WorldServer var5 = var2[var4]; if (var5 != null) { if (!dontLog) { logger.info( "Saving chunks for level \'" + var5.getWorldInfo().getWorldName() + "\'/" + var5.provider.getDimensionName()); } try { var5.saveAllChunks(true, (IProgressUpdate) null); } catch (MinecraftException var7) { logger.warn(var7.getMessage()); } } } } }
public static void setWorld(int id, WorldServer world) { if (world != null) { worlds.put(id, world); weakWorldMap.put(world, world); MinecraftServer.getServer().worldTickTimes.put(id, new long[100]); FMLLog.info( "Loading dimension %d (%s) (%s)", id, world.getWorldInfo().getWorldName(), world.getMinecraftServer()); } else { worlds.remove(id); MinecraftServer.getServer().worldTickTimes.remove(id); FMLLog.info("Unloading dimension %d", id); } ArrayList<WorldServer> tmp = new ArrayList<WorldServer>(); if (worlds.get(0) != null) tmp.add(worlds.get(0)); if (worlds.get(-1) != null) tmp.add(worlds.get(-1)); if (worlds.get(1) != null) tmp.add(worlds.get(1)); for (Entry<Integer, WorldServer> entry : worlds.entrySet()) { int dim = entry.getKey(); if (dim >= -1 && dim <= 1) { continue; } tmp.add(entry.getValue()); } MinecraftServer.getServer().worldServers = tmp.toArray(new WorldServer[tmp.size()]); }
protected void loadAllWorlds( String par1Str, String par2Str, long par3, WorldType par5WorldType, String par6Str) { this.convertMapIfNeeded(par1Str); this.setUserMessage("menu.loadingLevel"); ISaveHandler isavehandler = this.anvilConverterForAnvilFile.getSaveLoader(par1Str, true); WorldInfo worldinfo = isavehandler.loadWorldInfo(); WorldSettings worldsettings; if (worldinfo == null) { worldsettings = new WorldSettings( par3, this.getGameType(), this.canStructuresSpawn(), this.isHardcore(), par5WorldType); worldsettings.func_82750_a(par6Str); } else { worldsettings = new WorldSettings(worldinfo); } if (this.enableBonusChest) { worldsettings.enableBonusChest(); } WorldServer overWorld = (isDemo() ? new DemoWorldServer(this, isavehandler, par2Str, 0, theProfiler, func_98033_al()) : new WorldServer( this, isavehandler, par2Str, 0, worldsettings, theProfiler, func_98033_al())); for (int dim : DimensionManager.getStaticDimensionIDs()) { WorldServer world = (dim == 0 ? overWorld : new WorldServerMulti( this, isavehandler, par2Str, dim, worldsettings, overWorld, theProfiler, func_98033_al())); world.addWorldAccess(new WorldManager(this, world)); if (!this.isSinglePlayer()) { world.getWorldInfo().setGameType(this.getGameType()); } this.serverConfigManager.setPlayerManager(this.worldServers); MinecraftForge.EVENT_BUS.post(new WorldEvent.Load(world)); } this.serverConfigManager.setPlayerManager(new WorldServer[] {overWorld}); this.setDifficultyForAllWorlds(this.getDifficulty()); this.initialWorldChunkLoad(); }
public void setDifficultyForAllWorlds(EnumDifficulty difficulty) { for (int var2 = 0; var2 < this.worldServers.length; ++var2) { WorldServer var3 = this.worldServers[var2]; if (var3 != null) { if (var3.getWorldInfo().isHardcoreModeEnabled()) { var3.getWorldInfo().setDifficulty(EnumDifficulty.HARD); var3.setAllowedSpawnTypes(true, true); } else if (this.isSinglePlayer()) { var3.getWorldInfo().setDifficulty(difficulty); var3.setAllowedSpawnTypes(var3.getDifficulty() != EnumDifficulty.PEACEFUL, true); } else { var3.getWorldInfo().setDifficulty(difficulty); var3.setAllowedSpawnTypes(this.allowSpawnMonsters(), this.canSpawnAnimals); } } } }
public void addServerStatsToSnooper(PlayerUsageSnooper par1PlayerUsageSnooper) { par1PlayerUsageSnooper.addData("whitelist_enabled", Boolean.valueOf(false)); par1PlayerUsageSnooper.addData("whitelist_count", Integer.valueOf(0)); par1PlayerUsageSnooper.addData( "players_current", Integer.valueOf(this.getCurrentPlayerCount())); par1PlayerUsageSnooper.addData("players_max", Integer.valueOf(this.getMaxPlayers())); par1PlayerUsageSnooper.addData( "players_seen", Integer.valueOf(this.serverConfigManager.getAvailablePlayerDat().length)); par1PlayerUsageSnooper.addData("uses_auth", Boolean.valueOf(this.onlineMode)); par1PlayerUsageSnooper.addData("gui_state", this.getGuiEnabled() ? "enabled" : "disabled"); par1PlayerUsageSnooper.addData( "avg_tick_ms", Integer.valueOf((int) (MathHelper.average(this.tickTimeArray) * 1.0E-6D))); par1PlayerUsageSnooper.addData( "avg_sent_packet_count", Integer.valueOf((int) MathHelper.average(this.sentPacketCountArray))); par1PlayerUsageSnooper.addData( "avg_sent_packet_size", Integer.valueOf((int) MathHelper.average(this.sentPacketSizeArray))); par1PlayerUsageSnooper.addData( "avg_rec_packet_count", Integer.valueOf((int) MathHelper.average(this.receivedPacketCountArray))); par1PlayerUsageSnooper.addData( "avg_rec_packet_size", Integer.valueOf((int) MathHelper.average(this.receivedPacketSizeArray))); int i = 0; for (int j = 0; j < this.worldServers.length; ++j) { if (this.worldServers[j] != null) { WorldServer worldserver = this.worldServers[j]; WorldInfo worldinfo = worldserver.getWorldInfo(); par1PlayerUsageSnooper.addData( "world[" + i + "][dimension]", Integer.valueOf(worldserver.provider.dimensionId)); par1PlayerUsageSnooper.addData("world[" + i + "][mode]", worldinfo.getGameType()); par1PlayerUsageSnooper.addData( "world[" + i + "][difficulty]", Integer.valueOf(worldserver.difficultySetting)); par1PlayerUsageSnooper.addData( "world[" + i + "][hardcore]", Boolean.valueOf(worldinfo.isHardcoreModeEnabled())); par1PlayerUsageSnooper.addData( "world[" + i + "][generator_name]", worldinfo.getTerrainType().getWorldTypeName()); par1PlayerUsageSnooper.addData( "world[" + i + "][generator_version]", Integer.valueOf(worldinfo.getTerrainType().getGeneratorVersion())); par1PlayerUsageSnooper.addData( "world[" + i + "][height]", Integer.valueOf(this.buildLimit)); par1PlayerUsageSnooper.addData( "world[" + i + "][chunks_loaded]", Integer.valueOf(worldserver.getChunkProvider().getLoadedChunkCount())); ++i; } } par1PlayerUsageSnooper.addData("worlds", Integer.valueOf(i)); }
/** * @author blood - May 21st, 2016 * @reason - adjusted to support {@link DisplaceEntityEvent.Teleport.Portal} * @param playerIn The player teleporting to another dimension * @param targetDimensionId The id of target dimension. * @param teleporter The teleporter used to transport and create the portal */ public void transferPlayerToDimension( EntityPlayerMP playerIn, int targetDimensionId, net.minecraft.world.Teleporter teleporter) { DisplaceEntityEvent.Teleport.Portal event = SpongeCommonEventFactory.handleDisplaceEntityPortalEvent( playerIn, targetDimensionId, teleporter); if (event == null || event.isCancelled()) { return; } WorldServer fromWorld = (WorldServer) event.getFromTransform().getExtent(); WorldServer toWorld = (WorldServer) event.getToTransform().getExtent(); playerIn.dimension = toWorld.provider.getDimensionId(); // Support vanilla clients teleporting to custom dimensions int dimension = DimensionManager.getClientDimensionToSend( toWorld.provider.getDimensionId(), toWorld, playerIn); if (((IMixinEntityPlayerMP) playerIn).usesCustomClient()) { DimensionManager.sendDimensionRegistration(toWorld, playerIn, dimension); } playerIn.playerNetServerHandler.sendPacket( new S07PacketRespawn( playerIn.dimension, fromWorld.getDifficulty(), fromWorld.getWorldInfo().getTerrainType(), playerIn.theItemInWorldManager.getGameType())); fromWorld.removePlayerEntityDangerously(playerIn); playerIn.isDead = false; // we do not need to call transferEntityToWorld as we already have the correct transform and // created the portal in handleDisplaceEntityPortalEvent ((IMixinEntity) playerIn).setLocationAndAngles(event.getToTransform()); toWorld.spawnEntityInWorld(playerIn); toWorld.updateEntityWithOptionalForce(playerIn, false); playerIn.setWorld(toWorld); this.preparePlayer(playerIn, fromWorld); playerIn.playerNetServerHandler.setPlayerLocation( playerIn.posX, playerIn.posY, playerIn.posZ, playerIn.rotationYaw, playerIn.rotationPitch); playerIn.theItemInWorldManager.setWorld(toWorld); this.updateTimeAndWeatherForPlayer(playerIn, toWorld); this.syncPlayerInventory(playerIn); for (PotionEffect potioneffect : playerIn.getActivePotionEffects()) { playerIn.playerNetServerHandler.sendPacket( new S1DPacketEntityEffect(playerIn.getEntityId(), potioneffect)); } ((IMixinEntityPlayerMP) playerIn).refreshXpHealthAndFood(); // Forge needs to know when a player changes to new a dimension // This cannot be mapped to DisplaceEntityEvent.Teleport as this event must be called AFTER // transfer. net.minecraftforge.fml.common.FMLCommonHandler.instance() .firePlayerChangedDimensionEvent( playerIn, fromWorld.provider.getDimensionId(), toWorld.provider.getDimensionId()); }
public void addServerStatsToSnooper(PlayerUsageSnooper playerSnooper) { playerSnooper.addClientStat("whitelist_enabled", Boolean.valueOf(false)); playerSnooper.addClientStat("whitelist_count", Integer.valueOf(0)); if (this.serverConfigManager != null) { playerSnooper.addClientStat("players_current", Integer.valueOf(this.getCurrentPlayerCount())); playerSnooper.addClientStat("players_max", Integer.valueOf(this.getMaxPlayers())); playerSnooper.addClientStat( "players_seen", Integer.valueOf(this.serverConfigManager.getAvailablePlayerDat().length)); } playerSnooper.addClientStat("uses_auth", Boolean.valueOf(this.onlineMode)); playerSnooper.addClientStat("gui_state", this.getGuiEnabled() ? "enabled" : "disabled"); playerSnooper.addClientStat( "run_time", Long.valueOf( (getCurrentTimeMillis() - playerSnooper.getMinecraftStartTimeMillis()) / 60L * 1000L)); playerSnooper.addClientStat( "avg_tick_ms", Integer.valueOf((int) (MathHelper.average(this.tickTimeArray) * 1.0E-6D))); int var2 = 0; if (this.worldServers != null) { for (int var3 = 0; var3 < this.worldServers.length; ++var3) { if (this.worldServers[var3] != null) { WorldServer var4 = this.worldServers[var3]; WorldInfo var5 = var4.getWorldInfo(); playerSnooper.addClientStat( "world[" + var2 + "][dimension]", Integer.valueOf(var4.provider.getDimensionId())); playerSnooper.addClientStat("world[" + var2 + "][mode]", var5.getGameType()); playerSnooper.addClientStat("world[" + var2 + "][difficulty]", var4.getDifficulty()); playerSnooper.addClientStat( "world[" + var2 + "][hardcore]", Boolean.valueOf(var5.isHardcoreModeEnabled())); playerSnooper.addClientStat( "world[" + var2 + "][generator_name]", var5.getTerrainType().getWorldTypeName()); playerSnooper.addClientStat( "world[" + var2 + "][generator_version]", Integer.valueOf(var5.getTerrainType().getGeneratorVersion())); playerSnooper.addClientStat( "world[" + var2 + "][height]", Integer.valueOf(this.buildLimit)); playerSnooper.addClientStat( "world[" + var2 + "][chunks_loaded]", Integer.valueOf(var4.getChunkProvider().getLoadedChunkCount())); ++var2; } } } playerSnooper.addClientStat("worlds", Integer.valueOf(var2)); }
@Override public Optional<Pair<net.minecraft.world.World, World>> get(String name) { net.minecraft.world.WorldServer w = null; for (net.minecraft.world.WorldServer ws : net.minecraft.client.Minecraft.getMinecraft().getIntegratedServer().worldServers) { if (ws.getWorldInfo().getWorldName().equals(name)) { w = ws; break; } } if (w == null) { return Optional.absent(); } return Optional.of( new Pair<net.minecraft.world.World, World>(w, new ForgeWorld(this.context, w))); }
public void setDifficultyForAllWorlds(int par1) { for (int j = 0; j < this.worldServers.length; ++j) { WorldServer worldserver = this.worldServers[j]; if (worldserver != null) { if (worldserver.getWorldInfo().isHardcoreModeEnabled()) { worldserver.difficultySetting = 3; worldserver.setAllowedSpawnTypes(true, true); } else if (this.isSinglePlayer()) { worldserver.difficultySetting = par1; worldserver.setAllowedSpawnTypes(worldserver.difficultySetting > 0, true); } else { worldserver.difficultySetting = par1; worldserver.setAllowedSpawnTypes(this.allowSpawnMonsters(), this.canSpawnAnimals); } } } }
public World getWorld(int dimID) { if (worlds.containsKey(dimID)) return worlds.get(dimID); else if (!worlds.containsKey(dimID) && Arrays.asList(DimensionManager.getIDs()).contains(dimID)) { // dim there but not registered with us. WorldServer internal = DimensionManager.getWorld(dimID); int dim = internal.getWorldInfo().getDimension(); System.out.println("Registering dimension with BukkitForge: " + dim + "..." ); WorldProvider w = internal.provider; Environment env = w.isHellWorld ? Environment.NETHER : Environment.NORMAL; ChunkGenerator cg = new NormalChunkGenerator(internal);//(((WorldServer)ev.world).theChunkProviderServer); BukkitWorld bukkit = new BukkitWorld(internal, cg, env); BukkitServer.instance().worlds.put(dim, bukkit); return bukkit; } return null; }
public static int countLoadedChunks( ICommandSender sender, EntityPlayerMP player, boolean details, LoadedChunksVisitor visitor) { MinecraftServer server = ForgeTools.server; int total = 0; for (WorldServer s : server.worldServers) { World tmp = ((World) s); ImmutableSetMultimap<ChunkCoordIntPair, ForgeChunkManager.Ticket> forcedChunks = tmp.getPersistentChunks(); Set loadedChunks = new LinkedHashSet<ChunkCoordIntPair>(); for (ChunkCoordIntPair c : forcedChunks.keys()) { for (ForgeChunkManager.Ticket t : forcedChunks.get(c)) { loadedChunks = Sets.union(t.getChunkList(), loadedChunks); } } total += loadedChunks.size(); boolean playerInWorld = (player != null) ? s.getWorldInfo().equals(player.worldObj.getWorldInfo()) : false; visitor.visit(sender, player, details, playerInWorld, s, loadedChunks.size()); } return total; }
@Override public boolean teleport(Location location, PlayerTeleportEvent.TeleportCause cause) { if (getHandle().playerNetServerHandler == null) return false; // From = Players current Location Location from = this.getLocation(); // To = Players new Location if Teleport is Successful Location to = location; // Create & Call the Teleport Event. PlayerTeleportEvent event = new PlayerTeleportEvent((Player) this, from, to, cause); server.getPluginManager().callEvent(event); // Return False to inform the Plugin that the Teleport was unsuccessful/cancelled. if (event.isCancelled() == true) { return false; } // Update the From Location from = event.getFrom(); // Grab the new To Location dependent on whether the event was cancelled. to = event.getTo(); // Grab the To and From World Handles. WorldServer fromWorld = ((BukkitWorld) from.getWorld()).getHandle(); WorldServer toWorld = ((BukkitWorld) to.getWorld()).getHandle(); // Grab the EntityPlayerMP EntityPlayerMP entity = getHandle(); // Check if the fromWorld and toWorld are the same. if (fromWorld == toWorld) { entity.setPositionAndUpdate(location.getX(), location.getY(), location.getZ()); } else { // Close any foreign inventory if (getHandle().openContainer != getHandle().inventoryContainer) getHandle().closeInventory(); server .getHandle() .getConfigurationManager() .transferPlayerToDimension(entity, toWorld.getWorldInfo().getDimension()); entity.setPositionAndUpdate(location.getX(), location.getY(), location.getZ()); } return true; }
private static Entity sendEntityToWorld( Entity entity, int newDimension, Vector3 newPos, Facing3 newLook) { MinecraftServer server = MinecraftServer.getServer(); Entity currentEntity = entity; if (entity.dimension != newDimension) { if (entity instanceof EntityPlayerMP) { EntityPlayerMP player = (EntityPlayerMP) entity; ServerConfigurationManager scm = server.getConfigurationManager(); int oldDimension = player.dimension; player.dimension = newDimension; WorldServer oldWorld = server.worldServerForDimension(oldDimension); WorldServer newWorld = server.worldServerForDimension(newDimension); DimensionRegisterMessage packet = new DimensionRegisterMessage( newDimension, DimensionManager.getProviderType(newDimension)); LCRuntime.runtime.network().getPreferredPipe().sendForgeMessageTo(packet, player); player.closeScreen(); player.playerNetServerHandler.sendPacket( new S07PacketRespawn( player.dimension, player.worldObj.difficultySetting, newWorld.getWorldInfo().getTerrainType(), player.theItemInWorldManager.getGameType())); oldWorld.removePlayerEntityDangerously(player); player.isDead = false; player.setLocationAndAngles( newPos.x, newPos.y, newPos.z, (float) newLook.yaw, (float) newLook.pitch); newWorld.spawnEntityInWorld(player); player.setWorld(newWorld); scm.func_72375_a(player, oldWorld); player.playerNetServerHandler.setPlayerLocation( newPos.x, newPos.y, newPos.z, (float) newLook.yaw, (float) newLook.pitch); player.theItemInWorldManager.setWorld(newWorld); scm.updateTimeAndWeatherForPlayer(player, newWorld); scm.syncPlayerInventory(player); Iterator<?> var6 = player.getActivePotionEffects().iterator(); while (var6.hasNext()) player.playerNetServerHandler.sendPacket( new S1DPacketEntityEffect(player.getEntityId(), (PotionEffect) var6.next())); player.playerNetServerHandler.sendPacket( new S1FPacketSetExperience( player.experience, player.experienceTotal, player.experienceLevel)); } else { int oldDimension = entity.dimension; WorldServer oldWorld = server.worldServerForDimension(oldDimension); WorldServer newWorld = server.worldServerForDimension(newDimension); entity.dimension = newDimension; entity.worldObj.removeEntity(entity); entity.isDead = false; server .getConfigurationManager() .transferEntityToWorld(entity, oldDimension, oldWorld, newWorld); currentEntity = EntityList.createEntityByName(EntityList.getEntityString(entity), newWorld); if (currentEntity != null) { currentEntity.copyDataFrom(entity, true); currentEntity.setLocationAndAngles( newPos.x, newPos.y, newPos.z, (float) newLook.yaw, (float) newLook.pitch); newWorld.spawnEntityInWorld(currentEntity); } entity.isDead = true; oldWorld.resetUpdateEntityTick(); newWorld.resetUpdateEntityTick(); } } else { currentEntity.setLocationAndAngles( newPos.x, newPos.y, newPos.z, (float) newLook.yaw, (float) newLook.pitch); if (currentEntity instanceof EntityPlayerMP) { EntityPlayerMP mpEnt = (EntityPlayerMP) currentEntity; mpEnt.rotationYaw = (float) newLook.yaw; mpEnt.setPositionAndUpdate(newPos.x, newPos.y, newPos.z); mpEnt.worldObj.updateEntityWithOptionalForce(entity, false); } } return currentEntity; }
public static MobData calcMobs( ICommandSender sender, EntityPlayerMP player, boolean details, boolean kill, MobType type, float radius, HashMap<Chunk, Integer> mobs, WorldMobsVisitor visitor) { MobData total = new MobData(); for (WorldServer s : ForgeTools.server.worldServers) { MobData worldData = new MobData(); boolean playerInWorld = (player != null) ? s.getWorldInfo().equals(player.worldObj.getWorldInfo()) : false; List loadedEntityList = new ArrayList(s.loadedEntityList); for (int id = 0; id < loadedEntityList.size(); id++) { Object m = loadedEntityList.get(id); Chunk c; if (m instanceof EntityLiving) { c = s.getChunkFromChunkCoords( ((EntityLiving) m).chunkCoordX, ((EntityLiving) m).chunkCoordY); if (!c.isChunkLoaded) continue; } else continue; if (m instanceof EntityMob) { if (kill && type.is(MobType.hostile) && (player == null || ((EntityLiving) m).getDistanceToEntity(player) <= radius)) { ((EntityLiving) m).setDead(); worldData.incAmtRemoved(); } else worldData.incAmtHos(); } else if ((m instanceof IAnimals) && !(m instanceof INpc)) { if (kill && type.is(MobType.passive) && (player == null || ((EntityLiving) m).getDistanceToEntity(player) <= radius)) { ((EntityLiving) m).setDead(); worldData.incAmtRemoved(); } else worldData.incAmtPas(); } else if (m instanceof INpc) { if (kill && (type.is(MobType.npc)) && (player == null || ((EntityLiving) m).getDistanceToEntity(player) <= radius)) { ((EntityLiving) m).setDead(); worldData.incAmtRemoved(); } else worldData.incAmtNPC(); } if (!kill) { if (mobs.get(c) == null) { mobs.put(c, 1); } else { mobs.put(c, mobs.get(c) + 1); } } } visitor.visit(sender, playerInWorld, worldData, s, details, kill, type); total.incTotal(worldData); } return total; }
public void updateTimeLightAndEntities() { this.theProfiler.startSection("jobs"); Queue var1 = this.futureTaskQueue; synchronized (this.futureTaskQueue) { while (!this.futureTaskQueue.isEmpty()) { try { ((FutureTask) this.futureTaskQueue.poll()).run(); } catch (Throwable var9) { logger.fatal(var9); } } } this.theProfiler.endStartSection("levels"); int var11; for (var11 = 0; var11 < this.worldServers.length; ++var11) { long var2 = System.nanoTime(); if (var11 == 0 || this.getAllowNether()) { WorldServer var4 = this.worldServers[var11]; this.theProfiler.startSection(var4.getWorldInfo().getWorldName()); if (this.tickCounter % 20 == 0) { this.theProfiler.startSection("timeSync"); this.serverConfigManager.sendPacketToAllPlayersInDimension( new S03PacketTimeUpdate( var4.getTotalWorldTime(), var4.getWorldTime(), var4.getGameRules().getGameRuleBooleanValue("doDaylightCycle")), var4.provider.getDimensionId()); this.theProfiler.endSection(); } this.theProfiler.startSection("tick"); CrashReport var6; try { var4.tick(); } catch (Throwable var8) { var6 = CrashReport.makeCrashReport(var8, "Exception ticking world"); var4.addWorldInfoToCrashReport(var6); throw new ReportedException(var6); } try { var4.updateEntities(); } catch (Throwable var7) { var6 = CrashReport.makeCrashReport(var7, "Exception ticking world entities"); var4.addWorldInfoToCrashReport(var6); throw new ReportedException(var6); } this.theProfiler.endSection(); this.theProfiler.startSection("tracker"); var4.getEntityTracker().updateTrackedEntities(); this.theProfiler.endSection(); this.theProfiler.endSection(); } this.timeOfLastDimensionTick[var11][this.tickCounter % 100] = System.nanoTime() - var2; } this.theProfiler.endStartSection("connection"); this.getNetworkSystem().networkTick(); this.theProfiler.endStartSection("players"); this.serverConfigManager.onTick(); this.theProfiler.endStartSection("tickables"); for (var11 = 0; var11 < this.playersOnline.size(); ++var11) { ((IUpdatePlayerListBox) this.playersOnline.get(var11)).update(); } this.theProfiler.endSection(); }
public static int countDrops( ICommandSender sender, EntityPlayerMP player, HashMap<Chunk, Integer> items, boolean details, boolean kill, boolean killall, float radius, WorldDropsVisitor visitor) { int total = 0; // Iterate over loaded worlds for (WorldServer s : ForgeTools.server.worldServers) { boolean playerInWorld = (player != null) ? s.getWorldInfo().equals(player.worldObj.getWorldInfo()) : false; int worldItemCount = 0; int itemsDeleted = 0; // kill[all] are only relevant for the world the player is currently in if (!playerInWorld && (kill || killall)) continue; // Count entities List loadedEntityList = new ArrayList(s.loadedEntityList); for (int id = 0; id < loadedEntityList.size(); ++id) { Object t = loadedEntityList.get(id); if (t instanceof EntityItem) { EntityItem e = (EntityItem) t; Chunk c = s.getChunkFromBlockCoords((int) Math.round(e.posX), (int) Math.round(e.posZ)); if (!c.isChunkLoaded) continue; ++worldItemCount; if (((kill || killall) && sender != null && sender.getCommandSenderName().equals("Server")) || // Console is sending the command, so no player is needed (playerInWorld && (killall || (kill && e.getDistanceToEntity(player) <= radius)))) // Player wants to kill items around them { e.setDead(); ++itemsDeleted; continue; } if (items.get(c) == null) { items.put(c, 1); } else { items.put(c, items.get(c) + 1); } } } total += worldItemCount; visitor.visit( sender, player, playerInWorld, kill, killall, details, worldItemCount, itemsDeleted, s); } return total; }
public void updateTimeLightAndEntities() { this.theProfiler.startSection("levels"); int i; Integer[] ids = DimensionManager.getIDs(this.tickCounter % 200 == 0); for (int x = 0; x < ids.length; x++) { int id = ids[x]; long j = System.nanoTime(); if (id == 0 || this.getAllowNether()) { WorldServer worldserver = DimensionManager.getWorld(id); this.theProfiler.startSection(worldserver.getWorldInfo().getWorldName()); this.theProfiler.startSection("pools"); worldserver.getWorldVec3Pool().clear(); this.theProfiler.endSection(); if (this.tickCounter % 20 == 0) { this.theProfiler.startSection("timeSync"); this.serverConfigManager.sendPacketToAllPlayersInDimension( new Packet4UpdateTime(worldserver.getTotalWorldTime(), worldserver.getWorldTime()), worldserver.provider.dimensionId); this.theProfiler.endSection(); } this.theProfiler.startSection("tick"); FMLCommonHandler.instance().onPreWorldTick(worldserver); CrashReport crashreport; try { worldserver.tick(); } catch (Throwable throwable) { crashreport = CrashReport.makeCrashReport(throwable, "Exception ticking world"); worldserver.addWorldInfoToCrashReport(crashreport); throw new ReportedException(crashreport); } try { worldserver.updateEntities(); } catch (Throwable throwable1) { crashreport = CrashReport.makeCrashReport(throwable1, "Exception ticking world entities"); worldserver.addWorldInfoToCrashReport(crashreport); throw new ReportedException(crashreport); } FMLCommonHandler.instance().onPostWorldTick(worldserver); this.theProfiler.endSection(); this.theProfiler.startSection("tracker"); worldserver.getEntityTracker().updateTrackedEntities(); this.theProfiler.endSection(); this.theProfiler.endSection(); } worldTickTimes.get(id)[this.tickCounter % 100] = System.nanoTime() - j; } this.theProfiler.endStartSection("dim_unloading"); DimensionManager.unloadWorlds(worldTickTimes); this.theProfiler.endStartSection("connection"); this.getNetworkThread().networkTick(); this.theProfiler.endStartSection("players"); this.serverConfigManager.sendPlayerInfoToAllPlayers(); this.theProfiler.endStartSection("tickables"); for (i = 0; i < this.tickables.size(); ++i) { ((IUpdatePlayerListBox) this.tickables.get(i)).update(); } this.theProfiler.endSection(); }
public void initializeConnectionToPlayer(NetworkManager netManager, EntityPlayerMP playerIn) { GameProfile var3 = playerIn.getGameProfile(); PlayerProfileCache var4 = this.mcServer.getPlayerProfileCache(); GameProfile var5 = var4.func_152652_a(var3.getId()); String var6 = var5 == null ? var3.getName() : var5.getName(); var4.func_152649_a(var3); NBTTagCompound var7 = this.readPlayerDataFromFile(playerIn); playerIn.setWorld(this.mcServer.worldServerForDimension(playerIn.dimension)); playerIn.theItemInWorldManager.setWorld((WorldServer) playerIn.worldObj); String var8 = "local"; if (netManager.getRemoteAddress() != null) { var8 = netManager.getRemoteAddress().toString(); } logger.info( playerIn.getName() + "[" + var8 + "] logged in with entity id " + playerIn.getEntityId() + " at (" + playerIn.posX + ", " + playerIn.posY + ", " + playerIn.posZ + ")"); WorldServer var9 = this.mcServer.worldServerForDimension(playerIn.dimension); WorldInfo var10 = var9.getWorldInfo(); BlockPos var11 = var9.getSpawnPoint(); this.func_72381_a(playerIn, (EntityPlayerMP) null, var9); NetHandlerPlayServer var12 = new NetHandlerPlayServer(this.mcServer, netManager, playerIn); var12.sendPacket( new S01PacketJoinGame( playerIn.getEntityId(), playerIn.theItemInWorldManager.getGameType(), var10.isHardcoreModeEnabled(), var9.provider.getDimensionId(), var9.getDifficulty(), this.getMaxPlayers(), var10.getTerrainType(), var9.getGameRules().getGameRuleBooleanValue("reducedDebugInfo"))); var12.sendPacket( new S3FPacketCustomPayload( "MC|Brand", (new PacketBuffer(Unpooled.buffer())) .writeString(this.getServerInstance().getServerModName()))); var12.sendPacket( new S41PacketServerDifficulty(var10.getDifficulty(), var10.isDifficultyLocked())); var12.sendPacket(new S05PacketSpawnPosition(var11)); var12.sendPacket(new S39PacketPlayerAbilities(playerIn.capabilities)); var12.sendPacket(new S09PacketHeldItemChange(playerIn.inventory.currentItem)); playerIn.getStatFile().func_150877_d(); playerIn.getStatFile().func_150884_b(playerIn); this.func_96456_a((ServerScoreboard) var9.getScoreboard(), playerIn); this.mcServer.refreshStatusNextTick(); ChatComponentTranslation var13; if (!playerIn.getName().equalsIgnoreCase(var6)) { var13 = new ChatComponentTranslation( "multiplayer.player.joined.renamed", new Object[] {playerIn.getDisplayName(), var6}); } else { var13 = new ChatComponentTranslation( "multiplayer.player.joined", new Object[] {playerIn.getDisplayName()}); } var13.getChatStyle().setColor(EnumChatFormatting.YELLOW); this.sendChatMsg(var13); this.playerLoggedIn(playerIn); var12.setPlayerLocation( playerIn.posX, playerIn.posY, playerIn.posZ, playerIn.rotationYaw, playerIn.rotationPitch); this.updateTimeAndWeatherForPlayer(playerIn, var9); if (this.mcServer.getResourcePackUrl().length() > 0) { playerIn.func_175397_a( this.mcServer.getResourcePackUrl(), this.mcServer.getResourcePackHash()); } Iterator var14 = playerIn.getActivePotionEffects().iterator(); while (var14.hasNext()) { PotionEffect var15 = (PotionEffect) var14.next(); var12.sendPacket(new S1DPacketEntityEffect(playerIn.getEntityId(), var15)); } playerIn.addSelfToInternalCraftingInventory(); if (var7 != null && var7.hasKey("Riding", 10)) { Entity var16 = EntityList.createEntityFromNBT(var7.getCompoundTag("Riding"), var9); if (var16 != null) { var16.forceSpawn = true; var9.spawnEntityInWorld(var16); playerIn.mountEntity(var16); var16.forceSpawn = false; } } }
public BukkitServer(MinecraftServer server) { instance = this; cbBuild = BukkitContainer.CRAFT_VERSION; configMan = server.getConfigurationManager(); theServer = server; List<Integer> ids = Arrays.asList(DimensionManager.getIDs()); Iterator<Integer> _ = ids.iterator(); System.out.println("IS THE INSTANCE NULL? " + (instance == null ? "YES" : "NO")); this.pluginManager = new SimplePluginManager(this, commandMap); //pluginManager = new SimplePluginManager(this, commandMap); bukkitConfig = new YamlConfiguration(); YamlConfiguration yml = new YamlConfiguration(); try { yml.load(getClass().getClassLoader().getResourceAsStream("configurations/bukkit.yml")); if (!new File("bukkit.yml").exists()) { new File("bukkit.yml").createNewFile(); yml.save("bukkit.yml"); } bukkitConfig.load("bukkit.yml"); bukkitConfig.addDefaults(yml); bukkitConfig.save("bukkit.yml"); } catch (Exception e) { e.printStackTrace(); } String vanillaName = theServer.worldServerForDimension(0).getWorldInfo().getWorldName(); while(_.hasNext()) { int i = _.next(); WorldServer x = theServer.worldServerForDimension(i); BukkitWorld world = new BukkitWorld(x, this.getGenerator(x.getWorldInfo().getDimension()), this.wtToEnv(x)); worlds.put(i, world); //if (!x.getWorldInfo().getWorldName().equals(vanillaName)) pluginWorldMapping.put(x.getWorldInfo().getWorldName(), world); } this.theLogger = BukkitContainer.bukkitLogger; theLogger.info("Bukkit API for Vanilla, version " + apiVer + " starting up..."); thePluginLoader = new BukkitClassLoader(getClass().getClassLoader()); // I MAINTAIN THAT THIS WILL WORK EVENTUALLY /*try { System.out.println("This is a test of the SPM Loader!"); // this *should* load simplepluginamanger via BukkitClassLoader Class<?> pluginMan = thePluginLoader.loadClass("org.bukkit.plugin.SimplePluginManager"); System.out.println("Loaded class: " + pluginMan.getCanonicalName() + " via " + pluginMan.getClassLoader().getClass().getCanonicalName()); Method insn = pluginMan.getMethod("newInstance", new Class[] { BukkitServer.class, SimpleCommandMap.class }); insn.setAccessible(true); this.pluginManager = (PluginManager) insn.invoke(null, this, this.commandMap); } catch (Exception e1) { throw new RuntimeException("BukkitForge encountered an error (most likely it was installed incorrectly!)", e1); }*/ Bukkit.setServer(this); this.theHelpMap = new SimpleHelpMap(this); this.theMessenger = new StandardMessenger(); //theLogger.info("Testing the bukkit Logger!"); this.entityMetadata = new EntityMetadataStore(); this.playerMetadata = new PlayerMetadataStore(); this.worldMetadata = new WorldMetadataStore(); this.warningState = Warning.WarningState.DEFAULT; this.console = (BukkitConsoleCommandSender) BukkitConsoleCommandSender.getInstance(); // wait until server start /*try { Thread.currentThread().wait(); } catch (InterruptedException e) { theLogger.log(Level.FINE, "The server was interrupted, it might explode!", e); }*/ theLogger.info("Completing load..."); // fix for the 'mod recipes disappear' bug BukkitModRecipeHelper.saveCraftingManagerRecipes(); //configMan = theServer.getConfigurationManager(); //theServer = (DedicatedServer) server; HelpTopic myHelp = new CommandHelpTopic("bexec", "Run a command forcibly bukkit aliases", "", ""); Bukkit.getServer().getHelpMap().addTopic(myHelp); loadPlugins(); enablePlugins(PluginLoadOrder.STARTUP); theLogger.info("Loading PostWorld plugins..."); enablePlugins(PluginLoadOrder.POSTWORLD); theLogger.info("Loaded plugins: "); for (Plugin i : pluginManager.getPlugins()) { theLogger.info(i.getName() + "- Enabled: " + i.isEnabled()); } ForgeEventHandler.ready = true; commandMap.doneLoadingPlugins((ServerCommandManager) theServer.getCommandManager()); if (!theServer.isDedicatedServer()) { EntityPlayer par0 = theServer.getConfigurationManager().getPlayerForUsername(theServer.getServerOwner()); if (par0 != null) { par0.sendChatToPlayer(ChatColor.GREEN + "BukkitForge has finished loading! You may now enjoy a (relatively) lag-free game!"); theServer.getCommandManager().executeCommand(par0, "/plugins"); (new PlayerTracker()).onPlayerLogin(par0); } } }
public void initializeConnectionToPlayer( INetworkManager par1INetworkManager, EntityPlayerMP par2EntityPlayerMP) { this.readPlayerDataFromFile(par2EntityPlayerMP); par2EntityPlayerMP.setWorld( this.mcServer.worldServerForDimension(par2EntityPlayerMP.dimension)); par2EntityPlayerMP.theItemInWorldManager.setWorld((WorldServer) par2EntityPlayerMP.worldObj); String var3 = "local"; if (par1INetworkManager.getSocketAddress() != null) { var3 = par1INetworkManager.getSocketAddress().toString(); } logger.info( par2EntityPlayerMP.username + "[" + var3 + "] logged in with entity id " + par2EntityPlayerMP.entityId + " at (" + par2EntityPlayerMP.posX + ", " + par2EntityPlayerMP.posY + ", " + par2EntityPlayerMP.posZ + ")"); WorldServer var4 = this.mcServer.worldServerForDimension(par2EntityPlayerMP.dimension); ChunkCoordinates var5 = var4.getSpawnPoint(); this.func_72381_a(par2EntityPlayerMP, (EntityPlayerMP) null, var4); NetServerHandler var6 = new NetServerHandler(this.mcServer, par1INetworkManager, par2EntityPlayerMP); var6.sendPacketToPlayer( new Packet1Login( par2EntityPlayerMP.entityId, var4.getWorldInfo().getTerrainType(), par2EntityPlayerMP.theItemInWorldManager.getGameType(), var4.getWorldInfo().isHardcoreModeEnabled(), var4.provider.dimensionId, var4.difficultySetting, var4.getHeight(), this.getMaxPlayers())); var6.sendPacketToPlayer(new Packet6SpawnPosition(var5.posX, var5.posY, var5.posZ)); var6.sendPacketToPlayer(new Packet202PlayerAbilities(par2EntityPlayerMP.capabilities)); var6.sendPacketToPlayer(new Packet16BlockItemSwitch(par2EntityPlayerMP.inventory.currentItem)); this.updateTimeAndWeatherForPlayer(par2EntityPlayerMP, var4); this.sendPacketToAllPlayers( new Packet3Chat("\u00a7e" + par2EntityPlayerMP.username + " joined the game.")); this.playerLoggedIn(par2EntityPlayerMP); var6.setPlayerLocation( par2EntityPlayerMP.posX, par2EntityPlayerMP.posY, par2EntityPlayerMP.posZ, par2EntityPlayerMP.rotationYaw, par2EntityPlayerMP.rotationPitch); this.mcServer.getNetworkThread().addPlayer(var6); var6.sendPacketToPlayer(new Packet4UpdateTime(var4.getTotalWorldTime(), var4.getWorldTime())); if (this.mcServer.getTexturePack().length() > 0) { par2EntityPlayerMP.requestTexturePackLoad( this.mcServer.getTexturePack(), this.mcServer.textureSize()); } Iterator var7 = par2EntityPlayerMP.getActivePotionEffects().iterator(); while (var7.hasNext()) { PotionEffect var8 = (PotionEffect) var7.next(); var6.sendPacketToPlayer(new Packet41EntityEffect(par2EntityPlayerMP.entityId, var8)); } par2EntityPlayerMP.addSelfToInternalCraftingInventory(); }