Java 类net.minecraft.server.management.PlayerList 实例源码

项目:InControl    文件:GenericRuleEvaluator.java   
private boolean isFakePlayer(Entity entity) {
    if (!(entity instanceof EntityPlayer)) {
        return false;
    }

    if (entity instanceof FakePlayer) {
        return true;
    }

    // If this returns false it is still possible we have a fake player. Try to find the player in the list of online players
    PlayerList playerList = DimensionManager.getWorld(0).getMinecraftServer().getPlayerList();
    EntityPlayerMP playerByUUID = playerList.getPlayerByUUID(((EntityPlayer) entity).getGameProfile().getId());
    if (playerByUUID == null) {
        // The player isn't online. Then it can't be real
        return true;
    }

    // The player is in the list. But is it this player?
    return entity != playerByUUID;
}
项目:UniversalRemote    文件:ServerInjector.java   
@SideOnly(Side.CLIENT)
public static void InjectIntegrated(MinecraftServer server)
{
    PlayerList playerList = server.getPlayerList();

    try {
        if (!(playerList instanceof HookedIntegratedPlayerList) && playerList instanceof IntegratedPlayerList)
        {
            server.setPlayerList(new HookedIntegratedPlayerList((IntegratedPlayerList)playerList));
        }
        else
        {
            // uh ho...
            Util.logger.error("Unable to inject custom PlayerList into server due to unknown type! PlayerList was of type {}.", playerList.getClass().toString());
        }
    } catch (IllegalAccessException | NoSuchFieldException | SecurityException e) {
        Util.logger.logException("Exception trying to inject custom PlayerList into server!", e);
    }
}
项目:UniversalRemote    文件:ServerInjector.java   
@SideOnly(Side.SERVER)
public static void InjectDedicated(MinecraftServer server)
{
    PlayerList playerList = server.getPlayerList();

    try {
        if (playerList instanceof DedicatedPlayerList)
        {
            server.setPlayerList(new HookedDedicatedPlayerList((DedicatedPlayerList)playerList));
        }
        else
        {
            // uh ho...
            Util.logger.error("Unable to inject custom PlayerList into server due to unknown type! PlayerList was of type {}.", playerList.getClass().toString());
        }
    } catch (IllegalAccessException | NoSuchFieldException | SecurityException e) {
        Util.logger.logException("Exception trying to inject custom PlayerList into server!", e);
    }
}
项目:blockbuster    文件:Utils.java   
/**
 * Unload given record. It will send to all players a packet to unload a
 * record.
 */
public static void unloadRecord(Record record)
{
    PlayerList players = FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList();
    String filename = record.filename;

    for (String username : players.getAllUsernames())
    {
        EntityPlayerMP player = players.getPlayerByUsername(username);

        if (player != null)
        {
            IRecording recording = Recording.get(player);

            if (recording.hasRecording(filename))
            {
                recording.removeRecording(filename);

                Dispatcher.sendTo(new PacketUnloadFrames(filename), player);
            }
        }
    }
}
项目:DungeonDimension    文件:ItemCreativeTP.java   
@Override
public ActionResult<ItemStack> onItemRightClick(ItemStack is, World w, EntityPlayer p, EnumHand h) {
    if(!w.isRemote){
        EntityPlayerMP player = (EntityPlayerMP) p;
        if(!player.isCreative()){
            player.addChatMessage(new TextComponentString(ChatFormatting.RED + "You must be in creative to use this!"));
            return new ActionResult(EnumActionResult.PASS, is);
        }
        player.setPortal(player.getPosition());
        MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
        PlayerList list = server.getPlayerList();
        BlockPos pos = player.getPosition();
        if(player.isSneaking())
            list.transferPlayerToDimension(player, 0, new MonumentTeleporter(server.worldServerForDimension(0)));   
        else{
            DungeonDimension.getNextDimensionForWorld(w);
            list.transferPlayerToDimension(player, DungeonDimension.current_dimension, new MonumentTeleporter(server.worldServerForDimension(DungeonDimension.current_dimension))); 
        }
        return new ActionResult(EnumActionResult.SUCCESS, is);
    }
    return new ActionResult(EnumActionResult.PASS, is);
}
项目:CraftingHarmonics    文件:BasePerPlayerOperation.java   
/**
 * Called to apply the set
 */
