Exemplo n.º 1
0
  @Override
  public void processCommand(ICommandSender sender, String[] params) {
    EntityPlayerMP player;

    player = getCommandSenderAsPlayer(sender);

    if (params.length == 0) {
      if (TFCOptions.enableDebugMode) {
        TFCOptions.enableDebugMode = false;
        player.addChatMessage("Debug Mode Disabled");
      } else {
        TFCOptions.enableDebugMode = true;
        player.addChatMessage("Debug Mode Enabled");
      }
    }
  }
Exemplo n.º 2
0
  @Override
  public void processCommand(ICommandSender sender, String[] par2ArrayOfStr) {
    EntityPlayer player = getCommandSenderAsPlayer(sender);
    EntityPlayerMP other = func_82359_c(sender, par2ArrayOfStr[0]);

    if (par2ArrayOfStr.length != 1) {
      player.addChatMessage(getCommandUsage(sender));
      return;
    }

    NBTTagCompound playerdata =
        NecessitiesMain.instance.necessities_data.getCompoundTag(other.username);
    NecessitiesMain.instance.necessities_data.setCompoundTag(other.username, playerdata);
    NBTTagCompound tpa = playerdata.getCompoundTag("[Tpa]");
    playerdata.setCompoundTag("[Tpa]", tpa);

    if (tpa.hasKey("DenyAll")) {
      player.addChatMessage("Player " + other.username + " has blocked all teleport requests.");
      return;
    }
    tpa.setString("Command", "TPA");
    tpa.setString("Who", player.username);
    player.addChatMessage("Sending teleport request to player " + other.username);
    other.addChatMessage(
        player.username
            + " has requested to teleport to you.  Use /tpaccept to accept or /tpreject to refuse.");
  }
Exemplo n.º 3
0
  public static void setGamemode(EntityPlayerMP player, int mode) {
    if (mode < 0
        || mode >= NEIActions.gameModes.length
        || NEIActions.nameActionMap.containsKey(NEIActions.gameModes[mode])
            && !NEIServerConfig.canPlayerPerformAction(
                player.getName(), NEIActions.gameModes[mode])) {
      return;
    }

    // creative+
    NEIServerConfig.forPlayer(player.getName()).enableAction("creative+", mode == 2);
    if (mode == 2
        && !(player.openContainer
            instanceof ContainerCreativeInv)) // open the container immediately for the client
    {
      NEISPH.processCreativeInv(player, true);
    }

    // change it on the server
    player.theItemInWorldManager.setGameType(getGameType(mode));

    // tell the client to change it
    new PacketCustom(NEISPH.channel, 14).writeByte(mode).sendToPlayer(player);
    player.addChatMessage(new ChatComponentTranslation("nei.chat.gamemode." + mode));
  }
Exemplo n.º 4
0
  @Override
  public void processCommand(final ICommandSender sender, final String[] parms) {

    try {
      final EntityPlayerMP player = getCommandSenderAsPlayer(sender);
      final World world = player.worldObj;
      final DimensionEffectData data = DimensionEffectData.get(world);

      if (parms.length == 1) {
        if ("status".compareToIgnoreCase(parms[0]) == 0) {
          // Dump out some diagnostics for the currentAurora dimension
          player.addChatMessage(new ChatComponentText(statusOutput(world, data)));
        } else if ("reset".compareToIgnoreCase(parms[0]) == 0) {
          world.provider.resetRainAndThunder();
          player.addChatMessage(
              new ChatComponentText(StatCollector.translateToLocal("msg.RainReset")));
        } else if ("reload".compareToIgnoreCase(parms[0]) == 0) {
          BiomeRegistry.initialize();
          BlockRegistry.initialize();
          player.addChatMessage(
              new ChatComponentText(StatCollector.translateToLocal("msg.BiomeReload")));
        } else {
          final double d = parseDouble(parms[0], 0.0D, 100.0D) / 100.0D;
          data.setRainIntensity((float) d);
          player.addChatMessage(
              new ChatComponentText(
                  StatCollector.translateToLocalFormatted(
                      "msg.RainIntensitySet", FORMATTER.format(data.getRainIntensity() * 100))));
        }
      } else if (parms.length == 2) {
        if ("setmin".compareToIgnoreCase(parms[0]) == 0) {
          final double d = parseDouble(parms[1], 0.0D, 100.0D) / 100.0D;
          data.setMinRainIntensity((float) d);
          player.addChatMessage(
              new ChatComponentText(
                  StatCollector.translateToLocalFormatted(
                      "msg.MinRainIntensitySet",
                      FORMATTER.format(data.getMinRainIntensity() * 100))));
        } else if ("setmax".compareToIgnoreCase(parms[0]) == 0) {
          final double d = parseDouble(parms[1], 0.0D, 100.0D) / 100.0D;
          data.setMaxRainIntensity((float) d);
          player.addChatMessage(
              new ChatComponentText(
                  StatCollector.translateToLocalFormatted(
                      "msg.MaxRainIntensitySet",
                      FORMATTER.format(data.getMaxRainIntensity() * 100))));
        } else {
          throw new CommandException(getCommandUsage(sender));
        }
      } else {
        player.addChatMessage(new ChatComponentText(getCommandUsage(sender)));
      }
    } catch (final Exception ex) {
      ex.printStackTrace();
    }
  }
