/** moves provided player from overworld to nether or vice versa */
  public void transferPlayerToDimension(EntityPlayerMP playerIn, int dimension) {
    int var3 = playerIn.dimension;
    WorldServer var4 = this.mcServer.worldServerForDimension(playerIn.dimension);
    playerIn.dimension = dimension;
    WorldServer var5 = this.mcServer.worldServerForDimension(playerIn.dimension);
    playerIn.playerNetServerHandler.sendPacket(
        new S07PacketRespawn(
            playerIn.dimension,
            playerIn.worldObj.getDifficulty(),
            playerIn.worldObj.getWorldInfo().getTerrainType(),
            playerIn.theItemInWorldManager.getGameType()));
    var4.removePlayerEntityDangerously(playerIn);
    playerIn.isDead = false;
    this.transferEntityToWorld(playerIn, var3, var4, var5);
    this.func_72375_a(playerIn, var4);
    playerIn.playerNetServerHandler.setPlayerLocation(
        playerIn.posX, playerIn.posY, playerIn.posZ, playerIn.rotationYaw, playerIn.rotationPitch);
    playerIn.theItemInWorldManager.setWorld(var5);
    this.updateTimeAndWeatherForPlayer(playerIn, var5);
    this.syncPlayerInventory(playerIn);
    Iterator var6 = playerIn.getActivePotionEffects().iterator();

    while (var6.hasNext()) {
      PotionEffect var7 = (PotionEffect) var6.next();
      playerIn.playerNetServerHandler.sendPacket(
          new S1DPacketEntityEffect(playerIn.getEntityId(), var7));
    }
  }
  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));
    }
  }
  /**
   * @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());
  }
  @Override
  public String getResponceString(DatagramPacket packet) {
    LinkedHashMap<String, String> PlayerData = new LinkedHashMap();
    LinkedHashMap<String, String> tempMap = new LinkedHashMap();
    ArrayList<String> tempArgs = new ArrayList();

    String username = new String(Arrays.copyOfRange(packet.getData(), 11, packet.getLength()));
    EntityPlayerMP player = server.getConfigurationManager().getPlayerForUsername(username.trim());
    if (player == null) {
      return "";
    }

    PlayerInfo pi = PlayerInfo.getPlayerInfo(player);
    if (pi != null && sendhome) {
      if (pi.home != null) {
        PlayerData.put("home", TextFormatter.toJSON(pi.home));
      }
      if (pi.back != null) {
        PlayerData.put("back", TextFormatter.toJSON(pi.back));
      }
    }

    if (sendArmorAndHealth) {
      PlayerData.put("armor", "" + player.inventory.getTotalArmorValue());
      PlayerData.put("health", "" + player.getHealth());
    }

    PlayerData.put("wallet", "" + Wallet.getWallet(player));
    PlayerData.put("pos", TextFormatter.toJSON(new WorldPoint(player)));
    PlayerData.put("ping", "" + player.ping);
    PlayerData.put("gm", player.theItemInWorldManager.getGameType().getName());

    if (!player.getActivePotionEffects().isEmpty() && sendpotions) {
      PlayerData.put("potion", TextFormatter.toJSON(player.getActivePotionEffects()));
    }

    if (sendXP) {
      tempMap.clear();
      tempMap.put("lvl", "" + player.experienceLevel);
      tempMap.put("bar", "" + player.experience);
      PlayerData.put("xp", TextFormatter.toJSON(tempMap));
    }

    if (sendFood) {
      tempMap.clear();
      tempMap.put("food", "" + player.getFoodStats().getFoodLevel());
      tempMap.put("saturation", "" + player.getFoodStats().getSaturationLevel());
      PlayerData.put("foodStats", TextFormatter.toJSON(tempMap));
    }

    if (sendCapabilities) {
      tempMap.clear();
      tempMap.put("edit", "" + player.capabilities.allowEdit);
      tempMap.put("allowFly", "" + player.capabilities.allowFlying);
      tempMap.put("isFly", "" + player.capabilities.isFlying);
      tempMap.put("noDamage", "" + player.capabilities.disableDamage);
    }
    PlayerData.put("cap", TextFormatter.toJSON(tempMap));

    try {
      Group group = PermissionsAPI.getHighestGroup(player);
      PlayerData.put("group", group.name);
    } catch (Exception e) {
    }

    return dataString = TextFormatter.toJSON(PlayerData);
  }
  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 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();
  }
  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;
  }
Esempio n. 8
0
  public void processCommand(ICommandSender par1ICommandSender, String[] par2ArrayOfStr) {
    if (par2ArrayOfStr.length < 2) {
      throw new WrongUsageException("commands.effect.usage", new Object[0]);
    } else {
      EntityPlayerMP entityplayermp = getPlayer(par1ICommandSender, par2ArrayOfStr[0]);

      if (par2ArrayOfStr[1].equals("clear")) {
        if (entityplayermp.getActivePotionEffects().isEmpty()) {
          throw new CommandException(
              "commands.effect.failure.notActive.all",
              new Object[] {entityplayermp.getCommandSenderName()});
        }

        entityplayermp.clearActivePotions();
        notifyAdmins(
            par1ICommandSender,
            "commands.effect.success.removed.all",
            new Object[] {entityplayermp.getCommandSenderName()});
      } else {
        int i = parseIntWithMin(par1ICommandSender, par2ArrayOfStr[1], 1);
        int j = 600;
        int k = 30;
        int l = 0;

        if (i < 0 || i >= Potion.potionTypes.length || Potion.potionTypes[i] == null) {
          throw new NumberInvalidException(
              "commands.effect.notFound", new Object[] {Integer.valueOf(i)});
        }

        if (par2ArrayOfStr.length >= 3) {
          k = parseIntBounded(par1ICommandSender, par2ArrayOfStr[2], 0, 1000000);

          if (Potion.potionTypes[i].isInstant()) {
            j = k;
          } else {
            j = k * 20;
          }
        } else if (Potion.potionTypes[i].isInstant()) {
          j = 1;
        }

        if (par2ArrayOfStr.length >= 4) {
          l = parseIntBounded(par1ICommandSender, par2ArrayOfStr[3], 0, 255);
        }

        if (k == 0) {
          if (!entityplayermp.isPotionActive(i)) {
            throw new CommandException(
                "commands.effect.failure.notActive",
                new Object[] {
                  new ChatComponentTranslation(Potion.potionTypes[i].getName(), new Object[0]),
                  entityplayermp.getCommandSenderName()
                });
          }

          entityplayermp.removePotionEffect(i);
          notifyAdmins(
              par1ICommandSender,
              "commands.effect.success.removed",
              new Object[] {
                new ChatComponentTranslation(Potion.potionTypes[i].getName(), new Object[0]),
                entityplayermp.getCommandSenderName()
              });
        } else {
          PotionEffect potioneffect = new PotionEffect(i, j, l);
          entityplayermp.addPotionEffect(potioneffect);
          notifyAdmins(
              par1ICommandSender,
              "commands.effect.success",
              new Object[] {
                new ChatComponentTranslation(potioneffect.getEffectName(), new Object[0]),
                Integer.valueOf(i),
                Integer.valueOf(l),
                entityplayermp.getCommandSenderName(),
                Integer.valueOf(k)
              });
        }
      }
    }
  }