@Override
public final void apply() {
    // Make sure we're on the server...
    if(FMLCommonHandler.instance().getMinecraftServerInstance() == null) return;

    // Register the operation
    OperationSet.addPerPlayerOperation(this);

    // ... and run it on all connected players
    PlayerList playerList = FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList();

    for(EntityPlayerMP player : playerList.getPlayerList()) {
        doApply(player);
    }
}
项目:EZStorage2    文件:MessageSecurePlayer.java   
/** Actually handle it on the server thread here */
public void handle(MessageSecurePlayer m) {
    // make sure the provided player is valid
    PlayerList list = FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList();
    for (EntityPlayerMP p : list.getPlayerList()) {
        if (p.dimension == m.dimension && p.getUniqueID().toString().equals(m.player.id.toString())) {
            TileEntitySecurityBox tile = (TileEntitySecurityBox) p.worldObj.getTileEntity(m.pos);
            // add or remove from the list
            if (m.add) {
                tile.addAllowedPlayer(p);
            } else {
                tile.removeAllowedPlayer(p);
            }
            tile.markDirty();

            // resync with clients
            EZNetwork.sendSecureSyncMsg(p.worldObj, m.pos, tile.getAllowedPlayers());
        }
    }
}
项目:pnc-repressurized    文件:WorldPlayersInServerSensor.java   
@Override
public int getRedstoneValue(World world, BlockPos pos, int sensorRange, String textBoxText) {
    PlayerList playerList = FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList();
    if (textBoxText.equals("")) {
        return Math.min(15, playerList.getCurrentPlayerCount());
    } else {
        for (String userName : playerList.getOnlinePlayerNames()) {
            if (userName.equalsIgnoreCase(textBoxText)) return 15;
        }
        return 0;
    }
}
项目:WirelessCharger    文件:TilePersonalCharger.java   
private EntityPlayerMP getPlayer() {
    PlayerList pl = FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList();
    if (playerUUID != null) {
        return pl.getPlayerByUUID(playerUUID);
    }
    return null;
}
项目:UniversalRemote    文件:HookedIntegratedPlayerList.java   
@SuppressWarnings("unchecked")
public HookedIntegratedPlayerList(IntegratedPlayerList oldList) throws IllegalAccessException, NoSuchFieldException, SecurityException {
    super(oldList.getServerInstance());

    InjectionHandler.copyAllFieldsFromEx(this, oldList, IntegratedPlayerList.class);

    mcServer = InjectionHandler.readFieldOfType(PlayerList.class, this, MinecraftServer.class);
    gameType = InjectionHandler.readFieldOfType(PlayerList.class, this, GameType.class);
    playerEntityList = InjectionHandler.readFieldOfType(PlayerList.class, this, List.class);
    uuidToPlayerMap = InjectionHandler.readFieldOfType(PlayerList.class, this, Map.class);
}
项目:UniversalRemote    文件:HookedDedicatedPlayerList.java   
@SuppressWarnings("unchecked")
public HookedDedicatedPlayerList(DedicatedPlayerList oldList) throws IllegalAccessException, NoSuchFieldException, SecurityException {
    super(oldList.getServerInstance());

    InjectionHandler.copyAllFieldsFromEx(this, oldList, DedicatedPlayerList.class);

    mcServer = InjectionHandler.readFieldOfType(PlayerList.class, this, MinecraftServer.class);
    gameType = InjectionHandler.readFieldOfType(PlayerList.class, this, GameType.class);
    playerEntityList = InjectionHandler.readFieldOfType(PlayerList.class, this, List.class);
    uuidToPlayerMap = InjectionHandler.readFieldOfType(PlayerList.class, this, Map.class);
}
项目:CustomWorldGen    文件:NetworkDispatcher.java   
public NetworkDispatcher(NetworkManager manager, PlayerList scm)
{
    super(false);
    this.manager = manager;
    this.scm = scm;
    this.side = Side.SERVER;
    this.handshakeChannel = new EmbeddedChannel(new HandshakeInjector(this), new ChannelRegistrationHandler(), new FMLHandshakeCodec(), new HandshakeMessageHandler<FMLHandshakeServerState>(FMLHandshakeServerState.class));
    this.handshakeChannel.attr(FML_DISPATCHER).set(this);
    this.handshakeChannel.attr(NetworkRegistry.CHANNEL_SOURCE).set(Side.CLIENT);
    this.handshakeChannel.attr(NetworkRegistry.FML_CHANNEL).set("FML|HS");
    this.handshakeChannel.attr(IS_LOCAL).set(manager.isLocalChannel());
    if (DEBUG_HANDSHAKE)
        PacketLoggingHandler.register(manager);
}
项目:LittleThings-old    文件:CommandDimTeleport.java   
private Entity teleportPlayerToDim(World oldWorld, int newWorldID, double d, double e, double f, Entity entity)
{
    MinecraftServer server = entity.getServer();
    WorldServer oldWorldServer = server.worldServerForDimension(entity.dimension);
    WorldServer newWorldServer = server.worldServerForDimension(newWorldID);
    if (entity instanceof EntityPlayer) {
        EntityPlayerMP player = (EntityPlayerMP) entity;
        if (!player.worldObj.isRemote) {
            player.worldObj.theProfiler.startSection("portal");
            player.worldObj.theProfiler.startSection("changeDimension");
            PlayerList config = player.mcServer.getPlayerList();
            player.closeScreen();
            player.dimension = newWorldServer.provider.getDimension();
            player.playerNetServerHandler.sendPacket(new SPacketRespawn(player.dimension, player.worldObj.getDifficulty(), newWorldServer.getWorldInfo().getTerrainType(), player.interactionManager.getGameType()));
            oldWorldServer.removeEntity(player);
            player.isDead = false;
            player.setLocationAndAngles(d, e, f, player.rotationYaw, player.rotationPitch);
            newWorldServer.spawnEntityInWorld(player);
            player.setWorld(newWorldServer);
            config.preparePlayer(player, oldWorldServer);
            player.playerNetServerHandler.setPlayerLocation(d, e, f, entity.rotationYaw, entity.rotationPitch);
            player.interactionManager.setWorld(newWorldServer);
            config.updateTimeAndWeatherForPlayer(player, newWorldServer);
            config.syncPlayerInventory(player);
            player.worldObj.theProfiler.endSection();
            oldWorldServer.resetUpdateEntityTick();
            newWorldServer.resetUpdateEntityTick();
            player.worldObj.theProfiler.endSection();
            for (PotionEffect potionEffect : player.getActivePotionEffects()) {
                player.playerNetServerHandler.sendPacket(new SPacketEntityEffect(player.getEntityId(), potionEffect));
            }
            player.playerNetServerHandler.sendPacket(new SPacketSetExperience(player.experience, player.experienceTotal, player.experienceLevel));
            FMLCommonHandler.instance().firePlayerChangedDimensionEvent(player, oldWorldServer.provider.getDimension(), player.dimension);
        }
        player.worldObj.theProfiler.endSection();
        return player;
    }
    return null;
}
项目:metamorph    文件:CommandMetamorph.java   
/**
 * Broadcast a packet to all players 
 */