Exemplo n.º 5
0
 @Override
 public void onBlockSelected(EntityPlayerMP player, WorldPosition position) {
   String dimid =
       position.world != null ? Integer.toString(position.world.provider.dimensionId) : "null";
   Object[] data = {
     Integer.toString(position.x),
     Integer.toString(position.y),
     Integer.toString(position.z),
     dimid
   };
   player.addChatMessage(new ChatComponentTranslation("moreEMC.cmd.selected", data));
 }
  public void func_177452_b(EntityPlayer p_177452_1_, IChatComponent p_177452_2_) {
    Team var3 = p_177452_1_.getTeam();

    if (var3 == null) {
      this.sendChatMsg(p_177452_2_);
    } else {
      for (int var4 = 0; var4 < this.playerEntityList.size(); ++var4) {
        EntityPlayerMP var5 = (EntityPlayerMP) this.playerEntityList.get(var4);

        if (var5.getTeam() != var3) {
          var5.addChatMessage(p_177452_2_);
        }
      }
    }
  }
  public void func_177453_a(EntityPlayer p_177453_1_, IChatComponent p_177453_2_) {
    Team var3 = p_177453_1_.getTeam();

    if (var3 != null) {
      Collection var4 = var3.getMembershipCollection();
      Iterator var5 = var4.iterator();

      while (var5.hasNext()) {
        String var6 = (String) var5.next();
        EntityPlayerMP var7 = this.getPlayerByUsername(var6);

        if (var7 != null && var7 != p_177453_1_) {
          var7.addChatMessage(p_177453_2_);
        }
      }
    }
  }
  void initTicket() {
    if (Platform.isClient()) {
      return;
    }

    this.ct = ForgeChunkManager.requestTicket(AppEng.instance(), this.worldObj, Type.NORMAL);

    if (this.ct == null) {
      MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
      if (server != null) {
        List<EntityPlayerMP> pl = server.getConfigurationManager().playerEntityList;
        for (EntityPlayerMP p : pl) {
          p.addChatMessage(new ChatComponentText("Can't chunk load.."));
        }
      }
      return;
    }

    AELog.info("New Ticket " + this.ct.toString());
    ForgeChunkManager.forceChunk(
        this.ct, new ChunkCoordIntPair(this.xCoord >> 4, this.zCoord >> 4));
  }
Exemplo n.º 9
0
  private static void tryLearnStructure(ItemStack stack, WorldServer world, EntityPlayerMP player) {
    Map<String, ChunkPosition> nearbyStructures =
        StructureRegistry.instance.getNearestStructures(
            world, (int) player.posX, (int) player.posY, (int) player.posZ);

    String structureName = "";
    double max = Double.MAX_VALUE;

    for (Map.Entry<String, ChunkPosition> e : nearbyStructures.entrySet()) {
      ChunkPosition pos = e.getValue();
      if (Config.eyeDebug)
        player.addChatMessage(
            new ChatComponentTranslation(
                "openblocks.misc.structure_pos",
                e.getKey(),
                pos.chunkPosX,
                pos.chunkPosY,
                pos.chunkPosZ));

      double dx = pos.chunkPosX - player.posX;
      double dy = pos.chunkPosY - player.posY;
      double dz = pos.chunkPosZ - player.posZ;

      double dist = (dx * dx) + (dy * dy) + (dz * dz);

      if (dist < max) {
        max = dist;
        structureName = e.getKey();
      }
    }

    if (!Strings.isNullOrEmpty(structureName)) {
      Log.info("Learned structure %s, d = %f", structureName, max);
      NBTTagCompound tag = ItemUtils.getItemTag(stack);
      tag.setString(TAG_STRUCTURE, structureName);
    }
  }
