@Override
  public IMessage onMessage(MessageTelePipeUpdate message, MessageContext ctx) {
    TileEntity te =
        ctx.getServerHandler().playerEntity.worldObj.getTileEntity(message.x, message.y, message.z);
    if (te instanceof TileGenericPipe) {
      PipeTeleport<?> pipe = (PipeTeleport<?>) ((TileGenericPipe) te).pipe;
      // only allow the owner to change pipe state
      EntityPlayerMP entityPlayer = (EntityPlayerMP) ctx.getServerHandler().playerEntity;
      if (!PipeTeleport.canPlayerModifyPipe(entityPlayer, pipe)) {
        entityPlayer.addChatComponentMessage(
            new ChatComponentText("Sorry, You may not change pipe state."));
        return null;
      }
      int frequency = message._freq;
      if (frequency < 0) {
        frequency = 0;
      }
      pipe.setFrequency(frequency);
      pipe.state = (byte) message._state;
      pipe.isPublic = message._isPublic;
    }

    return null;
  }
Ejemplo n.º 2
0
 private void handleTelePipeData(Player player, DataInputStream data) {
   try {
     TileEntity te = getTileEntity(player, data);
     if (te instanceof TileGenericPipe) {
       PipeTeleport pipe = (PipeTeleport) ((TileGenericPipe) te).pipe;
       // only allow the owner to change pipe state
       EntityPlayerMP entityPlayer = (EntityPlayerMP) player;
       if (!PipeTeleport.canPlayerModifyPipe(entityPlayer, pipe)) {
         entityPlayer.sendChatToPlayer(
             ChatMessageComponent.createFromText("You may not change pipe state."));
         return;
       }
       int frequency = data.readInt();
       if (frequency < 0) {
         frequency = 0;
       }
       pipe.setFrequency(frequency);
       pipe.state = (byte) data.read();
       pipe.isPublic = (data.read() == 1);
     }
   } catch (IOException e) {
     AdditionalPipes.instance.logger.log(Level.SEVERE, "Error handling teleport pipe packet.", e);
   }
 }