private void broadcastPacket(IMessage packet)
{
    PlayerList players = FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList();

    for (String username : players.getAllUsernames())
    {
        EntityPlayerMP player = players.getPlayerByUsername(username);

        if (player != null)
        {
            Dispatcher.sendTo(packet, player);
        }
    }
}
项目:blockbuster    文件:Utils.java   
/**
 * Send given message to everyone on the server, to everyone.
 *
 * Invoke this method only on the server side.
 */
public static void broadcastMessage(ITextComponent message)
{
    PlayerList players = FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList();

    for (String username : players.getAllUsernames())
    {
        EntityPlayerMP player = players.getPlayerByUsername(username);

        if (player != null)
        {
            player.addChatMessage(message);
        }
    }
}
项目:blockbuster    文件:Utils.java   
/**
 * Send given error to everyone on the server, to everyone.
 *
 * Invoke this method only on the server side.
 */
public static void broadcastError(String string, Object... objects)
{
    PlayerList players = FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList();

    for (String username : players.getAllUsernames())
    {
        EntityPlayerMP player = players.getPlayerByUsername(username);

        if (player != null)
        {
            L10n.error(player, string, objects);
        }
    }
}
项目:blockbuster    文件:Utils.java   
/**
 * Send given error to everyone on the server, to everyone.
 *
 * Invoke this method only on the server side.
 */