Exemplo n.º 10
0
  @Override
  public void handleServerSide(EntityPlayer player) {
    GCEntityPlayerMP playerBase = PlayerUtil.getPlayerBaseServerFromPlayer(player, false);
    if (playerBase == null) {
      return;
    }

    switch (this.type) {
      case S_RESPAWN_PLAYER:
        playerBase.playerNetServerHandler.sendPacket(
            new S07PacketRespawn(
                player.dimension,
                player.worldObj.difficultySetting,
                player.worldObj.getWorldInfo().getTerrainType(),
                playerBase.theItemInWorldManager.getGameType()));
        break;
      case S_TELEPORT_ENTITY:
        try {
          final WorldProvider provider = WorldUtil.getProviderForName((String) this.data.get(0));
          final Integer dim = provider.dimensionId;
          GCLog.info(
              "Found matching world ("
                  + dim.toString()
                  + ") for name: "
                  + (String) this.data.get(0));

          if (playerBase.worldObj instanceof WorldServer) {
            final WorldServer world = (WorldServer) playerBase.worldObj;

            if (provider instanceof IOrbitDimension) {
              WorldUtil.transferEntityToDimension(playerBase, dim, world);
            } else {
              WorldUtil.transferEntityToDimension(playerBase, dim, world);
            }
          }

          playerBase.getPlayerStats().teleportCooldown = 300;
          GalacticraftCore.packetPipeline.sendTo(
              new PacketSimple(EnumSimplePacket.C_CLOSE_GUI, new Object[] {}), playerBase);
        } catch (final Exception e) {
          GCLog.severe(
              "Error occurred when attempting to transfer entity to dimension: "
                  + (String) this.data.get(0));
          e.printStackTrace();
        }
        break;
      case S_IGNITE_ROCKET:
        if (!player.worldObj.isRemote
            && !player.isDead
            && player.ridingEntity != null
            && !player.ridingEntity.isDead
            && player.ridingEntity instanceof EntityTieredRocket) {
          final EntityTieredRocket ship = (EntityTieredRocket) player.ridingEntity;

          if (!ship.landing) {
            if (ship.hasValidFuel()) {
              ItemStack stack2 = playerBase.getPlayerStats().extendedInventory.getStackInSlot(4);

              if (stack2 != null && stack2.getItem() instanceof ItemParaChute
                  || playerBase.getPlayerStats().launchAttempts > 0) {
                ship.igniteCheckingCooldown();
                playerBase.getPlayerStats().launchAttempts = 0;
              } else if (playerBase.getPlayerStats().chatCooldown == 0
                  && playerBase.getPlayerStats().launchAttempts == 0) {
                player.addChatMessage(
                    new ChatComponentText(GCCoreUtil.translate("gui.rocket.warning.noparachute")));
                playerBase.getPlayerStats().chatCooldown = 250;
                playerBase.getPlayerStats().launchAttempts = 1;
              }
            } else if (playerBase.getPlayerStats().chatCooldown == 0) {
              player.addChatMessage(
                  new ChatComponentText(GCCoreUtil.translate("gui.rocket.warning.nofuel")));
              playerBase.getPlayerStats().chatCooldown = 250;
            }
          }
        }
        break;
      case S_OPEN_SCHEMATIC_PAGE:
        if (player != null) {
          final ISchematicPage page =
              SchematicRegistry.getMatchingRecipeForID((Integer) this.data.get(0));

          player.openGui(
              GalacticraftCore.instance,
              page.getGuiID(),
              player.worldObj,
              (int) player.posX,
              (int) player.posY,
              (int) player.posZ);
        }
        break;
      case S_OPEN_FUEL_GUI:
        if (player.ridingEntity instanceof EntityBuggy) {
          GCCoreUtil.openBuggyInv(
              playerBase,
              (EntityBuggy) player.ridingEntity,
              ((EntityBuggy) player.ridingEntity).getType());
        } else if (player.ridingEntity instanceof EntitySpaceshipBase) {
          player.openGui(
              GalacticraftCore.instance,
              GuiIdsCore.ROCKET_INVENTORY,
              player.worldObj,
              (int) player.posX,
              (int) player.posY,
              (int) player.posZ);
        }
        break;
      case S_UPDATE_SHIP_YAW:
        if (player.ridingEntity instanceof EntitySpaceshipBase) {
          final EntitySpaceshipBase ship = (EntitySpaceshipBase) player.ridingEntity;

          if (ship != null) {
            ship.rotationYaw = (Float) this.data.get(0);
          }
        }
        break;
      case S_UPDATE_SHIP_PITCH:
        if (player.ridingEntity instanceof EntitySpaceshipBase) {
          final EntitySpaceshipBase ship = (EntitySpaceshipBase) player.ridingEntity;

          if (ship != null) {
            ship.rotationPitch = (Float) this.data.get(0);
          }
        }
        break;
      case S_SET_ENTITY_FIRE:
        Entity entity = player.worldObj.getEntityByID((Integer) this.data.get(0));

        if (entity instanceof EntityLiving) {
          ((EntityLiving) entity).setFire(3);
        }
        break;
      case S_OPEN_REFINERY_GUI:
        player.openGui(
            GalacticraftCore.instance,
            -1,
            player.worldObj,
            (Integer) this.data.get(0),
            (Integer) this.data.get(1),
            (Integer) this.data.get(2));
        break;
      case S_BIND_SPACE_STATION_ID:
        if ((playerBase.getPlayerStats().spaceStationDimensionID == -1
                || playerBase.getPlayerStats().spaceStationDimensionID == 0)
            && !ConfigManagerCore.disableSpaceStationCreation) {
          WorldUtil.bindSpaceStationToNewDimension(playerBase.worldObj, playerBase);

          WorldUtil.getSpaceStationRecipe((Integer) this.data.get(0)).matches(playerBase, true);
        }
        break;
      case S_UNLOCK_NEW_SCHEMATIC:
        final Container container = player.openContainer;

        if (container instanceof ContainerSchematic) {
          final ContainerSchematic schematicContainer = (ContainerSchematic) container;

          ItemStack stack = schematicContainer.craftMatrix.getStackInSlot(0);

          if (stack != null) {
            final ISchematicPage page = SchematicRegistry.getMatchingRecipeForItemStack(stack);

            if (page != null) {
              SchematicRegistry.unlockNewPage(playerBase, stack);

              if (--stack.stackSize <= 0) {
                stack = null;
              }

              schematicContainer.craftMatrix.setInventorySlotContents(0, stack);
              schematicContainer.craftMatrix.markDirty();

              GalacticraftCore.packetPipeline.sendTo(
                  new PacketSimple(
                      EnumSimplePacket.C_ADD_NEW_SCHEMATIC, new Object[] {page.getPageID()}),
                  playerBase);
            }
          }
        }
        break;
      case S_UPDATE_DISABLEABLE_BUTTON:
        final TileEntity tileAt =
            player.worldObj.getTileEntity(
                (Integer) this.data.get(0), (Integer) this.data.get(1), (Integer) this.data.get(2));

        if (tileAt instanceof IDisableableMachine) {
          final IDisableableMachine machine = (IDisableableMachine) tileAt;

          machine.setDisabled(
              (Integer) this.data.get(3), !machine.getDisabled((Integer) this.data.get(3)));
        }
        break;
      case S_ON_FAILED_CHEST_UNLOCK:
        if (playerBase.getPlayerStats().chatCooldown == 0) {
          player.addChatMessage(
              new ChatComponentText(
                  GCCoreUtil.translateWithFormat("gui.chest.warning.wrongkey", this.data.get(0))));
          playerBase.getPlayerStats().chatCooldown = 100;
        }
        break;
      case S_RENAME_SPACE_STATION:
        final SpaceStationWorldData ssdata =
            SpaceStationWorldData.getStationData(
                playerBase.worldObj, (Integer) this.data.get(1), playerBase);

        if (ssdata != null
            && ssdata.getOwner().equalsIgnoreCase(player.getGameProfile().getName())) {
          ssdata.setSpaceStationName((String) this.data.get(0));
          ssdata.setDirty(true);
        }
        break;
      case S_OPEN_EXTENDED_INVENTORY:
        player.openGui(
            GalacticraftCore.instance, GuiIdsCore.EXTENDED_INVENTORY, player.worldObj, 0, 0, 0);
        break;
      case S_ON_ADVANCED_GUI_CLICKED_INT:
        TileEntity tile1 =
            player.worldObj.getTileEntity(
                (Integer) this.data.get(1), (Integer) this.data.get(2), (Integer) this.data.get(3));

        switch ((Integer) this.data.get(0)) {
          case 0:
            if (tile1 instanceof TileEntityAirLockController) {
              TileEntityAirLockController launchController = (TileEntityAirLockController) tile1;
              launchController.redstoneActivation = (Integer) this.data.get(4) == 1;
            }
            break;
          case 1:
            if (tile1 instanceof TileEntityAirLockController) {
              TileEntityAirLockController launchController = (TileEntityAirLockController) tile1;
              launchController.playerDistanceActivation = (Integer) this.data.get(4) == 1;
            }
            break;
          case 2:
            if (tile1 instanceof TileEntityAirLockController) {
              TileEntityAirLockController launchController = (TileEntityAirLockController) tile1;
              launchController.playerDistanceSelection = (Integer) this.data.get(4);
            }
            break;
          case 3:
            if (tile1 instanceof TileEntityAirLockController) {
              TileEntityAirLockController launchController = (TileEntityAirLockController) tile1;
              launchController.playerNameMatches = (Integer) this.data.get(4) == 1;
            }
            break;
          case 4:
            if (tile1 instanceof TileEntityAirLockController) {
              TileEntityAirLockController launchController = (TileEntityAirLockController) tile1;
              launchController.invertSelection = (Integer) this.data.get(4) == 1;
            }
            break;
          case 5:
            if (tile1 instanceof TileEntityAirLockController) {
              TileEntityAirLockController launchController = (TileEntityAirLockController) tile1;
              launchController.lastHorizontalModeEnabled = launchController.horizontalModeEnabled;
              launchController.horizontalModeEnabled = (Integer) this.data.get(4) == 1;
            }
            break;
          case 6:
            if (tile1 instanceof IBubbleProvider) {
              IBubbleProvider distributor = (IBubbleProvider) tile1;
              distributor.setBubbleVisible((Integer) this.data.get(4) == 1);
            }
            break;
          default:
            break;
        }
        break;
      case S_ON_ADVANCED_GUI_CLICKED_STRING:
        TileEntity tile2 =
            player.worldObj.getTileEntity(
                (Integer) this.data.get(1), (Integer) this.data.get(2), (Integer) this.data.get(3));

        switch ((Integer) this.data.get(0)) {
          case 0:
            if (tile2 instanceof TileEntityAirLockController) {
              TileEntityAirLockController launchController = (TileEntityAirLockController) tile2;
              launchController.playerToOpenFor = (String) this.data.get(4);
            }
            break;
          default:
            break;
        }
        break;
      case S_UPDATE_SHIP_MOTION_Y:
        int entityID = (Integer) this.data.get(0);
        boolean up = (Boolean) this.data.get(1);

        Entity entity2 = player.worldObj.getEntityByID(entityID);

        if (entity2 instanceof EntityAutoRocket) {
          EntityAutoRocket autoRocket = (EntityAutoRocket) entity2;
          autoRocket.motionY += up ? 0.02F : -0.02F;
        }

        break;
      case S_START_NEW_SPACE_RACE:
        Integer teamID = (Integer) this.data.get(0);
        String teamName = (String) this.data.get(1);
        FlagData flagData = (FlagData) this.data.get(2);
        Vector3 teamColor = (Vector3) this.data.get(3);
        List<String> playerList = new ArrayList<String>();

        for (int i = 4; i < this.data.size(); i++) {
          playerList.add((String) this.data.get(i));
        }

        boolean previousData = SpaceRaceManager.getSpaceRaceFromID(teamID) != null;

        SpaceRace newRace = new SpaceRace(playerList, teamName, flagData, teamColor);

        if (teamID > 0) {
          newRace.setSpaceRaceID(teamID);
        }

        SpaceRaceManager.addSpaceRace(newRace);

        if (previousData) {
          SpaceRaceManager.sendSpaceRaceData(
              null, SpaceRaceManager.getSpaceRaceFromPlayer(playerBase.getGameProfile().getName()));
        }
        break;
      case S_REQUEST_FLAG_DATA:
        SpaceRaceManager.sendSpaceRaceData(
            playerBase, SpaceRaceManager.getSpaceRaceFromPlayer((String) this.data.get(0)));
        break;
      case S_INVITE_RACE_PLAYER:
        GCEntityPlayerMP playerInvited =
            PlayerUtil.getPlayerBaseServerFromPlayerUsername((String) this.data.get(0), true);
        if (playerInvited != null) {
          Integer teamInvitedTo = (Integer) this.data.get(1);
          SpaceRace race = SpaceRaceManager.getSpaceRaceFromID(teamInvitedTo);

          if (race != null) {
            playerInvited.getPlayerStats().spaceRaceInviteTeamID = teamInvitedTo;
            String dA = EnumColor.DARK_AQUA.code;
            String bG = EnumColor.BRIGHT_GREEN.code;
            String dB = EnumColor.PURPLE.code;
            String teamNameTotal = "";
            String[] teamNameSplit = race.getTeamName().split(" ");
            for (String teamNamePart : teamNameSplit) {
              teamNameTotal = teamNameTotal.concat(dB + teamNamePart + " ");
            }
            playerInvited.addChatMessage(
                new ChatComponentText(
                        "Received Space Race Team Invite from "
                            + bG
                            + player.getGameProfile().getName()
                            + dA
                            + ". To join "
                            + teamNameTotal
                            + dA
                            + "use command "
                            + EnumColor.AQUA
                            + "/joinrace")
                    .setChatStyle(new ChatStyle().setColor(EnumChatFormatting.DARK_AQUA)));
          }
        }
        break;
      case S_REMOVE_RACE_PLAYER:
        Integer teamInvitedTo = (Integer) this.data.get(1);
        SpaceRace race = SpaceRaceManager.getSpaceRaceFromID(teamInvitedTo);

        if (race != null) {
          String playerToRemove = (String) this.data.get(0);

          if (!race.getPlayerNames().remove(playerToRemove)) {
            player.addChatMessage(
                new ChatComponentText("Could not find player with name: " + playerToRemove));
          } else {
            SpaceRaceManager.onPlayerRemoval(playerToRemove, race);
          }
        }
        break;
      case S_ADD_RACE_PLAYER:
        Integer teamToAddPlayer = (Integer) this.data.get(1);
        SpaceRace spaceRaceToAddPlayer = SpaceRaceManager.getSpaceRaceFromID(teamToAddPlayer);

        if (spaceRaceToAddPlayer != null) {
          String playerToAdd = (String) this.data.get(0);

          if (!spaceRaceToAddPlayer.getPlayerNames().contains(playerToAdd)) {
            SpaceRace oldRace = null;
            while ((oldRace = SpaceRaceManager.getSpaceRaceFromPlayer(playerToAdd)) != null) {
              SpaceRaceManager.removeSpaceRace(oldRace);
            }

            spaceRaceToAddPlayer.getPlayerNames().add(playerToAdd);
            SpaceRaceManager.sendSpaceRaceData(null, spaceRaceToAddPlayer);

            for (String member : spaceRaceToAddPlayer.getPlayerNames()) {
              EntityPlayerMP memberObj =
                  MinecraftServer.getServer()
                      .getConfigurationManager()
                      .getPlayerForUsername(member);

              if (memberObj != null) {
                memberObj.addChatMessage(
                    new ChatComponentText(
                            EnumColor.BRIGHT_GREEN
                                + playerToAdd
                                + EnumColor.DARK_AQUA
                                + " has joined the Space Race!")
                        .setChatStyle(new ChatStyle().setColor(EnumChatFormatting.DARK_AQUA)));
              }
            }
          } else {
            player.addChatMessage(
                new ChatComponentText("You are already a part of this space race!")
                    .setChatStyle(new ChatStyle().setColor(EnumChatFormatting.DARK_RED)));
          }
        }
        break;
      default:
        break;
    }
  }
  // patch method
  @Overwrite
  public void processVanilla250Packet(C17PacketCustomPayload p_147349_1_) {
    PacketBuffer packetbuffer;
    ItemStack itemstack;
    ItemStack itemstack1;

    if ("MC|BEdit".equals(p_147349_1_.func_149559_c())) {
      packetbuffer = new PacketBuffer(Unpooled.wrappedBuffer(p_147349_1_.func_149558_e()));

      try {
        itemstack = packetbuffer.readItemStackFromBuffer();

        if (itemstack == null) {
          return;
        }

        if (!ItemWritableBook.func_150930_a(itemstack.getTagCompound())) {
          throw new IOException("Invalid book tag!");
        }

        itemstack1 = playerEntity.inventory.getCurrentItem();

        if (itemstack1 != null) {
          if (itemstack.getItem() == Items.writable_book
              && itemstack.getItem() == itemstack1.getItem()) {
            itemstack1.setTagInfo("pages", itemstack.getTagCompound().getTagList("pages", 8));
          }

          return;
        }
      } catch (Exception exception4) {
        logger.error("Couldn\'t handle book info", exception4);
        return;
      } finally {
        packetbuffer.release();
      }

      return;
    } else if ("MC|BSign".equals(p_147349_1_.func_149559_c())) {
      packetbuffer = new PacketBuffer(Unpooled.wrappedBuffer(p_147349_1_.func_149558_e()));

      try {
        itemstack = packetbuffer.readItemStackFromBuffer();

        if (itemstack != null) {
          if (!ItemEditableBook.validBookTagContents(itemstack.getTagCompound())) {
            throw new IOException("Invalid book tag!");
          }

          itemstack1 = playerEntity.inventory.getCurrentItem();

          if (itemstack1 == null) {
            return;
          }

          if (itemstack.getItem() == Items.written_book
              && itemstack1.getItem() == Items.writable_book) {
            itemstack1.setTagInfo("author", new NBTTagString(playerEntity.getCommandSenderName()));
            itemstack1.setTagInfo(
                "title", new NBTTagString(itemstack.getTagCompound().getString("title")));
            itemstack1.setTagInfo("pages", itemstack.getTagCompound().getTagList("pages", 8));
            itemstack1.func_150996_a(Items.written_book);
          }

          return;
        }
      } catch (Exception exception3) {
        logger.error("Couldn\'t sign book", exception3);
        return;
      } finally {
        packetbuffer.release();
      }

      return;
    } else {
      DataInputStream datainputstream;
      int i;

      if ("MC|TrSel".equals(p_147349_1_.func_149559_c())) {
        try {
          datainputstream =
              new DataInputStream(new ByteArrayInputStream(p_147349_1_.func_149558_e()));
          i = datainputstream.readInt();
          Container container = playerEntity.openContainer;

          if (container instanceof ContainerMerchant) {
            ((ContainerMerchant) container).setCurrentRecipeIndex(i);
          }
        } catch (Exception exception2) {
          logger.error("Couldn\'t select trade", exception2);
        }
      } else if ("MC|AdvCdm".equals(p_147349_1_.func_149559_c())) {
        if (!serverController.isCommandBlockEnabled()) {
          playerEntity.addChatMessage(
              new ChatComponentTranslation("advMode.notEnabled", new Object[0]));
        } else if (PermissionManager.checkPermission(playerEntity, "mc.cmdblocks")
            && playerEntity.capabilities.isCreativeMode) {
          packetbuffer = new PacketBuffer(Unpooled.wrappedBuffer(p_147349_1_.func_149558_e()));

          try {
            byte b0 = packetbuffer.readByte();
            CommandBlockLogic commandblocklogic = null;

            if (b0 == 0) {
              TileEntity tileentity =
                  playerEntity.worldObj.getTileEntity(
                      packetbuffer.readInt(), packetbuffer.readInt(), packetbuffer.readInt());

              if (tileentity instanceof TileEntityCommandBlock) {
                commandblocklogic = ((TileEntityCommandBlock) tileentity).func_145993_a();
              }
            } else if (b0 == 1) {
              Entity entity = playerEntity.worldObj.getEntityByID(packetbuffer.readInt());

              if (entity instanceof EntityMinecartCommandBlock) {
                commandblocklogic = ((EntityMinecartCommandBlock) entity).func_145822_e();
              }
            }

            String s1 = packetbuffer.readStringFromBuffer(packetbuffer.readableBytes());

            if (commandblocklogic != null) {
              commandblocklogic.func_145752_a(s1);
              commandblocklogic.func_145756_e();
              playerEntity.addChatMessage(
                  new ChatComponentTranslation("advMode.setCommand.success", new Object[] {s1}));
            }
          } catch (Exception exception1) {
            logger.error("Couldn\'t set command block", exception1);
          } finally {
            packetbuffer.release();
          }
        } else {
          playerEntity.addChatMessage(
              new ChatComponentTranslation("advMode.notAllowed", new Object[0]));
        }
      } else if ("MC|Beacon".equals(p_147349_1_.func_149559_c())) {
        if (playerEntity.openContainer instanceof ContainerBeacon) {
          try {
            datainputstream =
                new DataInputStream(new ByteArrayInputStream(p_147349_1_.func_149558_e()));
            i = datainputstream.readInt();
            int j = datainputstream.readInt();
            ContainerBeacon containerbeacon = (ContainerBeacon) playerEntity.openContainer;
            Slot slot = containerbeacon.getSlot(0);

            if (slot.getHasStack()) {
              slot.decrStackSize(1);
              TileEntityBeacon tileentitybeacon = containerbeacon.func_148327_e();
              tileentitybeacon.setPrimaryEffect(i);
              tileentitybeacon.setSecondaryEffect(j);
              tileentitybeacon.markDirty();
            }
          } catch (Exception exception) {
            logger.error("Couldn\'t set beacon", exception);
          }
        }
      } else if ("MC|ItemName".equals(p_147349_1_.func_149559_c())
          && playerEntity.openContainer instanceof ContainerRepair) {
        ContainerRepair containerrepair = (ContainerRepair) playerEntity.openContainer;

        if (p_147349_1_.func_149558_e() != null && p_147349_1_.func_149558_e().length >= 1) {
          String s =
              ChatAllowedCharacters.filerAllowedCharacters(
                  new String(p_147349_1_.func_149558_e(), Charsets.UTF_8));

          if (s.length() <= 30) {
            containerrepair.updateItemName(s);
          }
        } else {
          containerrepair.updateItemName("");
        }
      }
    }
  }