public static void broadcastInfo(String string, Object... objects)
{
    PlayerList players = FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList();

    for (String username : players.getAllUsernames())
    {
        EntityPlayerMP player = players.getPlayerByUsername(username);

        if (player != null)
        {
            L10n.info(player, string, objects);
        }
    }
}
项目:Enderthing    文件:ClientProxy.java   
@Nullable
@Override
public String queryNameFromUUID(UUID uuid)
{
    MinecraftServer svr = FMLClientHandler.instance().getServer();
    if (svr == null)
        return null;
    PlayerList playerList = svr.getPlayerList();
    if (playerList == null)
        return null;
    EntityPlayer player = playerList.getPlayerByUUID(uuid);
    if (player != null)
        return player.getName();
    return null;
}
项目:Enderthing    文件:ServerProxy.java   
@Override
public String queryNameFromUUID(UUID uuid)
{
    PlayerList playerList = FMLServerHandler.instance().getServer().getPlayerList();
    if (playerList == null)
        return null;
    EntityPlayer player = playerList.getPlayerByUUID(uuid);
    if (player != null)
        return player.getName();
    return null;
}
项目:DungeonDimension    文件:TileEntityMonumentTeleporter.java   
public void teleport(EntityPlayer ent){
    if(!worldObj.isRemote && !broken){
        ent.setPortal(getPos());
        MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
        PlayerList list = server.getPlayerList();
        if(worldID == -1){
            if(worldObj.provider instanceof WorldProviderSurface){
                worldID = DungeonDimension.getNextDimensionForWorld(worldObj);
            }else{
                worldID = 0;
            }
        }
        list.transferPlayerToDimension((EntityPlayerMP) ent, worldID, new MonumentTeleporter(server.worldServerForDimension(worldID))); 
    }
}
项目:CraftingHarmonics    文件:BasePerPlayerOperation.java   
public final void undo() {
    // Make sure we're on the server...
    if(FMLCommonHandler.instance().getMinecraftServerInstance() == null) return;

    // Remove the registration...
    OperationSet.removePerPlayerOperation(this);

    // ... and undo it on everybody connected
    PlayerList playerList = FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList();

    for(EntityPlayerMP player : playerList.getPlayerList()) {
        doUndo(player);
    }
}
项目:IIDY    文件:BlockStateTask.java   
@Override
public void finish(TaskResult result) {
    if (result == TaskResult.SUCCESS) {
        MinecraftServer s = FMLCommonHandler.instance().getMinecraftServerInstance();
        PlayerList pl = s.getPlayerList();
        EntityPlayerMP p = pl.getPlayerByUUID(UUID.fromString(targetPlayerUUID));
        if (p != null && finishMsg != null)
            p.sendMessage(new TextComponentString("§2[IIDY]§r§e " + finishMsg + ""));
        else
            IsItDoneYet.proxy.log.error("Error while sending notifaction to player!");
    } else
        FMLServerHandler.instance().getServer().getPlayerList().getPlayerByUUID(UUID.fromString(targetPlayerUUID)).sendMessage(new TextComponentString(
                ITask.FORMAT_RED + "[IIDY Task Failed] " + ITask.FORMAT_YELLOW + finishMsg + ITask.FORMAT_RESET));
}
项目:IIDY    文件:InventoryTask.java   
@Override
public void finish(TaskResult result) {
    if (result == TaskResult.SUCCESS) {
        MinecraftServer s = FMLCommonHandler.instance().getMinecraftServerInstance();
        PlayerList pl = s.getPlayerList();
        EntityPlayerMP p = pl.getPlayerByUUID(UUID.fromString(targetPlayerUUID));

        p.sendMessage(new TextComponentString(ITask.FORMAT_DARK_GREEN + "[IIDY] " + ITask.FORMAT_YELLOW + finishMsg + ITask.FORMAT_RESET));
    } else {
        FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().getPlayerByUUID(UUID.fromString(targetPlayerUUID)).sendMessage(new TextComponentString(ITask.FORMAT_RED
                + "[IIDY Task Failed] " + ITask.FORMAT_YELLOW + finishMsg + ITask.FORMAT_RESET));
    }
}
项目:EZStorage2    文件:SecurityOverrideHelper.java   
/** Sends a chat message to a list of secure players from another player */
public static void sendMessageToSecurePlayers(String chat, String chatSender, Iterable<SecurePlayer> list, EntityPlayerMP from) {
    PlayerList pl = from.getServer().getPlayerList();
    for (SecurePlayer p : list) {
        EntityPlayerMP match = pl.getPlayerByUsername(p.name);
        if (match != null)
            match.addChatMessage(new TextComponentString(chat));
    }
    from.addChatMessage(new TextComponentString(chatSender));
}
项目:morecommands    文件:PatchEntityPlayerMP.java   
@Override
public <T extends FMLStateEvent> boolean applyStateEventPatch(T e) {
    FMLServerAboutToStartEvent event = (FMLServerAboutToStartEvent) e;

    try {
        Constructor<PlayerList> ctor;

        if (event.getServer().isDedicatedServer())
            ctor = (Constructor<PlayerList>) (Constructor<?>) DedicatedPlayerList.class.getDeclaredConstructor(DedicatedServer.class);
        else
            ctor = (Constructor<PlayerList>) (Constructor<?>) IntegratedPlayerList.class.getDeclaredConstructor(IntegratedServer.class);

        ctor.setAccessible(true);

        if (event.getServer().isDedicatedServer())
            event.getServer().setPlayerList(ctor.newInstance((DedicatedServer) event.getServer()));
        else
            event.getServer().setPlayerList(ctor.newInstance((IntegratedServer) event.getServer()));

        PatchManager.instance().getGlobalAppliedPatches().setPatchSuccessfullyApplied(this.displayName, true);
        return true;
    }
    catch (Exception ex) {
        PatchManager.instance().getGlobalAppliedPatches().setPatchSuccessfullyApplied(this.displayName, false);
        return false;
    }
}
项目:morecommands    文件:PatchEntityPlayerMP.java   
private static void transferPlayerToDimension(PlayerList playerList, net.minecraft.entity.player.EntityPlayerMP player, int dimension, Teleporter teleporter) {
    int i = player.dimension;
    WorldServer worldserver = playerList.getServerInstance().getWorld(player.dimension);
    player.dimension = dimension;
    WorldServer worldserver1 = playerList.getServerInstance().getWorld(player.dimension);
    player.connection.sendPacket(new SPacketRespawn(player.dimension, worldserver1.getDifficulty(), worldserver1.getWorldInfo().getTerrainType(), player.interactionManager.getGameType()));

    //MoreCommands Bug fix: client world has wrong spawn position, because WorldClient is recreated after receiving S07PacketRespawn
    //with default spawn coordinates 8, 64, 8. This causes e.g. the compass to point to a wrong direction. A possible solution is sending a S05PacketSpawnPosition.
    //Fixes https://bugs.mojang.com/browse/MC-679
    player.connection.sendPacket(new SPacketSpawnPosition(new BlockPos(worldserver1.getWorldInfo().getSpawnX(), worldserver1.getWorldInfo().getSpawnY(), worldserver1.getWorldInfo().getSpawnZ())));

    playerList.updatePermissionLevel(player);
    worldserver.removeEntityDangerously(player);
    player.isDead = false;
    playerList.transferEntityToWorld(player, i, worldserver, worldserver1, teleporter);
    playerList.preparePlayer(player, worldserver);
    player.connection.setPlayerLocation(player.posX, player.posY, player.posZ, player.rotationYaw, player.rotationPitch);
    player.interactionManager.setWorld(worldserver1);
    player.connection.sendPacket(new SPacketPlayerAbilities(player.capabilities));
    playerList.updateTimeAndWeatherForPlayer(player, worldserver1);
    playerList.syncPlayerInventory(player);

    for (PotionEffect potioneffect : player.getActivePotionEffects())
    {
        player.connection.sendPacket(new SPacketEntityEffect(player.getEntityId(), potioneffect));
    }
    net.minecraftforge.fml.common.FMLCommonHandler.instance().firePlayerChangedDimensionEvent(player, i, dimension);
}
项目:ForgeSubWhitelist    文件:ForgeSubWhitelist.java   
@Override
public void run()
{
    UUID uuid = gameProfile.getId();
    PlayerList scm = server.getPlayerList();
    if (scm.canSendCommands(gameProfile) || scm.getWhitelistedPlayers().isWhitelisted(gameProfile))
    {
        logger.info("Letting {} join, manual or op.", gameProfile.getName());
        return;
    }
    if (closed) kick(scm.getPlayerByUUID(gameProfile.getId()));
    if (CACHE.contains(uuid)) return;

    for (Streamer s : streamers)
    {
        try
        {
            if (Boolean.parseBoolean(IOUtils.toString(new URL(s.fullUrl + uuid.toString()), UTF8)))
            {
                logger.info("Letting {} join, authorized by {} (token redacted)", gameProfile.getName(), s.redactedToken);
                CACHE.add(uuid);
                return;
            }
        }
        catch (IOException ignored)
        {
        }
    }
    kick(scm.getPlayerByUUID(gameProfile.getId()));
}
项目:enderutilities    文件:TickHandler.java   
private void teleportPlayers()
{
    PlayerList list = FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList();

    if (this.portalFlags.isEmpty() == false)
    {
        for (UUID uuid : this.portalFlags)
        {
            EntityPlayer player = list.getPlayerByUUID(uuid);

            if (player != null)
            {
                World world = player.getEntityWorld();
                BlockPos pos = player.getPosition();

                // The exact intersection is checked here, because the players get added
                // to the set when they enter the block space, even if they don't intersect with the portal yet.
                for (int i = 0; i < 3; i++)
                {
                    IBlockState state = world.getBlockState(pos);

                    if (state.getBlock() == EnderUtilitiesBlocks.PORTAL &&
                        player.getEntityBoundingBox().intersects(state.getBoundingBox(world, pos).offset(pos)))
                    {
                        ((BlockEnderUtilitiesPortal) state.getBlock()).teleportEntity(world, pos, state, player);
                        break;
                    }

                    pos = pos.up();
                }
            }
        }

        this.portalFlags.clear();
    }
}
项目:Backmemed    文件:MinecraftServer.java   
public PlayerList getPlayerList()
{
    return this.playerList;
}
项目:Backmemed    文件:MinecraftServer.java   
public void setPlayerList(PlayerList list)
{
    this.playerList = list;
}
项目:CustomWorldGen    文件:NetworkDispatcher.java   
public static NetworkDispatcher allocAndSet(NetworkManager manager, PlayerList scm)
{
    NetworkDispatcher net = new NetworkDispatcher(manager, scm);
    manager.channel().attr(FML_DISPATCHER).getAndSet(net);
    return net;
}
项目:CustomWorldGen    文件:FMLNetworkHandler.java   
public static void fmlServerHandshake(PlayerList scm, NetworkManager manager, EntityPlayerMP player)
{
    NetworkDispatcher dispatcher = NetworkDispatcher.allocAndSet(manager, scm);
    dispatcher.serverToClientHandshake(player);
}
项目:CustomWorldGen    文件:MinecraftServer.java   
public PlayerList getPlayerList()
{
    return this.playerList;
}
项目:CustomWorldGen    文件:MinecraftServer.java   
public void setPlayerList(PlayerList list)
{
    this.playerList = list;
}
项目:minecraft-territorialdealings    文件:Transition.java   
static void transferPlayerToDimension(EntityPlayerMP player, int dimensionTo, int targetHeight)
  {
if (!net.minecraftforge.common.ForgeHooks.onTravelToDimension(player, dimensionTo)) { return; } // Moving that here, to consolidate these functions.

net.minecraft.world.Teleporter teleporter = player.mcServer.worldServerForDimension(dimensionTo).getDefaultTeleporter();
PlayerList playerList = player.mcServer.getPlayerList();

      int dimensionFrom = player.dimension;

      // Changing dimensions...
      WorldServer wsPrev = player.mcServer.worldServerForDimension(player.dimension);

      player.dimension = dimensionTo;

      WorldServer wsNew = player.mcServer.worldServerForDimension(player.dimension);

      // Respawn? Used to recreate the player entity.
      player.connection.sendPacket(new SPacketRespawn(player.dimension, wsNew.getDifficulty(), wsNew.getWorldInfo().getTerrainType(), player.interactionManager.getGameType()));

      // Capabilities...
      playerList.updatePermissionLevel(player);

      // Begone from the old world?
      wsPrev.removeEntity(player);

      // Safety, I suppose.
      player.isDead = false;

      // We haven't reached the "set portal" level yet. Going deeper.
      transferEntityToWorld(player, dimensionFrom, wsPrev, wsNew, teleporter, targetHeight);

      // Getting chunks ready?
      playerList.preparePlayer(player, wsPrev);

      // Inserting their new position here? May not be necessary, since this is called by the drop and transfer, which sets the position beforehand and afterwards.
      player.connection.setPlayerLocation(player.posX, player.posY, player.posZ, player.rotationYaw, player.rotationPitch);

      // More formalities...
      player.interactionManager.setWorld(wsNew);
      player.connection.sendPacket(new SPacketPlayerAbilities(player.capabilities));

      playerList.updateTimeAndWeatherForPlayer(player, wsNew);
      playerList.syncPlayerInventory(player);

      // Reapplying potion effects
      for (PotionEffect potioneffect : player.getActivePotionEffects())
      {
          player.connection.sendPacket(new SPacketEntityEffect(player.getEntityId(), potioneffect));
      }

      // We're done.
      net.minecraftforge.fml.common.FMLCommonHandler.instance().firePlayerChangedDimensionEvent(player, dimensionFrom, dimensionTo);
  }
项目:CrystalMod    文件:TeleportUtil.java   
private static EntityPlayer teleportPlayerToDim(EntityPlayerMP player, MinecraftServer server, int sourceDim, int targetDim, double xCoord, double yCoord, double zCoord, float yaw, float pitch, Vector3d motion) {
    WorldServer sourceWorld = server.worldServerForDimension(sourceDim);
    WorldServer targetWorld = server.worldServerForDimension(targetDim);
    PlayerList playerList = server.getPlayerList();

    player.dimension = targetDim;
    player.connection.sendPacket(new SPacketRespawn(player.dimension, targetWorld.getDifficulty(), targetWorld.getWorldInfo().getTerrainType(), player.interactionManager.getGameType()));
    playerList.updatePermissionLevel(player);
    sourceWorld.removeEntityDangerously(player);
    player.isDead = false;

    //region Transfer to world

    player.setLocationAndAngles(xCoord, yCoord, zCoord, yaw, pitch);
    player.connection.setPlayerLocation(xCoord, yCoord, zCoord, yaw, pitch);
    targetWorld.spawnEntity(player);
    targetWorld.updateEntityWithOptionalForce(player, false);
    player.setWorld(targetWorld);

    //endregion

    playerList.preparePlayer(player, sourceWorld);
    player.connection.setPlayerLocation(xCoord, yCoord, zCoord, yaw, pitch);
    player.interactionManager.setWorld(targetWorld);
    player.connection.sendPacket(new SPacketPlayerAbilities(player.capabilities));

    playerList.updateTimeAndWeatherForPlayer(player, targetWorld);
    playerList.syncPlayerInventory(player);

    for (PotionEffect potioneffect : player.getActivePotionEffects()) {
        player.connection.sendPacket(new SPacketEntityEffect(player.getEntityId(), potioneffect));
    }
    net.minecraftforge.fml.common.FMLCommonHandler.instance().firePlayerChangedDimensionEvent(player, sourceDim, targetDim);
    player.setLocationAndAngles(xCoord, yCoord, zCoord, yaw, pitch);

    player.motionX += motion.x; player.motionY += motion.y; player.motionZ += motion.z;
    NBTTagCompound nbt = new NBTTagCompound();
    nbt.setDouble("X", motion.x);
    nbt.setDouble("Y", motion.y);
    nbt.setDouble("Z", motion.z);
    CrystalModNetwork.sendToAll(new PacketEntityMessage(player, "AddMotion", nbt));

    return player;
}
项目:Aether-Legacy    文件:TileEntityTreasureChest.java   
private void sendToAllInOurWorld(SPacketUpdateTileEntity pkt)
{
    PlayerList scm = FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList();

    scm.sendPacketToAllPlayers(pkt);
}
项目:malmo    文件:ServerStateMachine.java   
private EntityPlayerMP getPlayerFromUsername(String username)
{
    PlayerList scoman = FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList();
    EntityPlayerMP player = scoman.getPlayerByUsername(username);
    return player;
}
项目:malmo    文件:ServerStateMachine.java   
@Override
protected void execute()
{
    // Set up some initial conditions:
    ServerSection ss = currentMissionInit().getMission().getServerSection();
    ServerInitialConditions sic = (ss != null) ? ss.getServerInitialConditions() : null;
    if (sic != null && sic.getTime() != null)
    {
        boolean allowTimeToPass = (sic.getTime().isAllowPassageOfTime() != Boolean.FALSE);  // Defaults to true if unspecified.
        MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
        if (server.worlds != null && server.worlds.length != 0)
        {
            for (int i = 0; i < server.worlds.length; ++i)
            {
                World world = server.worlds[i];
                world.getGameRules().setOrCreateGameRule("doDaylightCycle", allowTimeToPass ? "true" : "false");
                if (sic.getTime().getStartTime() != null)
                    world.setWorldTime(sic.getTime().getStartTime());
            }
        }
    }
    ModSettings modsettings = currentMissionInit().getMission().getModSettings();
    if (modsettings != null && modsettings.getMsPerTick() != null)
        TimeHelper.serverTickLength = (long)(modsettings.getMsPerTick());

    if (getHandlers().quitProducer != null)
        getHandlers().quitProducer.prepare(currentMissionInit());

    if (getHandlers().worldDecorator != null)
        getHandlers().worldDecorator.prepare(currentMissionInit());

    // Fire the starting pistol:
    MalmoMod.safeSendToAll(MalmoMessageType.SERVER_GO);
    // And start the turn schedule turning, if there is one:
    if (!ServerStateMachine.this.userTurnSchedule.isEmpty())
    {
        String agentName = ServerStateMachine.this.userTurnSchedule.get(0);
        PlayerList scoman = FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList();
        EntityPlayerMP player = scoman.getPlayerByUsername(agentName);
        if (player != null)
        {
            MalmoMod.network.sendTo(new MalmoMod.MalmoMessage(MalmoMessageType.SERVER_YOUR_TURN, ""), player);
        }
        else if (getHandlers().worldDecorator != null)
        {
            // Not a player - is it a world decorator?
            getHandlers().worldDecorator.targetedUpdate(agentName);
        }
    }
}
项目:VanillaTeleporter    文件:TeleporterUtility.java   
/**
 * Transfers a player to a different dimension and location, as if they were being teleported by a dimension portal
 */
private static boolean transferPlayerToDimension(EntityPlayerMP player, double posX, double posY, double posZ, float yaw, float pitch, int dimension)
{
    MinecraftServer minecraftServer = FMLCommonHandler.instance().getMinecraftServerInstance();
    WorldServer srcWorld = minecraftServer.worldServerForDimension(player.dimension);
    WorldServer dstWorld = minecraftServer.worldServerForDimension(dimension);

    if(dstWorld != null)
    {

        // fire player change dimension event and check that action is valid before continuing
        if (!net.minecraftforge.common.ForgeHooks.onTravelToDimension(player, dimension)) return false;

        // (hard) set the player's dimension to the destination dimension
        player.dimension = dimension;

        // send a player respawn packet to the destination dimension so the player respawns there
        player.connection.sendPacket(
            new SPacketRespawn(
                player.dimension,
                player.world.getDifficulty(),
                player.world.getWorldInfo().getTerrainType(),
                player.interactionManager.getGameType()
            )
        );

        srcWorld.removeEntity(player); // remove the original player entity
        player.isDead = false; // make sure the player isn't dead (removeEntity sets player as dead)

        PlayerList playerList = player.mcServer.getPlayerList();

        // set player's location (net server handler)
        setPlayerPosition(player, posX, posY, posZ, yaw, pitch);        
        // spawn the player in the new world
        dstWorld.spawnEntity(player); 
        // update the entity (do not force)
        dstWorld.updateEntityWithOptionalForce(player, false);
        // set the player's world to the new world
        player.setWorld(dstWorld); 
        // add the player into the appropriate player list
        playerList.preparePlayer(player, srcWorld);
        // set item in world manager's world to the same as the player
        player.interactionManager.setWorld(dstWorld); 
        // update time and weather for the player so that it's the same as the world
        playerList.updateTimeAndWeatherForPlayer(player, dstWorld); 
        // sync the player's inventory
        playerList.syncPlayerInventory(player); 
        // add no experience (syncs experience)
        player.addExperience(0); 
        // update player's health
        player.setPlayerHealthUpdated();


        // fire the dimension changed event so that minecraft swithces dimensions properly
        FMLCommonHandler.instance().firePlayerChangedDimensionEvent(
            player,
            srcWorld.provider.getDimension(),
            dstWorld.provider.getDimension()
        );

        return true;

    }
    else
    {
        return false;
    }
}