Exemplo n.º 12
0
  @SubscribeEvent
  public void onServerPacket(ServerCustomPacketEvent event) {

    if (!event.packet.channel().equals(Telepads.channelName)) return;

    EntityPlayerMP p = ((NetHandlerPlayServer) event.handler).playerEntity;
    ByteBufInputStream dis = new ByteBufInputStream(event.packet.payload());
    ByteBuf buf = event.packet.payload();

    World world = p.worldObj;

    int x = (int) p.posX;
    int y = (int) p.posY;
    int z = (int) p.posZ;

    try {

      int packetID = dis.readInt();

      int x2 = dis.readInt();
      int y2 = dis.readInt();
      int z2 = dis.readInt();

      TETelepad pad = (TETelepad) p.worldObj.getTileEntity(x2, y2, z2);

      switch (packetID) {
        case IDENTIFIER_GUI:
          int id = dis.readInt();
          p.openGui(Telepads.instance, id, world, x2, y2, z2);
          break;

        case IDENTIFIER_NAMEPAD:
          String name = dis.readUTF();
          String channel = dis.readUTF();

          pad.telepadname = name;
          pad.TELEPORTCHANNEL = channel;

          TelepadWorldData.get(world).addPad(pad);
          pad.markDirty();
          TelepadWorldData.get(world).markDirty();

          ByteBuf buff = Unpooled.buffer();
          ByteBufOutputStream out = new ByteBufOutputStream(buff);
          try {

            out.writeInt(ServerPacketHandler.IDENTIFIER_NAMEPAD);
            out.writeInt(x2);
            out.writeInt(y2);
            out.writeInt(z2);
            out.writeUTF(name);
            out.writeUTF(channel);
            out.close();

            if (!p.worldObj.isRemote)
              Telepads.Channel.sendTo(new FMLProxyPacket(buf, Telepads.channelName), p);

          } catch (IOException e) {
            e.printStackTrace();
          }
          break;

        case IDENTIFIER_TELEPORTER:
          if (dis.readInt() == GuiTeleport.EXIT_BUTTON) {
            pad.resetTE();
            pad.getDescriptionPacket();
            break;
          } else {
            // reset pad BEFORE the player gets teleported, or else it might be out of range and
            // can't be reset
            pad.resetTE();
            pad.getDescriptionPacket();

            int otherPadX = dis.readInt();
            int otherPadY = dis.readInt();
            int otherPadZ = dis.readInt();

            int dimID = dis.readInt();

            // if the dimension id = the End, play endscreen and teleport to spawn point.
            // this is needed or game will act funny if you don't.
            if (dimID != p.worldObj.provider.dimensionId) {
              if (p.worldObj.provider.dimensionId == 1) {
                p.travelToDimension(1);
              } else {
                p.travelToDimension(dimID);
                p.setPositionAndUpdate(otherPadX + 2, otherPadY + 0.5d, otherPadZ);
              }

            } else {
              p.setPositionAndUpdate(otherPadX + 2, otherPadY + 0.5d, otherPadZ);
            }
          }

          break;

        case IDENTIFIER_PLATFORM:
          boolean b = dis.readBoolean();

          pad.isStandingOnPlatform = b;

          if (b == false) {
            pad.resetTE();
            pad.playerStandingOnPad = null;
          }

          break;

        case IDENTIFIER_RESETnNOTIFY:
          p.addChatMessage(new ChatComponentText(dis.readUTF()));
          pad.resetTE();
          break;
      }

      dis.close();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }